clif.cpp 595 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136
  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:
  234. #if PACKETVER >= 20170726
  235. return 0x6; //NPC_EVT_TYPE
  236. #else
  237. return (pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6);
  238. #endif
  239. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  240. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  241. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  242. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  243. default: return 0x1; //NPC_TYPE
  244. }
  245. }
  246. #endif
  247. static bool clif_session_isValid(struct map_session_data *sd) {
  248. return ( sd != NULL && session_isActive(sd->fd) );
  249. }
  250. /*==========================================
  251. * sub process of clif_send
  252. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  253. * In order to send area-wise packets, such as:
  254. * - AREA : everyone nearby your area
  255. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  256. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  257. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  258. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  259. *------------------------------------------*/
  260. static int clif_send_sub(struct block_list *bl, va_list ap)
  261. {
  262. struct block_list *src_bl;
  263. struct map_session_data *sd;
  264. unsigned char *buf;
  265. int len, type, fd;
  266. nullpo_ret(bl);
  267. nullpo_ret(sd = (struct map_session_data *)bl);
  268. fd = sd->fd;
  269. if (!fd) //Don't send to disconnected clients.
  270. return 0;
  271. buf = va_arg(ap,unsigned char*);
  272. len = va_arg(ap,int);
  273. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  274. type = va_arg(ap,int);
  275. switch(type) {
  276. case AREA_WOS:
  277. if (bl == src_bl)
  278. return 0;
  279. break;
  280. case AREA_WOC:
  281. if (sd->chatID || bl == src_bl)
  282. return 0;
  283. break;
  284. case AREA_WOSC:
  285. {
  286. if(src_bl->type == BL_PC) {
  287. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  288. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  289. return 0;
  290. }
  291. else if(src_bl->type == BL_NPC) {
  292. struct npc_data *nd = (struct npc_data *)src_bl;
  293. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  294. return 0;
  295. }
  296. }
  297. break;
  298. }
  299. if (session[fd] == NULL)
  300. return 0;
  301. /* unless visible, hold it here */
  302. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  303. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  304. return 0;
  305. WFIFOHEAD(fd, len);
  306. if (WFIFOP(fd,0) == buf) {
  307. ShowError("WARNING: Invalid use of clif_send function\n");
  308. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  309. ShowError(" Please correct your code.\n");
  310. // don't send to not move the pointer of the packet for next sessions in the loop
  311. //WFIFOSET(fd,0);//## TODO is this ok?
  312. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  313. return 0;
  314. }
  315. memcpy(WFIFOP(fd,0), buf, len);
  316. WFIFOSET(fd,len);
  317. return 0;
  318. }
  319. /*==========================================
  320. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  321. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  322. *------------------------------------------*/
  323. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  324. {
  325. int i;
  326. struct map_session_data *sd, *tsd;
  327. struct party_data *p = NULL;
  328. struct guild *g = NULL;
  329. struct battleground_data *bg = NULL;
  330. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  331. struct s_mapiterator* iter;
  332. if( type != ALL_CLIENT )
  333. nullpo_ret(bl);
  334. sd = BL_CAST(BL_PC, bl);
  335. switch(type) {
  336. case ALL_CLIENT: //All player clients.
  337. iter = mapit_getallusers();
  338. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ){
  339. WFIFOHEAD(tsd->fd, len);
  340. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  341. WFIFOSET(tsd->fd, len);
  342. }
  343. mapit_free(iter);
  344. break;
  345. case ALL_SAMEMAP: //All players on the same map
  346. iter = mapit_getallusers();
  347. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  348. {
  349. if( bl->m == tsd->bl.m ){
  350. WFIFOHEAD(tsd->fd, len);
  351. memcpy(WFIFOP(tsd->fd,0), buf, len);
  352. WFIFOSET(tsd->fd,len);
  353. }
  354. }
  355. mapit_free(iter);
  356. break;
  357. case AREA:
  358. case AREA_WOSC:
  359. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  360. clif_send (buf, len, bl, SELF);
  361. case AREA_WOC:
  362. case AREA_WOS:
  363. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  364. BL_PC, buf, len, bl, type);
  365. break;
  366. case AREA_CHAT_WOC:
  367. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  368. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  369. break;
  370. case CHAT:
  371. case CHAT_WOS:
  372. {
  373. struct chat_data *cd;
  374. if (sd) {
  375. cd = (struct chat_data*)map_id2bl(sd->chatID);
  376. } else if (bl->type == BL_CHAT) {
  377. cd = (struct chat_data*)bl;
  378. } else break;
  379. if (cd == NULL)
  380. break;
  381. for(i = 0; i < cd->users; i++) {
  382. if (type == CHAT_WOS && cd->usersd[i] == sd)
  383. continue;
  384. if ((fd=cd->usersd[i]->fd) >0 && session[fd]){ // Added check to see if session exists [PoW]
  385. WFIFOHEAD(fd,len);
  386. memcpy(WFIFOP(fd,0), buf, len);
  387. WFIFOSET(fd,len);
  388. }
  389. }
  390. }
  391. break;
  392. case PARTY_AREA:
  393. case PARTY_AREA_WOS:
  394. x0 = bl->x - AREA_SIZE;
  395. y0 = bl->y - AREA_SIZE;
  396. x1 = bl->x + AREA_SIZE;
  397. y1 = bl->y + AREA_SIZE;
  398. case PARTY:
  399. case PARTY_WOS:
  400. case PARTY_SAMEMAP:
  401. case PARTY_SAMEMAP_WOS:
  402. if (sd && sd->status.party_id)
  403. p = party_search(sd->status.party_id);
  404. if (p) {
  405. for(i=0;i<MAX_PARTY;i++){
  406. if( (sd = p->data[i].sd) == NULL )
  407. continue;
  408. if( !(fd=sd->fd) )
  409. continue;
  410. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  411. continue;
  412. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  413. continue;
  414. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  415. continue;
  416. WFIFOHEAD(fd, len);
  417. memcpy(WFIFOP(fd, 0), buf, len);
  418. WFIFOSET(fd, len);
  419. }
  420. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  421. break;
  422. iter = mapit_getallusers();
  423. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  424. {
  425. if( tsd->partyspy == p->party.party_id ){
  426. WFIFOHEAD(tsd->fd, len);
  427. memcpy(WFIFOP(tsd->fd,0), buf, len);
  428. WFIFOSET(tsd->fd,len);
  429. }
  430. }
  431. mapit_free(iter);
  432. }
  433. break;
  434. case DUEL:
  435. case DUEL_WOS:
  436. if (!sd || !sd->duel_group) break; //Invalid usage.
  437. iter = mapit_getallusers();
  438. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  439. {
  440. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  441. continue;
  442. if( sd->duel_group == tsd->duel_group ){
  443. WFIFOHEAD(tsd->fd, len);
  444. memcpy(WFIFOP(tsd->fd,0), buf, len);
  445. WFIFOSET(tsd->fd,len);
  446. }
  447. }
  448. mapit_free(iter);
  449. break;
  450. case SELF:
  451. if (sd && (fd=sd->fd)) {
  452. WFIFOHEAD(fd,len);
  453. memcpy(WFIFOP(fd,0), buf, len);
  454. WFIFOSET(fd,len);
  455. }
  456. break;
  457. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  458. case GUILD_AREA:
  459. case GUILD_AREA_WOS:
  460. x0 = bl->x - AREA_SIZE;
  461. y0 = bl->y - AREA_SIZE;
  462. x1 = bl->x + AREA_SIZE;
  463. y1 = bl->y + AREA_SIZE;
  464. case GUILD_SAMEMAP:
  465. case GUILD_SAMEMAP_WOS:
  466. case GUILD:
  467. case GUILD_WOS:
  468. case GUILD_NOBG:
  469. if (sd && sd->status.guild_id)
  470. g = sd->guild;
  471. if (g) {
  472. for(i = 0; i < g->max_member; i++) {
  473. if( (sd = g->member[i].sd) != NULL )
  474. {
  475. if( !(fd=sd->fd) )
  476. continue;
  477. if( type == GUILD_NOBG && sd->bg_id )
  478. continue;
  479. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  480. continue;
  481. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  482. continue;
  483. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  484. continue;
  485. WFIFOHEAD(fd,len);
  486. memcpy(WFIFOP(fd,0), buf, len);
  487. WFIFOSET(fd,len);
  488. }
  489. }
  490. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  491. break;
  492. iter = mapit_getallusers();
  493. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  494. {
  495. if( tsd->guildspy == g->guild_id ){
  496. WFIFOHEAD(tsd->fd, len);
  497. memcpy(WFIFOP(tsd->fd,0), buf, len);
  498. WFIFOSET(tsd->fd,len);
  499. }
  500. }
  501. mapit_free(iter);
  502. }
  503. break;
  504. case BG_AREA:
  505. case BG_AREA_WOS:
  506. x0 = bl->x - AREA_SIZE;
  507. y0 = bl->y - AREA_SIZE;
  508. x1 = bl->x + AREA_SIZE;
  509. y1 = bl->y + AREA_SIZE;
  510. case BG_SAMEMAP:
  511. case BG_SAMEMAP_WOS:
  512. case BG:
  513. case BG_WOS:
  514. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  515. {
  516. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  517. {
  518. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  519. continue;
  520. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  521. continue;
  522. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  523. continue;
  524. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  525. continue;
  526. WFIFOHEAD(fd,len);
  527. memcpy(WFIFOP(fd,0), buf, len);
  528. WFIFOSET(fd,len);
  529. }
  530. }
  531. break;
  532. case CLAN:
  533. if( sd && sd->clan ){
  534. struct clan* clan = sd->clan;
  535. for( i = 0; i < clan->max_member; i++ ){
  536. if( ( sd = clan->members[i] ) == NULL || !(fd = sd->fd) ){
  537. continue;
  538. }
  539. WFIFOHEAD(fd,len);
  540. memcpy(WFIFOP(fd,0), buf, len);
  541. WFIFOSET(fd,len);
  542. }
  543. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  544. break;
  545. iter = mapit_getallusers();
  546. while ((tsd = (TBL_PC*)mapit_next(iter)) != NULL){
  547. if (tsd->clanspy == clan->id){
  548. WFIFOHEAD(tsd->fd, len);
  549. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  550. WFIFOSET(tsd->fd, len);
  551. }
  552. }
  553. mapit_free(iter);
  554. }
  555. break;
  556. default:
  557. ShowError("clif_send: Unrecognized type %d\n",type);
  558. return -1;
  559. }
  560. return 0;
  561. }
  562. /// Notifies the client, that it's connection attempt was accepted.
  563. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  564. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  565. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  566. void clif_authok(struct map_session_data *sd)
  567. {
  568. #if PACKETVER < 20080102
  569. const int cmd = 0x73;
  570. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  571. const int cmd = 0x2eb;
  572. #else
  573. const int cmd = 0xa18;
  574. #endif
  575. int fd = sd->fd;
  576. WFIFOHEAD(fd,packet_len(cmd));
  577. WFIFOW(fd, 0) = cmd;
  578. WFIFOL(fd, 2) = client_tick(gettick());
  579. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  580. WFIFOB(fd, 9) = 5; // ignored
  581. WFIFOB(fd,10) = 5; // ignored
  582. #if PACKETVER >= 20080102
  583. WFIFOW(fd,11) = sd->status.font;
  584. #endif
  585. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  586. WFIFOB(fd,13) = sd->status.sex;
  587. #endif
  588. WFIFOSET(fd,packet_len(cmd));
  589. }
  590. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  591. /// 0074 <error code>.B
  592. /// error code:
  593. /// 0 = client type mismatch
  594. /// 1 = ID mismatch
  595. /// 2 = mobile - out of available time
  596. /// 3 = mobile - already logged in
  597. /// 4 = mobile - waiting state
  598. void clif_authrefuse(int fd, uint8 error_code)
  599. {
  600. WFIFOHEAD(fd,packet_len(0x74));
  601. WFIFOW(fd,0) = 0x74;
  602. WFIFOB(fd,2) = error_code;
  603. WFIFOSET(fd,packet_len(0x74));
  604. }
  605. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  606. /// 0081 <error code>.B
  607. /// error code:
  608. /// 0 = BAN_UNFAIR
  609. /// 1 = server closed -> MsgStringTable[4]
  610. /// 2 = ID already logged in -> MsgStringTable[5]
  611. /// 3 = timeout/too much lag -> MsgStringTable[241]
  612. /// 4 = server full -> MsgStringTable[264]
  613. /// 5 = underaged -> MsgStringTable[305]
  614. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  615. /// 9 = too many connections from this ip -> MsgStringTable[529]
  616. /// 10 = out of available time paid for -> MsgStringTable[530]
  617. /// 11 = BAN_PAY_SUSPEND
  618. /// 12 = BAN_PAY_CHANGE
  619. /// 13 = BAN_PAY_WRONGIP
  620. /// 14 = BAN_PAY_PNGAMEROOM
  621. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  622. /// 16 = BAN_JAPAN_REFUSE1
  623. /// 17 = BAN_JAPAN_REFUSE2
  624. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  625. /// 100 = BAN_PC_IP_UNFAIR
  626. /// 101 = BAN_PC_IP_COUNT_ALL
  627. /// 102 = BAN_PC_IP_COUNT
  628. /// 103 = BAN_GRAVITY_MEM_AGREE
  629. /// 104 = BAN_GAME_MEM_AGREE
  630. /// 105 = BAN_HAN_VALID
  631. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  632. /// 107 = BAN_OVER_CHARACTER_LIST
  633. /// 108 = BAN_IP_BLOCK
  634. /// 109 = BAN_INVALID_PWD_CNT
  635. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  636. /// ? = disconnected -> MsgStringTable[3]
  637. void clif_authfail_fd(int fd, int type)
  638. {
  639. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  640. return;
  641. WFIFOHEAD(fd, packet_len(0x81));
  642. WFIFOW(fd,0) = 0x81;
  643. WFIFOB(fd,2) = type;
  644. WFIFOSET(fd,packet_len(0x81));
  645. set_eof(fd);
  646. }
  647. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  648. /// 00b3 <type>.B
  649. /// type:
  650. /// 1 = disconnect, char-select
  651. /// ? = nothing
  652. void clif_charselectok(int id, uint8 ok)
  653. {
  654. struct map_session_data* sd;
  655. int fd;
  656. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  657. return;
  658. fd = sd->fd;
  659. WFIFOHEAD(fd,packet_len(0xb3));
  660. WFIFOW(fd,0) = 0xb3;
  661. WFIFOB(fd,2) = ok;
  662. WFIFOSET(fd,packet_len(0xb3));
  663. }
  664. /// Makes an item appear on the ground.
  665. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  666. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  667. /// 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)
  668. void clif_dropflooritem(struct flooritem_data* fitem, bool canShowEffect)
  669. {
  670. #if PACKETVER >= 20180418
  671. uint8 buf[22];
  672. uint32 header = 0xadd;
  673. #elif PACKETVER >= 20130000
  674. uint8 buf[19];
  675. uint32 header=0x84b;
  676. #else
  677. uint8 buf[17];
  678. uint32 header=0x09e;
  679. #endif
  680. int view, offset=0;
  681. nullpo_retv(fitem);
  682. if (fitem->item.nameid == 0)
  683. return;
  684. WBUFW(buf, offset+0) = header;
  685. WBUFL(buf, offset+2) = fitem->bl.id;
  686. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item.nameid)) > 0) ? view : fitem->item.nameid;
  687. #if PACKETVER >= 20130000
  688. WBUFW(buf, offset+8) = itemtype(fitem->item.nameid);
  689. offset +=2;
  690. #endif
  691. WBUFB(buf, offset+8) = fitem->item.identify;
  692. WBUFW(buf, offset+9) = fitem->bl.x;
  693. WBUFW(buf, offset+11) = fitem->bl.y;
  694. WBUFB(buf, offset+13) = fitem->subx;
  695. WBUFB(buf, offset+14) = fitem->suby;
  696. WBUFW(buf, offset+15) = fitem->item.amount;
  697. #if PACKETVER >= 20180418
  698. if( canShowEffect ){
  699. uint8 dropEffect = itemdb_dropeffect(fitem->item.nameid);
  700. if( dropEffect > 0 ){
  701. WBUFB(buf, offset+17) = 1;
  702. WBUFW(buf, offset+18) = dropEffect - 1;
  703. }else{
  704. WBUFB(buf, offset+17) = 0;
  705. WBUFW(buf, offset+18) = 0;
  706. }
  707. }else{
  708. WBUFB(buf, offset+17) = 0;
  709. WBUFW(buf, offset+18) = 0;
  710. }
  711. #endif
  712. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  713. }
  714. /// Makes an item disappear from the ground.
  715. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  716. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  717. {
  718. unsigned char buf[16];
  719. nullpo_retv(fitem);
  720. WBUFW(buf,0) = 0xa1;
  721. WBUFL(buf,2) = fitem->bl.id;
  722. if (fd == 0) {
  723. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  724. } else {
  725. WFIFOHEAD(fd,packet_len(0xa1));
  726. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  727. WFIFOSET(fd,packet_len(0xa1));
  728. }
  729. }
  730. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  731. /// 0080 <id>.L <type>.B
  732. /// type:
  733. /// 0 = out of sight
  734. /// 1 = died
  735. /// 2 = logged out
  736. /// 3 = teleport
  737. /// 4 = trickdead
  738. void clif_clearunit_single(int id, clr_type type, int fd)
  739. {
  740. WFIFOHEAD(fd, packet_len(0x80));
  741. WFIFOW(fd,0) = 0x80;
  742. WFIFOL(fd,2) = id;
  743. WFIFOB(fd,6) = type;
  744. WFIFOSET(fd, packet_len(0x80));
  745. }
  746. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  747. /// 0080 <id>.L <type>.B
  748. /// type:
  749. /// 0 = out of sight
  750. /// 1 = died
  751. /// 2 = logged out
  752. /// 3 = teleport
  753. /// 4 = trickdead
  754. void clif_clearunit_area(struct block_list* bl, clr_type type)
  755. {
  756. unsigned char buf[8];
  757. nullpo_retv(bl);
  758. WBUFW(buf,0) = 0x80;
  759. WBUFL(buf,2) = bl->id;
  760. WBUFB(buf,6) = type;
  761. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  762. if(disguised(bl)) {
  763. WBUFL(buf,2) = -bl->id;
  764. clif_send(buf, packet_len(0x80), bl, SELF);
  765. }
  766. }
  767. /// Used to make monsters with player-sprites disappear after dying
  768. /// like normal monsters, because the client does not remove those
  769. /// automatically.
  770. static TIMER_FUNC(clif_clearunit_delayed_sub){
  771. struct block_list *bl = (struct block_list *)data;
  772. clif_clearunit_area(bl, (clr_type) id);
  773. ers_free(delay_clearunit_ers,bl);
  774. return 0;
  775. }
  776. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  777. {
  778. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  779. memcpy (tbl, bl, sizeof (struct block_list));
  780. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  781. }
  782. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  783. {
  784. if(sd->sc.option&OPTION_COSTUME)
  785. {
  786. *rhand = *lhand = 0;
  787. return;
  788. }
  789. #if PACKETVER < 4
  790. *rhand = sd->status.weapon;
  791. *lhand = sd->status.shield;
  792. #else
  793. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  794. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  795. {
  796. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  797. if (id->view_id > 0)
  798. *rhand = id->view_id;
  799. else
  800. *rhand = id->nameid;
  801. } else
  802. *rhand = 0;
  803. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  804. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  805. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  806. {
  807. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  808. if (id->view_id > 0)
  809. *lhand = id->view_id;
  810. else
  811. *lhand = id->nameid;
  812. } else
  813. *lhand = 0;
  814. #endif
  815. }
  816. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  817. static int clif_setlevel_sub(int lv) {
  818. if( lv < battle_config.max_lv ) {
  819. ;
  820. } else if( lv < battle_config.aura_lv ) {
  821. lv = battle_config.max_lv - 1;
  822. } else {
  823. lv = battle_config.max_lv;
  824. }
  825. return lv;
  826. }
  827. static int clif_setlevel(struct block_list* bl) {
  828. int lv = status_get_lv(bl);
  829. if( battle_config.client_limit_unit_lv&bl->type )
  830. return clif_setlevel_sub(lv);
  831. switch( bl->type ) {
  832. case BL_NPC:
  833. case BL_PET:
  834. // npcs and pets do not have level
  835. return 0;
  836. }
  837. return lv;
  838. }
  839. /*==========================================
  840. * Prepares 'unit standing/spawning' packet
  841. *------------------------------------------*/
  842. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  843. {
  844. struct map_session_data* sd;
  845. struct status_change* sc = status_get_sc(bl);
  846. struct view_data* vd = status_get_viewdata(bl);
  847. unsigned char *buf = WBUFP(buffer, 0);
  848. #if PACKETVER < 20091103
  849. bool type = !pcdb_checkid(vd->class_);
  850. #endif
  851. unsigned short offset = 0;
  852. #if PACKETVER >= 20091103
  853. const char *name;
  854. #endif
  855. sd = BL_CAST(BL_PC, bl);
  856. #if PACKETVER < 20091103
  857. if(type)
  858. WBUFW(buf,0) = spawn ? 0x7c : 0x78;
  859. else
  860. #endif
  861. #if PACKETVER < 4
  862. WBUFW(buf,0) = spawn ? 0x79 : 0x78;
  863. #elif PACKETVER < 7
  864. WBUFW(buf,0) = spawn ? 0x1d9 : 0x1d8;
  865. #elif PACKETVER < 20080102
  866. WBUFW(buf,0) = spawn ? 0x22b : 0x22a;
  867. #elif PACKETVER < 20091103
  868. WBUFW(buf,0) = spawn ? 0x2ed : 0x2ee;
  869. #elif PACKETVER < 20101124
  870. WBUFW(buf,0) = spawn ? 0x7f8 : 0x7f9;
  871. #elif PACKETVER < 20120221
  872. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  873. #elif PACKETVER < 20131223
  874. WBUFW(buf,0) = spawn ? 0x90f : 0x915;
  875. #elif PACKETVER < 20150513
  876. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  877. #else
  878. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  879. #endif
  880. #if PACKETVER >= 20091103
  881. name = status_get_name(bl);
  882. #if PACKETVER < 20110111
  883. WBUFW(buf,2) = (uint16)((spawn ? 62 : 63)+strlen(name));
  884. #elif PACKETVER < 20120221
  885. WBUFW(buf,2) = (uint16)((spawn ? 64 : 65)+strlen(name));
  886. #elif PACKETVER < 20130807
  887. WBUFW(buf,2) = (uint16)((spawn ? 77 : 78)+strlen(name));
  888. #else
  889. WBUFW(buf,2) = (uint16)((spawn ? 79 : 80)+strlen(name));
  890. #endif
  891. WBUFB(buf,4) = clif_bl_type(bl);
  892. offset+=3;
  893. buf = WBUFP(buffer,offset);
  894. #elif PACKETVER >= 20071106
  895. if (type) { //Non-player packets
  896. WBUFB(buf,2) = clif_bl_type(bl);
  897. offset++;
  898. buf = WBUFP(buffer,offset);
  899. }
  900. #endif
  901. WBUFL(buf, 2) = bl->id;
  902. #if PACKETVER >= 20131223
  903. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  904. offset+=4;
  905. buf = WBUFP(buffer,offset);
  906. #endif
  907. WBUFW(buf, 6) = status_get_speed(bl);
  908. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  909. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  910. #if PACKETVER < 20091103
  911. if (type&&spawn) { //uses an older and different packet structure
  912. WBUFW(buf,12) = (sc)? sc->option : 0;
  913. WBUFW(buf,14) = vd->hair_style;
  914. WBUFW(buf,16) = vd->weapon;
  915. WBUFW(buf,18) = vd->head_bottom;
  916. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  917. WBUFW(buf,22) = vd->shield;
  918. } else {
  919. #endif
  920. #if PACKETVER >= 20091103
  921. WBUFL(buf,12) = (sc)? sc->option : 0;
  922. offset+=2;
  923. buf = WBUFP(buffer,offset);
  924. #elif PACKETVER >= 7
  925. if (!type) {
  926. WBUFL(buf,12) = (sc)? sc->option : 0;
  927. offset+=2;
  928. buf = WBUFP(buffer,offset);
  929. } else
  930. WBUFW(buf,12) = (sc)? sc->option : 0;
  931. #else
  932. WBUFW(buf,12) = (sc)? sc->option : 0;
  933. #endif
  934. WBUFW(buf,14) = vd->class_;
  935. WBUFW(buf,16) = vd->hair_style;
  936. WBUFW(buf,18) = vd->weapon;
  937. #if PACKETVER < 4
  938. WBUFW(buf,20) = vd->head_bottom;
  939. WBUFW(buf,22) = vd->shield;
  940. #else
  941. WBUFW(buf,20) = vd->shield;
  942. WBUFW(buf,22) = vd->head_bottom;
  943. #endif
  944. #if PACKETVER < 20091103
  945. }
  946. #endif
  947. WBUFW(buf,24) = vd->head_top;
  948. WBUFW(buf,26) = vd->head_mid;
  949. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG )
  950. { //The hell, why flags work like this?
  951. WBUFW(buf,22) = status_get_emblem_id(bl);
  952. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  953. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  954. }
  955. WBUFW(buf,28) = vd->hair_color;
  956. WBUFW(buf,30) = vd->cloth_color;
  957. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  958. #if PACKETVER < 20091103
  959. if (type&&spawn) { //End of packet 0x7c
  960. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  961. WBUFB(buf,35) = vd->sex;
  962. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  963. WBUFB(buf,39) = 0;
  964. WBUFB(buf,40) = 0;
  965. return packet_len(0x7c);
  966. }
  967. #endif
  968. #if PACKETVER >= 20110111
  969. WBUFW(buf,34) = vd->robe;
  970. offset+= 2;
  971. buf = WBUFP(buffer,offset);
  972. #endif
  973. WBUFL(buf,34) = status_get_guild_id(bl);
  974. WBUFW(buf,38) = status_get_emblem_id(bl);
  975. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  976. #if PACKETVER >= 20091103
  977. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  978. offset+=2;
  979. buf = WBUFP(buffer,offset);
  980. #elif PACKETVER >= 7
  981. if (!type) {
  982. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  983. offset+=2;
  984. buf = WBUFP(buffer,offset);
  985. } else
  986. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  987. #else
  988. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  989. #endif
  990. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  991. WBUFB(buf,45) = vd->sex;
  992. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  993. WBUFB(buf,49) = (sd)? 5 : 0;
  994. WBUFB(buf,50) = (sd)? 5 : 0;
  995. if (!spawn) {
  996. WBUFB(buf,51) = vd->dead_sit;
  997. offset++;
  998. buf = WBUFP(buffer,offset);
  999. }
  1000. WBUFW(buf,51) = clif_setlevel(bl);
  1001. #if PACKETVER < 20091103
  1002. if (type) //End for non-player packet
  1003. return packet_len(WBUFW(buffer,0));
  1004. #endif
  1005. #if PACKETVER >= 20080102
  1006. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  1007. #endif
  1008. #if PACKETVER >= 20120221
  1009. if ( battle_config.monster_hp_bars_info && bl->type == BL_MOB && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR) && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  1010. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  1011. WBUFL(buf,59) = status_get_hp(bl); // HP
  1012. } else {
  1013. WBUFL(buf,55) = -1; // maxHP
  1014. WBUFL(buf,59) = -1; // HP
  1015. }
  1016. WBUFB(buf,63) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1017. #endif
  1018. #if PACKETVER >= 20150513
  1019. WBUFW(buf,64) = vd->body_style; // body
  1020. offset+= 2;
  1021. buf = WBUFP(buffer,offset);
  1022. #endif
  1023. #if PACKETVER >= 20091103
  1024. #if PACKETVER >= 20120221
  1025. safestrncpy(WBUFCP(buf,64), name, NAME_LENGTH);
  1026. #else
  1027. safestrncpy(WBUFCP(buf,55), name, NAME_LENGTH);
  1028. #endif
  1029. return WBUFW(buffer,2);
  1030. #else
  1031. return packet_len(WBUFW(buffer,0));
  1032. #endif
  1033. }
  1034. /*==========================================
  1035. * Prepares 'unit walking' packet
  1036. *------------------------------------------*/
  1037. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1038. {
  1039. struct map_session_data* sd;
  1040. struct status_change* sc = status_get_sc(bl);
  1041. struct view_data* vd = status_get_viewdata(bl);
  1042. unsigned char* buf = WBUFP(buffer,0);
  1043. #if PACKETVER >= 7
  1044. unsigned short offset = 0;
  1045. #endif
  1046. #if PACKETVER >= 20091103
  1047. const char *name;
  1048. #endif
  1049. sd = BL_CAST(BL_PC, bl);
  1050. #if PACKETVER < 4
  1051. WBUFW(buf, 0) = 0x7b;
  1052. #elif PACKETVER < 7
  1053. WBUFW(buf, 0) = 0x1da;
  1054. #elif PACKETVER < 20080102
  1055. WBUFW(buf, 0) = 0x22c;
  1056. #elif PACKETVER < 20091103
  1057. WBUFW(buf, 0) = 0x2ec;
  1058. #elif PACKETVER < 20101124
  1059. WBUFW(buf, 0) = 0x7f7;
  1060. #elif PACKETVER < 20120221
  1061. WBUFW(buf, 0) = 0x856;
  1062. #elif PACKETVER < 20131223
  1063. WBUFW(buf, 0) = 0x914;
  1064. #elif PACKETVER < 20150513
  1065. WBUFW(buf, 0) = 0x9db;
  1066. #else
  1067. WBUFW(buf, 0) = 0x9fd;
  1068. #endif
  1069. #if PACKETVER >= 20091103
  1070. name = status_get_name(bl);
  1071. #if PACKETVER < 20110111
  1072. WBUFW(buf, 2) = (uint16)(69+strlen(name));
  1073. #elif PACKETVER < 20120221
  1074. WBUFW(buf, 2) = (uint16)(71+strlen(name));
  1075. #elif PACKETVER < 20130807
  1076. WBUFW(buf, 2) = (uint16)(84+strlen(name));
  1077. #else
  1078. WBUFW(buf, 2) = (uint16)(86+strlen(name));
  1079. #endif
  1080. offset+=2;
  1081. buf = WBUFP(buffer,offset);
  1082. #endif
  1083. #if PACKETVER >= 20071106
  1084. WBUFB(buf, 2) = clif_bl_type(bl);
  1085. offset++;
  1086. buf = WBUFP(buffer,offset);
  1087. #endif
  1088. WBUFL(buf, 2) = bl->id;
  1089. #if PACKETVER >= 20131223
  1090. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  1091. offset+=4;
  1092. buf = WBUFP(buffer,offset);
  1093. #endif
  1094. WBUFW(buf, 6) = status_get_speed(bl);
  1095. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1096. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1097. #if PACKETVER < 7
  1098. WBUFW(buf,12) = (sc)? sc->option : 0;
  1099. #else
  1100. WBUFL(buf,12) = (sc)? sc->option : 0;
  1101. offset+=2; //Shift the rest of elements by 2 bytes.
  1102. buf = WBUFP(buffer,offset);
  1103. #endif
  1104. WBUFW(buf,14) = vd->class_;
  1105. WBUFW(buf,16) = vd->hair_style;
  1106. WBUFW(buf,18) = vd->weapon;
  1107. #if PACKETVER < 4
  1108. WBUFW(buf,20) = vd->head_bottom;
  1109. WBUFL(buf,22) = client_tick(gettick());
  1110. WBUFW(buf,26) = vd->shield;
  1111. #else
  1112. WBUFW(buf,20) = vd->shield;
  1113. WBUFW(buf,22) = vd->head_bottom;
  1114. WBUFL(buf,24) = client_tick(gettick());
  1115. #endif
  1116. WBUFW(buf,28) = vd->head_top;
  1117. WBUFW(buf,30) = vd->head_mid;
  1118. WBUFW(buf,32) = vd->hair_color;
  1119. WBUFW(buf,34) = vd->cloth_color;
  1120. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1121. #if PACKETVER >= 20110111
  1122. WBUFW(buf,38) = vd->robe;
  1123. offset+= 2;
  1124. buf = WBUFP(buffer,offset);
  1125. #endif
  1126. WBUFL(buf,38) = status_get_guild_id(bl);
  1127. WBUFW(buf,42) = status_get_emblem_id(bl);
  1128. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1129. #if PACKETVER < 7
  1130. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1131. #else
  1132. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1133. offset+=2; //Shift the rest of elements by 2 bytes.
  1134. buf = WBUFP(buffer,offset);
  1135. #endif
  1136. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1137. WBUFB(buf,49) = vd->sex;
  1138. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1139. WBUFB(buf,56) = (sd)? 5 : 0;
  1140. WBUFB(buf,57) = (sd)? 5 : 0;
  1141. WBUFW(buf,58) = clif_setlevel(bl);
  1142. #if PACKETVER >= 20080102
  1143. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1144. #endif
  1145. #if PACKETVER >= 20120221
  1146. 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)) ) {
  1147. WBUFL(buf,62) = status_get_max_hp(bl); // maxHP
  1148. WBUFL(buf,66) = status_get_hp(bl); // HP
  1149. } else {
  1150. WBUFL(buf,62) = -1; // maxHP
  1151. WBUFL(buf,66) = -1; // HP
  1152. }
  1153. WBUFB(buf,70) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1154. #endif
  1155. #if PACKETVER >= 20150513
  1156. WBUFW(buf,71) = vd->body_style; // body
  1157. offset+= 2;
  1158. buf = WBUFP(buffer,offset);
  1159. #endif
  1160. #if PACKETVER >= 20091103
  1161. #if PACKETVER >= 20120221
  1162. safestrncpy(WBUFCP(buf,71), name, NAME_LENGTH);
  1163. #else
  1164. safestrncpy(WBUFCP(buf,62), name, NAME_LENGTH);
  1165. #endif
  1166. return WBUFW(buffer,2);
  1167. #else
  1168. return packet_len(WBUFW(buffer,0));
  1169. #endif
  1170. }
  1171. //Modifies the buffer for disguise characters and sends it to self.
  1172. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1173. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1174. {
  1175. #if PACKETVER >= 20091103
  1176. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1177. WBUFL(buf,5)=-bl->id;
  1178. #elif PACKETVER >= 20071106
  1179. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1180. WBUFL(buf,3)=-bl->id;
  1181. #else
  1182. WBUFL(buf,2)=-bl->id;
  1183. #endif
  1184. clif_send(buf, len, bl, SELF);
  1185. }
  1186. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1187. /// 01b0 <id>.L <type>.B <value>.L
  1188. /// type:
  1189. /// unused
  1190. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1191. {
  1192. nullpo_retv(bl);
  1193. if(!pcdb_checkid(class_))
  1194. {// player classes yield missing sprites
  1195. unsigned char buf[16];
  1196. WBUFW(buf,0)=0x1b0;
  1197. WBUFL(buf,2)=bl->id;
  1198. WBUFB(buf,6)=type;
  1199. WBUFL(buf,7)=class_;
  1200. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1201. }
  1202. }
  1203. /// Notifies the client of an object's spirits.
  1204. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1205. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1206. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1207. {
  1208. WFIFOHEAD(fd, packet_len(0x1e1));
  1209. WFIFOW(fd,0)=0x1e1;
  1210. WFIFOL(fd,2)=sd->bl.id;
  1211. WFIFOW(fd,6)=sd->spiritball;
  1212. WFIFOSET(fd, packet_len(0x1e1));
  1213. }
  1214. /*==========================================
  1215. * Kagerou/Oboro amulet spirit
  1216. *------------------------------------------*/
  1217. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1218. {
  1219. WFIFOHEAD(fd, packet_len(0x08cf));
  1220. WFIFOW(fd,0)=0x08cf;
  1221. WFIFOL(fd,2)=sd->bl.id;
  1222. WFIFOW(fd,6)=sd->spiritcharm_type;
  1223. WFIFOW(fd,8)=sd->spiritcharm;
  1224. WFIFOSET(fd, packet_len(0x08cf));
  1225. }
  1226. /*==========================================
  1227. * Run when player changes map / refreshes
  1228. * Tells its client to display all weather settings being used by this map
  1229. *------------------------------------------*/
  1230. static void clif_weather_check(struct map_session_data *sd)
  1231. {
  1232. int16 m = sd->bl.m;
  1233. int fd = sd->fd;
  1234. if (map_getmapflag(m, MF_SNOW)
  1235. || map_getmapflag(m, MF_CLOUDS)
  1236. || map_getmapflag(m, MF_FOG)
  1237. || map_getmapflag(m, MF_FIREWORKS)
  1238. || map_getmapflag(m, MF_SAKURA)
  1239. || map_getmapflag(m, MF_LEAVES)
  1240. || map_getmapflag(m, MF_CLOUDS2))
  1241. {
  1242. if (map_getmapflag(m, MF_SNOW))
  1243. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1244. if (map_getmapflag(m, MF_CLOUDS))
  1245. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1246. if (map_getmapflag(m, MF_CLOUDS2))
  1247. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1248. if (map_getmapflag(m, MF_FOG))
  1249. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1250. if (map_getmapflag(m, MF_FIREWORKS)) {
  1251. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1252. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1253. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1254. }
  1255. if (map_getmapflag(m, MF_SAKURA))
  1256. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1257. if (map_getmapflag(m, MF_LEAVES))
  1258. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1259. }
  1260. }
  1261. /**
  1262. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1263. **/
  1264. void clif_weather(int16 m)
  1265. {
  1266. struct s_mapiterator* iter;
  1267. struct map_session_data *sd=NULL;
  1268. iter = mapit_getallusers();
  1269. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1270. {
  1271. if( sd->bl.m == m )
  1272. clif_weather_check(sd);
  1273. }
  1274. mapit_free(iter);
  1275. }
  1276. /**
  1277. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1278. **/
  1279. int clif_spawn(struct block_list *bl)
  1280. {
  1281. unsigned char buf[128];
  1282. struct view_data *vd;
  1283. int len;
  1284. vd = status_get_viewdata(bl);
  1285. if( !vd || vd->class_ == JT_INVISIBLE )
  1286. return 0;
  1287. /**
  1288. * Hide NPC from maya purple card.
  1289. **/
  1290. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1291. return 0;
  1292. len = clif_set_unit_idle(bl, buf, (bl->type == BL_NPC && vd->dead_sit ? false : true));
  1293. clif_send(buf, len, bl, AREA_WOS);
  1294. if (disguised(bl))
  1295. clif_setdisguise(bl, buf, len);
  1296. if (vd->cloth_color)
  1297. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1298. if (vd->body_style)
  1299. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1300. switch (bl->type)
  1301. {
  1302. case BL_PC:
  1303. {
  1304. TBL_PC *sd = ((TBL_PC*)bl);
  1305. if (sd->spiritball > 0)
  1306. clif_spiritball(&sd->bl);
  1307. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1308. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1309. else if(sd->state.size==SZ_MEDIUM)
  1310. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1311. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1312. clif_sendbgemblem_area(sd);
  1313. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1314. clif_spiritcharm(sd);
  1315. if (sd->status.robe)
  1316. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1317. clif_efst_status_change_sub(bl, bl, AREA);
  1318. clif_hat_effects(sd,bl,AREA);
  1319. }
  1320. break;
  1321. case BL_MOB:
  1322. {
  1323. TBL_MOB *md = ((TBL_MOB*)bl);
  1324. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1325. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1326. else if(md->special_state.size==SZ_MEDIUM)
  1327. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1328. }
  1329. break;
  1330. case BL_NPC:
  1331. {
  1332. TBL_NPC *nd = ((TBL_NPC*)bl);
  1333. if( nd->size == SZ_BIG )
  1334. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1335. else if( nd->size == SZ_MEDIUM )
  1336. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1337. clif_efst_status_change_sub(bl, bl, AREA);
  1338. clif_progressbar_npc_area(nd);
  1339. }
  1340. break;
  1341. case BL_PET:
  1342. if (vd->head_bottom)
  1343. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1344. break;
  1345. }
  1346. return 0;
  1347. }
  1348. /// Sends information about owned homunculus to the client . [orn]
  1349. /// 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)
  1350. /// 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)
  1351. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1352. {
  1353. struct status_data *status;
  1354. unsigned char buf[128];
  1355. int offset;
  1356. #if PACKETVER < 20141016
  1357. const int cmd = 0x22e;
  1358. #else
  1359. const int cmd = 0x9f7;
  1360. #endif
  1361. int htype;
  1362. nullpo_retv(hd);
  1363. if (!clif_session_isValid(sd))
  1364. return;
  1365. status = &hd->battle_status;
  1366. htype = hom_class2type(hd->homunculus.class_);
  1367. memset(buf,0,packet_len(cmd));
  1368. WBUFW(buf,0) = cmd;
  1369. safestrncpy(WBUFCP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1370. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1371. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1372. WBUFW(buf,27) = hd->homunculus.level;
  1373. WBUFW(buf,29) = hd->homunculus.hunger;
  1374. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1375. WBUFW(buf,33) = 0; // equip id
  1376. WBUFW(buf,35) = cap_value(status->rhw.atk2 + status->batk, 0, INT16_MAX);
  1377. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1378. WBUFW(buf,39)=status->hit;
  1379. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1380. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1381. else
  1382. WBUFW(buf,41) = status->cri/10;
  1383. #ifdef RENEWAL
  1384. WBUFW(buf,43) = status->def + status->def2;
  1385. WBUFW(buf,45) = status->mdef + status->mdef2;
  1386. #else
  1387. WBUFW(buf,43) = status->def + status->vit;
  1388. WBUFW(buf,45) = status->mdef;
  1389. #endif
  1390. WBUFW(buf,47) = status->flee;
  1391. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1392. #if PACKETVER >= 20141016
  1393. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1394. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1395. if (status->max_hp > (INT32_MAX/100)) {
  1396. WBUFL(buf,51) = status->hp/(status->max_hp/100);
  1397. WBUFL(buf,55) = 100;
  1398. } else {
  1399. WBUFL(buf,51) = status->hp;
  1400. WBUFL(buf,55) = status->max_hp;
  1401. }
  1402. offset = 4;
  1403. #else
  1404. if (status->max_hp > INT16_MAX) {
  1405. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1406. WBUFW(buf,53) = 100;
  1407. } else {
  1408. WBUFW(buf,51) = status->hp;
  1409. WBUFW(buf,53) = status->max_hp;
  1410. }
  1411. offset = 0;
  1412. #endif
  1413. if (status->max_sp > INT16_MAX) {
  1414. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1415. WBUFW(buf,57+offset) = 100;
  1416. } else {
  1417. WBUFW(buf,55+offset) = status->sp;
  1418. WBUFW(buf,57+offset) = status->max_sp;
  1419. }
  1420. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1421. WBUFL(buf,63+offset) = hd->exp_next;
  1422. switch( htype ) {
  1423. case HT_REG:
  1424. case HT_EVO:
  1425. if( hd->homunculus.level >= battle_config.hom_max_level )
  1426. WBUFL(buf,63+offset) = 0;
  1427. break;
  1428. case HT_S:
  1429. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1430. WBUFL(buf,63+offset) = 0;
  1431. break;
  1432. }
  1433. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1434. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1435. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1436. }
  1437. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1438. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1439. /// type:
  1440. /// unused
  1441. /// state:
  1442. /// 0 = pre-init
  1443. /// 1 = intimacy
  1444. /// 2 = hunger
  1445. /// 3 = accessory?
  1446. /// ? = ignored
  1447. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1448. { //[orn]
  1449. int fd = sd->fd;
  1450. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1451. hom_calc_skilltree(sd->hd, 0);
  1452. WFIFOHEAD(fd, packet_len(0x230));
  1453. WFIFOW(fd,0)=0x230;
  1454. WFIFOB(fd,2)=0;
  1455. WFIFOB(fd,3)=state;
  1456. WFIFOL(fd,4)=sd->hd->bl.id;
  1457. WFIFOL(fd,8)=param;
  1458. WFIFOSET(fd,packet_len(0x230));
  1459. }
  1460. int clif_homskillinfoblock(struct map_session_data *sd)
  1461. { //[orn]
  1462. struct homun_data *hd;
  1463. int fd = sd->fd;
  1464. int i, len=4;
  1465. nullpo_ret(sd);
  1466. hd = sd->hd;
  1467. if ( !hd )
  1468. return 0 ;
  1469. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1470. WFIFOW(fd,0)=0x235;
  1471. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1472. int id = hd->homunculus.hskill[i].id;
  1473. if( id != 0 ){
  1474. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1475. short idx = hom_skill_get_index(id);
  1476. if (idx == -1)
  1477. continue;
  1478. WFIFOW(fd,len ) = id;
  1479. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1480. WFIFOW(fd,len+4) = 0;
  1481. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1482. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1483. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1484. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1485. 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;
  1486. len+=37;
  1487. }
  1488. }
  1489. WFIFOW(fd,2)=len;
  1490. WFIFOSET(fd,len);
  1491. return 0;
  1492. }
  1493. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1494. { //[orn]
  1495. struct homun_data *hd;
  1496. int fd;
  1497. short idx = -1;
  1498. nullpo_retv(sd);
  1499. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1500. return;
  1501. fd = sd->fd;
  1502. hd = sd->hd;
  1503. WFIFOHEAD(fd, packet_len(0x239));
  1504. WFIFOW(fd,0) = 0x239;
  1505. WFIFOW(fd,2) = skill_id;
  1506. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1507. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1508. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1509. 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;
  1510. WFIFOSET(fd,packet_len(0x239));
  1511. }
  1512. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1513. {
  1514. int fd=sd->fd;
  1515. WFIFOHEAD(fd,packet_len(0x22f));
  1516. WFIFOW(fd,0)=0x22f;
  1517. WFIFOB(fd,2)=fail;
  1518. WFIFOW(fd,3)=foodid;
  1519. WFIFOSET(fd,packet_len(0x22f));
  1520. return 0;
  1521. }
  1522. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1523. /// 0087 <walk start time>.L <walk data>.6B
  1524. void clif_walkok(struct map_session_data *sd)
  1525. {
  1526. int fd=sd->fd;
  1527. WFIFOHEAD(fd, packet_len(0x87));
  1528. WFIFOW(fd,0)=0x87;
  1529. WFIFOL(fd,2)=client_tick(gettick());
  1530. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1531. WFIFOSET(fd,packet_len(0x87));
  1532. }
  1533. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1534. {
  1535. uint8 buf[128];
  1536. int len;
  1537. struct status_change *sc = NULL;
  1538. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1539. clif_ally_only = true;
  1540. len = clif_set_unit_walking(bl,ud,buf);
  1541. clif_send(buf,len,bl,AREA_WOS);
  1542. if (disguised(bl))
  1543. clif_setdisguise(bl, buf, len);
  1544. if(vd->cloth_color)
  1545. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1546. if(vd->body_style)
  1547. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1548. switch(bl->type) {
  1549. case BL_PC:
  1550. {
  1551. TBL_PC *sd = ((TBL_PC*)bl);
  1552. // clif_movepc(sd);
  1553. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1554. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1555. else if(sd->state.size==SZ_MEDIUM)
  1556. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1557. if (sd->status.robe)
  1558. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1559. }
  1560. break;
  1561. case BL_MOB:
  1562. {
  1563. TBL_MOB *md = ((TBL_MOB*)bl);
  1564. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1565. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1566. else if(md->special_state.size==SZ_MEDIUM)
  1567. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1568. }
  1569. break;
  1570. case BL_PET:
  1571. if(vd->head_bottom) // needed to display pet equip properly
  1572. clif_pet_equip_area((TBL_PET*)bl);
  1573. break;
  1574. }
  1575. clif_ally_only = false;
  1576. }
  1577. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1578. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1579. /// Note: unit must not be self
  1580. void clif_move(struct unit_data *ud)
  1581. {
  1582. unsigned char buf[16];
  1583. struct view_data* vd;
  1584. struct block_list* bl = ud->bl;
  1585. struct status_change *sc = NULL;
  1586. vd = status_get_viewdata(bl);
  1587. if (!vd )
  1588. return;
  1589. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1590. else if( vd->class_ == JT_INVISIBLE ){
  1591. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1592. if(disguised(bl)) {
  1593. WBUFW(buf,0)=0x86;
  1594. WBUFL(buf,2)=-bl->id;
  1595. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1596. WBUFL(buf,12)=client_tick(gettick());
  1597. clif_send(buf, packet_len(0x86), bl, SELF);
  1598. }
  1599. return;
  1600. }
  1601. /**
  1602. * Hide NPC from maya purple card.
  1603. **/
  1604. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1605. return;
  1606. if (ud->state.speed_changed) {
  1607. // Since we don't know how to update the speed of other objects,
  1608. // use the old walk packet to update the data.
  1609. ud->state.speed_changed = 0;
  1610. clif_move2(bl, vd, ud);
  1611. return;
  1612. }
  1613. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1614. clif_ally_only = true;
  1615. WBUFW(buf,0)=0x86;
  1616. WBUFL(buf,2)=bl->id;
  1617. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1618. WBUFL(buf,12)=client_tick(gettick());
  1619. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1620. if (disguised(bl)) {
  1621. WBUFL(buf,2)=-bl->id;
  1622. clif_send(buf, packet_len(0x86), bl, SELF);
  1623. }
  1624. clif_ally_only = false;
  1625. }
  1626. /*==========================================
  1627. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1628. *------------------------------------------*/
  1629. static TIMER_FUNC(clif_delayquit){
  1630. struct map_session_data *sd = NULL;
  1631. //Remove player from map server
  1632. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1633. map_quit(sd);
  1634. return 0;
  1635. }
  1636. /*==========================================
  1637. *
  1638. *------------------------------------------*/
  1639. void clif_quitsave(int fd,struct map_session_data *sd) {
  1640. if (!battle_config.prevent_logout ||
  1641. sd->canlog_tick == 0 ||
  1642. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1643. map_quit(sd);
  1644. else if (sd->fd) {
  1645. //Disassociate session from player (session is deleted after this function was called)
  1646. //And set a timer to make him quit later.
  1647. session[sd->fd]->session_data = NULL;
  1648. sd->fd = 0;
  1649. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1650. }
  1651. }
  1652. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1653. /// 0091 <map name>.16B <x>.W <y>.W
  1654. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1655. {
  1656. int fd;
  1657. nullpo_retv(sd);
  1658. fd = sd->fd;
  1659. WFIFOHEAD(fd,packet_len(0x91));
  1660. WFIFOW(fd,0) = 0x91;
  1661. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1662. WFIFOW(fd,18) = x;
  1663. WFIFOW(fd,20) = y;
  1664. WFIFOSET(fd,packet_len(0x91));
  1665. }
  1666. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1667. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1668. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1669. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1670. {
  1671. int fd;
  1672. #if PACKETVER >= 20170315
  1673. int cmd = 0xac7;
  1674. #else
  1675. int cmd = 0x92;
  1676. #endif
  1677. nullpo_retv(sd);
  1678. fd = sd->fd;
  1679. WFIFOHEAD(fd,packet_len(cmd));
  1680. WFIFOW(fd,0) = cmd;
  1681. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1682. WFIFOW(fd,18) = x;
  1683. WFIFOW(fd,20) = y;
  1684. WFIFOL(fd,22) = htonl(ip);
  1685. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1686. #if PACKETVER >= 20170315
  1687. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1688. #endif
  1689. WFIFOSET(fd,packet_len(cmd));
  1690. }
  1691. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1692. /// This function combines both calls and allows to simplify the calling code
  1693. void clif_blown(struct block_list *bl)
  1694. {
  1695. clif_slide(bl, bl->x, bl->y);
  1696. clif_fixpos(bl);
  1697. }
  1698. /// Visually moves(slides) a character to x,y. If the target cell
  1699. /// isn't walkable, the char doesn't move at all. If the char is
  1700. /// sitting it will stand up (ZC_STOPMOVE).
  1701. /// 0088 <id>.L <x>.W <y>.W
  1702. void clif_fixpos(struct block_list *bl)
  1703. {
  1704. unsigned char buf[10];
  1705. nullpo_retv(bl);
  1706. WBUFW(buf,0) = 0x88;
  1707. WBUFL(buf,2) = bl->id;
  1708. WBUFW(buf,6) = bl->x;
  1709. WBUFW(buf,8) = bl->y;
  1710. clif_send(buf, packet_len(0x88), bl, AREA);
  1711. if( disguised(bl) ) {
  1712. WBUFL(buf,2) = -bl->id;
  1713. clif_send(buf, packet_len(0x88), bl, SELF);
  1714. }
  1715. }
  1716. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1717. /// 00c4 <shop id>.L
  1718. void clif_npcbuysell(struct map_session_data* sd, int id)
  1719. {
  1720. int fd;
  1721. nullpo_retv(sd);
  1722. fd=sd->fd;
  1723. WFIFOHEAD(fd, packet_len(0xc4));
  1724. WFIFOW(fd,0)=0xc4;
  1725. WFIFOL(fd,2)=id;
  1726. WFIFOSET(fd,packet_len(0xc4));
  1727. }
  1728. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1729. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1730. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1731. {
  1732. int fd,i,c;
  1733. bool discount;
  1734. nullpo_retv(sd);
  1735. nullpo_retv(nd);
  1736. fd = sd->fd;
  1737. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1738. WFIFOW(fd,0) = 0xc6;
  1739. c = 0;
  1740. discount = npc_shop_discount(nd);
  1741. for( i = 0; i < nd->u.shop.count; i++ )
  1742. {
  1743. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1744. int val = nd->u.shop.shop_item[i].value;
  1745. if( id == NULL )
  1746. continue;
  1747. WFIFOL(fd, 4+c*11) = val;
  1748. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1749. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1750. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1751. c++;
  1752. }
  1753. WFIFOW(fd,2) = 4 + c*11;
  1754. WFIFOSET(fd,WFIFOW(fd,2));
  1755. }
  1756. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1757. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1758. void clif_selllist(struct map_session_data *sd)
  1759. {
  1760. int fd,i,c=0,val;
  1761. struct npc_data *nd;
  1762. nullpo_retv(sd);
  1763. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1764. return;
  1765. fd=sd->fd;
  1766. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1767. WFIFOW(fd,0)=0xc7;
  1768. for( i = 0; i < MAX_INVENTORY; i++ )
  1769. {
  1770. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1771. {
  1772. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1773. continue;
  1774. val=sd->inventory_data[i]->value_sell;
  1775. if( val < 0 )
  1776. continue;
  1777. WFIFOW(fd,4+c*10)=i+2;
  1778. WFIFOL(fd,6+c*10)=val;
  1779. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1780. c++;
  1781. }
  1782. }
  1783. WFIFOW(fd,2)=c*10+4;
  1784. WFIFOSET(fd,WFIFOW(fd,2));
  1785. }
  1786. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1787. /// 09d4
  1788. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1789. // TODO: State tracking?
  1790. sd->npc_shopid = 0;
  1791. }
  1792. /**
  1793. * Presents list of items, that can be sold to a Market shop.
  1794. * @author: Ind and Yommy
  1795. **/
  1796. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1797. #if PACKETVER >= 20131223
  1798. struct npc_item_list *shop = nd->u.shop.shop_item;
  1799. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1800. struct item_data *id = NULL;
  1801. struct s_packet_db *info;
  1802. int fd;
  1803. nullpo_retv(sd);
  1804. if (sd->state.trading)
  1805. return;
  1806. info = &packet_db[cmd];
  1807. if (!info || info->len == 0)
  1808. return;
  1809. fd = sd->fd;
  1810. WFIFOHEAD(fd, 4 + shop_size * 13);
  1811. WFIFOW(fd,0) = cmd;
  1812. for (i = 0, c = 0; i < shop_size; i++) {
  1813. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1814. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1815. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1816. WFIFOL(fd, 7+c*13) = shop[i].value;
  1817. WFIFOL(fd,11+c*13) = shop[i].qty;
  1818. WFIFOW(fd,15+c*13) = id->weight;
  1819. c++;
  1820. }
  1821. }
  1822. WFIFOW(fd,2) = 4 + c*13;
  1823. WFIFOSET(fd,WFIFOW(fd,2));
  1824. sd->state.trading = 1;
  1825. #endif
  1826. }
  1827. /// Closes the Market shop window.
  1828. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1829. nullpo_retv(sd);
  1830. sd->npc_shopid = 0;
  1831. sd->state.trading = 0;
  1832. }
  1833. /// Purchase item from Market shop.
  1834. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1835. #if PACKETVER >= 20131223
  1836. unsigned short cmd = 0x9d7, len = 0;
  1837. struct npc_data* nd;
  1838. uint8 result = (res == 0 ? 1 : 0);
  1839. int fd = 0;
  1840. struct s_packet_db *info;
  1841. nullpo_retv(sd);
  1842. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1843. info = &packet_db[cmd];
  1844. if (!info || info->len == 0)
  1845. return;
  1846. fd = sd->fd;
  1847. len = 5 + 8*n;
  1848. WFIFOHEAD(fd, len);
  1849. WFIFOW(fd, 0) = cmd;
  1850. WFIFOW(fd, 2) = len;
  1851. if (result) {
  1852. uint8 i, j;
  1853. struct npc_item_list *shop = nd->u.shop.shop_item;
  1854. unsigned short count = nd->u.shop.count;
  1855. for (i = 0; i < n; i++) {
  1856. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1857. WFIFOW(fd, 7+i*8) = list[i].qty;
  1858. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1859. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1860. }
  1861. }
  1862. WFIFOB(fd, 4) = n;
  1863. WFIFOSET(fd, len);
  1864. #endif
  1865. }
  1866. /// Purchase item from Market shop.
  1867. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1868. #if PACKETVER >= 20131223
  1869. struct s_packet_db* info;
  1870. struct s_npc_buy_list *item_list;
  1871. uint16 len = 0, i = 0;
  1872. uint8 res = 0, n = 0;
  1873. nullpo_retv(sd);
  1874. if (!sd->npc_shopid)
  1875. return;
  1876. info = &packet_db[RFIFOW(fd,0)];
  1877. if (!info || info->len == 0)
  1878. return;
  1879. len = RFIFOW(fd,info->pos[0]);
  1880. n = (len-4) / 6;
  1881. CREATE(item_list, struct s_npc_buy_list, n);
  1882. for (i = 0; i < n; i++) {
  1883. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1884. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1885. }
  1886. res = npc_buylist(sd, n, item_list);
  1887. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1888. aFree(item_list);
  1889. #endif
  1890. }
  1891. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1892. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1893. /// Client behavior (dialog window):
  1894. /// - disable mouse targeting
  1895. /// - open the dialog window
  1896. /// - set npcid of dialog window (0 by default)
  1897. /// - if set to clear on next mes, clear contents
  1898. /// - append this text
  1899. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1900. {
  1901. int fd = sd->fd;
  1902. int slen = strlen(mes) + 9;
  1903. WFIFOHEAD(fd, slen);
  1904. WFIFOW(fd,0)=0xb4;
  1905. WFIFOW(fd,2)=slen;
  1906. WFIFOL(fd,4)=npcid;
  1907. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1908. WFIFOSET(fd,WFIFOW(fd,2));
  1909. }
  1910. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1911. /// 00b5 <npc id>.L
  1912. /// Client behavior (dialog window):
  1913. /// - disable mouse targeting
  1914. /// - open the dialog window
  1915. /// - add 'next' button
  1916. /// When 'next' is pressed:
  1917. /// - 00B9 <npcid of dialog window>.L
  1918. /// - set to clear on next mes
  1919. /// - remove 'next' button
  1920. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1921. {
  1922. int fd;
  1923. nullpo_retv(sd);
  1924. fd=sd->fd;
  1925. WFIFOHEAD(fd, packet_len(0xb5));
  1926. WFIFOW(fd,0)=0xb5;
  1927. WFIFOL(fd,2)=npcid;
  1928. WFIFOSET(fd,packet_len(0xb5));
  1929. }
  1930. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1931. /// 00b6 <npc id>.L
  1932. /// Client behavior:
  1933. /// - if dialog window is open:
  1934. /// - remove 'next' button
  1935. /// - add 'close' button
  1936. /// - else:
  1937. /// - enable mouse targeting
  1938. /// - close the dialog window
  1939. /// - close the menu window
  1940. /// When 'close' is pressed:
  1941. /// - enable mouse targeting
  1942. /// - close the dialog window
  1943. /// - close the menu window
  1944. /// - 0146 <npcid of dialog window>.L
  1945. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1946. {
  1947. int fd;
  1948. nullpo_retv(sd);
  1949. fd=sd->fd;
  1950. WFIFOHEAD(fd, packet_len(0xb6));
  1951. WFIFOW(fd,0)=0xb6;
  1952. WFIFOL(fd,2)=npcid;
  1953. WFIFOSET(fd,packet_len(0xb6));
  1954. }
  1955. /**
  1956. * Close script when player is idle
  1957. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1958. * @author [Ind/Hercules]
  1959. * @param sd : player pointer
  1960. * @param npcid : npc gid to close
  1961. */
  1962. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1963. {
  1964. struct s_packet_db* info;
  1965. int16 len;
  1966. int cmd = 0;
  1967. int fd;
  1968. nullpo_retv(sd);
  1969. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  1970. if(!cmd) cmd = 0x8d6; //default
  1971. info = &packet_db[cmd];
  1972. len = info->len;
  1973. fd = sd->fd;
  1974. WFIFOHEAD(fd, len);
  1975. WFIFOW(fd,0)=0x8d6;
  1976. WFIFOL(fd,info->pos[0])=npcid;
  1977. WFIFOSET(fd,len);
  1978. }
  1979. /*==========================================
  1980. *
  1981. *------------------------------------------*/
  1982. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1983. unsigned char *buf;
  1984. int fd = sd->fd;
  1985. sd->state.using_fake_npc = 1;
  1986. WFIFOHEAD(fd, packet_len(0x78));
  1987. buf = WFIFOP(fd,0);
  1988. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1989. WBUFW(buf,0)=0x78;
  1990. #if PACKETVER >= 20071106
  1991. WBUFB(buf,2) = 0; // object type
  1992. buf = WFIFOP(fd,1);
  1993. #endif
  1994. WBUFL(buf,2)=npcid;
  1995. WBUFW(buf,14)=111;
  1996. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1997. WBUFB(buf,49)=5;
  1998. WBUFB(buf,50)=5;
  1999. WFIFOSET(fd, packet_len(0x78));
  2000. }
  2001. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2002. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2003. /// Client behavior:
  2004. /// - disable mouse targeting
  2005. /// - close the menu window
  2006. /// - open the menu window
  2007. /// - add options to the menu (separated in the text by ":")
  2008. /// - set npcid of menu window
  2009. /// - if dialog window is open:
  2010. /// - remove 'next' button
  2011. /// When 'ok' is pressed:
  2012. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2013. /// - close the menu window
  2014. /// When 'cancel' is pressed:
  2015. /// - 00B8 <npcid of menu window>.L <-1>.B
  2016. /// - enable mouse targeting
  2017. /// - close a bunch of windows...
  2018. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2019. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2020. /// TODO investigate behavior of other windows [FlavioJS]
  2021. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2022. {
  2023. int fd = sd->fd;
  2024. int slen = strlen(mes) + 9;
  2025. struct block_list *bl = NULL;
  2026. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2027. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2028. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2029. clif_sendfakenpc(sd, npcid);
  2030. WFIFOHEAD(fd, slen);
  2031. WFIFOW(fd,0)=0xb7;
  2032. WFIFOW(fd,2)=slen;
  2033. WFIFOL(fd,4)=npcid;
  2034. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2035. WFIFOSET(fd,WFIFOW(fd,2));
  2036. }
  2037. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2038. /// 0142 <npc id>.L
  2039. /// Client behavior (inputnum window):
  2040. /// - if npcid exists in the client:
  2041. /// - open the inputnum window
  2042. /// - set npcid of inputnum window
  2043. /// When 'ok' is pressed:
  2044. /// - if inputnum window has text:
  2045. /// - if npcid exists in the client:
  2046. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2047. /// - close inputnum window
  2048. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2049. {
  2050. int fd;
  2051. struct block_list *bl = NULL;
  2052. nullpo_retv(sd);
  2053. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2054. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2055. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2056. clif_sendfakenpc(sd, npcid);
  2057. fd=sd->fd;
  2058. WFIFOHEAD(fd, packet_len(0x142));
  2059. WFIFOW(fd,0)=0x142;
  2060. WFIFOL(fd,2)=npcid;
  2061. WFIFOSET(fd,packet_len(0x142));
  2062. }
  2063. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2064. /// 01d4 <npc id>.L
  2065. /// Client behavior (inputstr window):
  2066. /// - if npcid is 0 or npcid exists in the client:
  2067. /// - open the inputstr window
  2068. /// - set npcid of inputstr window
  2069. /// When 'ok' is pressed:
  2070. /// - if inputstr window has text and isn't an insult(manner.txt):
  2071. /// - if npcid is 0 or npcid exists in the client:
  2072. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2073. /// - close inputstr window
  2074. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2075. {
  2076. int fd;
  2077. struct block_list *bl = NULL;
  2078. nullpo_retv(sd);
  2079. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2080. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2081. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2082. clif_sendfakenpc(sd, npcid);
  2083. fd=sd->fd;
  2084. WFIFOHEAD(fd, packet_len(0x1d4));
  2085. WFIFOW(fd,0)=0x1d4;
  2086. WFIFOL(fd,2)=npcid;
  2087. WFIFOSET(fd,packet_len(0x1d4));
  2088. }
  2089. /// Marks a position on client's minimap (ZC_COMPASS).
  2090. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2091. /// npc id:
  2092. /// is ignored in the client
  2093. /// type:
  2094. /// 0 = display mark for 15 seconds
  2095. /// 1 = display mark until dead or teleported
  2096. /// 2 = remove mark
  2097. /// color:
  2098. /// 0x00RRGGBB
  2099. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2100. {
  2101. int fd;
  2102. nullpo_retv(sd);
  2103. fd=sd->fd;
  2104. WFIFOHEAD(fd, packet_len(0x144));
  2105. WFIFOW(fd,0)=0x144;
  2106. WFIFOL(fd,2)=npc_id;
  2107. WFIFOL(fd,6)=type;
  2108. WFIFOL(fd,10)=x;
  2109. WFIFOL(fd,14)=y;
  2110. WFIFOB(fd,18)=id;
  2111. WFIFOL(fd,19)=color;
  2112. WFIFOSET(fd,packet_len(0x144));
  2113. }
  2114. /// Displays an illustration image.
  2115. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2116. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2117. /// type:
  2118. /// 0 = bottom left corner
  2119. /// 1 = bottom middle
  2120. /// 2 = bottom right corner
  2121. /// 3 = middle of screen, inside a movable window
  2122. /// 4 = middle of screen, movable with a close button, chrome-less
  2123. /// 255 = clear all displayed cutins
  2124. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2125. {
  2126. int fd;
  2127. nullpo_retv(sd);
  2128. fd=sd->fd;
  2129. WFIFOHEAD(fd, packet_len(0x1b3));
  2130. WFIFOW(fd,0)=0x1b3;
  2131. strncpy(WFIFOCP(fd,2),image,64);
  2132. WFIFOB(fd,66)=type;
  2133. WFIFOSET(fd,packet_len(0x1b3));
  2134. }
  2135. /*==========================================
  2136. * Fills in card data from the given item and into the buffer. [Skotlex]
  2137. *------------------------------------------*/
  2138. static void clif_addcards(unsigned char* buf, struct item* item)
  2139. {
  2140. int i=0,j;
  2141. if( item == NULL ) { //Blank data
  2142. WBUFW(buf,0) = 0;
  2143. WBUFW(buf,2) = 0;
  2144. WBUFW(buf,4) = 0;
  2145. WBUFW(buf,6) = 0;
  2146. return;
  2147. }
  2148. if( item->card[0] == CARD0_PET ) { //pet eggs
  2149. WBUFW(buf,0) = 0;
  2150. WBUFW(buf,2) = 0;
  2151. WBUFW(buf,4) = 0;
  2152. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2153. return;
  2154. }
  2155. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2156. WBUFW(buf,0) = item->card[0];
  2157. WBUFW(buf,2) = item->card[1];
  2158. WBUFW(buf,4) = item->card[2];
  2159. WBUFW(buf,6) = item->card[3];
  2160. return;
  2161. }
  2162. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2163. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2164. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2165. //Normal items.
  2166. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2167. WBUFW(buf,0) = j;
  2168. else
  2169. WBUFW(buf,0) = item->card[i];
  2170. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2171. WBUFW(buf,2) = j;
  2172. else
  2173. WBUFW(buf,2) = item->card[i];
  2174. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2175. WBUFW(buf,4) = j;
  2176. else
  2177. WBUFW(buf,4) = item->card[i];
  2178. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2179. WBUFW(buf,6) = j;
  2180. else
  2181. WBUFW(buf,6) = item->card[i];
  2182. }
  2183. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2184. /// A maximum of 5 random options can be supported.
  2185. void clif_add_random_options(unsigned char* buf, struct item *it) {
  2186. #if PACKETVER >= 20150225
  2187. int i;
  2188. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  2189. WBUFW(buf, i*5 + 0) = it->option[i].id; // OptIndex
  2190. WBUFW(buf, i*5 + 2) = it->option[i].value; // Value
  2191. WBUFB(buf, i*5 + 4) = it->option[i].param; // Param1
  2192. }
  2193. #if MAX_ITEM_RDM_OPT < 5
  2194. for ( ; i < 5; i++) {
  2195. WBUFW(buf, i*5 + 0) = 0; // OptIndex
  2196. WBUFW(buf, i*5 + 2) = 0; // Value
  2197. WBUFB(buf, i*5 + 4) = 0; // Param1
  2198. }
  2199. #endif
  2200. #endif
  2201. }
  2202. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2203. /// 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)
  2204. /// 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)
  2205. /// 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)
  2206. /// 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)
  2207. /// 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)
  2208. /// 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)
  2209. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2210. {
  2211. int fd, header, offs=0;
  2212. #if PACKETVER < 20061218
  2213. header = 0xa0;
  2214. #elif PACKETVER < 20071002
  2215. header = 0x29a;
  2216. #elif PACKETVER < 20120925
  2217. header = 0x2d4;
  2218. #elif PACKETVER < 20150225
  2219. header = 0x990;
  2220. #elif PACKETVER < 20160921
  2221. header = 0xa0c;
  2222. #else
  2223. header = 0xa37;
  2224. #endif
  2225. nullpo_retv(sd);
  2226. fd = sd->fd;
  2227. if( !session_isActive(fd) ) //Sasuke-
  2228. return;
  2229. WFIFOHEAD(fd,packet_len(header));
  2230. if( fail )
  2231. {
  2232. WFIFOW(fd,offs+0) = header;
  2233. WFIFOW(fd,offs+2) = n+2;
  2234. WFIFOW(fd,offs+4) = amount;
  2235. WFIFOW(fd,offs+6) = 0;
  2236. WFIFOB(fd,offs+8) = 0;
  2237. WFIFOB(fd,offs+9) = 0;
  2238. WFIFOB(fd,offs+10) = 0;
  2239. WFIFOW(fd,offs+11) = 0;
  2240. WFIFOW(fd,offs+13) = 0;
  2241. WFIFOW(fd,offs+15) = 0;
  2242. WFIFOW(fd,offs+17) = 0;
  2243. #if PACKETVER < 20120925
  2244. WFIFOW(fd,offs+19) = 0;
  2245. #else
  2246. WFIFOL(fd,offs+19) = 0;
  2247. offs += 2;
  2248. #endif
  2249. WFIFOB(fd,offs+21) = 0;
  2250. WFIFOB(fd,offs+22) = fail;
  2251. #if PACKETVER >= 20061218
  2252. WFIFOL(fd,offs+23) = 0;
  2253. #endif
  2254. #if PACKETVER >= 20071002
  2255. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2256. #if PACKETVER >= 20150225
  2257. clif_add_random_options(WFIFOP(fd,offs+31), &sd->inventory.u.items_inventory[n]);
  2258. #if PACKETVER >= 20160921
  2259. WFIFOB(fd,offs+54) = 0; // Favorite
  2260. WFIFOW(fd,offs+55) = 0; // View ID
  2261. #endif
  2262. #endif
  2263. #endif
  2264. }
  2265. else
  2266. {
  2267. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2268. return;
  2269. WFIFOW(fd,offs+0) = header;
  2270. WFIFOW(fd,offs+2) = n+2;
  2271. WFIFOW(fd,offs+4) = amount;
  2272. if (sd->inventory_data[n]->view_id > 0)
  2273. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2274. else
  2275. WFIFOW(fd,offs+6)=sd->inventory.u.items_inventory[n].nameid;
  2276. WFIFOB(fd,offs+8)=sd->inventory.u.items_inventory[n].identify;
  2277. WFIFOB(fd,offs+9)=sd->inventory.u.items_inventory[n].attribute;
  2278. WFIFOB(fd,offs+10)=sd->inventory.u.items_inventory[n].refine;
  2279. clif_addcards(WFIFOP(fd,offs+11), &sd->inventory.u.items_inventory[n]);
  2280. #if PACKETVER < 20120925
  2281. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2282. #else
  2283. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2284. offs += 2;
  2285. #endif
  2286. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2287. WFIFOB(fd,offs+22) = fail;
  2288. #if PACKETVER >= 20061218
  2289. WFIFOL(fd,offs+23)=sd->inventory.u.items_inventory[n].expire_time;
  2290. #endif
  2291. #if PACKETVER >= 20071002
  2292. /* Yellow color only for non-stackable item */
  2293. 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;
  2294. #endif
  2295. #if PACKETVER >= 20150225
  2296. clif_add_random_options(WFIFOP(fd,31), &sd->inventory.u.items_inventory[n]);
  2297. #if PACKETVER >= 20160921
  2298. WFIFOB(fd,offs+54) = sd->inventory.u.items_inventory[n].favorite;
  2299. WFIFOW(fd,offs+55) = sd->inventory_data[n]->look;
  2300. #endif
  2301. #endif
  2302. }
  2303. WFIFOSET(fd,packet_len(header));
  2304. }
  2305. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2306. /// 00af <index>.W <amount>.W
  2307. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2308. {
  2309. int fd;
  2310. nullpo_retv(sd);
  2311. fd=sd->fd;
  2312. WFIFOHEAD(fd, packet_len(0xaf));
  2313. WFIFOW(fd,0)=0xaf;
  2314. WFIFOW(fd,2)=n+2;
  2315. WFIFOW(fd,4)=amount;
  2316. WFIFOSET(fd,packet_len(0xaf));
  2317. }
  2318. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2319. /// 07fa <delete type>.W <index>.W <amount>.W
  2320. /// delete type:
  2321. /// 0 = Normal
  2322. /// 1 = Item used for a skill
  2323. /// 2 = Refine failed
  2324. /// 3 = Material changed
  2325. /// 4 = Moved to storage
  2326. /// 5 = Moved to cart
  2327. /// 6 = Item sold
  2328. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2329. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2330. {
  2331. #if PACKETVER < 20091117
  2332. clif_dropitem(sd,n,amount);
  2333. #else
  2334. int fd;
  2335. nullpo_retv(sd);
  2336. fd=sd->fd;
  2337. WFIFOHEAD(fd, packet_len(0x7fa));
  2338. WFIFOW(fd,0)=0x7fa;
  2339. WFIFOW(fd,2)=reason;
  2340. WFIFOW(fd,4)=n+2;
  2341. WFIFOW(fd,6)=amount;
  2342. WFIFOSET(fd,packet_len(0x7fa));
  2343. #endif
  2344. }
  2345. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2346. char normal = (equip < 0);
  2347. int offset = 0;
  2348. WBUFW(buf,n) = idx; //index
  2349. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2350. WBUFB(buf,n+4) = itemtype(id->nameid);
  2351. if (!normal){ //equip 31B
  2352. WBUFL(buf,n+5) = equip; //location
  2353. WBUFL(buf,n+9) = it->equip; //wear state
  2354. WBUFB(buf,n+13) = it->refine; //refine lvl
  2355. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2356. WBUFL(buf,n+22) = it->expire_time;
  2357. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2358. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2359. #if PACKETVER >= 20150225
  2360. //V6_ITEM_Option
  2361. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2362. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2363. offset += 26;
  2364. #endif
  2365. //V5_ITEM_flag
  2366. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2367. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2368. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2369. }
  2370. else { //normal 24B
  2371. WBUFW(buf,n+5) = it->amount;
  2372. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2373. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2374. WBUFL(buf,n+19) = it->expire_time;
  2375. //V5_ITEM_flag
  2376. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2377. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2378. }
  2379. }
  2380. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2381. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2382. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2383. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2384. #if PACKETVER >= 20120925
  2385. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2386. #else
  2387. WBUFW(buf,n) = idx; //index
  2388. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2389. WBUFB(buf,n+4) = itemtype(id->nameid);
  2390. WBUFB(buf,n+5) = it->identify;
  2391. if (equip >= 0) { //Equippable item 28.B
  2392. WBUFW(buf,n+6) = equip;
  2393. WBUFW(buf,n+8) = it->equip;
  2394. WBUFB(buf,n+10) = it->attribute;
  2395. WBUFB(buf,n+11) = it->refine;
  2396. clif_addcards(WBUFP(buf, n+12), it); //8B
  2397. #if PACKETVER >= 20071002
  2398. WBUFL(buf,n+20) = it->expire_time;
  2399. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2400. #endif
  2401. #if PACKETVER >= 20100629
  2402. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2403. #endif
  2404. } else { //Stackable item. 22.B
  2405. WBUFW(buf,n+6) = it->amount;
  2406. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2407. clif_addcards(WBUFP(buf, n+10), it); //8B
  2408. #if PACKETVER >= 20071002
  2409. WBUFL(buf,n+18) = it->expire_time;
  2410. #endif
  2411. }
  2412. #endif
  2413. }
  2414. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2415. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2416. void clif_inventorylist(struct map_session_data *sd) {
  2417. int i,n,ne,arrow=-1;
  2418. unsigned char *buf;
  2419. unsigned char *bufe;
  2420. #if PACKETVER < 5
  2421. const int s = 10; //Entry size
  2422. #elif PACKETVER < 20080102
  2423. const int s = 18;
  2424. #elif PACKETVER < 20120925
  2425. const int s = 22;
  2426. #else
  2427. const int s = 24;
  2428. #endif
  2429. #if PACKETVER < 20071002
  2430. const int se = 20;
  2431. #elif PACKETVER < 20100629
  2432. const int se = 26;
  2433. #elif PACKETVER < 20120925
  2434. const int se = 28;
  2435. #elif PACKETVER < 20150225
  2436. const int se = 31;
  2437. #else
  2438. const int se = 57;
  2439. #endif
  2440. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2441. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2442. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2443. {
  2444. if( sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2445. continue;
  2446. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2447. { //Non-stackable (Equippable)
  2448. clif_item_sub(bufe, ne*se+4, i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2449. ne++;
  2450. }
  2451. else { //Stackable.
  2452. clif_item_sub(buf, n*s+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], -2);
  2453. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->inventory.u.items_inventory[i].equip )
  2454. arrow=i;
  2455. n++;
  2456. }
  2457. }
  2458. if( n )
  2459. {
  2460. #if PACKETVER < 5
  2461. WBUFW(buf,0)=0xa3;
  2462. #elif PACKETVER < 20080102
  2463. WBUFW(buf,0)=0x1ee;
  2464. #elif PACKETVER < 20120925
  2465. WBUFW(buf,0)=0x2e8;
  2466. #else
  2467. WBUFW(buf,0)=0x991;
  2468. #endif
  2469. WBUFW(buf,2)=4+n*s;
  2470. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2471. }
  2472. if( arrow >= 0 )
  2473. clif_arrowequip(sd,arrow);
  2474. if( ne ) {
  2475. #if PACKETVER < 20071002
  2476. WBUFW(bufe,0)=0xa4;
  2477. #elif PACKETVER < 20120925
  2478. WBUFW(bufe,0)=0x2d0;
  2479. #elif PACKETVER < 20150225
  2480. WBUFW(bufe,0)=0x992;
  2481. #else
  2482. WBUFW(bufe,0)=0xa0d;
  2483. #endif
  2484. WBUFW(bufe,2)=4+ne*se;
  2485. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2486. }
  2487. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2488. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2489. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2490. continue;
  2491. if ( sd->inventory.u.items_inventory[i].favorite )
  2492. clif_favorite_item(sd, i);
  2493. }
  2494. #endif
  2495. if( buf ) aFree(buf);
  2496. if( bufe ) aFree(bufe);
  2497. }
  2498. //Required when items break/get-repaired. Only sends equippable item list.
  2499. void clif_equiplist(struct map_session_data *sd)
  2500. {
  2501. int i,n,fd = sd->fd;
  2502. unsigned char *buf;
  2503. #if PACKETVER < 20071002
  2504. const int cmd = 20;
  2505. #elif PACKETVER < 20100629
  2506. const int cmd = 26;
  2507. #elif PACKETVER < 20120925
  2508. const int cmd = 28;
  2509. #elif PACKETVER < 20150225
  2510. const int cmd = 31;
  2511. #else
  2512. const int cmd = 57;
  2513. #endif
  2514. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2515. buf = WFIFOP(fd,0);
  2516. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2517. if (sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2518. continue;
  2519. if(itemdb_isstackable2(sd->inventory_data[i]))
  2520. continue;
  2521. //Equippable
  2522. clif_item_sub(buf, n*cmd+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2523. n++;
  2524. }
  2525. if (n) {
  2526. #if PACKETVER < 20071002
  2527. WBUFW(buf,0)=0xa4;
  2528. #elif PACKETVER < 20120925
  2529. WBUFW(buf,0)=0x2d0;
  2530. #elif PACKETVER < 20150225
  2531. WBUFW(buf,0)=0x992;
  2532. #else
  2533. WBUFW(buf,0)=0xa0d;
  2534. #endif
  2535. WBUFW(buf,2)=4+n*cmd;
  2536. WFIFOSET(fd,WFIFOW(fd,2));
  2537. }
  2538. }
  2539. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename)
  2540. {
  2541. static const int client_buf = 0x5000; // Max buffer to send
  2542. struct item_data *id;
  2543. int i,n,ne,nn;
  2544. unsigned char *buf;
  2545. unsigned char *bufe;
  2546. #if PACKETVER < 5
  2547. const int s = 10; //Entry size.normal item
  2548. const int sidx=4; //start itemlist idx
  2549. const int cmd = 0xa5;
  2550. #elif PACKETVER < 20080102
  2551. const int s = 18;
  2552. const int sidx=4;
  2553. const int cmd = 0x1f0;
  2554. #elif PACKETVER < 20120925
  2555. const int s = 22;
  2556. const int sidx=4;
  2557. const int cmd = 0x2ea;
  2558. #else
  2559. const int s = 24;
  2560. const int sidx = 4+24;
  2561. const int cmd = 0x995;
  2562. #endif
  2563. #if PACKETVER < 20071002
  2564. const int se = 20; //entry size equip
  2565. const int sidxe = 4; //start itemlist idx
  2566. const int cmde = 0xa6;
  2567. #elif PACKETVER < 20100629
  2568. const int se = 26;
  2569. const int sidxe = 4;
  2570. const int cmde = 0x2d1;
  2571. #elif PACKETVER < 20120925
  2572. const int se = 28;
  2573. const int sidxe = 4;
  2574. const int cmde = 0x2d1;
  2575. #elif PACKETVER < 20150225
  2576. const int se = 31;
  2577. const int sidxe = 4+24;
  2578. const int cmde = 0x996;
  2579. #else
  2580. const int se = 57;
  2581. const int sidxe = 4+24;
  2582. const int cmde = 0xa10;
  2583. #endif
  2584. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2585. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2586. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2587. {
  2588. if( items[i].nameid <= 0 )
  2589. continue;
  2590. id = itemdb_search(items[i].nameid);
  2591. if( !itemdb_isstackable2(id) ) { //Equippable
  2592. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2593. ne++;
  2594. }
  2595. else { //Stackable
  2596. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2597. n++;
  2598. }
  2599. }
  2600. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2601. {
  2602. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2603. WFIFOHEAD(sd->fd,sidx+nn*s);
  2604. WFIFOW(sd->fd,0)=cmd;
  2605. WFIFOW(sd->fd,2)=sidx+nn*s;
  2606. #if PACKETVER >= 20120925
  2607. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2608. #endif
  2609. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2610. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2611. }
  2612. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2613. {
  2614. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2615. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2616. WFIFOW(sd->fd,0)=cmde;
  2617. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2618. #if PACKETVER >= 20120925
  2619. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2620. #endif
  2621. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2622. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2623. }
  2624. // Empty storage
  2625. if (n == 0 && ne == 0) {
  2626. WFIFOHEAD(sd->fd, 4+NAME_LENGTH);
  2627. WFIFOW(sd->fd,0) = cmd;
  2628. WFIFOW(sd->fd,2) = 4+NAME_LENGTH;
  2629. #if PACKETVER >= 20120925
  2630. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2631. #endif
  2632. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2633. }
  2634. if( buf ) aFree(buf);
  2635. if( bufe ) aFree(bufe);
  2636. }
  2637. void clif_cartlist(struct map_session_data *sd)
  2638. {
  2639. struct item_data *id;
  2640. int i,n,ne;
  2641. unsigned char *buf;
  2642. unsigned char *bufe;
  2643. #if PACKETVER < 5
  2644. const int s = 10; //Entry size.
  2645. #elif PACKETVER < 20080102
  2646. const int s = 18;
  2647. #elif PACKETVER < 20120925
  2648. const int s = 22;
  2649. #else
  2650. const int s = 24;
  2651. #endif
  2652. #if PACKETVER < 20071002
  2653. const int cmd = 20;
  2654. #elif PACKETVER < 20100629
  2655. const int cmd = 26;
  2656. #elif PACKETVER < 20120925
  2657. const int cmd = 28;
  2658. #elif PACKETVER < 20150225
  2659. const int cmd = 31;
  2660. #else
  2661. const int cmd = 57;
  2662. #endif
  2663. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2664. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2665. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2666. {
  2667. if( sd->cart.u.items_cart[i].nameid <= 0 )
  2668. continue;
  2669. id = itemdb_search(sd->cart.u.items_cart[i].nameid);
  2670. if( !itemdb_isstackable2(id) ) { //Equippable
  2671. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->cart.u.items_cart[i], id, id->equip);
  2672. ne++;
  2673. }
  2674. else { //Stackable
  2675. clif_item_sub(buf, n*s+4,i+2, &sd->cart.u.items_cart[i], id,-1);
  2676. n++;
  2677. }
  2678. }
  2679. if( n )
  2680. {
  2681. #if PACKETVER < 5
  2682. WBUFW(buf,0)=0x123;
  2683. #elif PACKETVER < 20080102
  2684. WBUFW(buf,0)=0x1ef;
  2685. #elif PACKETVER < 20120925
  2686. WBUFW(buf,0)=0x2e9;
  2687. #else
  2688. WBUFW(buf,0)=0x993;
  2689. #endif
  2690. WBUFW(buf,2)=4+n*s;
  2691. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2692. }
  2693. if( ne )
  2694. {
  2695. #if PACKETVER < 20071002
  2696. WBUFW(bufe,0)=0x122;
  2697. #elif PACKETVER < 20120925
  2698. WBUFW(bufe,0)=0x2d2;
  2699. #elif PACKETVER < 20150225
  2700. WBUFW(bufe,0)=0x994;
  2701. #else
  2702. WBUFW(bufe,0)=0xa0f;
  2703. #endif
  2704. WBUFW(bufe,2)=4+ne*cmd;
  2705. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2706. }
  2707. if( buf ) aFree(buf);
  2708. if( bufe ) aFree(bufe);
  2709. }
  2710. /// Removes cart (ZC_CARTOFF).
  2711. /// 012b
  2712. /// Client behaviour:
  2713. /// Closes the cart storage and removes all it's items from memory.
  2714. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2715. void clif_clearcart(int fd)
  2716. {
  2717. WFIFOHEAD(fd, packet_len(0x12b));
  2718. WFIFOW(fd,0) = 0x12b;
  2719. WFIFOSET(fd, packet_len(0x12b));
  2720. }
  2721. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2722. /// 01eb <account id>.L <x>.W <y>.W
  2723. void clif_guild_xy(struct map_session_data *sd)
  2724. {
  2725. unsigned char buf[10];
  2726. nullpo_retv(sd);
  2727. WBUFW(buf,0)=0x1eb;
  2728. WBUFL(buf,2)=sd->status.account_id;
  2729. WBUFW(buf,6)=sd->bl.x;
  2730. WBUFW(buf,8)=sd->bl.y;
  2731. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2732. }
  2733. /*==========================================
  2734. * Sends x/y dot to a single fd. [Skotlex]
  2735. *------------------------------------------*/
  2736. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2737. {
  2738. if( sd->bg_id )
  2739. return;
  2740. WFIFOHEAD(fd,packet_len(0x1eb));
  2741. WFIFOW(fd,0)=0x1eb;
  2742. WFIFOL(fd,2)=sd->status.account_id;
  2743. WFIFOW(fd,6)=sd->bl.x;
  2744. WFIFOW(fd,8)=sd->bl.y;
  2745. WFIFOSET(fd,packet_len(0x1eb));
  2746. }
  2747. // Guild XY locators [Valaris]
  2748. void clif_guild_xy_remove(struct map_session_data *sd)
  2749. {
  2750. unsigned char buf[10];
  2751. nullpo_retv(sd);
  2752. WBUFW(buf,0)=0x1eb;
  2753. WBUFL(buf,2)=sd->status.account_id;
  2754. WBUFW(buf,6)=-1;
  2755. WBUFW(buf,8)=-1;
  2756. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2757. }
  2758. /*==========================================
  2759. *
  2760. *------------------------------------------*/
  2761. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2762. {
  2763. struct map_session_data *sd, *tsd;
  2764. #if PACKETVER < 20100126
  2765. const int cmd = 0x106;
  2766. #else
  2767. const int cmd = 0x80e;
  2768. #endif
  2769. sd = va_arg(ap, struct map_session_data *);
  2770. tsd = (TBL_PC *)bl;
  2771. nullpo_ret(sd);
  2772. nullpo_ret(tsd);
  2773. if( !tsd->fd || tsd == sd )
  2774. return 0;
  2775. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2776. return 0;
  2777. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2778. WFIFOW(tsd->fd,0) = cmd;
  2779. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2780. #if PACKETVER < 20100126
  2781. if( sd->battle_status.max_hp > INT16_MAX )
  2782. { //To correctly display the %hp bar. [Skotlex]
  2783. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2784. WFIFOW(tsd->fd,8) = 100;
  2785. } else {
  2786. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2787. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2788. }
  2789. #else
  2790. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2791. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2792. #endif
  2793. WFIFOSET(tsd->fd,packet_len(cmd));
  2794. return 0;
  2795. }
  2796. /*==========================================
  2797. * Server tells all players that are allowed to view HP bars
  2798. * and are nearby 'sd' that 'sd' hp bar was updated.
  2799. *------------------------------------------*/
  2800. static int clif_hpmeter(struct map_session_data *sd)
  2801. {
  2802. nullpo_ret(sd);
  2803. map_foreachinallarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  2804. return 0;
  2805. }
  2806. /// Notifies client of a character parameter change.
  2807. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2808. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2809. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2810. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2811. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2812. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2813. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2814. /// TODO: Extract individual packets.
  2815. /// FIXME: Packet lengths from packet_len(cmd)
  2816. void clif_updatestatus(struct map_session_data *sd,int type)
  2817. {
  2818. int fd,len=8;
  2819. nullpo_retv(sd);
  2820. fd=sd->fd;
  2821. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2822. return;
  2823. WFIFOHEAD(fd, 14);
  2824. WFIFOW(fd,0)=0xb0;
  2825. WFIFOW(fd,2)=type;
  2826. switch(type){
  2827. // 00b0
  2828. case SP_WEIGHT:
  2829. pc_updateweightstatus(sd);
  2830. WFIFOHEAD(fd,14);
  2831. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2832. WFIFOW(fd,2)=type;
  2833. WFIFOL(fd,4)=sd->weight;
  2834. break;
  2835. case SP_MAXWEIGHT:
  2836. WFIFOL(fd,4)=sd->max_weight;
  2837. break;
  2838. case SP_SPEED:
  2839. WFIFOL(fd,4)=sd->battle_status.speed;
  2840. break;
  2841. case SP_BASELEVEL:
  2842. WFIFOL(fd,4)=sd->status.base_level;
  2843. break;
  2844. case SP_JOBLEVEL:
  2845. WFIFOL(fd,4)=sd->status.job_level;
  2846. break;
  2847. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2848. WFIFOL(fd,4)=sd->status.karma;
  2849. break;
  2850. case SP_MANNER:
  2851. WFIFOL(fd,4)=sd->status.manner;
  2852. break;
  2853. case SP_STATUSPOINT:
  2854. WFIFOL(fd,4)=sd->status.status_point;
  2855. break;
  2856. case SP_SKILLPOINT:
  2857. WFIFOL(fd,4)=sd->status.skill_point;
  2858. break;
  2859. case SP_HIT:
  2860. WFIFOL(fd,4)=sd->battle_status.hit;
  2861. break;
  2862. case SP_FLEE1:
  2863. WFIFOL(fd,4)=sd->battle_status.flee;
  2864. break;
  2865. case SP_FLEE2:
  2866. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2867. break;
  2868. case SP_MAXHP:
  2869. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2870. break;
  2871. case SP_MAXSP:
  2872. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2873. break;
  2874. case SP_HP:
  2875. // On officials the HP never go below 1, even if you die [Lemongrass]
  2876. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2877. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2878. break;
  2879. case SP_SP:
  2880. WFIFOL(fd,4)=sd->battle_status.sp;
  2881. break;
  2882. case SP_ASPD:
  2883. WFIFOL(fd,4)=sd->battle_status.amotion;
  2884. break;
  2885. case SP_ATK1:
  2886. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2887. break;
  2888. case SP_DEF1:
  2889. WFIFOL(fd,4)=pc_leftside_def(sd);
  2890. break;
  2891. case SP_MDEF1:
  2892. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2893. break;
  2894. case SP_ATK2:
  2895. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2896. break;
  2897. case SP_DEF2:
  2898. WFIFOL(fd,4)=pc_rightside_def(sd);
  2899. break;
  2900. case SP_MDEF2: {
  2901. //negative check (in case you have something like Berserk active)
  2902. int mdef2 = pc_rightside_mdef(sd);
  2903. WFIFOL(fd,4)=
  2904. #ifndef RENEWAL
  2905. ( mdef2 < 0 ) ? 0 :
  2906. #endif
  2907. mdef2;
  2908. }
  2909. break;
  2910. case SP_CRITICAL:
  2911. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2912. break;
  2913. case SP_MATK1:
  2914. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2915. break;
  2916. case SP_MATK2:
  2917. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2918. break;
  2919. case SP_ZENY:
  2920. WFIFOW(fd,0)=0xb1;
  2921. WFIFOL(fd,4)=sd->status.zeny;
  2922. break;
  2923. #if PACKETVER >= 20170830
  2924. case SP_BASEEXP:
  2925. WFIFOW(fd,0)=0xacb;
  2926. WFIFOQ(fd,4)=sd->status.base_exp;
  2927. len = packet_len(0xacb);
  2928. break;
  2929. case SP_JOBEXP:
  2930. WFIFOW(fd,0)=0xacb;
  2931. WFIFOQ(fd,4)=sd->status.job_exp;
  2932. len = packet_len(0xacb);
  2933. break;
  2934. case SP_NEXTBASEEXP:
  2935. WFIFOW(fd,0)=0xacb;
  2936. WFIFOQ(fd,4)=pc_nextbaseexp(sd);
  2937. len = packet_len(0xacb);
  2938. break;
  2939. case SP_NEXTJOBEXP:
  2940. WFIFOW(fd,0)=0xacb;
  2941. WFIFOQ(fd,4)=pc_nextjobexp(sd);
  2942. len = packet_len(0xacb);
  2943. break;
  2944. #else
  2945. case SP_BASEEXP:
  2946. WFIFOW(fd,0)=0xb1;
  2947. WFIFOL(fd,4)=sd->status.base_exp;
  2948. break;
  2949. case SP_JOBEXP:
  2950. WFIFOW(fd,0)=0xb1;
  2951. WFIFOL(fd,4)=sd->status.job_exp;
  2952. break;
  2953. case SP_NEXTBASEEXP:
  2954. WFIFOW(fd,0)=0xb1;
  2955. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2956. break;
  2957. case SP_NEXTJOBEXP:
  2958. WFIFOW(fd,0)=0xb1;
  2959. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2960. break;
  2961. #endif
  2962. /**
  2963. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2964. **/
  2965. case SP_USTR:
  2966. case SP_UAGI:
  2967. case SP_UVIT:
  2968. case SP_UINT:
  2969. case SP_UDEX:
  2970. case SP_ULUK:
  2971. WFIFOW(fd,0)=0xbe;
  2972. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2973. len=5;
  2974. break;
  2975. /**
  2976. * Tells the client how far it is allowed to attack (weapon range)
  2977. **/
  2978. case SP_ATTACKRANGE:
  2979. WFIFOW(fd,0)=0x13a;
  2980. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2981. len=4;
  2982. break;
  2983. case SP_STR:
  2984. WFIFOW(fd,0)=0x141;
  2985. WFIFOL(fd,2)=type;
  2986. WFIFOL(fd,6)=sd->status.str;
  2987. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2988. len=14;
  2989. break;
  2990. case SP_AGI:
  2991. WFIFOW(fd,0)=0x141;
  2992. WFIFOL(fd,2)=type;
  2993. WFIFOL(fd,6)=sd->status.agi;
  2994. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2995. len=14;
  2996. break;
  2997. case SP_VIT:
  2998. WFIFOW(fd,0)=0x141;
  2999. WFIFOL(fd,2)=type;
  3000. WFIFOL(fd,6)=sd->status.vit;
  3001. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3002. len=14;
  3003. break;
  3004. case SP_INT:
  3005. WFIFOW(fd,0)=0x141;
  3006. WFIFOL(fd,2)=type;
  3007. WFIFOL(fd,6)=sd->status.int_;
  3008. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3009. len=14;
  3010. break;
  3011. case SP_DEX:
  3012. WFIFOW(fd,0)=0x141;
  3013. WFIFOL(fd,2)=type;
  3014. WFIFOL(fd,6)=sd->status.dex;
  3015. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3016. len=14;
  3017. break;
  3018. case SP_LUK:
  3019. WFIFOW(fd,0)=0x141;
  3020. WFIFOL(fd,2)=type;
  3021. WFIFOL(fd,6)=sd->status.luk;
  3022. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3023. len=14;
  3024. break;
  3025. case SP_CARTINFO:
  3026. WFIFOW(fd,0)=0x121;
  3027. WFIFOW(fd,2)=sd->cart_num;
  3028. WFIFOW(fd,4)=MAX_CART;
  3029. WFIFOL(fd,6)=sd->cart_weight;
  3030. WFIFOL(fd,10)=sd->cart_weight_max;
  3031. len=14;
  3032. break;
  3033. default:
  3034. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3035. return;
  3036. }
  3037. WFIFOSET(fd,len);
  3038. // Additional update packets that should be sent right after
  3039. switch( type ){
  3040. case SP_BASELEVEL:
  3041. if( sd->status.party_id ){
  3042. struct party_data* p;
  3043. int i;
  3044. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3045. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3046. if( i < MAX_PARTY ){
  3047. p->party.member[i].lv = sd->status.base_level;
  3048. clif_party_job_and_level(sd);
  3049. }
  3050. }
  3051. }
  3052. break;
  3053. case SP_HP:
  3054. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3055. clif_hpmeter(sd);
  3056. }
  3057. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3058. clif_party_hp(sd);
  3059. }
  3060. if( sd->bg_id ){
  3061. clif_bg_hp(sd);
  3062. }
  3063. break;
  3064. }
  3065. }
  3066. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3067. /// 01ab <account id>.L <var id>.W <value>.L
  3068. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3069. {
  3070. unsigned char buf[12];
  3071. nullpo_retv(sd);
  3072. WBUFW(buf,0)=0x1ab;
  3073. WBUFL(buf,2)=sd->bl.id;
  3074. WBUFW(buf,6)=type;
  3075. switch(type)
  3076. {
  3077. case SP_MANNER:
  3078. WBUFL(buf,8)=val;
  3079. break;
  3080. default:
  3081. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3082. return;
  3083. }
  3084. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3085. }
  3086. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3087. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3088. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  3089. unsigned char buf[32];
  3090. #if PACKETVER < 4
  3091. const int cmd = 0xc3;
  3092. #else
  3093. const int cmd = 0x1d7;
  3094. #endif
  3095. WBUFW(buf,0) = cmd;
  3096. WBUFL(buf,2) = id;
  3097. WBUFB(buf,6) = type;
  3098. WBUFW(buf,7) = val;
  3099. #if PACKETVER >= 4
  3100. WBUFW(buf,9) = val2;
  3101. #endif
  3102. clif_send(buf,packet_len(cmd), bl, target);
  3103. }
  3104. /// Updates sprite/style properties of an object.
  3105. void clif_changelook(struct block_list *bl, int type, int val) {
  3106. struct map_session_data* sd;
  3107. struct status_change* sc;
  3108. struct view_data* vd;
  3109. enum send_target target = AREA;
  3110. int val2 = 0;
  3111. nullpo_retv(bl);
  3112. sd = BL_CAST(BL_PC, bl);
  3113. sc = status_get_sc(bl);
  3114. vd = status_get_viewdata(bl);
  3115. if( vd ) //temp hack to let Warp Portal change appearance
  3116. switch(type) {
  3117. case LOOK_WEAPON:
  3118. if (sd) {
  3119. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3120. val = vd->weapon;
  3121. }
  3122. else
  3123. vd->weapon = val;
  3124. break;
  3125. case LOOK_SHIELD:
  3126. if (sd) {
  3127. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3128. val = vd->shield;
  3129. }
  3130. else
  3131. vd->shield = val;
  3132. break;
  3133. case LOOK_BASE:
  3134. if (!sd)
  3135. break;
  3136. if ( val == JT_INVISIBLE )
  3137. return;
  3138. if (sd->sc.option&OPTION_COSTUME)
  3139. vd->weapon = vd->shield = 0;
  3140. if (!vd->cloth_color)
  3141. break;
  3142. if (sd) {
  3143. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3144. vd->cloth_color = 0;
  3145. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3146. vd->cloth_color = 0;
  3147. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3148. vd->cloth_color = 0;
  3149. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3150. vd->cloth_color = 0;
  3151. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3152. vd->cloth_color = 0;
  3153. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3154. vd->body_style = 0;
  3155. }
  3156. break;
  3157. case LOOK_HAIR:
  3158. vd->hair_style = val;
  3159. break;
  3160. case LOOK_HEAD_BOTTOM:
  3161. vd->head_bottom = val;
  3162. break;
  3163. case LOOK_HEAD_TOP:
  3164. vd->head_top = val;
  3165. break;
  3166. case LOOK_HEAD_MID:
  3167. vd->head_mid = val;
  3168. break;
  3169. case LOOK_HAIR_COLOR:
  3170. vd->hair_color = val;
  3171. break;
  3172. case LOOK_CLOTHES_COLOR:
  3173. if (val && sd) {
  3174. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3175. val = 0;
  3176. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3177. val = 0;
  3178. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3179. val = 0;
  3180. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3181. val = 0;
  3182. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3183. val = 0;
  3184. }
  3185. vd->cloth_color = val;
  3186. break;
  3187. case LOOK_SHOES:
  3188. #if PACKETVER > 3
  3189. if (sd) {
  3190. int n;
  3191. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3192. if(sd->inventory_data[n]->view_id > 0)
  3193. val = sd->inventory_data[n]->view_id;
  3194. else
  3195. val = sd->inventory.u.items_inventory[n].nameid;
  3196. } else
  3197. val = 0;
  3198. }
  3199. #endif
  3200. //Shoes? No packet uses this....
  3201. break;
  3202. case LOOK_BODY:
  3203. // unknown purpose
  3204. break;
  3205. case LOOK_ROBE:
  3206. #if PACKETVER < 20110111
  3207. return;
  3208. #else
  3209. vd->robe = val;
  3210. #endif
  3211. break;
  3212. case LOOK_BODY2:
  3213. #if PACKETVER < 20150513
  3214. return;
  3215. #else
  3216. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3217. val = 0;
  3218. vd->body_style = val;
  3219. #endif
  3220. break;
  3221. }
  3222. // prevent leaking the presence of GM-hidden objects
  3223. if( sc && sc->option&OPTION_INVISIBLE )
  3224. target = SELF;
  3225. #if PACKETVER < 4
  3226. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3227. #else
  3228. if (bl->type != BL_NPC) {
  3229. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3230. type = LOOK_WEAPON;
  3231. val = (vd ? vd->weapon : 0);
  3232. val2 = (vd ? vd->shield : 0);
  3233. }
  3234. if (disguised(bl)) {
  3235. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3236. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3237. } else
  3238. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3239. } else
  3240. unit_refresh(bl);
  3241. #endif
  3242. }
  3243. //Sends a change-base-look packet required for traps as they are triggered.
  3244. void clif_changetraplook(struct block_list *bl,int val) {
  3245. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3246. }
  3247. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3248. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3249. clif_sprite_change(bl, id, type, val, 0, target);
  3250. }
  3251. /// Character status (ZC_STATUS).
  3252. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3253. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3254. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3255. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3256. void clif_initialstatus(struct map_session_data *sd) {
  3257. int fd, mdef2;
  3258. unsigned char *buf;
  3259. nullpo_retv(sd);
  3260. fd=sd->fd;
  3261. WFIFOHEAD(fd, packet_len(0xbd));
  3262. buf = WFIFOP(fd,0);
  3263. WBUFW(buf,0) = 0xbd;
  3264. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3265. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3266. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3267. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3268. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3269. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3270. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3271. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3272. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3273. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3274. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3275. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3276. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3277. WBUFW(buf,16) = pc_leftside_atk(sd);
  3278. WBUFW(buf,18) = pc_rightside_atk(sd);
  3279. WBUFW(buf,20) = pc_rightside_matk(sd);
  3280. WBUFW(buf,22) = pc_leftside_matk(sd);
  3281. WBUFW(buf,24) = pc_leftside_def(sd);
  3282. WBUFW(buf,26) = pc_rightside_def(sd);
  3283. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3284. mdef2 = pc_rightside_mdef(sd);
  3285. WBUFW(buf,30) =
  3286. #ifndef RENEWAL
  3287. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3288. #endif
  3289. mdef2;
  3290. WBUFW(buf,32) = sd->battle_status.hit;
  3291. WBUFW(buf,34) = sd->battle_status.flee;
  3292. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3293. WBUFW(buf,38) = sd->battle_status.cri/10;
  3294. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3295. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3296. WFIFOSET(fd, packet_len(0xbd));
  3297. clif_updatestatus(sd, SP_STR);
  3298. clif_updatestatus(sd, SP_AGI);
  3299. clif_updatestatus(sd, SP_VIT);
  3300. clif_updatestatus(sd, SP_INT);
  3301. clif_updatestatus(sd, SP_DEX);
  3302. clif_updatestatus(sd, SP_LUK);
  3303. clif_updatestatus(sd, SP_ATTACKRANGE);
  3304. clif_updatestatus(sd, SP_ASPD);
  3305. }
  3306. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3307. /// 013c <index>.W
  3308. void clif_arrowequip(struct map_session_data *sd,int val) {
  3309. int fd;
  3310. nullpo_retv(sd);
  3311. #if PACKETVER >= 20121128
  3312. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3313. #endif
  3314. fd=sd->fd;
  3315. WFIFOHEAD(fd, packet_len(0x013c));
  3316. WFIFOW(fd,0) = 0x013c;
  3317. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3318. WFIFOSET(fd, packet_len(0x013c));
  3319. }
  3320. /// Ammunition action message (ZC_ACTION_FAILURE).
  3321. /// 013b <type>.W
  3322. /// type:
  3323. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3324. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3325. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3326. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3327. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3328. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3329. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3330. int fd;
  3331. nullpo_retv(sd);
  3332. fd=sd->fd;
  3333. WFIFOHEAD(fd, packet_len(0x013b));
  3334. WFIFOW(fd,0) = 0x013b;
  3335. WFIFOW(fd,2) = type;
  3336. WFIFOSET(fd, packet_len(0x013b));
  3337. }
  3338. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3339. /// 01ad <packet len>.W { <name id>.W }*
  3340. void clif_arrow_create_list(struct map_session_data *sd)
  3341. {
  3342. int i, c;
  3343. int fd;
  3344. nullpo_retv(sd);
  3345. fd = sd->fd;
  3346. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3347. WFIFOW(fd,0) = 0x1ad;
  3348. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3349. short j, nameid = skill_arrow_db[i].nameid;
  3350. if (nameid > 0 && itemdb_exists(nameid) &&
  3351. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3352. !sd->inventory.u.items_inventory[j].equip && sd->inventory.u.items_inventory[j].identify)
  3353. {
  3354. if ((j = itemdb_viewid(nameid)) > 0)
  3355. WFIFOW(fd,c*2+4) = j;
  3356. else
  3357. WFIFOW(fd,c*2+4) = nameid;
  3358. c++;
  3359. }
  3360. }
  3361. WFIFOW(fd,2) = c*2+4;
  3362. WFIFOSET(fd, WFIFOW(fd,2));
  3363. if (c > 0) {
  3364. sd->menuskill_id = AC_MAKINGARROW;
  3365. sd->menuskill_val = c;
  3366. }
  3367. }
  3368. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3369. /// 00bc <status id>.W <result>.B <value>.B
  3370. /// status id:
  3371. /// SP_STR ~ SP_LUK
  3372. /// result:
  3373. /// 0 = failure
  3374. /// 1 = success
  3375. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3376. int fd;
  3377. nullpo_retv(sd);
  3378. fd=sd->fd;
  3379. WFIFOHEAD(fd, packet_len(0xbc));
  3380. WFIFOW(fd,0) = 0xbc;
  3381. WFIFOW(fd,2) = type;
  3382. WFIFOB(fd,4) = ok;
  3383. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3384. WFIFOSET(fd, packet_len(0xbc));
  3385. }
  3386. /// Notifies the client about the result of a request to equip an item.
  3387. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3388. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3389. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3390. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3391. /// @ok: //inversed forv2 v5
  3392. /// 0 = failure
  3393. /// 1 = success
  3394. /// 2 = failure due to low level
  3395. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3396. {
  3397. int fd = 0, cmd = 0, look = 0;
  3398. struct s_packet_db *info = NULL;
  3399. nullpo_retv(sd);
  3400. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3401. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3402. return;
  3403. fd = sd->fd;
  3404. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3405. look = sd->inventory_data[n]->look;
  3406. WFIFOHEAD(fd, info->len);
  3407. WFIFOW(fd, 0) = cmd;
  3408. WFIFOW(fd, info->pos[0]) = n+2;
  3409. switch (cmd) {
  3410. case 0xaa:
  3411. WFIFOW(fd, info->pos[1]) = pos;
  3412. #if PACKETVER < 20100629
  3413. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3414. #else
  3415. WFIFOL(fd, info->pos[2]) = look;
  3416. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3417. #endif
  3418. break;
  3419. case 0x8d0:
  3420. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3421. flag = 1;
  3422. case 0x999:
  3423. if (cmd == 0x999)
  3424. WFIFOL(fd, info->pos[1]) = pos;
  3425. else
  3426. WFIFOW(fd, info->pos[1]) = pos;
  3427. WFIFOL(fd, info->pos[2]) = look;
  3428. WFIFOW(fd, info->pos[3]) = flag;
  3429. break;
  3430. }
  3431. WFIFOSET(fd, info->len);
  3432. }
  3433. /// Notifies the client about the result of a request to take off an item.
  3434. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3435. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3436. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3437. /// @ok : //inversed for v2 v5
  3438. /// 0 = failure
  3439. /// 1 = success
  3440. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3441. {
  3442. int fd, header, offs = 0;
  3443. #if PACKETVER >= 20130000
  3444. header = 0x99a;
  3445. ok = ok ? 0 : 1;
  3446. #elif PACKETVER >= 20110824
  3447. header = 0x8d1;
  3448. ok = ok ? 0 : 1;
  3449. #else
  3450. header = 0xac;
  3451. #endif
  3452. nullpo_retv(sd);
  3453. fd=sd->fd;
  3454. WFIFOHEAD(fd, packet_len(header));
  3455. WFIFOW(fd,offs+0) = header;
  3456. WFIFOW(fd,offs+2) = n+2;
  3457. #if PACKETVER >= 20130000
  3458. WFIFOL(fd,offs+4) = pos;
  3459. offs += 2;
  3460. #else
  3461. WFIFOW(fd,offs+4) = pos;
  3462. #endif
  3463. WFIFOB(fd,offs+6) = ok;
  3464. WFIFOSET(fd, packet_len(header));
  3465. }
  3466. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3467. /// 019b <id>.L <effect id>.L
  3468. /// effect id:
  3469. /// 0 = base level up
  3470. /// 1 = job level up
  3471. /// 2 = refine failure
  3472. /// 3 = refine success
  3473. /// 4 = game over
  3474. /// 5 = pharmacy success
  3475. /// 6 = pharmacy failure
  3476. /// 7 = base level up (super novice)
  3477. /// 8 = job level up (super novice)
  3478. /// 9 = base level up (taekwon)
  3479. void clif_misceffect(struct block_list* bl,int type)
  3480. {
  3481. unsigned char buf[32];
  3482. nullpo_retv(bl);
  3483. WBUFW(buf,0) = 0x19b;
  3484. WBUFL(buf,2) = bl->id;
  3485. WBUFL(buf,6) = type;
  3486. clif_send(buf,packet_len(0x19b),bl,AREA);
  3487. }
  3488. /// Notifies clients in the area of a state change.
  3489. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3490. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3491. void clif_changeoption(struct block_list* bl)
  3492. {
  3493. unsigned char buf[32];
  3494. struct status_change *sc;
  3495. struct map_session_data* sd;
  3496. nullpo_retv(bl);
  3497. sc = status_get_sc(bl);
  3498. if (!sc) return; //How can an option change if there's no sc?
  3499. sd = BL_CAST(BL_PC, bl);
  3500. #if PACKETVER >= 7
  3501. WBUFW(buf,0) = 0x229;
  3502. WBUFL(buf,2) = bl->id;
  3503. WBUFW(buf,6) = sc->opt1;
  3504. WBUFW(buf,8) = sc->opt2;
  3505. WBUFL(buf,10) = sc->option;
  3506. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3507. if(disguised(bl)) {
  3508. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3509. WBUFL(buf,2) = -bl->id;
  3510. clif_send(buf,packet_len(0x229),bl,SELF);
  3511. WBUFL(buf,2) = bl->id;
  3512. WBUFL(buf,10) = OPTION_INVISIBLE;
  3513. clif_send(buf,packet_len(0x229),bl,SELF);
  3514. } else
  3515. clif_send(buf,packet_len(0x229),bl,AREA);
  3516. #else
  3517. WBUFW(buf,0) = 0x119;
  3518. WBUFL(buf,2) = bl->id;
  3519. WBUFW(buf,6) = sc->opt1;
  3520. WBUFW(buf,8) = sc->opt2;
  3521. WBUFW(buf,10) = sc->option;
  3522. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3523. if(disguised(bl)) {
  3524. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3525. WBUFL(buf,2) = -bl->id;
  3526. clif_send(buf,packet_len(0x119),bl,SELF);
  3527. WBUFL(buf,2) = bl->id;
  3528. WBUFW(buf,10) = OPTION_INVISIBLE;
  3529. clif_send(buf,packet_len(0x119),bl,SELF);
  3530. } else
  3531. clif_send(buf,packet_len(0x119),bl,AREA);
  3532. #endif
  3533. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3534. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3535. if (sc->data[SC_PROVOKE]) {
  3536. const struct TimerData *td = get_timer(sc->data[SC_PROVOKE]->timer);
  3537. clif_status_change(bl, StatusIconChangeTable[SC_PROVOKE], 1, (!td ? INFINITE_TICK : DIFF_TICK(td->tick, gettick())), 0, 0, 0);
  3538. }
  3539. }
  3540. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3541. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3542. void clif_changeoption2(struct block_list* bl)
  3543. {
  3544. unsigned char buf[20];
  3545. struct status_change *sc;
  3546. sc = status_get_sc(bl);
  3547. if (!sc) return; //How can an option change if there's no sc?
  3548. WBUFW(buf,0) = 0x28a;
  3549. WBUFL(buf,2) = bl->id;
  3550. WBUFL(buf,6) = sc->option;
  3551. WBUFL(buf,10) = clif_setlevel(bl);
  3552. WBUFL(buf,14) = sc->opt3;
  3553. if(disguised(bl)) {
  3554. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3555. WBUFL(buf,2) = -bl->id;
  3556. clif_send(buf,packet_len(0x28a),bl,SELF);
  3557. WBUFL(buf,2) = bl->id;
  3558. WBUFL(buf,6) = OPTION_INVISIBLE;
  3559. clif_send(buf,packet_len(0x28a),bl,SELF);
  3560. } else
  3561. clif_send(buf,packet_len(0x28a),bl,AREA);
  3562. }
  3563. /// Notifies the client about the result of an item use request.
  3564. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3565. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3566. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3567. {
  3568. nullpo_retv(sd);
  3569. if(!ok) {
  3570. int fd=sd->fd;
  3571. WFIFOHEAD(fd,packet_len(0xa8));
  3572. WFIFOW(fd,0)=0xa8;
  3573. WFIFOW(fd,2)=index+2;
  3574. WFIFOW(fd,4)=amount;
  3575. WFIFOB(fd,6)=ok;
  3576. WFIFOSET(fd,packet_len(0xa8));
  3577. }
  3578. else {
  3579. #if PACKETVER < 3
  3580. int fd=sd->fd;
  3581. WFIFOHEAD(fd,packet_len(0xa8));
  3582. WFIFOW(fd,0)=0xa8;
  3583. WFIFOW(fd,2)=index+2;
  3584. WFIFOW(fd,4)=amount;
  3585. WFIFOB(fd,6)=ok;
  3586. WFIFOSET(fd,packet_len(0xa8));
  3587. #else
  3588. unsigned char buf[32];
  3589. WBUFW(buf,0)=0x1c8;
  3590. WBUFW(buf,2)=index+2;
  3591. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3592. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3593. else
  3594. WBUFW(buf,4)=sd->inventory.u.items_inventory[index].nameid;
  3595. WBUFL(buf,6)=sd->bl.id;
  3596. WBUFW(buf,10)=amount;
  3597. WBUFB(buf,12)=ok;
  3598. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3599. #endif
  3600. }
  3601. }
  3602. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3603. /// 00d6 <flag>.B
  3604. /// flag:
  3605. /// 0 = Room has been successfully created (opens chat room)
  3606. /// 1 = Room limit exceeded
  3607. /// 2 = Same room already exists
  3608. void clif_createchat(struct map_session_data* sd, int flag)
  3609. {
  3610. int fd;
  3611. nullpo_retv(sd);
  3612. fd = sd->fd;
  3613. WFIFOHEAD(fd,packet_len(0xd6));
  3614. WFIFOW(fd,0) = 0xd6;
  3615. WFIFOB(fd,2) = flag;
  3616. WFIFOSET(fd,packet_len(0xd6));
  3617. }
  3618. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3619. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3620. /// type:
  3621. /// 0 = private (password protected)
  3622. /// 1 = public
  3623. /// 2 = arena (npc waiting room)
  3624. /// 3 = PK zone (non-clickable)
  3625. void clif_dispchat(struct chat_data* cd, int fd)
  3626. {
  3627. unsigned char buf[128];
  3628. uint8 type;
  3629. if( cd == NULL || cd->owner == NULL )
  3630. return;
  3631. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3632. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3633. : 1;
  3634. WBUFW(buf, 0) = 0xd7;
  3635. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3636. WBUFL(buf, 4) = cd->owner->id;
  3637. WBUFL(buf, 8) = cd->bl.id;
  3638. WBUFW(buf,12) = cd->limit;
  3639. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3640. WBUFB(buf,16) = type;
  3641. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3642. if( fd ) {
  3643. WFIFOHEAD(fd,WBUFW(buf,2));
  3644. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3645. WFIFOSET(fd,WBUFW(buf,2));
  3646. } else {
  3647. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3648. }
  3649. }
  3650. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3651. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3652. /// type:
  3653. /// 0 = private (password protected)
  3654. /// 1 = public
  3655. /// 2 = arena (npc waiting room)
  3656. /// 3 = PK zone (non-clickable)
  3657. void clif_changechatstatus(struct chat_data* cd)
  3658. {
  3659. unsigned char buf[128];
  3660. uint8 type;
  3661. if( cd == NULL || cd->usersd[0] == NULL )
  3662. return;
  3663. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3664. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3665. : 1;
  3666. WBUFW(buf, 0) = 0xdf;
  3667. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3668. WBUFL(buf, 4) = cd->owner->id;
  3669. WBUFL(buf, 8) = cd->bl.id;
  3670. WBUFW(buf,12) = cd->limit;
  3671. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3672. WBUFB(buf,16) = type;
  3673. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3674. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3675. }
  3676. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3677. /// 00d8 <chat id>.L
  3678. void clif_clearchat(struct chat_data *cd,int fd)
  3679. {
  3680. unsigned char buf[32];
  3681. nullpo_retv(cd);
  3682. WBUFW(buf,0) = 0xd8;
  3683. WBUFL(buf,2) = cd->bl.id;
  3684. if( fd ) {
  3685. WFIFOHEAD(fd,packet_len(0xd8));
  3686. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3687. WFIFOSET(fd,packet_len(0xd8));
  3688. } else {
  3689. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3690. }
  3691. }
  3692. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3693. /// 00da <result>.B
  3694. /// result:
  3695. /// 0 = room full
  3696. /// 1 = wrong password
  3697. /// 2 = kicked
  3698. /// 3 = success (no message)
  3699. /// 4 = no enough zeny
  3700. /// 5 = too low level
  3701. /// 6 = too high level
  3702. /// 7 = unsuitable job class
  3703. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3704. {
  3705. int fd;
  3706. nullpo_retv(sd);
  3707. fd = sd->fd;
  3708. WFIFOHEAD(fd,packet_len(0xda));
  3709. WFIFOW(fd,0) = 0xda;
  3710. WFIFOB(fd,2) = flag;
  3711. WFIFOSET(fd,packet_len(0xda));
  3712. }
  3713. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3714. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3715. /// role:
  3716. /// 0 = owner (menu)
  3717. /// 1 = normal
  3718. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3719. {
  3720. int fd;
  3721. int i,t;
  3722. nullpo_retv(sd);
  3723. nullpo_retv(cd);
  3724. fd = sd->fd;
  3725. if (!session_isActive(fd))
  3726. return;
  3727. t = (int)(cd->owner->type == BL_NPC);
  3728. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3729. WFIFOW(fd, 0) = 0xdb;
  3730. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3731. WFIFOL(fd, 4) = cd->bl.id;
  3732. if(cd->owner->type == BL_NPC){
  3733. WFIFOL(fd, 30) = 1;
  3734. WFIFOL(fd, 8) = 0;
  3735. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3736. for (i = 0; i < cd->users; i++) {
  3737. WFIFOL(fd, 8+(i+1)*28) = 1;
  3738. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3739. }
  3740. }else{
  3741. for (i = 0; i < cd->users; i++) {
  3742. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3743. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3744. }
  3745. }
  3746. WFIFOSET(fd, WFIFOW(fd, 2));
  3747. }
  3748. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3749. /// 00dc <users>.W <name>.24B
  3750. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3751. {
  3752. unsigned char buf[29];
  3753. nullpo_retv(sd);
  3754. nullpo_retv(cd);
  3755. WBUFW(buf, 0) = 0xdc;
  3756. WBUFW(buf, 2) = cd->users;
  3757. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3758. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3759. }
  3760. /// Announce the new owner (ZC_ROLE_CHANGE).
  3761. /// 00e1 <role>.L <nick>.24B
  3762. /// role:
  3763. /// 0 = owner (menu)
  3764. /// 1 = normal
  3765. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3766. {
  3767. unsigned char buf[64];
  3768. nullpo_retv(sd);
  3769. nullpo_retv(cd);
  3770. WBUFW(buf, 0) = 0xe1;
  3771. WBUFL(buf, 2) = 1;
  3772. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3773. WBUFW(buf,30) = 0xe1;
  3774. WBUFL(buf,32) = 0;
  3775. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3776. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3777. }
  3778. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3779. /// 00dd <users>.W <nick>.24B <flag>.B
  3780. /// flag:
  3781. /// 0 = left
  3782. /// 1 = kicked
  3783. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3784. {
  3785. unsigned char buf[32];
  3786. nullpo_retv(sd);
  3787. nullpo_retv(cd);
  3788. WBUFW(buf, 0) = 0xdd;
  3789. WBUFW(buf, 2) = cd->users-1;
  3790. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3791. WBUFB(buf,28) = flag;
  3792. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3793. }
  3794. /// Opens a trade request window from char 'name'.
  3795. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3796. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3797. void clif_traderequest(struct map_session_data* sd, const char* name)
  3798. {
  3799. int fd = sd->fd;
  3800. #if PACKETVER < 6
  3801. WFIFOHEAD(fd,packet_len(0xe5));
  3802. WFIFOW(fd,0) = 0xe5;
  3803. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3804. WFIFOSET(fd,packet_len(0xe5));
  3805. #else
  3806. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3807. if( !tsd ) return;
  3808. WFIFOHEAD(fd,packet_len(0x1f4));
  3809. WFIFOW(fd,0) = 0x1f4;
  3810. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3811. WFIFOL(fd,26) = tsd->status.char_id;
  3812. WFIFOW(fd,30) = tsd->status.base_level;
  3813. WFIFOSET(fd,packet_len(0x1f4));
  3814. #endif
  3815. }
  3816. /// Reply to a trade-request.
  3817. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3818. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3819. /// result:
  3820. /// 0 = Char is too far
  3821. /// 1 = Character does not exist
  3822. /// 2 = Trade failed
  3823. /// 3 = Accept
  3824. /// 4 = Cancel
  3825. /// 5 = Busy
  3826. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3827. {
  3828. int fd = sd->fd;
  3829. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3830. if( PACKETVER < 6 || !tsd ) {
  3831. WFIFOHEAD(fd,packet_len(0xe7));
  3832. WFIFOW(fd,0) = 0xe7;
  3833. WFIFOB(fd,2) = type;
  3834. WFIFOSET(fd,packet_len(0xe7));
  3835. } else {
  3836. WFIFOHEAD(fd,packet_len(0x1f5));
  3837. WFIFOW(fd,0) = 0x1f5;
  3838. WFIFOB(fd,2) = type;
  3839. WFIFOL(fd,3) = tsd->status.char_id;
  3840. WFIFOW(fd,7) = tsd->status.base_level;
  3841. WFIFOSET(fd,packet_len(0x1f5));
  3842. }
  3843. }
  3844. /// Notifies the client about an item from other player in current trade.
  3845. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3846. /// 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)
  3847. /// 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)
  3848. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3849. {
  3850. int fd;
  3851. unsigned char *buf;
  3852. #if PACKETVER < 20100223
  3853. const int cmd = 0xe9;
  3854. #elif PACKETVER < 20150225
  3855. const int cmd = 0x80f;
  3856. #else
  3857. const int cmd = 0xa09;
  3858. #endif
  3859. nullpo_retv(sd);
  3860. nullpo_retv(tsd);
  3861. fd = tsd->fd;
  3862. buf = WFIFOP(fd,0);
  3863. WFIFOHEAD(fd,packet_len(cmd));
  3864. WBUFW(buf,0) = cmd;
  3865. if( index == 0 )
  3866. {
  3867. #if PACKETVER < 20100223
  3868. WBUFL(buf,2) = amount; //amount
  3869. WBUFW(buf,6) = 0; // type id
  3870. #else
  3871. WBUFW(buf,2) = 0; // type id
  3872. WBUFB(buf,4) = 0; // item type
  3873. WBUFL(buf,5) = amount; // amount
  3874. buf = WBUFP(buf,1); //Advance 1B
  3875. #endif
  3876. WBUFB(buf,8) = 0; //identify flag
  3877. WBUFB(buf,9) = 0; // attribute
  3878. WBUFB(buf,10)= 0; //refine
  3879. WBUFW(buf,11)= 0; //card (4w)
  3880. WBUFW(buf,13)= 0; //card (4w)
  3881. WBUFW(buf,15)= 0; //card (4w)
  3882. WBUFW(buf,17)= 0; //card (4w)
  3883. #if PACKETVER >= 20150225
  3884. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3885. #endif
  3886. }
  3887. else
  3888. {
  3889. index -= 2; //index fix
  3890. #if PACKETVER < 20100223
  3891. WBUFL(buf,2) = amount; //amount
  3892. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3893. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3894. else
  3895. WBUFW(buf,6) = sd->inventory.u.items_inventory[index].nameid; // type id
  3896. #else
  3897. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3898. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3899. else
  3900. WBUFW(buf,2) = sd->inventory.u.items_inventory[index].nameid; // type id
  3901. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3902. WBUFL(buf,5) = amount; // amount
  3903. buf = WBUFP(buf,1); //Advance 1B
  3904. #endif
  3905. WBUFB(buf,8) = sd->inventory.u.items_inventory[index].identify; //identify flag
  3906. WBUFB(buf,9) = sd->inventory.u.items_inventory[index].attribute; // attribute
  3907. WBUFB(buf,10)= sd->inventory.u.items_inventory[index].refine; //refine
  3908. clif_addcards(WBUFP(buf, 11), &sd->inventory.u.items_inventory[index]);
  3909. #if PACKETVER >= 20150225
  3910. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3911. #endif
  3912. }
  3913. WFIFOSET(fd,packet_len(cmd));
  3914. }
  3915. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3916. /// 00ea <index>.W <result>.B
  3917. /// result:
  3918. /// 0 = success
  3919. /// 1 = overweight
  3920. /// 2 = trade canceled
  3921. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3922. {
  3923. int fd;
  3924. nullpo_retv(sd);
  3925. fd = sd->fd;
  3926. WFIFOHEAD(fd,packet_len(0xea));
  3927. WFIFOW(fd,0) = 0xea;
  3928. WFIFOW(fd,2) = index;
  3929. WFIFOB(fd,4) = fail;
  3930. WFIFOSET(fd,packet_len(0xea));
  3931. }
  3932. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3933. /// 00ec <who>.B
  3934. /// who:
  3935. /// 0 = self
  3936. /// 1 = other player
  3937. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3938. {
  3939. int fd;
  3940. nullpo_retv(sd);
  3941. fd = sd->fd;
  3942. WFIFOHEAD(fd,packet_len(0xec));
  3943. WFIFOW(fd,0) = 0xec;
  3944. WFIFOB(fd,2) = fail;
  3945. WFIFOSET(fd,packet_len(0xec));
  3946. }
  3947. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3948. /// 00ee
  3949. void clif_tradecancelled(struct map_session_data* sd)
  3950. {
  3951. int fd;
  3952. nullpo_retv(sd);
  3953. fd = sd->fd;
  3954. WFIFOHEAD(fd,packet_len(0xee));
  3955. WFIFOW(fd,0) = 0xee;
  3956. WFIFOSET(fd,packet_len(0xee));
  3957. }
  3958. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3959. /// 00f0 <result>.B
  3960. /// result:
  3961. /// 0 = success
  3962. /// 1 = failure
  3963. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3964. {
  3965. int fd;
  3966. nullpo_retv(sd);
  3967. fd = sd->fd;
  3968. WFIFOHEAD(fd,packet_len(0xf0));
  3969. WFIFOW(fd,0) = 0xf0;
  3970. WFIFOB(fd,2) = fail;
  3971. WFIFOSET(fd,packet_len(0xf0));
  3972. }
  3973. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3974. /// 00f1
  3975. /// NOTE: Unknown purpose. Items are not removed until the window is
  3976. /// refreshed (ex. by putting another item in there).
  3977. void clif_tradeundo(struct map_session_data* sd)
  3978. {
  3979. int fd = sd->fd;
  3980. WFIFOHEAD(fd,packet_len(0xf1));
  3981. WFIFOW(fd,0) = 0xf1;
  3982. WFIFOSET(fd,packet_len(0xf1));
  3983. }
  3984. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3985. /// 00f2 <current count>.W <max count>.W
  3986. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3987. {
  3988. int fd;
  3989. nullpo_retv(sd);
  3990. fd=sd->fd;
  3991. WFIFOHEAD(fd,packet_len(0xf2));
  3992. WFIFOW(fd,0) = 0xf2;
  3993. WFIFOW(fd,2) = amount;
  3994. WFIFOW(fd,4) = max_amount;
  3995. WFIFOSET(fd,packet_len(0xf2));
  3996. }
  3997. /// Notifies the client of an item being added to the storage.
  3998. /// 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)
  3999. /// 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)
  4000. /// 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)
  4001. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  4002. {
  4003. #if PACKETVER < 5
  4004. const int cmd = 0xf4;
  4005. #elif PACKETVER < 20150225
  4006. const int cmd = 0x1c4;
  4007. #else
  4008. const int cmd = 0xa0a;
  4009. #endif
  4010. int view,fd;
  4011. int offset = 0;
  4012. nullpo_retv(sd);
  4013. nullpo_retv(i);
  4014. fd=sd->fd;
  4015. view = itemdb_viewid(i->nameid);
  4016. WFIFOHEAD(fd,packet_len(cmd));
  4017. WFIFOW(fd, 0) = cmd; // Storage item added
  4018. WFIFOW(fd, 2) = index+1; // index
  4019. WFIFOL(fd, 4) = amount; // amount
  4020. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  4021. #if PACKETVER >= 5
  4022. WFIFOB(fd,10) = itemtype(i->nameid); //type
  4023. offset += 1;
  4024. #endif
  4025. WFIFOB(fd,10+offset) = i->identify; //identify flag
  4026. WFIFOB(fd,11+offset) = i->attribute; // attribute
  4027. WFIFOB(fd,12+offset) = i->refine; //refine
  4028. clif_addcards(WFIFOP(fd,13+offset), i);
  4029. #if PACKETVER >= 20150225
  4030. clif_add_random_options(WFIFOP(fd,21+offset), i);
  4031. #endif
  4032. WFIFOSET(fd,packet_len(cmd));
  4033. }
  4034. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4035. /// 00f6 <index>.W <amount>.L
  4036. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4037. {
  4038. int fd;
  4039. nullpo_retv(sd);
  4040. fd=sd->fd;
  4041. WFIFOHEAD(fd,packet_len(0xf6));
  4042. WFIFOW(fd,0)=0xf6; // Storage item removed
  4043. WFIFOW(fd,2)=index+1;
  4044. WFIFOL(fd,4)=amount;
  4045. WFIFOSET(fd,packet_len(0xf6));
  4046. }
  4047. /// Closes storage (ZC_CLOSE_STORE).
  4048. /// 00f8
  4049. void clif_storageclose(struct map_session_data* sd)
  4050. {
  4051. int fd;
  4052. nullpo_retv(sd);
  4053. fd=sd->fd;
  4054. WFIFOHEAD(fd,packet_len(0xf8));
  4055. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4056. WFIFOSET(fd,packet_len(0xf8));
  4057. }
  4058. /*==========================================
  4059. * Server tells 'sd' player client the abouts of 'dstsd' player
  4060. *------------------------------------------*/
  4061. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4062. {
  4063. struct block_list *d_bl;
  4064. int i;
  4065. if( dstsd->chatID ) {
  4066. struct chat_data *cd = NULL;
  4067. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4068. clif_dispchat(cd,sd->fd);
  4069. } else if( dstsd->state.vending )
  4070. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4071. else if( dstsd->state.buyingstore )
  4072. clif_buyingstore_entry_single(sd, dstsd);
  4073. if(dstsd->spiritball > 0)
  4074. clif_spiritball_single(sd->fd, dstsd);
  4075. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4076. clif_spiritcharm_single(sd->fd, dstsd);
  4077. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4078. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4079. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4080. )
  4081. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4082. // display link (sd - dstsd) to sd
  4083. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4084. if( i < MAX_DEVOTION )
  4085. clif_devotion(&sd->bl, sd);
  4086. // display links (dstsd - devotees) to sd
  4087. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4088. if( i < MAX_DEVOTION )
  4089. clif_devotion(&dstsd->bl, sd);
  4090. // display link (dstsd - crusader) to sd
  4091. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4092. clif_devotion(d_bl, sd);
  4093. }
  4094. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  4095. {
  4096. uint8 buf[128];
  4097. struct unit_data *ud;
  4098. struct view_data *vd;
  4099. int len;
  4100. vd = status_get_viewdata(bl);
  4101. if (!vd || vd->class_ == JT_INVISIBLE)
  4102. return;
  4103. /**
  4104. * Hide NPC from maya purple card.
  4105. **/
  4106. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4107. return;
  4108. ud = unit_bl2ud(bl);
  4109. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4110. clif_send(buf,len,&sd->bl,SELF);
  4111. if (vd->cloth_color)
  4112. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4113. if (vd->body_style)
  4114. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4115. switch (bl->type)
  4116. {
  4117. case BL_PC:
  4118. {
  4119. TBL_PC* tsd = (TBL_PC*)bl;
  4120. clif_getareachar_pc(sd, tsd);
  4121. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4122. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4123. else if(tsd->state.size==SZ_MEDIUM)
  4124. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4125. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4126. clif_sendbgemblem_single(sd->fd,tsd);
  4127. if ( tsd->status.robe )
  4128. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4129. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4130. clif_hat_effects(sd,bl,SELF);
  4131. }
  4132. break;
  4133. case BL_MER: // Devotion Effects
  4134. if( ((TBL_MER*)bl)->devotion_flag )
  4135. clif_devotion(bl, sd);
  4136. break;
  4137. case BL_NPC:
  4138. {
  4139. TBL_NPC* nd = (TBL_NPC*)bl;
  4140. if( nd->chat_id )
  4141. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4142. if( nd->size == SZ_BIG )
  4143. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4144. else if( nd->size == SZ_MEDIUM )
  4145. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4146. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4147. clif_progressbar_npc(nd, sd);
  4148. }
  4149. break;
  4150. case BL_MOB:
  4151. {
  4152. TBL_MOB* md = (TBL_MOB*)bl;
  4153. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4154. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4155. else if(md->special_state.size==SZ_MEDIUM)
  4156. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4157. #if PACKETVER >= 20120404
  4158. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4159. int i;
  4160. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4161. if( md->dmglog[i].id == sd->status.char_id )
  4162. clif_monster_hp_bar(md, sd->fd);
  4163. }
  4164. #endif
  4165. }
  4166. break;
  4167. case BL_PET:
  4168. if (vd->head_bottom)
  4169. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4170. break;
  4171. }
  4172. }
  4173. //Modifies the type of damage according to status changes [Skotlex]
  4174. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4175. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4176. {
  4177. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4178. }
  4179. /*==========================================
  4180. * Estimates walk delay based on the damage criteria. [Skotlex]
  4181. *------------------------------------------*/
  4182. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4183. {
  4184. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4185. return 0;
  4186. if (bl->type == BL_PC) {
  4187. if (battle_config.pc_walk_delay_rate != 100)
  4188. delay = delay*battle_config.pc_walk_delay_rate/100;
  4189. } else
  4190. if (battle_config.walk_delay_rate != 100)
  4191. delay = delay*battle_config.walk_delay_rate/100;
  4192. if (div_ > 1) //Multi-hit skills mean higher delays.
  4193. delay += battle_config.multihit_delay*(div_-1);
  4194. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4195. }
  4196. /*========================================== [Playtester]
  4197. * Returns hallucination damage the client displays
  4198. *------------------------------------------*/
  4199. static int clif_hallucination_damage()
  4200. {
  4201. int digit = rnd() % 5 + 1;
  4202. switch (digit)
  4203. {
  4204. case 1:
  4205. return (rnd() % 10);
  4206. case 2:
  4207. return (rnd() % 100);
  4208. case 3:
  4209. return (rnd() % 1000);
  4210. case 4:
  4211. return (rnd() % 10000);
  4212. }
  4213. return (rnd() % 32767);
  4214. }
  4215. /// Sends a 'damage' packet (src performs action on dst)
  4216. /// 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)
  4217. /// 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)
  4218. /// 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)
  4219. /// type:
  4220. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4221. /// 1 = pick up item
  4222. /// 2 = sit down
  4223. /// 3 = stand up
  4224. /// 4 = damage (endure)
  4225. /// 5 = (splash?)
  4226. /// 6 = (skill?)
  4227. /// 7 = (repeat damage?)
  4228. /// 8 = multi-hit damage
  4229. /// 9 = multi-hit damage (endure)
  4230. /// 10 = critical hit
  4231. /// 11 = lucky dodge
  4232. /// 12 = (touch skill?)
  4233. /// 13 = multi-hit critical
  4234. 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)
  4235. {
  4236. unsigned char buf[34];
  4237. struct status_change *sc;
  4238. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4239. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4240. #if PACKETVER < 20071113
  4241. const int cmd = 0x8a;
  4242. int offset = 0;
  4243. #elif PACKETVER < 20131223
  4244. const int cmd = 0x2e1;
  4245. int offset = 2;
  4246. #else
  4247. const int cmd = 0x8c8;
  4248. int offset = 3;
  4249. #endif
  4250. nullpo_ret(src);
  4251. nullpo_ret(dst);
  4252. if (type != DMG_MULTI_HIT_CRITICAL)
  4253. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4254. sc = status_get_sc(dst);
  4255. if(sc && sc->count) {
  4256. if(sc->data[SC_HALLUCINATION]) {
  4257. if(damage) damage = clif_hallucination_damage();
  4258. if(damage2) damage2 = clif_hallucination_damage();
  4259. }
  4260. }
  4261. WBUFW(buf,0) = cmd;
  4262. WBUFL(buf,2) = src->id;
  4263. WBUFL(buf,6) = dst->id;
  4264. WBUFL(buf,10) = client_tick(tick);
  4265. WBUFL(buf,14) = sdelay;
  4266. WBUFL(buf,18) = ddelay;
  4267. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4268. #if PACKETVER < 20071113
  4269. WBUFW(buf,22) = damage ? div : 0;
  4270. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4271. #else
  4272. WBUFL(buf, 22) = damage ? div : 0;
  4273. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4274. #endif
  4275. } else {
  4276. #if PACKETVER < 20071113
  4277. WBUFW(buf,22) = min(damage, INT16_MAX);
  4278. WBUFW(buf,27+offset) = damage2;
  4279. #else
  4280. WBUFL(buf,22) = damage;
  4281. WBUFL(buf,27+offset) = damage2;
  4282. #endif
  4283. }
  4284. #if PACKETVER >= 20131223
  4285. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4286. #endif
  4287. WBUFW(buf,24+offset) = div;
  4288. WBUFB(buf,26+offset) = type;
  4289. if(disguised(dst)) {
  4290. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4291. WBUFL(buf,6) = -dst->id;
  4292. clif_send(buf, packet_len(cmd), dst, SELF);
  4293. } else
  4294. clif_send(buf, packet_len(cmd), dst, AREA);
  4295. if(disguised(src)) {
  4296. WBUFL(buf,2) = -src->id;
  4297. if (disguised(dst))
  4298. WBUFL(buf,6) = dst->id;
  4299. #if PACKETVER < 20071113
  4300. if(damage > 0) WBUFW(buf,22) = -1;
  4301. if(damage2 > 0) WBUFW(buf,27) = -1;
  4302. #else
  4303. if(damage > 0) WBUFL(buf,22) = -1;
  4304. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4305. #endif
  4306. clif_send(buf,packet_len(cmd),src,SELF);
  4307. }
  4308. if(src == dst) {
  4309. unit_setdir(src, unit_getdir(src));
  4310. }
  4311. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4312. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4313. //Return adjusted can't walk delay for further processing.
  4314. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4315. }
  4316. /*==========================================
  4317. * src picks up dst
  4318. *------------------------------------------*/
  4319. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4320. {
  4321. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4322. unsigned char buf[32];
  4323. nullpo_retv(src);
  4324. nullpo_retv(dst);
  4325. WBUFW(buf, 0) = 0x8a;
  4326. WBUFL(buf, 2) = src->id;
  4327. WBUFL(buf, 6) = dst->id;
  4328. WBUFB(buf,26) = 1;
  4329. clif_send(buf, packet_len(0x8a), src, AREA);
  4330. }
  4331. /*==========================================
  4332. * inform clients in area that `bl` is sitting
  4333. *------------------------------------------*/
  4334. void clif_sitting(struct block_list* bl)
  4335. {
  4336. unsigned char buf[32];
  4337. nullpo_retv(bl);
  4338. WBUFW(buf, 0) = 0x8a;
  4339. WBUFL(buf, 2) = bl->id;
  4340. WBUFB(buf,26) = 2;
  4341. clif_send(buf, packet_len(0x8a), bl, AREA);
  4342. if(disguised(bl)) {
  4343. WBUFL(buf, 2) = - bl->id;
  4344. clif_send(buf, packet_len(0x8a), bl, SELF);
  4345. }
  4346. }
  4347. /*==========================================
  4348. * inform clients in area that `bl` is standing
  4349. *------------------------------------------*/
  4350. void clif_standing(struct block_list* bl)
  4351. {
  4352. unsigned char buf[32];
  4353. nullpo_retv(bl);
  4354. WBUFW(buf, 0) = 0x8a;
  4355. WBUFL(buf, 2) = bl->id;
  4356. WBUFB(buf,26) = 3;
  4357. clif_send(buf, packet_len(0x8a), bl, AREA);
  4358. if(disguised(bl)) {
  4359. WBUFL(buf, 2) = - bl->id;
  4360. clif_send(buf, packet_len(0x8a), bl, SELF);
  4361. }
  4362. }
  4363. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4364. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4365. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4366. {
  4367. unsigned char buf[32];
  4368. WBUFW(buf,0) = 0x192;
  4369. WBUFW(buf,2) = x;
  4370. WBUFW(buf,4) = y;
  4371. WBUFW(buf,6) = type;
  4372. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4373. if( fd )
  4374. {
  4375. WFIFOHEAD(fd,packet_len(0x192));
  4376. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4377. WFIFOSET(fd,packet_len(0x192));
  4378. }
  4379. else
  4380. {
  4381. struct block_list dummy_bl;
  4382. dummy_bl.type = BL_NUL;
  4383. dummy_bl.x = x;
  4384. dummy_bl.y = y;
  4385. dummy_bl.m = m;
  4386. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4387. }
  4388. }
  4389. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4390. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4391. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4392. {
  4393. int view,fd;
  4394. fd=sd->fd;
  4395. WFIFOHEAD(fd,packet_len(0x9d));
  4396. WFIFOW(fd,0)=0x9d;
  4397. WFIFOL(fd,2)=fitem->bl.id;
  4398. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4399. WFIFOW(fd,6)=view;
  4400. else
  4401. WFIFOW(fd,6)=fitem->item.nameid;
  4402. WFIFOB(fd,8)=fitem->item.identify;
  4403. WFIFOW(fd,9)=fitem->bl.x;
  4404. WFIFOW(fd,11)=fitem->bl.y;
  4405. WFIFOW(fd,13)=fitem->item.amount;
  4406. WFIFOB(fd,15)=fitem->subx;
  4407. WFIFOB(fd,16)=fitem->suby;
  4408. WFIFOSET(fd,packet_len(0x9d));
  4409. }
  4410. /// Notifes client about Graffiti
  4411. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4412. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4413. unsigned char buf[128];
  4414. nullpo_retv(bl);
  4415. nullpo_retv(unit);
  4416. WBUFW(buf, 0) = 0x1c9;
  4417. WBUFL(buf, 2) = unit->bl.id;
  4418. WBUFL(buf, 6) = unit->group->src_id;
  4419. WBUFW(buf,10) = unit->bl.x;
  4420. WBUFW(buf,12) = unit->bl.y;
  4421. WBUFB(buf,14) = unit->group->unit_id;
  4422. WBUFB(buf,15) = 1;
  4423. WBUFB(buf,16) = 1;
  4424. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4425. clif_send(buf,packet_len(0x1c9),bl,target);
  4426. }
  4427. /// Notifies the client of a skill unit.
  4428. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4429. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4430. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4431. /// 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)
  4432. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4433. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4434. unsigned char buf[128];
  4435. nullpo_retv(bl);
  4436. nullpo_retv(unit);
  4437. if (bl->type == BL_PC)
  4438. fd = ((TBL_PC*)bl)->fd;
  4439. if (unit->group->state.guildaura)
  4440. return;
  4441. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4442. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4443. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4444. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4445. else
  4446. unit_id = unit->group->unit_id;
  4447. if (!visible)
  4448. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4449. #if PACKETVER >= 3
  4450. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4451. clif_graffiti(bl, unit, target);
  4452. return;
  4453. }
  4454. #endif
  4455. #if PACKETVER <= 20120702
  4456. header = 0x011f;
  4457. //#if PACKETVER < 20110718
  4458. // header = 0x011f;
  4459. //#elif PACKETVER < 20121212
  4460. // header = 0x08c7;
  4461. #elif PACKETVER < 20130731
  4462. header = 0x099f;
  4463. #else
  4464. header = 0x09ca;
  4465. #endif
  4466. len = packet_len(header);
  4467. WBUFW(buf,pos) = header;
  4468. if (header != 0x011f) {
  4469. WBUFW(buf, pos+2) = len;
  4470. pos += 2;
  4471. }
  4472. WBUFL(buf,pos+2) = unit->bl.id;
  4473. WBUFL(buf,pos+6) = unit->group->src_id;
  4474. WBUFW(buf,pos+10) = unit->bl.x;
  4475. WBUFW(buf,pos+12) = unit->bl.y;
  4476. switch (header) {
  4477. case 0x011f:
  4478. WBUFB(buf,pos+14) = unit_id;
  4479. WBUFB(buf,pos+15) = visible;
  4480. break;
  4481. case 0x08c7:
  4482. WBUFB(buf,pos+14) = unit_id;
  4483. WBUFW(buf,pos+15) = unit->range;
  4484. WBUFB(buf,pos+17) = visible;
  4485. break;
  4486. case 0x099f:
  4487. WBUFL(buf,pos+14) = unit_id;
  4488. WBUFW(buf,pos+18) = unit->range;
  4489. WBUFB(buf,pos+20) = visible;
  4490. break;
  4491. case 0x09ca:
  4492. WBUFL(buf,pos+14) = unit_id;
  4493. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4494. WBUFB(buf,pos+19) = visible;
  4495. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4496. break;
  4497. }
  4498. clif_send(buf, len, bl, target);
  4499. if (unit->group->skill_id == WZ_ICEWALL)
  4500. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4501. }
  4502. /*==========================================
  4503. * Server tells client to remove unit of id 'unit->bl.id'
  4504. *------------------------------------------*/
  4505. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4506. {
  4507. nullpo_retv(unit);
  4508. WFIFOHEAD(fd,packet_len(0x120));
  4509. WFIFOW(fd, 0)=0x120;
  4510. WFIFOL(fd, 2)=unit->bl.id;
  4511. WFIFOSET(fd,packet_len(0x120));
  4512. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4513. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4514. }
  4515. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4516. /// 0120 <id>.L
  4517. void clif_skill_delunit(struct skill_unit *unit)
  4518. {
  4519. unsigned char buf[16];
  4520. nullpo_retv(unit);
  4521. WBUFW(buf, 0)=0x120;
  4522. WBUFL(buf, 2)=unit->bl.id;
  4523. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4524. }
  4525. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4526. /// 01ac <id>.L
  4527. /// Only affects units with class [139,153] client-side.
  4528. void clif_skillunit_update(struct block_list* bl)
  4529. {
  4530. unsigned char buf[6];
  4531. nullpo_retv(bl);
  4532. WBUFW(buf,0) = 0x1ac;
  4533. WBUFL(buf,2) = bl->id;
  4534. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4535. }
  4536. /*==========================================
  4537. *
  4538. *------------------------------------------*/
  4539. static int clif_getareachar(struct block_list* bl,va_list ap)
  4540. {
  4541. struct map_session_data *sd;
  4542. nullpo_ret(bl);
  4543. sd=va_arg(ap,struct map_session_data*);
  4544. if (sd == NULL || !sd->fd)
  4545. return 0;
  4546. switch(bl->type){
  4547. case BL_ITEM:
  4548. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4549. break;
  4550. case BL_SKILL:
  4551. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4552. break;
  4553. default:
  4554. if(&sd->bl == bl)
  4555. break;
  4556. clif_getareachar_unit(sd,bl);
  4557. break;
  4558. }
  4559. return 0;
  4560. }
  4561. /*==========================================
  4562. * tbl has gone out of view-size of bl
  4563. *------------------------------------------*/
  4564. int clif_outsight(struct block_list *bl,va_list ap)
  4565. {
  4566. struct block_list *tbl;
  4567. struct view_data *vd;
  4568. TBL_PC *sd, *tsd;
  4569. tbl=va_arg(ap,struct block_list*);
  4570. if(bl == tbl) return 0;
  4571. sd = BL_CAST(BL_PC, bl);
  4572. tsd = BL_CAST(BL_PC, tbl);
  4573. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4574. nullpo_ret(bl);
  4575. switch(bl->type){
  4576. case BL_PC:
  4577. if(sd->vd.class_ != JT_INVISIBLE)
  4578. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4579. if(sd->chatID){
  4580. struct chat_data *cd;
  4581. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4582. if(cd->usersd[0]==sd)
  4583. clif_dispchat(cd,tsd->fd);
  4584. }
  4585. if(sd->state.vending)
  4586. clif_closevendingboard(bl,tsd->fd);
  4587. if(sd->state.buyingstore)
  4588. clif_buyingstore_disappear_entry_single(tsd, sd);
  4589. break;
  4590. case BL_ITEM:
  4591. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4592. break;
  4593. case BL_SKILL:
  4594. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4595. break;
  4596. case BL_NPC:
  4597. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4598. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4599. break;
  4600. default:
  4601. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4602. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4603. break;
  4604. }
  4605. }
  4606. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4607. nullpo_ret(tbl);
  4608. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4609. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4610. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4611. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4612. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4613. }
  4614. return 0;
  4615. }
  4616. /*==========================================
  4617. * tbl has come into view of bl
  4618. *------------------------------------------*/
  4619. int clif_insight(struct block_list *bl,va_list ap)
  4620. {
  4621. struct block_list *tbl;
  4622. TBL_PC *sd, *tsd;
  4623. tbl=va_arg(ap,struct block_list*);
  4624. if (bl == tbl) return 0;
  4625. sd = BL_CAST(BL_PC, bl);
  4626. tsd = BL_CAST(BL_PC, tbl);
  4627. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4628. switch(bl->type){
  4629. case BL_ITEM:
  4630. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4631. break;
  4632. case BL_SKILL:
  4633. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4634. break;
  4635. default:
  4636. clif_getareachar_unit(tsd,bl);
  4637. break;
  4638. }
  4639. }
  4640. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4641. clif_getareachar_unit(sd,tbl);
  4642. }
  4643. return 0;
  4644. }
  4645. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4646. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4647. void clif_skillinfoblock(struct map_session_data *sd)
  4648. {
  4649. int fd;
  4650. int i,len,id;
  4651. nullpo_retv(sd);
  4652. fd = sd->fd;
  4653. if (!fd)
  4654. return;
  4655. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4656. WFIFOW(fd,0) = 0x10f;
  4657. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4658. {
  4659. if( (id = sd->status.skill[i].id) != 0 )
  4660. {
  4661. // workaround for bugreport:5348
  4662. if (len + 37 > 8192)
  4663. break;
  4664. WFIFOW(fd,len) = id;
  4665. WFIFOL(fd,len+2) = skill_get_inf(id);
  4666. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4667. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4668. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4669. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4670. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4671. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4672. else
  4673. WFIFOB(fd,len+36) = 0;
  4674. len += 37;
  4675. }
  4676. }
  4677. WFIFOW(fd,2)=len;
  4678. WFIFOSET(fd,len);
  4679. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4680. for ( ; i < MAX_SKILL; i++)
  4681. {
  4682. if( (id = sd->status.skill[i].id) != 0 )
  4683. {
  4684. clif_addskill(sd, id);
  4685. clif_skillinfo(sd, id, 0);
  4686. }
  4687. }
  4688. }
  4689. /**
  4690. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4691. **/
  4692. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4693. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4694. void clif_addskill(struct map_session_data *sd, int skill_id)
  4695. {
  4696. int fd;
  4697. uint16 idx = 0;
  4698. nullpo_retv(sd);
  4699. fd = sd->fd;
  4700. if (!fd || !(idx = skill_get_index(skill_id)))
  4701. return;
  4702. if( sd->status.skill[idx].id <= 0 )
  4703. return;
  4704. WFIFOHEAD(fd, packet_len(0x111));
  4705. WFIFOW(fd,0) = 0x111;
  4706. WFIFOW(fd,2) = skill_id;
  4707. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4708. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4709. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4710. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4711. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4712. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4713. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4714. else
  4715. WFIFOB(fd,38) = 0;
  4716. WFIFOSET(fd,packet_len(0x111));
  4717. }
  4718. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4719. /// 0441 <skill id>.W
  4720. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4721. {
  4722. #if PACKETVER >= 20081217
  4723. int fd;
  4724. uint16 idx = 0;
  4725. nullpo_retv(sd);
  4726. fd = sd->fd;
  4727. if (!fd || !(idx = skill_get_index(skill_id)))
  4728. return;
  4729. WFIFOHEAD(fd,packet_len(0x441));
  4730. WFIFOW(fd,0) = 0x441;
  4731. WFIFOW(fd,2) = skill_id;
  4732. WFIFOSET(fd,packet_len(0x441));
  4733. #endif
  4734. clif_skillinfoblock(sd);
  4735. }
  4736. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4737. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4738. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4739. int fd;
  4740. nullpo_retv(sd);
  4741. fd = sd->fd;
  4742. WFIFOHEAD(fd, packet_len(0x10e));
  4743. WFIFOW(fd, 0) = 0x10e;
  4744. WFIFOW(fd, 2) = skill_id;
  4745. WFIFOW(fd, 4) = lv;
  4746. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4747. WFIFOW(fd, 8) = range;
  4748. WFIFOB(fd, 10) = upgradable;
  4749. WFIFOSET(fd, packet_len(0x10e));
  4750. }
  4751. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4752. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4753. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4754. {
  4755. const int fd = sd->fd;
  4756. uint16 idx = skill_get_index(skill_id);
  4757. if (!idx)
  4758. return;
  4759. WFIFOHEAD(fd,packet_len(0x7e1));
  4760. WFIFOW(fd,0) = 0x7e1;
  4761. WFIFOW(fd,2) = skill_id;
  4762. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4763. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4764. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4765. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4766. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4767. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4768. else
  4769. WFIFOB(fd,14) = 0;
  4770. WFIFOSET(fd,packet_len(0x7e1));
  4771. }
  4772. /// Notifies clients in area, that an object is about to use a skill.
  4773. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4774. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4775. /// property:
  4776. /// 0 = Yellow cast aura
  4777. /// 1 = Water elemental cast aura
  4778. /// 2 = Earth elemental cast aura
  4779. /// 3 = Fire elemental cast aura
  4780. /// 4 = Wind elemental cast aura
  4781. /// 5 = Poison elemental cast aura
  4782. /// 6 = Holy elemental cast aura
  4783. /// ? = like 0
  4784. /// is disposable:
  4785. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4786. /// 1 = no text
  4787. 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)
  4788. {
  4789. #if PACKETVER < 20091124
  4790. const int cmd = 0x13e;
  4791. #else
  4792. const int cmd = 0x7fb;
  4793. #endif
  4794. unsigned char buf[32];
  4795. WBUFW(buf,0) = cmd;
  4796. WBUFL(buf,2) = src_id;
  4797. WBUFL(buf,6) = dst_id;
  4798. WBUFW(buf,10) = dst_x;
  4799. WBUFW(buf,12) = dst_y;
  4800. WBUFW(buf,14) = skill_id;
  4801. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4802. WBUFL(buf,20) = casttime;
  4803. #if PACKETVER >= 20091124
  4804. WBUFB(buf,24) = 0; // isDisposable
  4805. #endif
  4806. if (disguised(bl)) {
  4807. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4808. WBUFL(buf,2) = -src_id;
  4809. clif_send(buf,packet_len(cmd), bl, SELF);
  4810. } else
  4811. clif_send(buf,packet_len(cmd), bl, AREA);
  4812. }
  4813. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4814. /// 01b9 <id>.L
  4815. void clif_skillcastcancel(struct block_list* bl)
  4816. {
  4817. unsigned char buf[16];
  4818. nullpo_retv(bl);
  4819. WBUFW(buf,0) = 0x1b9;
  4820. WBUFL(buf,2) = bl->id;
  4821. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4822. }
  4823. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4824. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4825. /// num (only used when skill id = NV_BASIC and cause = 0):
  4826. /// 0 = "skill failed" MsgStringTable[159]
  4827. /// 1 = "no emotions" MsgStringTable[160]
  4828. /// 2 = "no sit" MsgStringTable[161]
  4829. /// 3 = "no chat" MsgStringTable[162]
  4830. /// 4 = "no party" MsgStringTable[163]
  4831. /// 5 = "no shout" MsgStringTable[164]
  4832. /// 6 = "no PKing" MsgStringTable[165]
  4833. /// 7 = "no alligning" MsgStringTable[383]
  4834. /// ? = ignored
  4835. /// cause:
  4836. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4837. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4838. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4839. /// "skill failed" MsgStringTable[204] (otherwise)
  4840. /// ... = @see enum useskill_fail_cause
  4841. /// ? = ignored
  4842. ///
  4843. /// if(result!=0) doesn't display any of the previous messages
  4844. /// Note: when this packet is received an unknown flag is always set to 0,
  4845. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4846. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4847. {
  4848. int fd;
  4849. if (!sd) { //Since this is the most common nullpo....
  4850. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4851. return;
  4852. }
  4853. fd=sd->fd;
  4854. if (!fd) return;
  4855. if(battle_config.display_skill_fail&1)
  4856. return; //Disable all skill failed messages
  4857. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4858. return; //Disable delay failed messages
  4859. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4860. return;
  4861. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4862. return;
  4863. WFIFOHEAD(fd,packet_len(0x110));
  4864. WFIFOW(fd,0) = 0x110;
  4865. WFIFOW(fd,2) = skill_id;
  4866. WFIFOL(fd,4) = btype;
  4867. WFIFOB(fd,8) = 0;// success
  4868. WFIFOB(fd,9) = cause;
  4869. WFIFOSET(fd,packet_len(0x110));
  4870. }
  4871. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4872. /// 043d <skill ID>.W <tick>.L
  4873. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  4874. {
  4875. #if PACKETVER>=20081112
  4876. int fd;
  4877. nullpo_retv(sd);
  4878. fd=sd->fd;
  4879. WFIFOHEAD(fd,packet_len(0x43d));
  4880. WFIFOW(fd,0) = 0x43d;
  4881. WFIFOW(fd,2) = skill_id;
  4882. WFIFOL(fd,4) = client_tick(tick);
  4883. WFIFOSET(fd,packet_len(0x43d));
  4884. #endif
  4885. }
  4886. /// Skill attack effect and damage.
  4887. /// 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)
  4888. /// 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)
  4889. 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)
  4890. {
  4891. unsigned char buf[64];
  4892. struct status_change *sc;
  4893. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4894. nullpo_ret(src);
  4895. nullpo_ret(dst);
  4896. type = clif_calc_delay(type,div,damage,ddelay);
  4897. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4898. if(sc->data[SC_HALLUCINATION] && damage)
  4899. damage = clif_hallucination_damage();
  4900. }
  4901. #if PACKETVER < 3
  4902. WBUFW(buf,0)=0x114;
  4903. WBUFW(buf,2)=skill_id;
  4904. WBUFL(buf,4)=src->id;
  4905. WBUFL(buf,8)=dst->id;
  4906. WBUFL(buf,12)=client_tick(tick);
  4907. WBUFL(buf,16)=sdelay;
  4908. WBUFL(buf,20)=ddelay;
  4909. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4910. WBUFW(buf,24)=damage?div:0;
  4911. } else {
  4912. WBUFW(buf,24)=damage;
  4913. }
  4914. WBUFW(buf,26)=skill_lv;
  4915. WBUFW(buf,28)=div;
  4916. WBUFB(buf,30)=type;
  4917. if (disguised(dst)) {
  4918. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4919. WBUFL(buf,8)=-dst->id;
  4920. clif_send(buf,packet_len(0x114),dst,SELF);
  4921. } else
  4922. clif_send(buf,packet_len(0x114),dst,AREA);
  4923. if(disguised(src)) {
  4924. WBUFL(buf,4)=-src->id;
  4925. if (disguised(dst))
  4926. WBUFL(buf,8)=dst->id;
  4927. if(damage > 0)
  4928. WBUFW(buf,24)=-1;
  4929. clif_send(buf,packet_len(0x114),src,SELF);
  4930. }
  4931. #else
  4932. WBUFW(buf,0)=0x1de;
  4933. WBUFW(buf,2)=skill_id;
  4934. WBUFL(buf,4)=src->id;
  4935. WBUFL(buf,8)=dst->id;
  4936. WBUFL(buf,12)=client_tick(tick);
  4937. WBUFL(buf,16)=sdelay;
  4938. WBUFL(buf,20)=ddelay;
  4939. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4940. WBUFL(buf,24)=damage?div:0;
  4941. } else {
  4942. WBUFL(buf,24)=damage;
  4943. }
  4944. WBUFW(buf,28)=skill_lv;
  4945. WBUFW(buf,30)=div;
  4946. // For some reason, late 2013 and newer clients have
  4947. // a issue that causes players and monsters to endure
  4948. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4949. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4950. #if PACKETVER < 20131223
  4951. WBUFB(buf,32)=type;
  4952. #else
  4953. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  4954. #endif
  4955. if (disguised(dst)) {
  4956. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4957. WBUFL(buf,8)=-dst->id;
  4958. clif_send(buf,packet_len(0x1de),dst,SELF);
  4959. } else
  4960. clif_send(buf,packet_len(0x1de),dst,AREA);
  4961. if(disguised(src)) {
  4962. WBUFL(buf,4)=-src->id;
  4963. if (disguised(dst))
  4964. WBUFL(buf,8)=dst->id;
  4965. if(damage > 0)
  4966. WBUFL(buf,24)=-1;
  4967. clif_send(buf,packet_len(0x1de),src,SELF);
  4968. }
  4969. #endif
  4970. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4971. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4972. }
  4973. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4974. /// 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
  4975. /*
  4976. 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)
  4977. {
  4978. unsigned char buf[64];
  4979. struct status_change *sc;
  4980. nullpo_ret(src);
  4981. nullpo_ret(dst);
  4982. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4983. type = clif_calc_delay(type,div,damage,ddelay);
  4984. sc = status_get_sc(dst);
  4985. if(sc && sc->count) {
  4986. if(sc->data[SC_HALLUCINATION] && damage)
  4987. damage = clif_hallucination_damage();
  4988. }
  4989. WBUFW(buf,0)=0x115;
  4990. WBUFW(buf,2)=skill_id;
  4991. WBUFL(buf,4)=src->id;
  4992. WBUFL(buf,8)=dst->id;
  4993. WBUFL(buf,12)=client_tick(tick);
  4994. WBUFL(buf,16)=sdelay;
  4995. WBUFL(buf,20)=ddelay;
  4996. WBUFW(buf,24)=dst->x;
  4997. WBUFW(buf,26)=dst->y;
  4998. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4999. WBUFW(buf,28)=damage?div:0;
  5000. } else {
  5001. WBUFW(buf,28)=damage;
  5002. }
  5003. WBUFW(buf,30)=skill_lv;
  5004. WBUFW(buf,32)=div;
  5005. WBUFB(buf,34)=type;
  5006. clif_send(buf,packet_len(0x115),src,AREA);
  5007. if(disguised(src)) {
  5008. WBUFL(buf,4)=-src->id;
  5009. if(damage > 0)
  5010. WBUFW(buf,28)=-1;
  5011. clif_send(buf,packet_len(0x115),src,SELF);
  5012. }
  5013. if (disguised(dst)) {
  5014. WBUFL(buf,8)=-dst->id;
  5015. if (disguised(src))
  5016. WBUFL(buf,4)=src->id;
  5017. else if(damage > 0)
  5018. WBUFW(buf,28)=-1;
  5019. clif_send(buf,packet_len(0x115),dst,SELF);
  5020. }
  5021. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5022. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5023. }
  5024. */
  5025. /// Non-damaging skill effect
  5026. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5027. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5028. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5029. {
  5030. unsigned char buf[17];
  5031. #if PACKETVER < 20130731
  5032. const int cmd = 0x11a;
  5033. #else
  5034. const int cmd = 0x9cb;
  5035. #endif
  5036. int offset = 0;
  5037. bool success = ( tick != 0 );
  5038. nullpo_ret(dst);
  5039. WBUFW(buf,0) = cmd;
  5040. WBUFW(buf,2) = skill_id;
  5041. #if PACKETVER < 20130731
  5042. WBUFW(buf,4) = min(heal, INT16_MAX);
  5043. #else
  5044. WBUFL(buf,4) = min(heal, INT32_MAX);
  5045. offset += 2;
  5046. #endif
  5047. WBUFL(buf,6+offset) = dst->id;
  5048. WBUFL(buf,10+offset) = src ? src->id : 0;
  5049. WBUFB(buf,14+offset) = success;
  5050. if (disguised(dst)) {
  5051. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5052. WBUFL(buf,6+offset) = -dst->id;
  5053. clif_send(buf, packet_len(cmd), dst, SELF);
  5054. } else
  5055. clif_send(buf, packet_len(cmd), dst, AREA);
  5056. if(src && disguised(src)) {
  5057. WBUFL(buf,10+offset) = -src->id;
  5058. if (disguised(dst))
  5059. WBUFL(buf,6+offset) = dst->id;
  5060. clif_send(buf, packet_len(cmd), src, SELF);
  5061. }
  5062. return success;
  5063. }
  5064. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5065. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5066. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5067. {
  5068. unsigned char buf[32];
  5069. nullpo_retv(src);
  5070. WBUFW(buf,0)=0x117;
  5071. WBUFW(buf,2)=skill_id;
  5072. WBUFL(buf,4)=src->id;
  5073. WBUFW(buf,8)=val;
  5074. WBUFW(buf,10)=x;
  5075. WBUFW(buf,12)=y;
  5076. WBUFL(buf,14)=client_tick(tick);
  5077. if(disguised(src)) {
  5078. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5079. WBUFL(buf,4)=-src->id;
  5080. clif_send(buf,packet_len(0x117),src,SELF);
  5081. } else
  5082. clif_send(buf,packet_len(0x117),src,AREA);
  5083. }
  5084. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5085. /// 011c <skill id>.W { <map name>.16B }*4
  5086. 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)
  5087. {
  5088. int fd;
  5089. nullpo_retv(sd);
  5090. fd = sd->fd;
  5091. WFIFOHEAD(fd,packet_len(0x11c));
  5092. WFIFOW(fd,0) = 0x11c;
  5093. WFIFOW(fd,2) = skill_id;
  5094. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5095. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5096. else // normal map name
  5097. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5098. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5099. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5100. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5101. WFIFOSET(fd,packet_len(0x11c));
  5102. sd->menuskill_id = skill_id;
  5103. if (skill_id == AL_WARP) {
  5104. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5105. sd->state.workinprogress = WIP_DISABLE_ALL;
  5106. } else
  5107. sd->menuskill_val = skill_lv;
  5108. }
  5109. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5110. /// 011e <type>.B
  5111. /// type:
  5112. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5113. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5114. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5115. ///
  5116. /// @param sd Who receives the message
  5117. /// @param type What message
  5118. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5119. {
  5120. int fd;
  5121. nullpo_retv(sd);
  5122. fd=sd->fd;
  5123. WFIFOHEAD(fd,packet_len(0x11e));
  5124. WFIFOW(fd,0)=0x11e;
  5125. WFIFOB(fd,2)=type;
  5126. WFIFOSET(fd,packet_len(0x11e));
  5127. }
  5128. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5129. /// 0189 <type>.W
  5130. /// type:
  5131. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5132. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5133. ///
  5134. /// @param sd Who receives the message
  5135. /// @param type What message
  5136. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5137. {
  5138. int fd;
  5139. nullpo_retv(sd);
  5140. fd=sd->fd;
  5141. WFIFOHEAD(fd,packet_len(0x189));
  5142. WFIFOW(fd,0)=0x189;
  5143. WFIFOW(fd,2)=type;
  5144. WFIFOSET(fd,packet_len(0x189));
  5145. }
  5146. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5147. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5148. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5149. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5150. {
  5151. struct status_data *status;
  5152. unsigned char buf[64];
  5153. int i, fix;
  5154. nullpo_retv(sd);
  5155. nullpo_retv(dst);
  5156. if( dst->type != BL_MOB )
  5157. return;
  5158. status = status_get_status_data(dst);
  5159. WBUFW(buf, 0)=0x18c;
  5160. WBUFW(buf, 2)=status_get_class(dst);
  5161. WBUFW(buf, 4)=status_get_lv(dst);
  5162. WBUFW(buf, 6)=status->size;
  5163. WBUFL(buf, 8)=status->hp;
  5164. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5165. +(battle_config.estimation_type&2?status->def2:0);
  5166. WBUFW(buf,14)=status->race;
  5167. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5168. +(battle_config.estimation_type&2?status->mdef2:0);
  5169. WBUFW(buf,18)= status->def_ele;
  5170. for(i=0;i<9;i++)
  5171. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5172. WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5173. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5174. }
  5175. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5176. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5177. /// material id:
  5178. /// unused by the client
  5179. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5180. {
  5181. int i,c,view,fd;
  5182. nullpo_retv(sd);
  5183. if (sd->menuskill_id == skill_id)
  5184. return; //Avoid resending the menu twice or more times...
  5185. if (skill_id == GC_CREATENEWPOISON)
  5186. skill_id = GC_RESEARCHNEWPOISON;
  5187. fd = sd->fd;
  5188. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5189. WFIFOW(fd, 0) = 0x18d;
  5190. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5191. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5192. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5193. )
  5194. {
  5195. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5196. WFIFOW(fd,c*8+ 4) = view;
  5197. else
  5198. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5199. WFIFOW(fd,c*8+ 6) = 0;
  5200. WFIFOW(fd,c*8+ 8) = 0;
  5201. WFIFOW(fd,c*8+10) = 0;
  5202. c++;
  5203. }
  5204. }
  5205. WFIFOW(fd, 2) = c*8+8;
  5206. WFIFOSET(fd,WFIFOW(fd,2));
  5207. if (c > 0) {
  5208. sd->menuskill_id = skill_id;
  5209. sd->menuskill_val = trigger;
  5210. return;
  5211. }
  5212. }
  5213. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5214. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5215. /// mk type:
  5216. /// 1 = cooking
  5217. /// 2 = arrow
  5218. /// 3 = elemental
  5219. /// 4 = GN_MIX_COOKING
  5220. /// 5 = GN_MAKEBOMB
  5221. /// 6 = GN_S_PHARMACY
  5222. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5223. {
  5224. int fd;
  5225. int i, c;
  5226. int view;
  5227. nullpo_retv(sd);
  5228. fd = sd->fd;
  5229. if(sd->menuskill_id == skill_id)
  5230. return; //Avoid resending the menu twice or more times...
  5231. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5232. WFIFOW(fd,0) = 0x25a;
  5233. WFIFOW(fd,4) = list_type; // list type
  5234. c = 0;
  5235. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5236. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5237. continue;
  5238. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5239. WFIFOW(fd, 6 + 2 * c) = view;
  5240. else
  5241. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5242. c++;
  5243. }
  5244. if( c > 0 || skill_id == AM_PHARMACY) {
  5245. sd->menuskill_id = skill_id;
  5246. sd->menuskill_val = trigger;
  5247. sd->menuskill_val2 = qty; // amount.
  5248. WFIFOW(fd,2) = 6 + 2 * c;
  5249. WFIFOSET(fd,WFIFOW(fd,2));
  5250. } else {
  5251. clif_menuskill_clear(sd);
  5252. #if PACKETVER >= 20090922
  5253. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5254. #else
  5255. WFIFOW(fd,2) = 6 + 2 * c;
  5256. WFIFOSET(fd,WFIFOW(fd,2));
  5257. #endif
  5258. }
  5259. }
  5260. /// Notifies clients of a status change.
  5261. /// 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)]
  5262. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5263. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5264. /// @param bl Sends packet to clients around this object
  5265. /// @param id ID of object that has this effect
  5266. /// @param type Status icon see enum efst_types
  5267. /// @param flag 1:Active, 0:Deactive
  5268. /// @param tick Duration in ms
  5269. /// @param val1
  5270. /// @param val2
  5271. /// @param val3
  5272. 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)
  5273. {
  5274. unsigned char buf[32];
  5275. if (type == EFST_BLANK) //It shows nothing on the client...
  5276. return;
  5277. if (type == EFST_POSTDELAY && tick == 0)
  5278. return;
  5279. nullpo_retv(bl);
  5280. #if PACKETVER >= 20120618
  5281. if (flag && battle_config.display_status_timers)
  5282. WBUFW(buf,0) = 0x983;
  5283. else
  5284. #elif PACKETVER >= 20090121
  5285. if (flag && battle_config.display_status_timers)
  5286. WBUFW(buf,0) = 0x43f;
  5287. else
  5288. #endif
  5289. WBUFW(buf,0) = 0x196;
  5290. WBUFW(buf,2) = type;
  5291. WBUFL(buf,4) = id;
  5292. WBUFB(buf,8) = flag;
  5293. #if PACKETVER >= 20120618
  5294. if (flag && battle_config.display_status_timers) {
  5295. if (tick <= 0)
  5296. tick = 9999; // this is indeed what official servers do
  5297. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5298. WBUFL(buf,13) = client_tick(tick);
  5299. WBUFL(buf,17) = val1;
  5300. WBUFL(buf,21) = val2;
  5301. WBUFL(buf,25) = val3;
  5302. }
  5303. #elif PACKETVER >= 20090121
  5304. if (flag && battle_config.display_status_timers) {
  5305. if (tick <= 0)
  5306. tick = 9999; // this is indeed what official servers do
  5307. WBUFL(buf,9) = client_tick(tick);
  5308. WBUFL(buf,13) = val1;
  5309. WBUFL(buf,17) = val2;
  5310. WBUFL(buf,21) = val3;
  5311. }
  5312. #endif
  5313. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5314. }
  5315. /* Sends status effect to clients around the bl
  5316. * @param bl Object that has the effect
  5317. * @param type Status icon see enum efst_types
  5318. * @param flag 1:Active, 0:Deactive
  5319. * @param tick Duration in ms
  5320. * @param val1
  5321. * @param val2
  5322. * @param val3
  5323. */
  5324. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5325. struct map_session_data *sd = NULL;
  5326. if (type == EFST_BLANK) //It shows nothing on the client...
  5327. return;
  5328. if (type == EFST_POSTDELAY && tick == 0)
  5329. return;
  5330. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5331. return;
  5332. nullpo_retv(bl);
  5333. sd = BL_CAST(BL_PC, bl);
  5334. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5335. return;
  5336. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5337. }
  5338. /**
  5339. * Send any active EFST to those around.
  5340. * @param tbl: Unit to send the packet to
  5341. * @param bl: Objects walking into view
  5342. * @param target: Client send type
  5343. */
  5344. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5345. unsigned char i;
  5346. struct sc_display_entry **sc_display;
  5347. unsigned char sc_display_count;
  5348. bool spheres_sent;
  5349. nullpo_retv(bl);
  5350. switch( bl->type ){
  5351. case BL_PC: {
  5352. struct map_session_data* sd = (struct map_session_data*)bl;
  5353. sc_display = sd->sc_display;
  5354. sc_display_count = sd->sc_display_count;
  5355. spheres_sent = !sd->state.connect_new;
  5356. }
  5357. break;
  5358. case BL_NPC: {
  5359. struct npc_data* nd = (struct npc_data*)bl;
  5360. sc_display = nd->sc_display;
  5361. sc_display_count = nd->sc_display_count;
  5362. spheres_sent = true;
  5363. }
  5364. break;
  5365. default:
  5366. return;
  5367. }
  5368. for (i = 0; i < sc_display_count; i++) {
  5369. enum sc_type type = sc_display[i]->type;
  5370. struct status_change *sc = status_get_sc(bl);
  5371. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5372. t_tick tick = 0;
  5373. if (td)
  5374. tick = DIFF_TICK(td->tick, gettick());
  5375. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5376. #if PACKETVER > 20120418
  5377. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5378. #else
  5379. 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);
  5380. #endif
  5381. }else{
  5382. #if PACKETVER > 20120418
  5383. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5384. #else
  5385. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5386. #endif
  5387. }
  5388. }
  5389. }
  5390. /// Notifies the client when a player enters the screen with an active EFST.
  5391. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5392. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5393. 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) {
  5394. #if PACKETVER >= 20111108
  5395. unsigned char buf[32];
  5396. #if PACKETVER >= 20120618
  5397. const int cmd = 0x984;
  5398. #elif PACKETVER >= 20111108
  5399. const int cmd = 0x8ff;
  5400. #endif
  5401. int offset = 0;
  5402. if (type == EFST_BLANK)
  5403. return;
  5404. nullpo_retv(bl);
  5405. if (tick <= 0)
  5406. tick = 9999;
  5407. WBUFW(buf,offset + 0) = cmd;
  5408. WBUFL(buf,offset + 2) = tid;
  5409. WBUFW(buf,offset + 6) = type;
  5410. #if PACKETVER >= 20111108
  5411. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5412. #if PACKETVER >= 20120618
  5413. WBUFL(buf,offset + 12) = client_tick(tick);
  5414. offset += 4;
  5415. #endif
  5416. WBUFL(buf,offset + 12) = val1;
  5417. WBUFL(buf,offset + 16) = val2;
  5418. WBUFL(buf,offset + 20) = val3;
  5419. #endif
  5420. clif_send(buf,packet_len(cmd),bl,target);
  5421. #endif
  5422. }
  5423. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5424. /// 008e <packet len>.W <message>.?B
  5425. void clif_displaymessage(const int fd, const char* mes)
  5426. {
  5427. nullpo_retv(mes);
  5428. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5429. if (fd == 0)
  5430. ;
  5431. else {
  5432. char *message, *line;
  5433. message = aStrdup(mes);
  5434. line = strtok(message, "\n");
  5435. while(line != NULL) {
  5436. #if PACKETVER == 20141022
  5437. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5438. /** so we redirect to ZC_NPC_CHAT **/
  5439. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5440. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5441. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5442. if (len > 0) {
  5443. WFIFOHEAD(fd, 13 + len);
  5444. WFIFOW(fd, 0) = 0x2C1;
  5445. WFIFOW(fd, 2) = 13 + len;
  5446. WFIFOL(fd, 4) = 0;
  5447. WFIFOL(fd, 8) = color;
  5448. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5449. WFIFOSET(fd, WFIFOW(fd, 2));
  5450. }
  5451. #else
  5452. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5453. int len = strnlen(line, CHAT_SIZE_MAX);
  5454. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5455. WFIFOHEAD(fd, 5 + len);
  5456. WFIFOW(fd,0) = 0x8e;
  5457. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5458. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5459. WFIFOSET(fd, 5 + len);
  5460. }
  5461. #endif
  5462. line = strtok(NULL, "\n");
  5463. }
  5464. aFree(message);
  5465. }
  5466. }
  5467. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5468. /// 009a <packet len>.W <message>.?B
  5469. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5470. {
  5471. nullpo_retv(mes);
  5472. if (len < 2)
  5473. return;
  5474. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5475. std::unique_ptr<unsigned char> buf(new unsigned char[4+lp+len]);
  5476. WBUFW(buf.get(),0) = 0x9a;
  5477. WBUFW(buf.get(),2) = 4 + lp + len;
  5478. if (type&BC_BLUE)
  5479. 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.
  5480. else if (type&BC_WOE)
  5481. WBUFL(buf.get(),4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5482. memcpy(WBUFP(buf.get(), 4 + lp), mes, len);
  5483. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5484. }
  5485. /*==========================================
  5486. * Displays a message on a 'bl' to all it's nearby clients
  5487. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5488. *------------------------------------------*/
  5489. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5490. size_t len;
  5491. nullpo_retv(bl);
  5492. if(!message)
  5493. return;
  5494. len = strlen(message)+1;
  5495. static_assert(CHAT_SIZE_MAX > 8, "CHAT_SIZE_MAX too small for packet");
  5496. if( len > CHAT_SIZE_MAX ) {
  5497. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  5498. len = CHAT_SIZE_MAX;
  5499. }
  5500. std::unique_ptr<char> buf(new char[8+len]);
  5501. WBUFW(buf.get(),0)=0x8d;
  5502. WBUFW(buf.get(),2)=static_cast<uint16>(len+8);
  5503. WBUFL(buf.get(),4)=bl->id;
  5504. safestrncpy(WBUFCP(buf.get(),8),message,len);
  5505. clif_send((unsigned char *)buf.get(),WBUFW(buf.get(),2),bl,target);
  5506. }
  5507. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5508. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5509. 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)
  5510. {
  5511. nullpo_retv(mes);
  5512. if (len < 2)
  5513. return;
  5514. std::unique_ptr<unsigned char> buf(new unsigned char[16+len]);
  5515. WBUFW(buf.get(),0) = 0x1c3;
  5516. WBUFW(buf.get(),2) = len + 16;
  5517. WBUFL(buf.get(),4) = fontColor;
  5518. WBUFW(buf.get(),8) = fontType;
  5519. WBUFW(buf.get(),10) = fontSize;
  5520. WBUFW(buf.get(),12) = fontAlign;
  5521. WBUFW(buf.get(),14) = fontY;
  5522. memcpy(WBUFP(buf.get(),16), mes, len);
  5523. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5524. }
  5525. /*
  5526. * Display *msg to all *users in channel
  5527. */
  5528. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5529. DBIterator *iter;
  5530. struct map_session_data *user;
  5531. unsigned short msg_len = 0, len = 0;
  5532. unsigned char buf[CHAT_SIZE_MAX];
  5533. if (!channel || !msg)
  5534. return;
  5535. msg_len = (unsigned short)(strlen(msg) + 1);
  5536. if( msg_len > sizeof(buf)-12 ) {
  5537. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5538. msg_len = sizeof(buf)-12;
  5539. }
  5540. WBUFW(buf,0) = 0x2C1;
  5541. WBUFW(buf,2) = (len = msg_len + 12);
  5542. WBUFL(buf,4) = 0;
  5543. WBUFL(buf,8) = color;
  5544. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5545. iter = db_iterator(channel->users);
  5546. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5547. clif_send(buf, len, &user->bl, SELF);
  5548. }
  5549. dbi_destroy(iter);
  5550. }
  5551. /// Displays heal effect.
  5552. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5553. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5554. /// var id:
  5555. /// 5 = HP (SP_HP)
  5556. /// 7 = SP (SP_SP)
  5557. /// ? = ignored
  5558. void clif_heal(int fd,int type,int val) {
  5559. #if PACKETVER < 20141022
  5560. const int cmd = 0x13d;
  5561. #else
  5562. const int cmd = 0xa27;
  5563. #endif
  5564. WFIFOHEAD(fd, packet_len(cmd));
  5565. WFIFOW(fd,0) = cmd;
  5566. WFIFOW(fd,2) = type;
  5567. #if PACKETVER < 20141022
  5568. WFIFOW(fd,4) = min(val, INT16_MAX);
  5569. #else
  5570. WFIFOL(fd,4) = min(val, INT32_MAX);
  5571. #endif
  5572. WFIFOSET(fd, packet_len(cmd));
  5573. }
  5574. /// Displays resurrection effect (ZC_RESURRECTION).
  5575. /// 0148 <id>.L <type>.W
  5576. /// type:
  5577. /// ignored
  5578. void clif_resurrection(struct block_list *bl,int type)
  5579. {
  5580. unsigned char buf[16];
  5581. nullpo_retv(bl);
  5582. WBUFW(buf,0)=0x148;
  5583. WBUFL(buf,2)=bl->id;
  5584. WBUFW(buf,6)=0;
  5585. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5586. if (disguised(bl))
  5587. clif_spawn(bl);
  5588. }
  5589. /// Sets the map property
  5590. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5591. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5592. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5593. {
  5594. #if PACKETVER >= 20121010
  5595. short cmd = 0x99b;
  5596. unsigned char buf[8];
  5597. #else
  5598. short cmd = 0x199;
  5599. unsigned char buf[4];
  5600. #endif
  5601. WBUFW(buf,0)=cmd;
  5602. WBUFW(buf,2)=property;
  5603. #if PACKETVER >= 20121010
  5604. struct map_data *mapdata = map_getmapdata(bl->m);
  5605. WBUFL(buf,4) = ((mapdata->flag[MF_PVP]?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5606. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5607. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5608. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5609. ((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
  5610. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5611. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5612. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5613. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5614. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5615. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5616. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5617. #endif
  5618. clif_send(buf,packet_len(cmd),bl,t);
  5619. }
  5620. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5621. /// 01d6 <type>.W
  5622. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5623. {
  5624. int fd;
  5625. nullpo_retv(sd);
  5626. fd=sd->fd;
  5627. WFIFOHEAD(fd,packet_len(0x1D6));
  5628. WFIFOW(fd,0)=0x1D6;
  5629. WFIFOW(fd,2)=type;
  5630. WFIFOSET(fd,packet_len(0x1D6));
  5631. }
  5632. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5633. /// 019a <id>.L <ranking>.L <total>.L
  5634. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5635. {
  5636. if(type == 2) {
  5637. int fd = sd->fd;
  5638. WFIFOHEAD(fd,packet_len(0x19a));
  5639. WFIFOW(fd,0) = 0x19a;
  5640. WFIFOL(fd,2) = sd->bl.id;
  5641. WFIFOL(fd,6) = pvprank;
  5642. WFIFOL(fd,10) = pvpnum;
  5643. WFIFOSET(fd,packet_len(0x19a));
  5644. } else {
  5645. unsigned char buf[32];
  5646. WBUFW(buf,0) = 0x19a;
  5647. WBUFL(buf,2) = sd->bl.id;
  5648. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5649. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5650. else
  5651. WBUFL(buf,6) = pvprank;
  5652. WBUFL(buf,10) = pvpnum;
  5653. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5654. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5655. else if(!type)
  5656. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5657. else
  5658. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5659. }
  5660. }
  5661. /*==========================================
  5662. *
  5663. *------------------------------------------*/
  5664. void clif_map_property_mapall(int map_idx, enum map_property property)
  5665. {
  5666. struct block_list bl;
  5667. bl.id = 0;
  5668. bl.type = BL_NUL;
  5669. bl.m = map_idx;
  5670. clif_map_property( &bl, property, ALL_SAMEMAP );
  5671. }
  5672. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5673. /// 0188 <result>.W <index>.W <refine>.W
  5674. /// result:
  5675. /// 0 = success
  5676. /// 1 = failure
  5677. /// 2 = downgrade
  5678. void clif_refine(int fd, int fail, int index, int val)
  5679. {
  5680. WFIFOHEAD(fd,packet_len(0x188));
  5681. WFIFOW(fd,0)=0x188;
  5682. WFIFOW(fd,2)=fail;
  5683. WFIFOW(fd,4)=index+2;
  5684. WFIFOW(fd,6)=val;
  5685. WFIFOSET(fd,packet_len(0x188));
  5686. }
  5687. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5688. /// 0223 <result>.L <nameid>.W
  5689. /// result:
  5690. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5691. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5692. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5693. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5694. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5695. {
  5696. WFIFOHEAD(fd,packet_len(0x223));
  5697. WFIFOW(fd,0)=0x223;
  5698. WFIFOL(fd,2)=result;
  5699. WFIFOW(fd,6)=item_id;
  5700. WFIFOSET(fd,packet_len(0x223));
  5701. }
  5702. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5703. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5704. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5705. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5706. int fd;
  5707. nullpo_retv(sd);
  5708. fd = sd->fd;
  5709. #if PACKETVER < 20091104
  5710. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5711. WFIFOW(fd,0) = 0x97;
  5712. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5713. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5714. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5715. WFIFOSET(fd,WFIFOW(fd,2));
  5716. #else
  5717. struct map_session_data *ssd = map_nick2sd(nick,false);
  5718. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5719. WFIFOW(fd,0) = 0x97;
  5720. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5721. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5722. // If it is not a message from the server or a player from another map-server
  5723. if( ssd ){
  5724. gmlvl = pc_get_group_level(ssd);
  5725. }
  5726. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5727. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5728. WFIFOSET(fd,WFIFOW(fd,2));
  5729. #endif
  5730. }
  5731. /// Inform the player about the result of his whisper action
  5732. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5733. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5734. /// result:
  5735. /// 0 = success to send wisper
  5736. /// 1 = target character is not loged in
  5737. /// 2 = ignored by target
  5738. /// 3 = everyone ignored by target
  5739. void clif_wis_end(int fd, int result)
  5740. {
  5741. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5742. #if PACKETVER < 20131223
  5743. const int cmd = 0x98;
  5744. #else
  5745. const int cmd = 0x9df;
  5746. #endif
  5747. if (!sd)
  5748. return;
  5749. WFIFOHEAD(fd,packet_len(cmd));
  5750. WFIFOW(fd,0) = cmd;
  5751. WFIFOB(fd,2) = (char)result;
  5752. #if PACKETVER >= 20131223
  5753. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5754. #endif
  5755. WFIFOSET(fd,packet_len(cmd));
  5756. }
  5757. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5758. /// 0194 <char id>.L <name>.24B
  5759. /// 0af7 <flag>.W <char id>.L <name>.24B
  5760. void clif_solved_charname(int fd, int charid, const char* name)
  5761. {
  5762. #if PACKETVER >= 20180221
  5763. WFIFOHEAD(fd,packet_len(0xaf7));
  5764. WFIFOW(fd,0) = 0xaf7;
  5765. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5766. WFIFOL(fd,4) = charid;
  5767. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5768. WFIFOSET(fd,packet_len(0x0af7));
  5769. #else
  5770. WFIFOHEAD(fd,packet_len(0x194));
  5771. WFIFOW(fd,0)=0x194;
  5772. WFIFOL(fd,2)=charid;
  5773. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5774. WFIFOSET(fd,packet_len(0x194));
  5775. #endif
  5776. }
  5777. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5778. /// 017b <packet len>.W { <name id>.W }*
  5779. void clif_use_card(struct map_session_data *sd,int idx)
  5780. {
  5781. int i,c,ep;
  5782. int fd=sd->fd;
  5783. nullpo_retv(sd);
  5784. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5785. return;
  5786. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5787. return; //Avoid parsing invalid item indexes (no card/no item)
  5788. ep=sd->inventory_data[idx]->equip;
  5789. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5790. WFIFOW(fd,0)=0x17b;
  5791. for(i=c=0;i<MAX_INVENTORY;i++){
  5792. int j;
  5793. if(sd->inventory_data[i] == NULL)
  5794. continue;
  5795. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5796. continue;
  5797. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5798. continue;
  5799. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5800. continue;
  5801. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5802. continue;
  5803. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5804. continue;
  5805. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5806. if( j == sd->inventory_data[i]->slot ) // No room
  5807. continue;
  5808. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5809. continue;
  5810. WFIFOW(fd,4+c*2)=i+2;
  5811. c++;
  5812. }
  5813. if( !c ) return; // no item is available for card insertion
  5814. WFIFOW(fd,2)=4+c*2;
  5815. WFIFOSET(fd,WFIFOW(fd,2));
  5816. }
  5817. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5818. /// 017d <equip index>.W <card index>.W <result>.B
  5819. /// result:
  5820. /// 0 = success
  5821. /// 1 = failure
  5822. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5823. {
  5824. int fd;
  5825. nullpo_retv(sd);
  5826. fd=sd->fd;
  5827. WFIFOHEAD(fd,packet_len(0x17d));
  5828. WFIFOW(fd,0)=0x17d;
  5829. WFIFOW(fd,2)=idx_equip+2;
  5830. WFIFOW(fd,4)=idx_card+2;
  5831. WFIFOB(fd,6)=flag;
  5832. WFIFOSET(fd,packet_len(0x17d));
  5833. }
  5834. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5835. /// 0177 <packet len>.W { <name id>.W }*
  5836. void clif_item_identify_list(struct map_session_data *sd)
  5837. {
  5838. int i,c;
  5839. int fd;
  5840. nullpo_retv(sd);
  5841. fd=sd->fd;
  5842. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5843. WFIFOW(fd,0)=0x177;
  5844. for(i=c=0;i<MAX_INVENTORY;i++){
  5845. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5846. WFIFOW(fd,c*2+4)=i+2;
  5847. c++;
  5848. }
  5849. }
  5850. if(c > 0) {
  5851. WFIFOW(fd,2)=c*2+4;
  5852. WFIFOSET(fd,WFIFOW(fd,2));
  5853. sd->menuskill_id = MC_IDENTIFY;
  5854. sd->menuskill_val = c;
  5855. sd->state.workinprogress = WIP_DISABLE_ALL;
  5856. }
  5857. }
  5858. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5859. /// 0179 <index>.W <result>.B
  5860. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5861. {
  5862. int fd;
  5863. nullpo_retv(sd);
  5864. fd=sd->fd;
  5865. WFIFOHEAD(fd,packet_len(0x179));
  5866. WFIFOW(fd, 0)=0x179;
  5867. WFIFOW(fd, 2)=idx+2;
  5868. WFIFOB(fd, 4)=flag;
  5869. WFIFOSET(fd,packet_len(0x179));
  5870. }
  5871. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5872. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5873. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5874. {
  5875. int i,c;
  5876. int fd;
  5877. nullpo_retv(sd);
  5878. nullpo_retv(dstsd);
  5879. fd=sd->fd;
  5880. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5881. WFIFOW(fd,0)=0x1fc;
  5882. for(i=c=0;i<MAX_INVENTORY;i++){
  5883. unsigned short nameid;
  5884. if((nameid=dstsd->inventory.u.items_inventory[i].nameid) > 0 && dstsd->inventory.u.items_inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5885. WFIFOW(fd,c*13+4) = i;
  5886. WFIFOW(fd,c*13+6) = nameid;
  5887. WFIFOB(fd,c*13+8) = dstsd->inventory.u.items_inventory[i].refine;
  5888. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->inventory.u.items_inventory[i]);
  5889. c++;
  5890. }
  5891. }
  5892. if(c > 0) {
  5893. WFIFOW(fd,2)=c*13+4;
  5894. WFIFOSET(fd,WFIFOW(fd,2));
  5895. sd->menuskill_id = BS_REPAIRWEAPON;
  5896. sd->menuskill_val = dstsd->bl.id;
  5897. sd->menuskill_val2 = lv;
  5898. }else
  5899. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5900. }
  5901. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5902. /// 01fe <index>.W <result>.B
  5903. /// index:
  5904. /// ignored (inventory index)
  5905. /// result:
  5906. /// 0 = Item repair success.
  5907. /// 1 = Item repair failure.
  5908. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5909. {
  5910. int fd;
  5911. nullpo_retv(sd);
  5912. fd = sd->fd;
  5913. WFIFOHEAD(fd,packet_len(0x1fe));
  5914. WFIFOW(fd, 0)=0x1fe;
  5915. WFIFOW(fd, 2)=idx+2;
  5916. WFIFOB(fd, 4)=flag;
  5917. WFIFOSET(fd,packet_len(0x1fe));
  5918. }
  5919. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5920. /// 02bb <equip location>.W <account id>.L
  5921. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5922. {
  5923. int fd = sd->fd;
  5924. WFIFOHEAD(fd,packet_len(0x2bb));
  5925. WFIFOW(fd,0) = 0x2bb;
  5926. WFIFOW(fd,2) = position;
  5927. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5928. WFIFOSET(fd,packet_len(0x2bb));
  5929. }
  5930. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5931. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5932. void clif_item_refine_list(struct map_session_data *sd)
  5933. {
  5934. int i,c;
  5935. int fd;
  5936. uint16 skill_lv;
  5937. int refine_item[5];
  5938. nullpo_retv(sd);
  5939. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5940. fd=sd->fd;
  5941. refine_item[0] = -1;
  5942. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5943. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5944. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5945. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5946. WFIFOW(fd,0) = 0x221;
  5947. for(i = c = 0; i < MAX_INVENTORY; i++) {
  5948. unsigned char wlv;
  5949. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5950. sd->inventory.u.items_inventory[i].identify && (wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid)) >=1 &&
  5951. refine_item[wlv] != -1 && !(sd->inventory.u.items_inventory[i].equip&EQP_ARMS)){
  5952. WFIFOW(fd,c*13+ 4)=i+2;
  5953. WFIFOW(fd,c*13+ 6) = sd->inventory.u.items_inventory[i].nameid;
  5954. WFIFOB(fd,c*13+ 8) = sd->inventory.u.items_inventory[i].refine;
  5955. clif_addcards(WFIFOP(fd,c*13+9), &sd->inventory.u.items_inventory[i]);
  5956. c++;
  5957. }
  5958. }
  5959. WFIFOW(fd,2)=c*13+4;
  5960. WFIFOSET(fd,WFIFOW(fd,2));
  5961. if (c > 0) {
  5962. sd->menuskill_id = WS_WEAPONREFINE;
  5963. sd->menuskill_val = skill_lv;
  5964. }
  5965. }
  5966. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5967. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5968. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5969. {
  5970. int fd;
  5971. nullpo_retv(sd);
  5972. fd=sd->fd;
  5973. WFIFOHEAD(fd,packet_len(0x147));
  5974. WFIFOW(fd, 0)=0x147;
  5975. WFIFOW(fd, 2)=skill_id;
  5976. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5977. WFIFOW(fd, 6)=0;
  5978. WFIFOW(fd, 8)=skill_lv;
  5979. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5980. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5981. safestrncpy(WFIFOCP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5982. WFIFOB(fd,38)=0;
  5983. WFIFOSET(fd,packet_len(0x147));
  5984. }
  5985. /// Adds an item to character's cart.
  5986. /// 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)
  5987. /// 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)
  5988. /// 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)
  5989. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5990. {
  5991. #if PACKETVER < 5
  5992. const int cmd = 0x124;
  5993. #elif PACKETVER < 20150225
  5994. const int cmd = 0x1c5;
  5995. #else
  5996. const int cmd = 0xa0b;
  5997. #endif
  5998. int view,fd;
  5999. unsigned char *buf;
  6000. int offset = 0;
  6001. nullpo_retv(sd);
  6002. fd=sd->fd;
  6003. if(n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0)
  6004. return;
  6005. WFIFOHEAD(fd,packet_len(cmd));
  6006. buf=WFIFOP(fd,0);
  6007. WBUFW(buf,0)=cmd;
  6008. WBUFW(buf,2)=n+2;
  6009. WBUFL(buf,4)=amount;
  6010. if((view = itemdb_viewid(sd->cart.u.items_cart[n].nameid)) > 0)
  6011. WBUFW(buf,8)=view;
  6012. else
  6013. WBUFW(buf,8)=sd->cart.u.items_cart[n].nameid;
  6014. #if PACKETVER >= 5
  6015. WBUFB(buf,10)=itemdb_type(sd->cart.u.items_cart[n].nameid);
  6016. offset += 1;
  6017. #endif
  6018. WBUFB(buf,10+offset)=sd->cart.u.items_cart[n].identify;
  6019. WBUFB(buf,11+offset)=sd->cart.u.items_cart[n].attribute;
  6020. WBUFB(buf,12+offset)=sd->cart.u.items_cart[n].refine;
  6021. clif_addcards(WBUFP(buf,13+offset), &sd->cart.u.items_cart[n]);
  6022. #if PACKETVER >= 20150225
  6023. clif_add_random_options(WBUFP(buf,21+offset), &sd->cart.u.items_cart[n]);
  6024. #endif
  6025. WFIFOSET(fd,packet_len(cmd));
  6026. }
  6027. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6028. /* Acknowledge an item have been added to cart
  6029. * 012c <result>B
  6030. * result :
  6031. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6032. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6033. */
  6034. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6035. {
  6036. int fd;
  6037. unsigned char *buf;
  6038. nullpo_retv(sd);
  6039. fd = sd->fd;
  6040. buf = WFIFOP(fd,0);
  6041. WBUFW(buf,0) = 0x12c;
  6042. WBUFB(buf,2) = flag;
  6043. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6044. }
  6045. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6046. void clif_bank_open(struct map_session_data *sd){
  6047. int fd;
  6048. nullpo_retv(sd);
  6049. fd = sd->fd;
  6050. WFIFOHEAD(fd,4);
  6051. WFIFOW(fd,0) = 0x09b7;
  6052. WFIFOW(fd,2) = 0;
  6053. WFIFOSET(fd,4);
  6054. }
  6055. /*
  6056. * Request to Open the banking system
  6057. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6058. */
  6059. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6060. //TODO check if preventing trade or stuff like that
  6061. //also mark something in case char ain't available for saving, should we check now ?
  6062. nullpo_retv(sd);
  6063. if( !battle_config.feature_banking ) {
  6064. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6065. return;
  6066. }
  6067. else {
  6068. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6069. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6070. if(sd->status.account_id == aid){
  6071. sd->state.banking = 1;
  6072. //request save ?
  6073. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6074. //on succes open bank ?
  6075. clif_bank_open(sd);
  6076. }
  6077. }
  6078. }
  6079. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6080. void clif_bank_close(struct map_session_data *sd){
  6081. int fd;
  6082. nullpo_retv(sd);
  6083. fd = sd->fd;
  6084. WFIFOHEAD(fd,4);
  6085. WFIFOW(fd,0) = 0x09B9;
  6086. WFIFOW(fd,2) = 0;
  6087. WFIFOSET(fd,4);
  6088. }
  6089. /*
  6090. * Request to close the banking system
  6091. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6092. */
  6093. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6094. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6095. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6096. nullpo_retv(sd);
  6097. if( !battle_config.feature_banking ) {
  6098. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6099. //still allow to go trough to not stuck player if we have disable it while they was in
  6100. }
  6101. if(sd->status.account_id == aid){
  6102. sd->state.banking = 0;
  6103. clif_bank_close(sd);
  6104. }
  6105. }
  6106. /*
  6107. * Display how much we got in bank (I suppose)
  6108. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6109. */
  6110. void clif_Bank_Check(struct map_session_data* sd) {
  6111. unsigned char buf[13];
  6112. struct s_packet_db* info;
  6113. int16 len;
  6114. int cmd = 0;
  6115. nullpo_retv(sd);
  6116. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6117. if(!cmd) cmd = 0x09A6; //default
  6118. info = &packet_db[cmd];
  6119. len = info->len;
  6120. if(!len) return; //version as packet disable
  6121. // sd->state.banking = 1; //mark opening and closing
  6122. WBUFW(buf,0) = cmd;
  6123. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6124. WBUFW(buf,info->pos[1]) = 0; //reason
  6125. clif_send(buf,len,&sd->bl,SELF);
  6126. }
  6127. /*
  6128. * Requesting the data in bank
  6129. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6130. */
  6131. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6132. nullpo_retv(sd);
  6133. if( !battle_config.feature_banking ) {
  6134. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6135. return;
  6136. }
  6137. else {
  6138. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6139. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6140. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6141. clif_Bank_Check(sd);
  6142. }
  6143. }
  6144. /*
  6145. * Acknowledge of deposit some money in bank
  6146. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6147. */
  6148. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6149. unsigned char buf[17];
  6150. struct s_packet_db* info;
  6151. int16 len;
  6152. int cmd =0;
  6153. nullpo_retv(sd);
  6154. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6155. if(!cmd) cmd = 0x09A8;
  6156. info = &packet_db[cmd];
  6157. len = info->len;
  6158. if(!len) return; //version as packet disable
  6159. WBUFW(buf,0) = cmd;
  6160. WBUFW(buf,info->pos[0]) = (short)reason;
  6161. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6162. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6163. clif_send(buf,len,&sd->bl,SELF);
  6164. }
  6165. /*
  6166. * Request saving some money in bank
  6167. * @author : original [Yommy/Hercules]
  6168. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6169. */
  6170. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6171. nullpo_retv(sd);
  6172. if( !battle_config.feature_banking ) {
  6173. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6174. return;
  6175. }
  6176. else {
  6177. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6178. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6179. int money = RFIFOL(fd,info->pos[1]);
  6180. if(sd->status.account_id == aid){
  6181. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6182. clif_bank_deposit(sd,reason);
  6183. }
  6184. }
  6185. }
  6186. /*
  6187. * Acknowledge of withdrawing some money from bank
  6188. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6189. */
  6190. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6191. unsigned char buf[17];
  6192. struct s_packet_db* info;
  6193. int16 len;
  6194. int cmd;
  6195. nullpo_retv(sd);
  6196. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6197. if(!cmd) cmd = 0x09AA;
  6198. info = &packet_db[cmd];
  6199. len = info->len;
  6200. if(!len) return; //version as packet disable
  6201. WBUFW(buf,0) = cmd;
  6202. WBUFW(buf,info->pos[0]) = (short)reason;
  6203. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6204. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6205. clif_send(buf,len,&sd->bl,SELF);
  6206. }
  6207. /*
  6208. * Request Withdrawing some money from bank
  6209. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6210. */
  6211. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6212. nullpo_retv(sd);
  6213. if( !battle_config.feature_banking ) {
  6214. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6215. return;
  6216. }
  6217. else {
  6218. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6219. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6220. int money = RFIFOL(fd,info->pos[1]);
  6221. if(sd->status.account_id == aid){
  6222. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6223. clif_bank_withdraw(sd,reason);
  6224. }
  6225. }
  6226. }
  6227. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6228. /// 0125 <index>.W <amount>.L
  6229. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6230. {
  6231. int fd;
  6232. nullpo_retv(sd);
  6233. fd=sd->fd;
  6234. WFIFOHEAD(fd,packet_len(0x125));
  6235. WFIFOW(fd,0)=0x125;
  6236. WFIFOW(fd,2)=n+2;
  6237. WFIFOL(fd,4)=amount;
  6238. WFIFOSET(fd,packet_len(0x125));
  6239. }
  6240. /// Opens the shop creation menu (ZC_OPENSTORE).
  6241. /// 012d <num>.W
  6242. /// num:
  6243. /// number of allowed item slots
  6244. void clif_openvendingreq(struct map_session_data* sd, int num)
  6245. {
  6246. int fd;
  6247. nullpo_retv(sd);
  6248. fd = sd->fd;
  6249. WFIFOHEAD(fd,packet_len(0x12d));
  6250. WFIFOW(fd,0) = 0x12d;
  6251. WFIFOW(fd,2) = num;
  6252. WFIFOSET(fd,packet_len(0x12d));
  6253. }
  6254. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6255. /// 0131 <owner id>.L <message>.80B
  6256. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6257. {
  6258. unsigned char buf[128];
  6259. nullpo_retv(bl);
  6260. WBUFW(buf,0) = 0x131;
  6261. WBUFL(buf,2) = bl->id;
  6262. safestrncpy(WBUFCP(buf,6), message, 80);
  6263. if( fd ) {
  6264. WFIFOHEAD(fd,packet_len(0x131));
  6265. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6266. WFIFOSET(fd,packet_len(0x131));
  6267. } else {
  6268. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6269. }
  6270. }
  6271. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6272. /// 0132 <owner id>.L
  6273. void clif_closevendingboard(struct block_list* bl, int fd)
  6274. {
  6275. unsigned char buf[16];
  6276. nullpo_retv(bl);
  6277. WBUFW(buf,0) = 0x132;
  6278. WBUFL(buf,2) = bl->id;
  6279. if( fd ) {
  6280. WFIFOHEAD(fd,packet_len(0x132));
  6281. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6282. WFIFOSET(fd,packet_len(0x132));
  6283. } else {
  6284. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6285. }
  6286. }
  6287. /// Sends a list of items in a shop.
  6288. /// 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)
  6289. /// 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)
  6290. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6291. {
  6292. int i,fd;
  6293. int count;
  6294. struct map_session_data* vsd;
  6295. #if PACKETVER < 20100105
  6296. const int cmd = 0x133;
  6297. const int offset = 8;
  6298. #else
  6299. const int cmd = 0x800;
  6300. const int offset = 12;
  6301. #endif
  6302. #if PACKETVER < 20150225
  6303. const int item_length = 22;
  6304. #elif PACKETVER < 20160921
  6305. const int item_length = 47;
  6306. #else
  6307. const int item_length = 53;
  6308. #endif
  6309. nullpo_retv(sd);
  6310. nullpo_retv(vending);
  6311. nullpo_retv(vsd=map_id2sd(id));
  6312. fd = sd->fd;
  6313. count = vsd->vend_num;
  6314. WFIFOHEAD(fd, offset+count*item_length);
  6315. WFIFOW(fd,0) = cmd;
  6316. WFIFOW(fd,2) = offset+count*item_length;
  6317. WFIFOL(fd,4) = id;
  6318. #if PACKETVER >= 20100105
  6319. WFIFOL(fd,8) = vsd->vender_id;
  6320. #endif
  6321. for( i = 0; i < count; i++ )
  6322. {
  6323. int index = vending[i].index;
  6324. struct item_data* data = itemdb_search(vsd->cart.u.items_cart[index].nameid);
  6325. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6326. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6327. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6328. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6329. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->cart.u.items_cart[index].nameid;
  6330. WFIFOB(fd,offset+11+i*item_length) = vsd->cart.u.items_cart[index].identify;
  6331. WFIFOB(fd,offset+12+i*item_length) = vsd->cart.u.items_cart[index].attribute;
  6332. WFIFOB(fd,offset+13+i*item_length) = vsd->cart.u.items_cart[index].refine;
  6333. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->cart.u.items_cart[index]);
  6334. #if PACKETVER >= 20150225
  6335. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->cart.u.items_cart[index]);
  6336. #if PACKETVER >= 20160921
  6337. WFIFOL(fd,offset+47+i*item_length) = pc_equippoint_sub(sd,data);
  6338. WFIFOW(fd,offset+51+i*item_length) = data->look;
  6339. #endif
  6340. #endif
  6341. }
  6342. WFIFOSET(fd,WFIFOW(fd,2));
  6343. }
  6344. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6345. /// 0135 <index>.W <amount>.W <result>.B
  6346. /// result:
  6347. /// 0 = success
  6348. /// 1 = not enough zeny
  6349. /// 2 = overweight
  6350. /// 4 = out of stock
  6351. /// 5 = "cannot use an npc shop while in a trade"
  6352. /// 6 = Because the store information was incorrect the item was not purchased.
  6353. /// 7 = No sales information.
  6354. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6355. {
  6356. int fd;
  6357. nullpo_retv(sd);
  6358. fd = sd->fd;
  6359. WFIFOHEAD(fd,packet_len(0x135));
  6360. WFIFOW(fd,0) = 0x135;
  6361. WFIFOW(fd,2) = index+2;
  6362. WFIFOW(fd,4) = amount;
  6363. WFIFOB(fd,6) = fail;
  6364. WFIFOSET(fd,packet_len(0x135));
  6365. }
  6366. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6367. /// 0a28 <Result>.B
  6368. /// result:
  6369. /// 0 = Successed
  6370. /// 1 = Failed
  6371. void clif_openvending_ack(struct map_session_data* sd, int result)
  6372. {
  6373. int fd;
  6374. nullpo_retv(sd);
  6375. fd = sd->fd;
  6376. WFIFOHEAD(fd, 3);
  6377. WFIFOW(fd,0) = 0xa28;
  6378. WFIFOB(fd,2) = result;
  6379. WFIFOSET(fd, 3);
  6380. }
  6381. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6382. /// 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 }*
  6383. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6384. {
  6385. int i,fd;
  6386. int count;
  6387. #if PACKETVER < 20150225
  6388. const int item_length = 22;
  6389. #else
  6390. const int item_length = 47;
  6391. #endif
  6392. nullpo_retv(sd);
  6393. fd = sd->fd;
  6394. count = sd->vend_num;
  6395. WFIFOHEAD(fd, 8+count*item_length);
  6396. WFIFOW(fd,0) = 0x136;
  6397. WFIFOW(fd,2) = 8+count*item_length;
  6398. WFIFOL(fd,4) = id;
  6399. for( i = 0; i < count; i++ ) {
  6400. int index = vending[i].index;
  6401. struct item_data* data = itemdb_search(sd->cart.u.items_cart[index].nameid);
  6402. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6403. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6404. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6405. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6406. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->cart.u.items_cart[index].nameid;
  6407. WFIFOB(fd,19+i*item_length) = sd->cart.u.items_cart[index].identify;
  6408. WFIFOB(fd,20+i*item_length) = sd->cart.u.items_cart[index].attribute;
  6409. WFIFOB(fd,21+i*item_length) = sd->cart.u.items_cart[index].refine;
  6410. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->cart.u.items_cart[index]);
  6411. #if PACKETVER >= 20150225
  6412. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->cart.u.items_cart[index]);
  6413. #endif
  6414. }
  6415. WFIFOSET(fd,WFIFOW(fd,2));
  6416. #if PACKETVER >= 20141022
  6417. /// 0 = Successed
  6418. /// 1 = Failed
  6419. clif_openvending_ack(sd, 0);
  6420. #endif
  6421. }
  6422. /// Inform merchant that someone has bought an item.
  6423. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6424. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6425. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6426. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6427. const int cmd = 0x137;
  6428. #else
  6429. const int cmd = 0x9e5;
  6430. #endif
  6431. int fd = sd->fd;
  6432. nullpo_retv(sd);
  6433. WFIFOHEAD(fd,packet_len(cmd));
  6434. WFIFOW(fd,0) = cmd;
  6435. WFIFOW(fd,2) = index+2;
  6436. WFIFOW(fd,4) = amount;
  6437. #if PACKETVER >= 20141016
  6438. WFIFOL(fd,6) = char_id; // GID
  6439. WFIFOL(fd,10) = (int)time(NULL); // Date
  6440. WFIFOL(fd,14) = zeny; // zeny
  6441. #endif
  6442. WFIFOSET(fd,packet_len(cmd));
  6443. }
  6444. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6445. /// 00fa <result>.B
  6446. /// result:
  6447. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6448. /// 1 = MsgStringTable[78]="party name already exists"
  6449. /// 2 = MsgStringTable[79]="already in a party"
  6450. /// 3 = cannot organize parties on this map
  6451. /// ? = nothing
  6452. void clif_party_created(struct map_session_data *sd,int result)
  6453. {
  6454. int fd;
  6455. nullpo_retv(sd);
  6456. fd=sd->fd;
  6457. WFIFOHEAD(fd,packet_len(0xfa));
  6458. WFIFOW(fd,0)=0xfa;
  6459. WFIFOB(fd,2)=result;
  6460. WFIFOSET(fd,packet_len(0xfa));
  6461. }
  6462. /// Adds new member to a party.
  6463. /// 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)
  6464. /// 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)
  6465. /// 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)
  6466. /// role:
  6467. /// 0 = leader
  6468. /// 1 = normal
  6469. /// state:
  6470. /// 0 = connected
  6471. /// 1 = disconnected
  6472. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6473. {
  6474. int i;
  6475. #if PACKETVER < 20170502
  6476. unsigned char buf[81];
  6477. int cmd = 0x1e9;
  6478. int offset = 0;
  6479. #else
  6480. unsigned char buf[85];
  6481. int cmd = 0xa43;
  6482. int offset = 4;
  6483. #endif
  6484. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6485. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6486. } else {
  6487. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6488. }
  6489. if (i >= MAX_PARTY) return; //Should never happen...
  6490. sd = p->data[i].sd;
  6491. WBUFW(buf, 0) = cmd;
  6492. WBUFL(buf, 2) = sd->status.account_id;
  6493. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6494. #if PACKETVER >= 20170502
  6495. WBUFW(buf,10) = sd->status.class_;
  6496. WBUFW(buf,12) = sd->status.base_level;
  6497. #endif
  6498. WBUFW(buf,offset+10) = sd->bl.x;
  6499. WBUFW(buf,offset+12) = sd->bl.y;
  6500. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6501. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6502. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6503. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6504. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6505. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6506. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6507. }
  6508. /// Sends party information (ZC_GROUP_LIST).
  6509. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6510. /// role:
  6511. /// 0 = leader
  6512. /// 1 = normal
  6513. /// state:
  6514. /// 0 = connected
  6515. /// 1 = disconnected
  6516. /// 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
  6517. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6518. {
  6519. struct map_session_data* party_sd = NULL;
  6520. int i, c;
  6521. #if PACKETVER < 20170502
  6522. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6523. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6524. int cmd = 0xfb;
  6525. #else
  6526. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6527. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6528. int cmd = 0xa44;
  6529. #endif
  6530. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6531. nullpo_retv(p);
  6532. WBUFW(buf,0) = cmd;
  6533. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6534. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6535. {
  6536. struct party_member* m = &p->party.member[i];
  6537. if(!m->account_id) continue;
  6538. if(party_sd == NULL) party_sd = p->data[i].sd;
  6539. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6540. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6541. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6542. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6543. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6544. #if PACKETVER >= 20170502
  6545. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6546. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6547. #endif
  6548. c++;
  6549. }
  6550. #if PACKETVER < 20170502
  6551. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6552. #else
  6553. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6554. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6555. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6556. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6557. #endif
  6558. if(sd) { // send only to self
  6559. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6560. } else if (party_sd) { // send to whole party
  6561. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6562. }
  6563. }
  6564. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6565. /// 02c9 <flag>.B
  6566. /// flag:
  6567. /// 0 = allow party invites
  6568. /// 1 = auto-deny party invites
  6569. void clif_partyinvitationstate(struct map_session_data* sd)
  6570. {
  6571. int fd;
  6572. nullpo_retv(sd);
  6573. fd = sd->fd;
  6574. WFIFOHEAD(fd, packet_len(0x2c9));
  6575. WFIFOW(fd, 0) = 0x2c9;
  6576. WFIFOB(fd, 2) = 0; // not implemented
  6577. WFIFOSET(fd, packet_len(0x2c9));
  6578. }
  6579. /// Party invitation request.
  6580. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6581. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6582. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6583. {
  6584. #if PACKETVER < 20070821
  6585. const int cmd = 0xfe;
  6586. #else
  6587. const int cmd = 0x2c6;
  6588. #endif
  6589. int fd;
  6590. struct party_data *p;
  6591. nullpo_retv(sd);
  6592. nullpo_retv(tsd);
  6593. fd=tsd->fd;
  6594. if( (p=party_search(sd->status.party_id))==NULL )
  6595. return;
  6596. WFIFOHEAD(fd,packet_len(cmd));
  6597. WFIFOW(fd,0)=cmd;
  6598. WFIFOL(fd,2)=sd->status.party_id;
  6599. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6600. WFIFOSET(fd,packet_len(cmd));
  6601. }
  6602. /// Party invite result.
  6603. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6604. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6605. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6606. {
  6607. int fd;
  6608. nullpo_retv(sd);
  6609. fd=sd->fd;
  6610. #if PACKETVER < 20070904
  6611. if( reply == PARTY_REPLY_OFFLINE ) {
  6612. clif_displaymessage(fd, msg_txt(sd,3));
  6613. return;
  6614. }
  6615. #endif
  6616. #if PACKETVER < 20070821
  6617. WFIFOHEAD(fd,packet_len(0xfd));
  6618. WFIFOW(fd,0) = 0xfd;
  6619. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6620. WFIFOB(fd,26) = reply;
  6621. WFIFOSET(fd,packet_len(0xfd));
  6622. #else
  6623. WFIFOHEAD(fd,packet_len(0x2c5));
  6624. WFIFOW(fd,0) = 0x2c5;
  6625. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6626. WFIFOL(fd,26) = reply;
  6627. WFIFOSET(fd,packet_len(0x2c5));
  6628. #endif
  6629. }
  6630. /// Updates party settings.
  6631. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6632. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6633. /// exp option:
  6634. /// 0 = exp sharing disabled
  6635. /// 1 = exp sharing enabled
  6636. /// 2 = cannot change exp sharing
  6637. ///
  6638. /// flag:
  6639. /// 0 = send to party
  6640. /// 1 = send to sd
  6641. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6642. {
  6643. unsigned char buf[16];
  6644. #if PACKETVER < 20090603
  6645. const int cmd = 0x101;
  6646. #else
  6647. const int cmd = 0x7d8;
  6648. #endif
  6649. nullpo_retv(p);
  6650. if(!sd && flag==0){
  6651. int i;
  6652. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6653. if (i < MAX_PARTY)
  6654. sd = p->data[i].sd;
  6655. }
  6656. if(!sd) return;
  6657. WBUFW(buf,0)=cmd;
  6658. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6659. #if PACKETVER >= 20090603
  6660. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6661. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6662. #endif
  6663. if(flag==0)
  6664. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6665. else
  6666. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6667. }
  6668. /**
  6669. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6670. * @param sd Send the notification for this player
  6671. * @param account_id Account ID of kicked member
  6672. * @param name Name of kicked member
  6673. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6674. * @param target Send target
  6675. **/
  6676. 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) {
  6677. unsigned char buf[2+4+NAME_LENGTH+1];
  6678. if (!sd)
  6679. return;
  6680. WBUFW(buf,0) = 0x0105;
  6681. WBUFL(buf,2) = account_id;
  6682. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6683. WBUFB(buf,6+NAME_LENGTH) = result;
  6684. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6685. }
  6686. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6687. /// 0109 <packet len>.W <account id>.L <message>.?B
  6688. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6689. {
  6690. struct map_session_data *sd;
  6691. int i;
  6692. nullpo_retv(p);
  6693. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6694. if(i < MAX_PARTY){
  6695. unsigned char buf[1024];
  6696. if( len > sizeof(buf)-8 )
  6697. {
  6698. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6699. len = sizeof(buf)-8;
  6700. }
  6701. sd = p->data[i].sd;
  6702. WBUFW(buf,0)=0x109;
  6703. WBUFW(buf,2)=len+8;
  6704. WBUFL(buf,4)=account_id;
  6705. safestrncpy(WBUFCP(buf,8), mes, len);
  6706. clif_send(buf,len+8,&sd->bl,PARTY);
  6707. }
  6708. }
  6709. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6710. /// 0107 <account id>.L <x>.W <y>.W
  6711. void clif_party_xy(struct map_session_data *sd)
  6712. {
  6713. unsigned char buf[16];
  6714. nullpo_retv(sd);
  6715. WBUFW(buf,0)=0x107;
  6716. WBUFL(buf,2)=sd->status.account_id;
  6717. WBUFW(buf,6)=sd->bl.x;
  6718. WBUFW(buf,8)=sd->bl.y;
  6719. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6720. }
  6721. /*==========================================
  6722. * Sends x/y dot to a single fd. [Skotlex]
  6723. *------------------------------------------*/
  6724. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6725. {
  6726. WFIFOHEAD(fd,packet_len(0x107));
  6727. WFIFOW(fd,0)=0x107;
  6728. WFIFOL(fd,2)=sd->status.account_id;
  6729. WFIFOW(fd,6)=sd->bl.x;
  6730. WFIFOW(fd,8)=sd->bl.y;
  6731. WFIFOSET(fd,packet_len(0x107));
  6732. }
  6733. /// Updates HP bar of a party member.
  6734. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6735. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6736. void clif_party_hp(struct map_session_data *sd)
  6737. {
  6738. unsigned char buf[16];
  6739. #if PACKETVER < 20100126
  6740. const int cmd = 0x106;
  6741. #else
  6742. const int cmd = 0x80e;
  6743. #endif
  6744. nullpo_retv(sd);
  6745. WBUFW(buf,0)=cmd;
  6746. WBUFL(buf,2)=sd->status.account_id;
  6747. #if PACKETVER < 20100126
  6748. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6749. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6750. WBUFW(buf,8) = 100;
  6751. } else {
  6752. WBUFW(buf,6) = sd->battle_status.hp;
  6753. WBUFW(buf,8) = sd->battle_status.max_hp;
  6754. }
  6755. #else
  6756. WBUFL(buf,6) = sd->battle_status.hp;
  6757. WBUFL(buf,10) = sd->battle_status.max_hp;
  6758. #endif
  6759. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6760. }
  6761. /// Notifies the party members of a character's death or revival.
  6762. /// 0AB2 <GID>.L <dead>.B
  6763. void clif_party_dead( struct map_session_data *sd ){
  6764. #if PACKETVER >= 20170502
  6765. unsigned char buf[7];
  6766. nullpo_retv(sd);
  6767. WBUFW(buf, 0) = 0xab2;
  6768. WBUFL(buf, 2) = sd->status.account_id;
  6769. WBUFB(buf, 6) = pc_isdead(sd);
  6770. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6771. #endif
  6772. }
  6773. /// Updates the job and level of a party member
  6774. /// 0abd <account id>.L <job>.W <level>.W
  6775. void clif_party_job_and_level(struct map_session_data *sd){
  6776. #if PACKETVER >= 20170502
  6777. unsigned char buf[10];
  6778. nullpo_retv(sd);
  6779. WBUFW(buf, 0) = 0xabd;
  6780. WBUFL(buf, 2) = sd->status.account_id;
  6781. WBUFW(buf, 6) = sd->status.class_;
  6782. WBUFW(buf, 8) = sd->status.base_level;
  6783. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6784. #endif
  6785. }
  6786. /*==========================================
  6787. * Sends HP bar to a single fd. [Skotlex]
  6788. *------------------------------------------*/
  6789. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6790. {
  6791. #if PACKETVER < 20100126
  6792. const int cmd = 0x106;
  6793. #else
  6794. const int cmd = 0x80e;
  6795. #endif
  6796. WFIFOHEAD(fd,packet_len(cmd));
  6797. WFIFOW(fd,0) = cmd;
  6798. WFIFOL(fd,2) = id;
  6799. #if PACKETVER < 20100126
  6800. if( maxhp > INT16_MAX )
  6801. {// To correctly display the %hp bar. [Skotlex]
  6802. WFIFOW(fd,6) = hp/(maxhp/100);
  6803. WFIFOW(fd,8) = 100;
  6804. } else {
  6805. WFIFOW(fd,6) = hp;
  6806. WFIFOW(fd,8) = maxhp;
  6807. }
  6808. #else
  6809. WFIFOL(fd,6) = hp;
  6810. WFIFOL(fd,10) = maxhp;
  6811. #endif
  6812. WFIFOSET(fd, packet_len(cmd));
  6813. }
  6814. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6815. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6816. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6817. {
  6818. int fd;
  6819. nullpo_retv(sd);
  6820. nullpo_retv(bl);
  6821. fd=sd->fd;
  6822. WFIFOHEAD(fd,packet_len(0x139));
  6823. WFIFOW(fd, 0)=0x139;
  6824. WFIFOL(fd, 2)=bl->id;
  6825. WFIFOW(fd, 6)=bl->x;
  6826. WFIFOW(fd, 8)=bl->y;
  6827. WFIFOW(fd,10)=sd->bl.x;
  6828. WFIFOW(fd,12)=sd->bl.y;
  6829. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6830. WFIFOSET(fd,packet_len(0x139));
  6831. }
  6832. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6833. /// 018f <result>.W <name id>.W
  6834. /// result:
  6835. /// 0 = success
  6836. /// 1 = failure
  6837. /// 2 = success (alchemist)
  6838. /// 3 = failure (alchemist)
  6839. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6840. {
  6841. int view,fd;
  6842. nullpo_retv(sd);
  6843. fd = sd->fd;
  6844. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6845. WFIFOHEAD(fd,packet_len(0x18f));
  6846. WFIFOW(fd, 0)=0x18f;
  6847. WFIFOW(fd, 2)=flag;
  6848. if((view = itemdb_viewid(nameid)) > 0)
  6849. WFIFOW(fd, 4)=view;
  6850. else
  6851. WFIFOW(fd, 4)=nameid;
  6852. WFIFOSET(fd,packet_len(0x18f));
  6853. }
  6854. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6855. /// 019e
  6856. void clif_catch_process(struct map_session_data *sd)
  6857. {
  6858. int fd;
  6859. nullpo_retv(sd);
  6860. fd=sd->fd;
  6861. WFIFOHEAD(fd,packet_len(0x19e));
  6862. WFIFOW(fd,0)=0x19e;
  6863. WFIFOSET(fd,packet_len(0x19e));
  6864. }
  6865. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6866. /// 01a0 <result>.B
  6867. /// 0 = failure
  6868. /// 1 = success
  6869. void clif_pet_roulette(struct map_session_data *sd,int data)
  6870. {
  6871. int fd;
  6872. nullpo_retv(sd);
  6873. fd=sd->fd;
  6874. WFIFOHEAD(fd,packet_len(0x1a0));
  6875. WFIFOW(fd,0)=0x1a0;
  6876. WFIFOB(fd,2)=data;
  6877. WFIFOSET(fd,packet_len(0x1a0));
  6878. }
  6879. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6880. /// 01a6 <packet len>.W { <index>.W }*
  6881. void clif_sendegg(struct map_session_data *sd)
  6882. {
  6883. int i,n=0,fd;
  6884. nullpo_retv(sd);
  6885. fd=sd->fd;
  6886. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6887. clif_displaymessage(fd, msg_txt(sd,666));
  6888. return;
  6889. }
  6890. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6891. WFIFOW(fd,0)=0x1a6;
  6892. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6893. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6894. sd->inventory_data[i]->type != IT_PETEGG ||
  6895. sd->inventory.u.items_inventory[i].amount <= 0)
  6896. continue;
  6897. WFIFOW(fd,n*2+4)=i+2;
  6898. n++;
  6899. }
  6900. WFIFOW(fd,2)=4+n*2;
  6901. WFIFOSET(fd,WFIFOW(fd,2));
  6902. sd->menuskill_id = SA_TAMINGMONSTER;
  6903. sd->menuskill_val = -1;
  6904. }
  6905. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6906. /// 01a4 <type>.B <id>.L <data>.L
  6907. /// type:
  6908. /// 0 = pre-init (data = 0)
  6909. /// 1 = intimacy (data = 0~4)
  6910. /// 2 = hunger (data = 0~4)
  6911. /// 3 = accessory
  6912. /// 4 = performance (data = 1~3: normal, 4: special)
  6913. /// 5 = hairstyle
  6914. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6915. ///
  6916. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6917. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6918. {
  6919. uint8 buf[16];
  6920. nullpo_retv(pd);
  6921. WBUFW(buf,0) = 0x1a4;
  6922. WBUFB(buf,2) = type;
  6923. WBUFL(buf,3) = pd->bl.id;
  6924. WBUFL(buf,7) = param;
  6925. if (sd)
  6926. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6927. else
  6928. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6929. }
  6930. /// Pet's base data (ZC_PROPERTY_PET).
  6931. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6932. void clif_send_petstatus(struct map_session_data *sd)
  6933. {
  6934. int fd;
  6935. struct s_pet *pet;
  6936. nullpo_retv(sd);
  6937. nullpo_retv(sd->pd);
  6938. fd=sd->fd;
  6939. pet = &sd->pd->pet;
  6940. WFIFOHEAD(fd,packet_len(0x1a2));
  6941. WFIFOW(fd,0)=0x1a2;
  6942. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6943. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6944. WFIFOW(fd,27)=pet->level;
  6945. WFIFOW(fd,29)=pet->hungry;
  6946. WFIFOW(fd,31)=pet->intimate;
  6947. WFIFOW(fd,33)=pet->equip;
  6948. #if PACKETVER >= 20081126
  6949. WFIFOW(fd,35)=pet->class_;
  6950. #endif
  6951. WFIFOSET(fd,packet_len(0x1a2));
  6952. }
  6953. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6954. /// 01aa <id>.L <data>.L
  6955. /// data:
  6956. /// @see CZ_PET_ACT.
  6957. void clif_pet_emotion(struct pet_data *pd,int param)
  6958. {
  6959. unsigned char buf[16];
  6960. nullpo_retv(pd);
  6961. memset(buf,0,packet_len(0x1aa));
  6962. WBUFW(buf,0)=0x1aa;
  6963. WBUFL(buf,2)=pd->bl.id;
  6964. WBUFL(buf,6)=param;
  6965. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6966. }
  6967. /// Result of request to feed a pet (ZC_FEED_PET).
  6968. /// 01a3 <result>.B <name id>.W
  6969. /// result:
  6970. /// 0 = failure
  6971. /// 1 = success
  6972. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6973. {
  6974. int fd;
  6975. nullpo_retv(sd);
  6976. fd=sd->fd;
  6977. WFIFOHEAD(fd,packet_len(0x1a3));
  6978. WFIFOW(fd,0)=0x1a3;
  6979. WFIFOB(fd,2)=fail;
  6980. WFIFOW(fd,3)=foodid;
  6981. WFIFOSET(fd,packet_len(0x1a3));
  6982. }
  6983. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6984. /// 01cd { <skill id>.L }*7
  6985. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6986. {
  6987. int fd;
  6988. nullpo_retv(sd);
  6989. fd=sd->fd;
  6990. WFIFOHEAD(fd,packet_len(0x1cd));
  6991. WFIFOW(fd, 0)=0x1cd;
  6992. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6993. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6994. else
  6995. WFIFOL(fd,2)= 0x00000000;
  6996. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6997. WFIFOL(fd,6)= MG_COLDBOLT;
  6998. else
  6999. WFIFOL(fd,6)= 0x00000000;
  7000. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7001. WFIFOL(fd,10)= MG_FIREBOLT;
  7002. else
  7003. WFIFOL(fd,10)= 0x00000000;
  7004. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7005. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7006. else
  7007. WFIFOL(fd,14)= 0x00000000;
  7008. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7009. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7010. else
  7011. WFIFOL(fd,18)= 0x00000000;
  7012. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7013. WFIFOL(fd,22)= MG_FIREBALL;
  7014. else
  7015. WFIFOL(fd,22)= 0x00000000;
  7016. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7017. WFIFOL(fd,26)= MG_FROSTDIVER;
  7018. else
  7019. WFIFOL(fd,26)= 0x00000000;
  7020. WFIFOSET(fd,packet_len(0x1cd));
  7021. sd->menuskill_id = SA_AUTOSPELL;
  7022. sd->menuskill_val = skill_lv;
  7023. }
  7024. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7025. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7026. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7027. {
  7028. unsigned char buf[56];
  7029. nullpo_retv(src);
  7030. memset(buf,0,packet_len(0x1cf));
  7031. WBUFW(buf,0) = 0x1cf;
  7032. WBUFL(buf,2) = src->id;
  7033. if( src->type == BL_MER )
  7034. {
  7035. struct mercenary_data *md = BL_CAST(BL_MER,src);
  7036. if( md && md->master && md->devotion_flag )
  7037. WBUFL(buf,6) = md->master->bl.id;
  7038. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7039. }
  7040. else
  7041. {
  7042. int i;
  7043. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7044. if( sd == NULL )
  7045. return;
  7046. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7047. WBUFL(buf,6+4*i) = sd->devotion[i];
  7048. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7049. }
  7050. if( tsd )
  7051. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7052. else
  7053. clif_send(buf, packet_len(0x1cf), src, AREA);
  7054. }
  7055. /*==========================================
  7056. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  7057. * Notifies clients in an area of an object's spirits.
  7058. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7059. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7060. *------------------------------------------*/
  7061. void clif_spiritball(struct block_list *bl) {
  7062. unsigned char buf[16];
  7063. TBL_PC *sd = BL_CAST(BL_PC,bl);
  7064. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  7065. nullpo_retv(bl);
  7066. WBUFW(buf, 0) = 0x1d0;
  7067. WBUFL(buf, 2) = bl->id;
  7068. WBUFW(buf, 6) = 0; //init to 0
  7069. switch(bl->type){
  7070. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7071. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7072. }
  7073. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7074. }
  7075. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7076. /// 01d2 <account id>.L <delay>.L
  7077. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7078. {
  7079. unsigned char buf[32];
  7080. nullpo_retv(bl);
  7081. WBUFW(buf,0)=0x1d2;
  7082. WBUFL(buf,2)=bl->id;
  7083. WBUFL(buf,6)=client_tick(wait);
  7084. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7085. }
  7086. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7087. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7088. /// flag:
  7089. /// 0 = inactive
  7090. /// 1 = active
  7091. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7092. {
  7093. unsigned char buf[32];
  7094. nullpo_retv(src);
  7095. WBUFW(buf,0)=0x1d1;
  7096. WBUFL(buf,2)=src->id;
  7097. WBUFL(buf,6)=dst_id;
  7098. WBUFL(buf,10)=active;
  7099. clif_send(buf,packet_len(0x1d1),src,AREA);
  7100. }
  7101. /// MVP effect (ZC_MVP).
  7102. /// 010c <account id>.L
  7103. void clif_mvp_effect(struct map_session_data *sd)
  7104. {
  7105. unsigned char buf[16];
  7106. nullpo_retv(sd);
  7107. WBUFW(buf,0)=0x10c;
  7108. WBUFL(buf,2)=sd->bl.id;
  7109. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7110. }
  7111. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7112. /// 010a <name id>.W
  7113. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  7114. {
  7115. int view,fd;
  7116. nullpo_retv(sd);
  7117. fd=sd->fd;
  7118. WFIFOHEAD(fd,packet_len(0x10a));
  7119. WFIFOW(fd,0)=0x10a;
  7120. if((view = itemdb_viewid(nameid)) > 0)
  7121. WFIFOW(fd,2)=view;
  7122. else
  7123. WFIFOW(fd,2)=nameid;
  7124. WFIFOSET(fd,packet_len(0x10a));
  7125. }
  7126. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7127. /// 010b <exp>.L
  7128. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7129. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7130. if (battle_config.mvp_exp_reward_message) {
  7131. char e_msg[CHAT_SIZE_MAX];
  7132. sprintf(e_msg, msg_txt(sd, 717), exp);
  7133. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7134. }
  7135. #else
  7136. int fd;
  7137. nullpo_retv(sd);
  7138. fd = sd->fd;
  7139. WFIFOHEAD(fd, packet_len(0x10b));
  7140. WFIFOW(fd,0) = 0x10b;
  7141. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7142. WFIFOSET(fd, packet_len(0x10b));
  7143. #endif
  7144. }
  7145. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7146. /// 010d
  7147. ///
  7148. /// "You are the MVP, but cannot obtain the reward because
  7149. /// you are overweight."
  7150. void clif_mvp_noitem(struct map_session_data* sd)
  7151. {
  7152. int fd = sd->fd;
  7153. WFIFOHEAD(fd,packet_len(0x10d));
  7154. WFIFOW(fd,0) = 0x10d;
  7155. WFIFOSET(fd,packet_len(0x10d));
  7156. }
  7157. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7158. /// 0167 <result>.B
  7159. /// result:
  7160. /// 0 = "Guild has been created."
  7161. /// 1 = "You are already in a Guild."
  7162. /// 2 = "That Guild Name already exists."
  7163. /// 3 = "You need the neccessary item to create a Guild."
  7164. void clif_guild_created(struct map_session_data *sd,int flag)
  7165. {
  7166. int fd;
  7167. nullpo_retv(sd);
  7168. fd=sd->fd;
  7169. WFIFOHEAD(fd,packet_len(0x167));
  7170. WFIFOW(fd,0)=0x167;
  7171. WFIFOB(fd,2)=flag;
  7172. WFIFOSET(fd,packet_len(0x167));
  7173. }
  7174. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7175. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7176. /// mode:
  7177. /// &0x01 = allow invite
  7178. /// &0x10 = allow expel
  7179. void clif_guild_belonginfo(struct map_session_data *sd)
  7180. {
  7181. int ps,fd;
  7182. struct guild* g;
  7183. nullpo_retv(sd);
  7184. nullpo_retv(g = sd->guild);
  7185. fd=sd->fd;
  7186. ps=guild_getposition(sd);
  7187. WFIFOHEAD(fd,packet_len(0x16c));
  7188. WFIFOW(fd,0)=0x16c;
  7189. WFIFOL(fd,2)=g->guild_id;
  7190. WFIFOL(fd,6)=g->emblem_id;
  7191. WFIFOL(fd,10)=g->position[ps].mode;
  7192. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7193. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7194. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7195. WFIFOSET(fd,packet_len(0x16c));
  7196. }
  7197. /// Guild member login notice.
  7198. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7199. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7200. /// status:
  7201. /// 0 = offline
  7202. /// 1 = online
  7203. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7204. {
  7205. unsigned char buf[64];
  7206. struct map_session_data* sd;
  7207. nullpo_retv(g);
  7208. WBUFW(buf, 0)=0x1f2;
  7209. WBUFL(buf, 2)=g->member[idx].account_id;
  7210. WBUFL(buf, 6)=g->member[idx].char_id;
  7211. WBUFL(buf,10)=flag;
  7212. if( ( sd = g->member[idx].sd ) != NULL )
  7213. {
  7214. WBUFW(buf,14) = sd->status.sex;
  7215. WBUFW(buf,16) = sd->status.hair;
  7216. WBUFW(buf,18) = sd->status.hair_color;
  7217. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7218. }
  7219. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7220. {
  7221. WBUFW(buf,14) = 0;
  7222. WBUFW(buf,16) = 0;
  7223. WBUFW(buf,18) = 0;
  7224. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7225. }
  7226. }
  7227. // Function `clif_guild_memberlogin_notice` sends info about
  7228. // logins and logouts of a guild member to the rest members.
  7229. // But at the 1st time (after a player login or map changing)
  7230. // the client won't show the message.
  7231. // So I suggest use this function for sending "first-time-info"
  7232. // to some player on entering the game or changing location.
  7233. // At next time the client would always show the message.
  7234. // The function sends all the statuses in the single packet
  7235. // to economize traffic. [LuzZza]
  7236. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7237. {
  7238. struct guild *g;
  7239. unsigned char buf[14*128];
  7240. int i, count=0, p_len;
  7241. nullpo_retv(sd);
  7242. p_len = packet_len(0x16d);
  7243. if(!(g = sd->guild))
  7244. return;
  7245. for(i=0; i<g->max_member; i++) {
  7246. if(g->member[i].account_id > 0 &&
  7247. g->member[i].account_id != sd->status.account_id) {
  7248. WBUFW(buf,count*p_len) = 0x16d;
  7249. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7250. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7251. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7252. count++;
  7253. }
  7254. }
  7255. clif_send(buf, p_len*count, &sd->bl, SELF);
  7256. }
  7257. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7258. /// 014e <menu flag>.L
  7259. /// menu flag:
  7260. /// 0x00 = Basic Info (always on)
  7261. /// &0x01 = Member manager
  7262. /// &0x02 = Positions
  7263. /// &0x04 = Skills
  7264. /// &0x10 = Expulsion list
  7265. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7266. /// &0x80 = Notice
  7267. void clif_guild_masterormember(struct map_session_data *sd)
  7268. {
  7269. int fd;
  7270. nullpo_retv(sd);
  7271. fd=sd->fd;
  7272. WFIFOHEAD(fd,packet_len(0x14e));
  7273. WFIFOW(fd,0) = 0x14e;
  7274. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7275. WFIFOSET(fd,packet_len(0x14e));
  7276. }
  7277. /// Guild basic information (Territories [Valaris])
  7278. /// 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)
  7279. /// 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)
  7280. /// 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)
  7281. void clif_guild_basicinfo(struct map_session_data *sd) {
  7282. int fd;
  7283. struct guild *g;
  7284. #if PACKETVER < 20160622
  7285. int cmd = 0x1b6;
  7286. int offset = NAME_LENGTH;
  7287. #else
  7288. int cmd = 0xa84;
  7289. int offset = 0;
  7290. #endif
  7291. nullpo_retv(sd);
  7292. fd = sd->fd;
  7293. if( (g = sd->guild) == NULL )
  7294. return;
  7295. WFIFOHEAD(fd,packet_len(cmd));
  7296. WFIFOW(fd, 0)=cmd;
  7297. WFIFOL(fd, 2)=g->guild_id;
  7298. WFIFOL(fd, 6)=g->guild_lv;
  7299. WFIFOL(fd,10)=g->connect_member;
  7300. WFIFOL(fd,14)=g->max_member;
  7301. WFIFOL(fd,18)=g->average_lv;
  7302. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7303. WFIFOL(fd,26)=g->next_exp;
  7304. WFIFOL(fd,30)=0; // Tax Points
  7305. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7306. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7307. WFIFOL(fd,42)=g->emblem_id;
  7308. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7309. #if PACKETVER < 20160622
  7310. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7311. #endif
  7312. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7313. WFIFOL(fd,70+offset+16) = 0; // zeny
  7314. #if PACKETVER >= 20160622
  7315. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7316. #endif
  7317. WFIFOSET(fd,packet_len(cmd));
  7318. }
  7319. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7320. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7321. void clif_guild_allianceinfo(struct map_session_data *sd)
  7322. {
  7323. int fd,i,c;
  7324. struct guild *g;
  7325. nullpo_retv(sd);
  7326. if( (g = sd->guild) == NULL )
  7327. return;
  7328. fd = sd->fd;
  7329. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7330. WFIFOW(fd, 0)=0x14c;
  7331. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7332. struct guild_alliance *a=&g->alliance[i];
  7333. if(a->guild_id>0){
  7334. WFIFOL(fd,c*32+4)=a->opposition;
  7335. WFIFOL(fd,c*32+8)=a->guild_id;
  7336. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7337. c++;
  7338. }
  7339. }
  7340. WFIFOW(fd, 2)=c*32+4;
  7341. WFIFOSET(fd,WFIFOW(fd,2));
  7342. }
  7343. /// Guild member manager information
  7344. /// 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)
  7345. /// state:
  7346. /// 0 = offline
  7347. /// 1 = online
  7348. /// memo:
  7349. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7350. /// 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)
  7351. void clif_guild_memberlist(struct map_session_data *sd)
  7352. {
  7353. int fd;
  7354. int i,c;
  7355. struct guild *g;
  7356. #if PACKETVER < 20161026
  7357. int cmd = 0x154;
  7358. int size = 104;
  7359. #else
  7360. int cmd = 0xaa5;
  7361. int size = 34;
  7362. #endif
  7363. nullpo_retv(sd);
  7364. if( (fd = sd->fd) == 0 )
  7365. return;
  7366. if( (g = sd->guild) == NULL )
  7367. return;
  7368. WFIFOHEAD(fd, g->max_member * size + 4);
  7369. WFIFOW(fd, 0)=cmd;
  7370. for(i=0,c=0;i<g->max_member;i++){
  7371. struct guild_member *m=&g->member[i];
  7372. if(m->account_id==0)
  7373. continue;
  7374. WFIFOL(fd,c*size+ 4)=m->account_id;
  7375. WFIFOL(fd,c*size+ 8)=m->char_id;
  7376. WFIFOW(fd,c*size+12)=m->hair;
  7377. WFIFOW(fd,c*size+14)=m->hair_color;
  7378. WFIFOW(fd,c*size+16)=m->gender;
  7379. WFIFOW(fd,c*size+18)=m->class_;
  7380. WFIFOW(fd,c*size+20)=m->lv;
  7381. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7382. WFIFOL(fd,c*size+26)=m->online;
  7383. WFIFOL(fd,c*size+30)=m->position;
  7384. #if PACKETVER < 20161026
  7385. 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.
  7386. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7387. #else
  7388. WFIFOL(fd,c*size+34)=m->last_login;
  7389. #endif
  7390. c++;
  7391. }
  7392. WFIFOW(fd, 2)=c*size+4;
  7393. WFIFOSET(fd,WFIFOW(fd,2));
  7394. }
  7395. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7396. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7397. void clif_guild_positionnamelist(struct map_session_data *sd)
  7398. {
  7399. int i,fd;
  7400. struct guild *g;
  7401. nullpo_retv(sd);
  7402. if( (g = sd->guild) == NULL )
  7403. return;
  7404. fd = sd->fd;
  7405. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7406. WFIFOW(fd, 0)=0x166;
  7407. for(i=0;i<MAX_GUILDPOSITION;i++){
  7408. WFIFOL(fd,i*28+4)=i;
  7409. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7410. }
  7411. WFIFOW(fd,2)=i*28+4;
  7412. WFIFOSET(fd,WFIFOW(fd,2));
  7413. }
  7414. /// Guild position information (ZC_POSITION_INFO).
  7415. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7416. /// mode:
  7417. /// &0x01 = allow invite
  7418. /// &0x10 = allow expel
  7419. /// ranking:
  7420. /// TODO
  7421. void clif_guild_positioninfolist(struct map_session_data *sd)
  7422. {
  7423. int i,fd;
  7424. struct guild *g;
  7425. nullpo_retv(sd);
  7426. if( (g = sd->guild) == NULL )
  7427. return;
  7428. fd = sd->fd;
  7429. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7430. WFIFOW(fd, 0)=0x160;
  7431. for(i=0;i<MAX_GUILDPOSITION;i++){
  7432. struct guild_position *p=&g->position[i];
  7433. WFIFOL(fd,i*16+ 4)=i;
  7434. WFIFOL(fd,i*16+ 8)=p->mode;
  7435. WFIFOL(fd,i*16+12)=i;
  7436. WFIFOL(fd,i*16+16)=p->exp_mode;
  7437. }
  7438. WFIFOW(fd, 2)=i*16+4;
  7439. WFIFOSET(fd,WFIFOW(fd,2));
  7440. }
  7441. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7442. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7443. /// mode:
  7444. /// &0x01 = allow invite
  7445. /// &0x10 = allow expel
  7446. /// ranking:
  7447. /// TODO
  7448. void clif_guild_positionchanged(struct guild *g,int idx)
  7449. {
  7450. // FIXME: This packet is intended to update the clients after a
  7451. // commit of position info changes, not sending one packet per
  7452. // position.
  7453. struct map_session_data *sd;
  7454. unsigned char buf[128];
  7455. nullpo_retv(g);
  7456. WBUFW(buf, 0)=0x174;
  7457. WBUFW(buf, 2)=44; // packet len
  7458. // GUILD_REG_POSITION_INFO{
  7459. WBUFL(buf, 4)=idx;
  7460. WBUFL(buf, 8)=g->position[idx].mode;
  7461. WBUFL(buf,12)=idx;
  7462. WBUFL(buf,16)=g->position[idx].exp_mode;
  7463. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7464. // }*
  7465. if( (sd=guild_getavailablesd(g))!=NULL )
  7466. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7467. }
  7468. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7469. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7470. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7471. {
  7472. // FIXME: This packet is intended to update the clients after a
  7473. // commit of member position assignment changes, not sending one
  7474. // packet per position.
  7475. struct map_session_data *sd;
  7476. unsigned char buf[64];
  7477. nullpo_retv(g);
  7478. WBUFW(buf, 0)=0x156;
  7479. WBUFW(buf, 2)=16; // packet len
  7480. // MEMBER_POSITION_INFO{
  7481. WBUFL(buf, 4)=g->member[idx].account_id;
  7482. WBUFL(buf, 8)=g->member[idx].char_id;
  7483. WBUFL(buf,12)=g->member[idx].position;
  7484. // }*
  7485. if( (sd=guild_getavailablesd(g))!=NULL )
  7486. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7487. }
  7488. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7489. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7490. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7491. {
  7492. int fd;
  7493. nullpo_retv(sd);
  7494. nullpo_retv(g);
  7495. fd = sd->fd;
  7496. if( g->emblem_len <= 0 )
  7497. return;
  7498. WFIFOHEAD(fd,g->emblem_len+12);
  7499. WFIFOW(fd,0)=0x152;
  7500. WFIFOW(fd,2)=g->emblem_len+12;
  7501. WFIFOL(fd,4)=g->guild_id;
  7502. WFIFOL(fd,8)=g->emblem_id;
  7503. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7504. WFIFOSET(fd,WFIFOW(fd,2));
  7505. }
  7506. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7507. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7508. void clif_guild_emblem_area(struct block_list* bl)
  7509. {
  7510. uint8 buf[12];
  7511. nullpo_retv(bl);
  7512. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7513. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7514. WBUFW(buf,0) = 0x1b4;
  7515. WBUFL(buf,2) = bl->id;
  7516. WBUFL(buf,6) = status_get_guild_id(bl);
  7517. WBUFW(buf,10) = status_get_emblem_id(bl);
  7518. clif_send(buf, 12, bl, AREA_WOS);
  7519. }
  7520. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7521. /// 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 }*
  7522. void clif_guild_skillinfo(struct map_session_data* sd)
  7523. {
  7524. int fd;
  7525. struct guild* g;
  7526. int i,c;
  7527. nullpo_retv(sd);
  7528. if( (g = sd->guild) == NULL )
  7529. return;
  7530. fd = sd->fd;
  7531. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7532. WFIFOW(fd,0) = 0x0162;
  7533. WFIFOW(fd,4) = g->skill_point;
  7534. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7535. {
  7536. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7537. {
  7538. int id = g->skill[i].id;
  7539. int p = 6 + c*37;
  7540. WFIFOW(fd,p+0) = id;
  7541. WFIFOL(fd,p+2) = skill_get_inf(id);
  7542. WFIFOW(fd,p+6) = g->skill[i].lv;
  7543. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7544. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7545. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7546. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7547. c++;
  7548. }
  7549. }
  7550. WFIFOW(fd,2) = 6 + c*37;
  7551. WFIFOSET(fd,WFIFOW(fd,2));
  7552. }
  7553. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7554. /// 016f <subject>.60B <notice>.120B
  7555. void clif_guild_notice(struct map_session_data* sd)
  7556. {
  7557. int fd;
  7558. struct guild* g;
  7559. nullpo_retv(sd);
  7560. nullpo_retv(g = sd->guild);
  7561. fd = sd->fd;
  7562. if ( !session_isActive(fd) )
  7563. return;
  7564. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7565. return;
  7566. WFIFOHEAD(fd,packet_len(0x16f));
  7567. WFIFOW(fd,0) = 0x16f;
  7568. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7569. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7570. WFIFOSET(fd,packet_len(0x16f));
  7571. }
  7572. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7573. /// 016a <guild id>.L <guild name>.24B
  7574. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7575. {
  7576. int fd;
  7577. nullpo_retv(sd);
  7578. nullpo_retv(g);
  7579. fd=sd->fd;
  7580. WFIFOHEAD(fd,packet_len(0x16a));
  7581. WFIFOW(fd,0)=0x16a;
  7582. WFIFOL(fd,2)=g->guild_id;
  7583. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7584. WFIFOSET(fd,packet_len(0x16a));
  7585. }
  7586. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7587. /// 0169 <answer>.B
  7588. /// answer:
  7589. /// 0 = Already in guild.
  7590. /// 1 = Offer rejected.
  7591. /// 2 = Offer accepted.
  7592. /// 3 = Guild full.
  7593. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7594. {
  7595. int fd;
  7596. nullpo_retv(sd);
  7597. fd=sd->fd;
  7598. WFIFOHEAD(fd,packet_len(0x169));
  7599. WFIFOW(fd,0)=0x169;
  7600. WFIFOB(fd,2)=flag;
  7601. WFIFOSET(fd,packet_len(0x169));
  7602. }
  7603. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7604. /// 015a <char name>.24B <reason>.40B
  7605. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7606. {
  7607. unsigned char buf[128];
  7608. nullpo_retv(sd);
  7609. WBUFW(buf, 0)=0x15a;
  7610. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7611. memcpy(WBUFP(buf,26),mes,40);
  7612. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7613. }
  7614. /// Notifies clients of a guild of an expelled member.
  7615. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7616. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7617. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7618. {
  7619. unsigned char buf[128];
  7620. #if PACKETVER < 20100803
  7621. const unsigned short cmd = 0x15c;
  7622. #else
  7623. const unsigned short cmd = 0x839;
  7624. #endif
  7625. nullpo_retv(sd);
  7626. WBUFW(buf,0) = cmd;
  7627. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7628. safestrncpy(WBUFCP(buf,26), mes, 40);
  7629. #if PACKETVER < 20100803
  7630. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7631. #endif
  7632. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7633. }
  7634. /// Guild expulsion list (ZC_BAN_LIST).
  7635. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7636. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7637. void clif_guild_expulsionlist(struct map_session_data* sd)
  7638. {
  7639. #if PACKETVER < 20100803
  7640. const int offset = NAME_LENGTH*2+40;
  7641. #else
  7642. const int offset = NAME_LENGTH+40;
  7643. #endif
  7644. int fd, i, c = 0;
  7645. struct guild* g;
  7646. nullpo_retv(sd);
  7647. if( (g = sd->guild) == NULL )
  7648. return;
  7649. fd = sd->fd;
  7650. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7651. WFIFOW(fd,0) = 0x163;
  7652. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7653. {
  7654. struct guild_expulsion* e = &g->expulsion[i];
  7655. if( e->account_id > 0 )
  7656. {
  7657. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7658. #if PACKETVER < 20100803
  7659. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7660. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7661. #else
  7662. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7663. #endif
  7664. c++;
  7665. }
  7666. }
  7667. WFIFOW(fd,2) = 4 + c*offset;
  7668. WFIFOSET(fd,WFIFOW(fd,2));
  7669. }
  7670. /// Guild chat message (ZC_GUILD_CHAT).
  7671. /// 017f <packet len>.W <message>.?B
  7672. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7673. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7674. struct map_session_data *sd;
  7675. uint8 buf[256];
  7676. if( len == 0 )
  7677. {
  7678. return;
  7679. }
  7680. else if( len > sizeof(buf)-5 )
  7681. {
  7682. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7683. len = sizeof(buf)-5;
  7684. }
  7685. WBUFW(buf, 0) = 0x17f;
  7686. WBUFW(buf, 2) = len + 5;
  7687. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7688. if ((sd = guild_getavailablesd(g)) != NULL)
  7689. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7690. }
  7691. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7692. /// 0171 <inviter account id>.L <guild name>.24B
  7693. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7694. {
  7695. int fd;
  7696. nullpo_retv(sd);
  7697. fd=sd->fd;
  7698. WFIFOHEAD(fd,packet_len(0x171));
  7699. WFIFOW(fd,0)=0x171;
  7700. WFIFOL(fd,2)=account_id;
  7701. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7702. WFIFOSET(fd,packet_len(0x171));
  7703. }
  7704. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7705. /// 0173 <answer>.B
  7706. /// answer:
  7707. /// 0 = Already allied.
  7708. /// 1 = You rejected the offer.
  7709. /// 2 = You accepted the offer.
  7710. /// 3 = They have too any alliances.
  7711. /// 4 = You have too many alliances.
  7712. /// 5 = Alliances are disabled.
  7713. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7714. {
  7715. int fd;
  7716. nullpo_retv(sd);
  7717. fd=sd->fd;
  7718. WFIFOHEAD(fd,packet_len(0x173));
  7719. WFIFOW(fd,0)=0x173;
  7720. WFIFOL(fd,2)=flag;
  7721. WFIFOSET(fd,packet_len(0x173));
  7722. }
  7723. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7724. /// 0184 <other guild id>.L <relation>.L
  7725. /// relation:
  7726. /// 0 = Ally
  7727. /// 1 = Enemy
  7728. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7729. {
  7730. int fd;
  7731. nullpo_retv(sd);
  7732. fd = sd->fd;
  7733. if (fd <= 0)
  7734. return;
  7735. WFIFOHEAD(fd,packet_len(0x184));
  7736. WFIFOW(fd,0)=0x184;
  7737. WFIFOL(fd,2)=guild_id;
  7738. WFIFOL(fd,6)=flag;
  7739. WFIFOSET(fd,packet_len(0x184));
  7740. }
  7741. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7742. /// 0181 <result>.B
  7743. /// result:
  7744. /// 0 = Antagonist has been set.
  7745. /// 1 = Guild has too many Antagonists.
  7746. /// 2 = Already set as an Antagonist.
  7747. /// 3 = Antagonists are disabled.
  7748. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7749. {
  7750. int fd;
  7751. nullpo_retv(sd);
  7752. fd=sd->fd;
  7753. WFIFOHEAD(fd,packet_len(0x181));
  7754. WFIFOW(fd,0)=0x181;
  7755. WFIFOB(fd,2)=flag;
  7756. WFIFOSET(fd,packet_len(0x181));
  7757. }
  7758. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7759. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7760. /*
  7761. void clif_guild_allianceadded(struct guild *g,int idx)
  7762. {
  7763. unsigned char buf[64];
  7764. WBUFW(buf,0)=0x185;
  7765. WBUFL(buf,2)=g->alliance[idx].opposition;
  7766. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7767. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7768. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7769. }
  7770. */
  7771. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7772. /// 015e <reason>.L
  7773. /// 0 = success
  7774. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7775. /// 2 = there are still members in the guild
  7776. void clif_guild_broken(struct map_session_data *sd,int flag)
  7777. {
  7778. int fd;
  7779. nullpo_retv(sd);
  7780. fd=sd->fd;
  7781. WFIFOHEAD(fd,packet_len(0x15e));
  7782. WFIFOW(fd,0)=0x15e;
  7783. WFIFOL(fd,2)=flag;
  7784. WFIFOSET(fd,packet_len(0x15e));
  7785. }
  7786. /// Displays emotion on an object (ZC_EMOTION).
  7787. /// 00c0 <id>.L <type>.B
  7788. /// type:
  7789. /// enum emotion_type
  7790. void clif_emotion(struct block_list *bl,int type)
  7791. {
  7792. unsigned char buf[8];
  7793. nullpo_retv(bl);
  7794. WBUFW(buf,0)=0xc0;
  7795. WBUFL(buf,2)=bl->id;
  7796. WBUFB(buf,6)=type;
  7797. clif_send(buf,packet_len(0xc0),bl,AREA);
  7798. }
  7799. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7800. /// 0191 <id>.L <contents>.80B
  7801. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7802. {
  7803. unsigned char buf[MESSAGE_SIZE+6];
  7804. nullpo_retv(bl);
  7805. WBUFW(buf,0) = 0x191;
  7806. WBUFL(buf,2) = bl->id;
  7807. safestrncpy(WBUFCP(buf,6),talkie,MESSAGE_SIZE);
  7808. clif_send(buf,packet_len(0x191),bl,AREA);
  7809. }
  7810. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7811. /// 01ea <id>.L
  7812. void clif_wedding_effect(struct block_list *bl)
  7813. {
  7814. unsigned char buf[6];
  7815. nullpo_retv(bl);
  7816. WBUFW(buf,0) = 0x1ea;
  7817. WBUFL(buf,2) = bl->id;
  7818. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7819. }
  7820. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7821. /// 01e6 <partner name>.24B
  7822. void clif_callpartner(struct map_session_data *sd)
  7823. {
  7824. unsigned char buf[26];
  7825. nullpo_retv(sd);
  7826. WBUFW(buf,0) = 0x1e6;
  7827. if( sd->status.partner_id ) {
  7828. const char *p = map_charid2nick(sd->status.partner_id);
  7829. struct map_session_data *p_sd = pc_get_partner(sd);
  7830. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7831. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7832. else
  7833. WBUFB(buf,2) = 0;
  7834. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7835. WBUFB(buf,2) = 0;
  7836. }
  7837. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7838. }
  7839. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7840. /// 01e4
  7841. /// This packet while still implemented by the client is no longer being officially used.
  7842. /*
  7843. void clif_marriage_process(struct map_session_data *sd)
  7844. {
  7845. int fd;
  7846. nullpo_retv(sd);
  7847. fd=sd->fd;
  7848. WFIFOHEAD(fd,packet_len(0x1e4));
  7849. WFIFOW(fd,0)=0x1e4;
  7850. WFIFOSET(fd,packet_len(0x1e4));
  7851. }
  7852. */
  7853. /// Notice of divorce (ZC_DIVORCE).
  7854. /// 0205 <partner name>.24B
  7855. void clif_divorced(struct map_session_data* sd, const char* name)
  7856. {
  7857. int fd;
  7858. nullpo_retv(sd);
  7859. fd=sd->fd;
  7860. WFIFOHEAD(fd,packet_len(0x205));
  7861. WFIFOW(fd,0)=0x205;
  7862. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7863. WFIFOSET(fd, packet_len(0x205));
  7864. }
  7865. /// Marriage proposal (ZC_REQ_COUPLE).
  7866. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7867. /// This packet while still implemented by the client is no longer being officially used.
  7868. /*
  7869. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7870. {
  7871. nullpo_retv(sd);
  7872. WFIFOHEAD(fd,packet_len(0x1e2));
  7873. WFIFOW(fd,0) = 0x1e2;
  7874. WFIFOL(fd,2) = ssd->status.account_id;
  7875. WFIFOL(fd,6) = ssd->status.char_id;
  7876. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7877. WFIFOSET(fd, packet_len(0x1e2));
  7878. }
  7879. */
  7880. /*==========================================
  7881. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7882. *------------------------------------------*/
  7883. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7884. {
  7885. unsigned char buf[256];
  7886. if( len == 0 ) {
  7887. return;
  7888. } else if( len > sizeof(buf)-5 ) {
  7889. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7890. len = sizeof(buf)-5;
  7891. }
  7892. WBUFW(buf, 0) = 0x17f;
  7893. WBUFW(buf, 2) = len + 5;
  7894. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7895. clif_send(buf, WBUFW(buf,2), src, target);
  7896. }
  7897. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7898. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7899. /// 00cd <result>.B
  7900. /// result:
  7901. /// 0 = failure
  7902. /// 1 = success
  7903. void clif_GM_kickack(struct map_session_data *sd, int id)
  7904. {
  7905. int fd;
  7906. nullpo_retv(sd);
  7907. fd = sd->fd;
  7908. WFIFOHEAD(fd,packet_len(0xcd));
  7909. WFIFOW(fd,0) = 0xcd;
  7910. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7911. WFIFOSET(fd, packet_len(0xcd));
  7912. }
  7913. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7914. {
  7915. int fd;
  7916. nullpo_retv(tsd);
  7917. fd = tsd->fd;
  7918. if (sd == NULL)
  7919. tsd->state.keepshop = true;
  7920. if (fd > 0)
  7921. clif_authfail_fd(fd, 15);
  7922. else
  7923. map_quit(tsd);
  7924. if (sd)
  7925. clif_GM_kickack(sd, tsd->status.account_id);
  7926. }
  7927. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7928. /// 014a <result>.L
  7929. /// result:
  7930. /// 0 = "A manner point has been successfully aligned."
  7931. /// 1 = MP_FAILURE_EXHAUST
  7932. /// 2 = MP_FAILURE_ALREADY_GIVING
  7933. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7934. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7935. /// 5 = "You got a good point from %s."
  7936. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7937. {
  7938. int fd;
  7939. nullpo_retv(sd);
  7940. fd = sd->fd;
  7941. WFIFOHEAD(fd,packet_len(0x14a));
  7942. WFIFOW(fd,0) = 0x14a;
  7943. WFIFOL(fd,2) = type;
  7944. WFIFOSET(fd, packet_len(0x14a));
  7945. }
  7946. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7947. /// 014b <type>.B <GM name>.24B
  7948. /// type:
  7949. /// 0 = positive (unmute)
  7950. /// 1 = negative (mute)
  7951. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7952. {
  7953. int fd;
  7954. nullpo_retv(sd);
  7955. nullpo_retv(tsd);
  7956. fd = tsd->fd;
  7957. WFIFOHEAD(fd,packet_len(0x14b));
  7958. WFIFOW(fd,0) = 0x14b;
  7959. WFIFOB(fd,2) = type;
  7960. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7961. WFIFOSET(fd, packet_len(0x14b));
  7962. }
  7963. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7964. /// 00d1 <type>.B <result>.B
  7965. /// type:
  7966. /// 0 = /ex (deny)
  7967. /// 1 = /in (allow)
  7968. /// result:
  7969. /// 0 = success
  7970. /// 1 = failure
  7971. /// 2 = too many blocks
  7972. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7973. {
  7974. int fd;
  7975. nullpo_retv(sd);
  7976. fd=sd->fd;
  7977. WFIFOHEAD(fd,packet_len(0xd1));
  7978. WFIFOW(fd,0)=0xd1;
  7979. WFIFOB(fd,2)=type;
  7980. WFIFOB(fd,3)=flag;
  7981. WFIFOSET(fd,packet_len(0xd1));
  7982. }
  7983. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7984. /// 00d2 <type>.B <result>.B
  7985. /// type:
  7986. /// 0 = /exall (deny)
  7987. /// 1 = /inall (allow)
  7988. /// result:
  7989. /// 0 = success
  7990. /// 1 = failure
  7991. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7992. {
  7993. int fd;
  7994. nullpo_retv(sd);
  7995. fd=sd->fd;
  7996. WFIFOHEAD(fd,packet_len(0xd2));
  7997. WFIFOW(fd,0)=0xd2;
  7998. WFIFOB(fd,2)=type;
  7999. WFIFOB(fd,3)=flag;
  8000. WFIFOSET(fd,packet_len(0xd2));
  8001. }
  8002. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8003. /// 07fe <bgm>.24B
  8004. void clif_playBGM(struct map_session_data* sd, const char* name)
  8005. {
  8006. int fd;
  8007. nullpo_retv(sd);
  8008. fd = sd->fd;
  8009. WFIFOHEAD(fd,packet_len(0x7fe));
  8010. WFIFOW(fd,0) = 0x7fe;
  8011. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8012. WFIFOSET(fd,packet_len(0x7fe));
  8013. }
  8014. /// Plays/stops a wave sound (ZC_SOUND).
  8015. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8016. /// file name:
  8017. /// relative to data\wav
  8018. /// act:
  8019. /// 0 = play (once)
  8020. /// 1 = play (repeat, does not work)
  8021. /// 2 = stops all sound instances of file name (does not work)
  8022. /// term:
  8023. /// unknown purpose, only relevant to act = 1
  8024. /// npc id:
  8025. /// The accustic direction of the sound is determined by the
  8026. /// relative position of the NPC to the player (3D sound).
  8027. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  8028. {
  8029. int fd;
  8030. nullpo_retv(sd);
  8031. nullpo_retv(bl);
  8032. fd = sd->fd;
  8033. WFIFOHEAD(fd,packet_len(0x1d3));
  8034. WFIFOW(fd,0) = 0x1d3;
  8035. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8036. WFIFOB(fd,26) = type;
  8037. WFIFOL(fd,27) = 0;
  8038. WFIFOL(fd,31) = bl->id;
  8039. WFIFOSET(fd,packet_len(0x1d3));
  8040. }
  8041. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8042. {
  8043. unsigned char buf[40];
  8044. nullpo_retv(bl);
  8045. WBUFW(buf,0) = 0x1d3;
  8046. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8047. WBUFB(buf,26) = type;
  8048. WBUFL(buf,27) = 0;
  8049. WBUFL(buf,31) = bl->id;
  8050. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8051. }
  8052. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8053. /// 01f3 <id>.L <effect id>.L
  8054. /// effect id:
  8055. /// @see doc/effect_list.txt
  8056. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8057. {
  8058. unsigned char buf[24];
  8059. nullpo_retv(bl);
  8060. memset(buf, 0, packet_len(0x1f3));
  8061. WBUFW(buf,0) = 0x1f3;
  8062. WBUFL(buf,2) = bl->id;
  8063. WBUFL(buf,6) = type;
  8064. clif_send(buf, packet_len(0x1f3), bl, target);
  8065. if (disguised(bl)) {
  8066. WBUFL(buf,2) = -bl->id;
  8067. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8068. }
  8069. }
  8070. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8071. {
  8072. WFIFOHEAD(fd,10);
  8073. WFIFOW(fd,0) = 0x1f3;
  8074. WFIFOL(fd,2) = bl->id;
  8075. WFIFOL(fd,6) = type;
  8076. WFIFOSET(fd,10);
  8077. }
  8078. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8079. /// 0284 <id>.L <effect id>.L <num data>.L
  8080. /// effect id:
  8081. /// @see doc/effect_list.txt
  8082. /// num data:
  8083. /// effect-dependent value
  8084. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8085. {
  8086. uint8 buf[14];
  8087. WBUFW(buf,0) = 0x284;
  8088. WBUFL(buf,2) = bl->id;
  8089. WBUFL(buf,6) = effect_id;
  8090. WBUFL(buf,10) = num;
  8091. clif_send(buf, packet_len(0x284), bl, target);
  8092. if( disguised(bl) )
  8093. {
  8094. WBUFL(buf,2) = -bl->id;
  8095. clif_send(buf, packet_len(0x284), bl, SELF);
  8096. }
  8097. }
  8098. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8099. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8100. 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) {
  8101. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8102. uint8 buf[CHAT_SIZE_MAX];
  8103. nullpo_retv(bl);
  8104. if (msg_len > sizeof(buf) - 12) {
  8105. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8106. msg_len = sizeof(buf) - 12;
  8107. }
  8108. if (rgb2bgr)
  8109. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8110. WBUFW(buf,0) = 0x2C1;
  8111. WBUFW(buf,2) = msg_len + 12;
  8112. WBUFL(buf,4) = bl->id;
  8113. WBUFL(buf,8) = color;
  8114. memcpy(WBUFCP(buf,12), msg, msg_len);
  8115. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8116. }
  8117. /**
  8118. * Notifies the client that the storage window is still open
  8119. *
  8120. * Should only be used in cases where the client closed the
  8121. * storage window without server's consent
  8122. */
  8123. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8124. // Notify the client that the storage is open
  8125. if( sd->state.storage_flag == 1 ) {
  8126. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8127. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8128. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8129. }
  8130. // Notify the client that the gstorage is open otherwise it will
  8131. // remain locked forever and nobody will be able to access it
  8132. if( sd->state.storage_flag == 2 ) {
  8133. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8134. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8135. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8136. else {
  8137. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8138. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8139. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8140. }
  8141. }
  8142. }
  8143. // refresh the client's screen, getting rid of any effects
  8144. void clif_refresh(struct map_session_data *sd)
  8145. {
  8146. nullpo_retv(sd);
  8147. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8148. clif_inventorylist(sd);
  8149. clif_equipswitch_list(sd);
  8150. if(pc_iscarton(sd)) {
  8151. clif_cartlist(sd);
  8152. clif_updatestatus(sd,SP_CARTINFO);
  8153. }
  8154. clif_updatestatus(sd,SP_WEIGHT);
  8155. clif_updatestatus(sd,SP_MAXWEIGHT);
  8156. clif_updatestatus(sd,SP_STR);
  8157. clif_updatestatus(sd,SP_AGI);
  8158. clif_updatestatus(sd,SP_VIT);
  8159. clif_updatestatus(sd,SP_INT);
  8160. clif_updatestatus(sd,SP_DEX);
  8161. clif_updatestatus(sd,SP_LUK);
  8162. if (sd->spiritball)
  8163. clif_spiritball_single(sd->fd, sd);
  8164. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8165. clif_spiritcharm_single(sd->fd, sd);
  8166. if (sd->vd.cloth_color)
  8167. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8168. if (sd->vd.body_style)
  8169. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8170. if(hom_is_active(sd->hd))
  8171. clif_send_homdata(sd,SP_ACK,0);
  8172. if( sd->md ) {
  8173. clif_mercenary_info(sd);
  8174. clif_mercenary_skillblock(sd);
  8175. }
  8176. if( sd->ed )
  8177. clif_elemental_info(sd);
  8178. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8179. clif_weather_check(sd);
  8180. if( sd->chatID )
  8181. chat_leavechat(sd,0);
  8182. if( sd->state.vending )
  8183. clif_openvending(sd, sd->bl.id, sd->vending);
  8184. if( pc_issit(sd) )
  8185. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8186. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8187. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8188. else
  8189. clif_changed_dir(&sd->bl, SELF);
  8190. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8191. //Issue #2143
  8192. //Cancel Trading State
  8193. if (sd->state.trading)
  8194. trade_tradecancel(sd);
  8195. //Cancel Buying/Selling State
  8196. if (sd->state.buyingstore)
  8197. buyingstore_close(sd);
  8198. mail_clear(sd);
  8199. if( disguised(&sd->bl) ) {/* refresh-da */
  8200. short disguise = sd->disguise;
  8201. pc_disguise(sd, 0);
  8202. pc_disguise(sd, disguise);
  8203. }
  8204. clif_refresh_storagewindow(sd);
  8205. }
  8206. /// Updates the object's (bl) name on client.
  8207. /// Used to update when a char leaves a party/guild. [Skotlex]
  8208. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8209. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8210. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8211. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8212. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8213. unsigned char buf[106];
  8214. int cmd = 0x95;
  8215. nullpo_retv(src);
  8216. nullpo_retv(bl);
  8217. WBUFW(buf,0) = cmd;
  8218. WBUFL(buf,2) = bl->id;
  8219. switch( bl->type )
  8220. {
  8221. case BL_PC:
  8222. {
  8223. struct map_session_data *sd = (struct map_session_data *)bl;
  8224. struct party_data *p = NULL;
  8225. #if PACKETVER >= 20150513
  8226. WBUFW(buf, 0) = cmd = 0xa30;
  8227. #else
  8228. WBUFW(buf, 0) = cmd = 0x195;
  8229. #endif
  8230. //Requesting your own "shadow" name. [Skotlex]
  8231. if( src == bl && target == SELF && sd->disguise ){
  8232. WBUFL(buf,2) = -bl->id;
  8233. }
  8234. if( sd->fakename[0] ) {
  8235. safestrncpy(WBUFCP(buf,6), sd->fakename, NAME_LENGTH);
  8236. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  8237. #if PACKETVER >= 20150513
  8238. WBUFL(buf,102) = 0; // Title ID
  8239. #endif
  8240. break;
  8241. }
  8242. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  8243. if( sd->status.party_id ){
  8244. p = party_search(sd->status.party_id);
  8245. }
  8246. // do not display party unless the player is also in a guild
  8247. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8248. safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH);
  8249. }else{
  8250. WBUFB(buf,30) = 0;
  8251. }
  8252. if( sd->guild ){
  8253. int position;
  8254. // Will get the position of the guild the player is in
  8255. position = guild_getposition(sd);
  8256. safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH);
  8257. safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH);
  8258. }else if( sd->clan ){
  8259. WBUFB(buf,54) = 0;
  8260. safestrncpy(WBUFCP(buf,78), sd->clan->name,NAME_LENGTH);
  8261. }else{ //Assume no guild and no clan
  8262. WBUFB(buf,54) = 0;
  8263. WBUFB(buf,78) = 0;
  8264. }
  8265. #if PACKETVER >= 20150513
  8266. WBUFL(buf,102) = sd->status.title_id; // Title ID
  8267. #endif
  8268. }
  8269. break;
  8270. //[blackhole89]
  8271. case BL_HOM:
  8272. safestrncpy(WBUFCP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8273. break;
  8274. case BL_MER:
  8275. safestrncpy(WBUFCP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8276. break;
  8277. case BL_PET:
  8278. safestrncpy(WBUFCP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8279. break;
  8280. case BL_NPC:
  8281. safestrncpy(WBUFCP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8282. break;
  8283. case BL_MOB:
  8284. {
  8285. struct mob_data *md = (struct mob_data *)bl;
  8286. nullpo_retv(md);
  8287. safestrncpy(WBUFCP(buf,6), md->name, NAME_LENGTH);
  8288. if( md->guardian_data && md->guardian_data->guild_id )
  8289. {
  8290. #if PACKETVER >= 20150513
  8291. WBUFW(buf, 0) = cmd = 0xa30;
  8292. #else
  8293. WBUFW(buf, 0) = cmd = 0x195;
  8294. #endif
  8295. WBUFB(buf,30) = 0;
  8296. safestrncpy(WBUFCP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8297. safestrncpy(WBUFCP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8298. }
  8299. else if( battle_config.show_mob_info )
  8300. {
  8301. char mobhp[50], *str_p = mobhp;
  8302. #if PACKETVER >= 20150513
  8303. WBUFW(buf, 0) = cmd = 0xa30;
  8304. #else
  8305. WBUFW(buf, 0) = cmd = 0x195;
  8306. #endif
  8307. if( battle_config.show_mob_info&4 )
  8308. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8309. if( battle_config.show_mob_info&1 )
  8310. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8311. if( battle_config.show_mob_info&2 )
  8312. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8313. //Even thought mobhp ain't a name, we send it as one so the client
  8314. //can parse it. [Skotlex]
  8315. if( str_p != mobhp )
  8316. {
  8317. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8318. safestrncpy(WBUFCP(buf,30), mobhp, NAME_LENGTH);
  8319. WBUFB(buf,54) = 0;
  8320. WBUFB(buf,78) = 0;
  8321. }
  8322. }
  8323. #if PACKETVER >= 20150513
  8324. WBUFL(buf, 102) = 0; // Title ID
  8325. #endif
  8326. }
  8327. break;
  8328. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8329. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8330. // break;
  8331. return;
  8332. case BL_ELEM:
  8333. safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8334. break;
  8335. default:
  8336. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8337. return;
  8338. }
  8339. clif_send(buf, packet_len(cmd), src, target);
  8340. }
  8341. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8342. /// 01ff <id>.L <x>.W <y>.W
  8343. ///
  8344. /// Visually moves(instant) a character to x,y. The char moves even
  8345. /// when the target cell isn't walkable. If the char is sitting it
  8346. /// stays that way.
  8347. void clif_slide(struct block_list *bl, int x, int y)
  8348. {
  8349. unsigned char buf[10];
  8350. nullpo_retv(bl);
  8351. WBUFW(buf, 0) = 0x01ff;
  8352. WBUFL(buf, 2) = bl->id;
  8353. WBUFW(buf, 6) = x;
  8354. WBUFW(buf, 8) = y;
  8355. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8356. if( disguised(bl) )
  8357. {
  8358. WBUFL(buf,2) = -bl->id;
  8359. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8360. }
  8361. }
  8362. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8363. /// 008d <packet len>.W <id>.L <message>.?B
  8364. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8365. {
  8366. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8367. int len_mes = strlen(mes)+1; //Account for \0
  8368. if (len_mes > sizeof(buf)-8) {
  8369. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8370. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8371. }
  8372. // send message to others
  8373. if (flag == AREA) {
  8374. WBUFW(buf,0) = 0x8d;
  8375. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8376. WBUFL(buf,4) = bl->id;
  8377. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8378. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8379. }
  8380. // send back message to the speaker
  8381. if( bl->type == BL_PC ) {
  8382. WBUFW(buf,0) = 0x8e;
  8383. WBUFW(buf, 2) = len_mes + 4;
  8384. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8385. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8386. }
  8387. }
  8388. /*==========================
  8389. * Minimap fix [Kevin]
  8390. * Remove dot from minimap
  8391. *--------------------------*/
  8392. void clif_party_xy_remove(struct map_session_data *sd)
  8393. {
  8394. unsigned char buf[16];
  8395. nullpo_retv(sd);
  8396. WBUFW(buf,0)=0x107;
  8397. WBUFL(buf,2)=sd->status.account_id;
  8398. WBUFW(buf,6)=-1;
  8399. WBUFW(buf,8)=-1;
  8400. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8401. }
  8402. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8403. /// 0215 <msg id>.L
  8404. /// msg id:
  8405. /// 0x15 = End all negative status (PA_GOSPEL)
  8406. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8407. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8408. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8409. /// 0x19 = All stats +20 (PA_GOSPEL)
  8410. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8411. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8412. /// 0x1e = DEF +25% (PA_GOSPEL)
  8413. /// 0x1f = ATK +100% (PA_GOSPEL)
  8414. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8415. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8416. /// ? = nothing
  8417. void clif_gospel_info(struct map_session_data *sd, int type)
  8418. {
  8419. int fd=sd->fd;
  8420. WFIFOHEAD(fd,packet_len(0x215));
  8421. WFIFOW(fd,0)=0x215;
  8422. WFIFOL(fd,2)=type;
  8423. WFIFOSET(fd, packet_len(0x215));
  8424. }
  8425. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8426. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8427. /// result:
  8428. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8429. /// star:
  8430. /// 0 = Place of the Sun
  8431. /// 1 = Place of the Moon
  8432. /// 2 = Place of the Stars
  8433. /// 1 = Star Gladiator %s's %s: <mapname>
  8434. /// star:
  8435. /// 0 = Place of the Sun
  8436. /// 1 = Place of the Moon
  8437. /// 2 = Place of the Stars
  8438. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8439. /// star:
  8440. /// 0 = Target of the Sun
  8441. /// 1 = Target of the Moon
  8442. /// 2 = Target of the Stars
  8443. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8444. /// star:
  8445. /// 0 = Monster of the Sun
  8446. /// 1 = Monster of the Moon
  8447. /// 2 = Monster of the Stars
  8448. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8449. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8450. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8451. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8452. /// 40 = Target HP : <monster_id used as HP>
  8453. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8454. {
  8455. int fd = sd->fd;
  8456. WFIFOHEAD(fd,packet_len(0x20e));
  8457. WFIFOW(fd,0) = 0x20e;
  8458. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8459. WFIFOL(fd,26) = monster_id;
  8460. WFIFOB(fd,30) = star;
  8461. WFIFOB(fd,31) = result;
  8462. WFIFOSET(fd,packet_len(0x20e));
  8463. }
  8464. /*==========================================
  8465. * Info about Star Glaldiator save map [Komurka]
  8466. * type: 1: Information, 0: Map registered
  8467. *------------------------------------------*/
  8468. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8469. {
  8470. char mapname[MAP_NAME_LENGTH_EXT];
  8471. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8472. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8473. }
  8474. /*==========================================
  8475. * Info about Star Glaldiator hate mob [Komurka]
  8476. * type: 1: Register mob, 0: Information.
  8477. *------------------------------------------*/
  8478. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8479. {
  8480. if( pcdb_checkid(class_) ) {
  8481. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8482. } else if( mobdb_checkid(class_) ) {
  8483. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8484. } else {
  8485. 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);
  8486. }
  8487. }
  8488. /*==========================================
  8489. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8490. *------------------------------------------*/
  8491. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8492. {
  8493. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8494. }
  8495. /*==========================================
  8496. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8497. *------------------------------------------*/
  8498. void clif_feel_hate_reset(struct map_session_data *sd)
  8499. {
  8500. clif_starskill(sd, "", 0, 0, 30);
  8501. }
  8502. /// Send out reply to configuration change
  8503. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8504. /// type: see enum e_config_type
  8505. /// value:
  8506. /// false = disabled
  8507. /// true = enabled
  8508. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8509. int fd;
  8510. nullpo_retv(sd);
  8511. fd = sd->fd;
  8512. WFIFOHEAD(fd, packet_len(0x2d9));
  8513. WFIFOW(fd, 0) = 0x2d9;
  8514. WFIFOL(fd, 2) = type;
  8515. WFIFOL(fd, 6) = enabled;
  8516. WFIFOSET(fd, packet_len(0x2d9));
  8517. }
  8518. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8519. /// 02da <open equip window>.B
  8520. /// open equip window:
  8521. /// 0 = disabled
  8522. /// 1 = enabled
  8523. void clif_equipcheckbox(struct map_session_data* sd)
  8524. {
  8525. int fd;
  8526. nullpo_retv(sd);
  8527. fd = sd->fd;
  8528. WFIFOHEAD(fd, packet_len(0x2da));
  8529. WFIFOW(fd, 0) = 0x2da;
  8530. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8531. WFIFOSET(fd, packet_len(0x2da));
  8532. }
  8533. /// Sends info about a player's equipped items.
  8534. /// 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)
  8535. /// 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)
  8536. /// 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)
  8537. /// 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)
  8538. /// 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)
  8539. /// 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)
  8540. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8541. {
  8542. uint8* buf;
  8543. int i, n, fd, offset = 0;
  8544. #if PACKETVER < 20100629
  8545. const int s = 26;
  8546. #elif PACKETVER < 20120925
  8547. const int s = 28;
  8548. #elif PACKETVER < 20150225
  8549. const int s = 31;
  8550. #else
  8551. const int s = 57;
  8552. #endif
  8553. nullpo_retv(sd);
  8554. nullpo_retv(tsd);
  8555. fd = sd->fd;
  8556. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8557. buf = WFIFOP(fd,0);
  8558. #if PACKETVER < 20101124
  8559. WBUFW(buf, 0) = 0x2d7;
  8560. #elif PACKETVER < 20120925
  8561. WBUFW(buf, 0) = 0x859;
  8562. #elif PACKETVER < 20150225
  8563. WBUFW(buf, 0) = 0x997;
  8564. #else
  8565. WBUFW(buf, 0) = 0xa2d;
  8566. #endif
  8567. safestrncpy(WBUFCP(buf, 4), tsd->status.name, NAME_LENGTH);
  8568. WBUFW(buf,28) = tsd->status.class_;
  8569. WBUFW(buf,30) = tsd->vd.hair_style;
  8570. WBUFW(buf,32) = tsd->vd.head_bottom;
  8571. WBUFW(buf,34) = tsd->vd.head_mid;
  8572. WBUFW(buf,36) = tsd->vd.head_top;
  8573. #if PACKETVER >= 20110111
  8574. WBUFW(buf,38) = tsd->vd.robe;
  8575. offset+= 2;
  8576. buf = WBUFP(buf,2);
  8577. #endif
  8578. WBUFW(buf,38) = tsd->vd.hair_color;
  8579. WBUFW(buf,40) = tsd->vd.cloth_color;
  8580. WBUFB(buf,42) = tsd->vd.sex;
  8581. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8582. {
  8583. if (tsd->inventory.u.items_inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8584. continue;
  8585. if (!tsd->inventory.u.items_inventory[i].equip)
  8586. continue;
  8587. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8588. continue;
  8589. // Add item info : refine, identify flag, element, etc.
  8590. 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));
  8591. n++;
  8592. }
  8593. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8594. WFIFOSET(fd, WFIFOW(fd, 2));
  8595. }
  8596. /// Display msgstringtable.txt string (ZC_MSG).
  8597. /// 0291 <message>.W
  8598. void clif_msg(struct map_session_data* sd, unsigned short id)
  8599. {
  8600. int fd;
  8601. nullpo_retv(sd);
  8602. fd = sd->fd;
  8603. WFIFOHEAD(fd, packet_len(0x291));
  8604. WFIFOW(fd, 0) = 0x291;
  8605. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8606. WFIFOSET(fd, packet_len(0x291));
  8607. }
  8608. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8609. /// 0x7e2 <message>.W <value>.L
  8610. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8611. {
  8612. int fd = sd->fd;
  8613. WFIFOHEAD(fd, packet_len(0x7e2));
  8614. WFIFOW(fd,0) = 0x7e2;
  8615. WFIFOW(fd,2) = id;
  8616. WFIFOL(fd,4) = value;
  8617. WFIFOSET(fd, packet_len(0x7e2));
  8618. }
  8619. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8620. /// 07e6 <skill id>.W <msg id>.L
  8621. ///
  8622. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8623. /// "[SkillName] Message"
  8624. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8625. {
  8626. int fd = sd->fd;
  8627. WFIFOHEAD(fd, packet_len(0x7e6));
  8628. WFIFOW(fd,0) = 0x7e6;
  8629. WFIFOW(fd,2) = skill_id;
  8630. WFIFOL(fd,4) = msg_id;
  8631. WFIFOSET(fd, packet_len(0x7e6));
  8632. }
  8633. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8634. /// 09cd <msg id>.W <color>.L
  8635. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8636. nullpo_retv(sd);
  8637. int fd = sd->fd;
  8638. WFIFOHEAD(fd, packet_len(0x9cd));
  8639. WFIFOW(fd, 0) = 0x9cd;
  8640. WFIFOW(fd, 2) = msg_id;
  8641. WFIFOL(fd, 4) = color;
  8642. WFIFOSET(fd, packet_len(0x9cd));
  8643. }
  8644. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8645. /// Returns true if the packet was parsed successfully.
  8646. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8647. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8648. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8649. const char* seperator = " : ";
  8650. int fd;
  8651. struct s_packet_db* info;
  8652. uint16 packetLength, inputLength;
  8653. const char *input, *name, *message;
  8654. size_t nameLength, messageLength;
  8655. fd = sd->fd;
  8656. info = &packet_db[RFIFOW(fd,0)];
  8657. packetLength = RFIFOW(fd,info->pos[0]);
  8658. input = RFIFOCP(fd,info->pos[1]);
  8659. // basic structure check for the 4-byte header
  8660. if( packetLength < 4 ){
  8661. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8662. return false;
  8663. }else{
  8664. inputLength = packetLength - 4;
  8665. }
  8666. // process <name> part of the packet
  8667. if( whisperFormat ) {
  8668. // name has fixed width
  8669. if( inputLength < NAME_LENGTH + 1 ) {
  8670. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8671. return false;
  8672. }
  8673. name = input;
  8674. // validate name
  8675. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8676. // only restriction is that the name must be zero-terminated
  8677. if( name[nameLength] != '\0' ) {
  8678. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8679. return false;
  8680. }
  8681. message = input + NAME_LENGTH;
  8682. messageLength = inputLength - NAME_LENGTH;
  8683. }else{
  8684. // name and message are separated by ' : '
  8685. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8686. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8687. // check if there's enough data provided
  8688. if( inputLength < nameLength + seperatorLength + 1 ){
  8689. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8690. return false;
  8691. }
  8692. name = input;
  8693. // validate name
  8694. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8695. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8696. {
  8697. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8698. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8699. set_eof(sd->fd); // Just kick them out to correct it.
  8700. return false;
  8701. }
  8702. message = input + nameLength + seperatorLength;
  8703. messageLength = inputLength - nameLength - seperatorLength;
  8704. }
  8705. #if PACKETVER < 20151001
  8706. // the declared length must match real length
  8707. if( messageLength != strnlen(message, messageLength)+1 ) {
  8708. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8709. return false;
  8710. }
  8711. // verify <message> part of the packet
  8712. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8713. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8714. return false;
  8715. }
  8716. #else
  8717. // No zero termination anymore
  8718. messageLength += 1;
  8719. #endif
  8720. // messages mustn't be too long
  8721. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8722. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8723. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8724. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8725. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8726. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8727. return false;
  8728. }
  8729. // If it is not a whisper message, set the name to the fakename of the player
  8730. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8731. strcpy( out_name, sd->fakename );
  8732. }else{
  8733. safestrncpy( out_name, name, nameLength + 1 );
  8734. }
  8735. safestrncpy( out_message, message, messageLength );
  8736. if( whisperFormat ){
  8737. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8738. out_full_message[nameLength] = '\0';
  8739. }else{
  8740. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8741. }
  8742. if( is_atcommand( fd, sd, out_message, 1 ) )
  8743. return false;
  8744. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8745. return false; //no "chatting" while muted.
  8746. if( battle_config.min_chat_delay ) { //[Skotlex]
  8747. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8748. return false;
  8749. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8750. }
  8751. if (battle_config.idletime_option&IDLE_CHAT)
  8752. sd->idletime = last_tick;
  8753. return true;
  8754. }
  8755. /**
  8756. * Displays a message if the player enters a PK Zone (during pk_mode)
  8757. * @param sd: Player data
  8758. */
  8759. inline void clif_pk_mode_message(struct map_session_data * sd)
  8760. {
  8761. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8762. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8763. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8764. char output[CHAT_SIZE_MAX];
  8765. // 1504: You've entered a PK Zone (safe until level %d).
  8766. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8767. battle_config.pk_min_level);
  8768. clif_showscript(&sd->bl, output, SELF);
  8769. } else {
  8770. // 1503: You've entered a PK Zone.
  8771. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8772. }
  8773. }
  8774. return;
  8775. }
  8776. // ---------------------
  8777. // clif_parse_wanttoconnect
  8778. // ---------------------
  8779. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8780. // error codes:
  8781. // 0 - Success
  8782. // 1 - Unknown packet_ver
  8783. // 2 - Invalid account_id
  8784. // 3 - Invalid char_id
  8785. // 4 - Invalid login_id1 (reserved)
  8786. // 5 - Invalid client_tick (reserved)
  8787. // 6 - Invalid sex
  8788. // Only the first 'invalid' error that appears is used.
  8789. static int clif_parse_WantToConnection_sub(int fd)
  8790. {
  8791. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8792. unsigned short cmd;
  8793. //By default, start searching on the default one.
  8794. cmd = RFIFOW(fd, 0);
  8795. packet_len = RFIFOREST(fd);
  8796. // FIXME: If the packet is not received at once, this will FAIL.
  8797. // Figure out, when it happens, that only part of the packet is
  8798. // received, or fix the function to be able to deal with that
  8799. // case.
  8800. if( packet_len != packet_db[cmd].len )
  8801. return 1; /* wrong length */
  8802. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8803. return 2; /* invalid account_id */
  8804. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8805. return 3; /* invalid char_id */
  8806. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8807. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8808. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8809. return 6; /* invalid sex */
  8810. else
  8811. return 0;
  8812. }
  8813. /// Request to connect to map-server.
  8814. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8815. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8816. /// There are various variants of this packet, some of them have padding between fields.
  8817. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8818. {
  8819. struct block_list* bl;
  8820. struct auth_node* node;
  8821. int cmd, account_id, char_id, login_id1, sex, err;
  8822. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8823. if (sd) {
  8824. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8825. return;
  8826. }
  8827. cmd = RFIFOW(fd, 0);
  8828. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8829. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8830. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8831. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8832. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8833. err = clif_parse_WantToConnection_sub(fd);
  8834. if( err ){ // connection rejected
  8835. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8836. err == 1 ? "." :
  8837. err == 2 ? ", possibly for having an invalid account_id." :
  8838. err == 3 ? ", possibly for having an invalid char_id." :
  8839. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8840. err == 4 ? ", possibly for having an invalid login_id1." :
  8841. err == 5 ? ", possibly for having an invalid client_tick." :
  8842. */
  8843. err == 6 ? ", possibly for having an invalid sex." :
  8844. ". ERROR invalid error code"));
  8845. WFIFOHEAD(fd,packet_len(0x6a));
  8846. WFIFOW(fd,0) = 0x6a;
  8847. WFIFOB(fd,2) = err;
  8848. WFIFOSET(fd,packet_len(0x6a));
  8849. #ifdef DUMP_INVALID_PACKET
  8850. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8851. #endif
  8852. RFIFOSKIP(fd, RFIFOREST(fd));
  8853. set_eof(fd);
  8854. return;
  8855. }
  8856. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8857. clif_authfail_fd(fd,1);// server closed
  8858. return;
  8859. }
  8860. //Check for double login.
  8861. bl = map_id2bl(account_id);
  8862. if(bl && bl->type != BL_PC) {
  8863. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8864. WFIFOHEAD(fd,packet_len(0x6a));
  8865. WFIFOW(fd,0) = 0x6a;
  8866. WFIFOB(fd,2) = 3; // Rejected by server
  8867. WFIFOSET(fd,packet_len(0x6a));
  8868. set_eof(fd);
  8869. return;
  8870. }
  8871. if (bl ||
  8872. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8873. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8874. {
  8875. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8876. return;
  8877. }
  8878. CREATE(sd, TBL_PC, 1);
  8879. sd->fd = fd;
  8880. #ifdef PACKET_OBFUSCATION
  8881. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8882. #endif
  8883. session[fd]->session_data = sd;
  8884. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8885. #if PACKETVER < 20070521
  8886. WFIFOHEAD(fd,4);
  8887. WFIFOL(fd,0) = sd->bl.id;
  8888. WFIFOSET(fd,4);
  8889. #else
  8890. WFIFOHEAD(fd,packet_len(0x283));
  8891. WFIFOW(fd,0) = 0x283;
  8892. WFIFOL(fd,2) = sd->bl.id;
  8893. WFIFOSET(fd,packet_len(0x283));
  8894. #endif
  8895. chrif_authreq(sd,false);
  8896. }
  8897. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8898. /// 007d
  8899. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8900. {
  8901. bool guild_notice = false;
  8902. if(sd->bl.prev != NULL)
  8903. return;
  8904. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8905. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8906. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8907. sd->state.connect_new = 0;
  8908. return;
  8909. }
  8910. if (sd->state.rewarp) { //Rewarp player.
  8911. sd->state.rewarp = 0;
  8912. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8913. return;
  8914. }
  8915. sd->state.warping = 0;
  8916. // look
  8917. #if PACKETVER < 4
  8918. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8919. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8920. #else
  8921. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8922. #endif
  8923. pc_set_costume_view(sd);
  8924. if(sd->vd.cloth_color)
  8925. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8926. if(sd->vd.body_style)
  8927. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8928. // item
  8929. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8930. pc_checkitem(sd);
  8931. clif_equipswitch_list(sd);
  8932. // cart
  8933. if(pc_iscarton(sd)) {
  8934. clif_cartlist(sd);
  8935. clif_updatestatus(sd,SP_CARTINFO);
  8936. }
  8937. // weight
  8938. clif_updatestatus(sd,SP_WEIGHT);
  8939. clif_updatestatus(sd,SP_MAXWEIGHT);
  8940. // guild
  8941. // (needs to go before clif_spawn() to show guild emblems correctly)
  8942. if(sd->status.guild_id)
  8943. guild_send_memberinfoshort(sd,1);
  8944. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8945. if(battle_config.pc_invincible_time > 0) {
  8946. if(mapdata_flag_gvg(mapdata))
  8947. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8948. else
  8949. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8950. }
  8951. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8952. map_spawnmobs(sd->bl.m);
  8953. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8954. mapdata->users_pvp++;
  8955. }
  8956. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8957. // reset the callshop flag if the player changes map
  8958. sd->state.callshop = 0;
  8959. if(map_addblock(&sd->bl))
  8960. return;
  8961. clif_spawn(&sd->bl);
  8962. // Party
  8963. // (needs to go after clif_spawn() to show hp bars correctly)
  8964. if(sd->status.party_id) {
  8965. party_send_movemap(sd);
  8966. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8967. }
  8968. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8969. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  8970. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8971. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  8972. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8973. sd->pvp_rank = 0;
  8974. sd->pvp_lastusers = 0;
  8975. sd->pvp_point = 5;
  8976. sd->pvp_won = 0;
  8977. sd->pvp_lost = 0;
  8978. }
  8979. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8980. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8981. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8982. else if (mapdata->flag[MF_GVG_DUNGEON])
  8983. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8984. else if( mapdata_flag_gvg(mapdata) )
  8985. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8986. else
  8987. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8988. // info about nearby objects
  8989. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8990. 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);
  8991. // pet
  8992. if( sd->pd ) {
  8993. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8994. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8995. pet_return_egg( sd, sd->pd );
  8996. } else {
  8997. if(map_addblock(&sd->pd->bl))
  8998. return;
  8999. clif_spawn(&sd->pd->bl);
  9000. clif_send_petdata(sd,sd->pd,0,0);
  9001. clif_send_petstatus(sd);
  9002. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9003. }
  9004. }
  9005. //homunculus [blackhole89]
  9006. if( hom_is_active(sd->hd) ) {
  9007. if(map_addblock(&sd->hd->bl))
  9008. return;
  9009. clif_spawn(&sd->hd->bl);
  9010. clif_send_homdata(sd,SP_ACK,0);
  9011. clif_hominfo(sd,sd->hd,1);
  9012. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9013. clif_homskillinfoblock(sd);
  9014. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9015. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  9016. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9017. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9018. }
  9019. if( sd->md ) {
  9020. if(map_addblock(&sd->md->bl))
  9021. return;
  9022. clif_spawn(&sd->md->bl);
  9023. clif_mercenary_info(sd);
  9024. clif_mercenary_skillblock(sd);
  9025. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  9026. }
  9027. if( sd->ed ) {
  9028. if (map_addblock(&sd->ed->bl))
  9029. return;
  9030. clif_spawn(&sd->ed->bl);
  9031. clif_elemental_info(sd);
  9032. clif_elemental_updatestatus(sd,SP_HP);
  9033. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9034. clif_elemental_updatestatus(sd,SP_SP);
  9035. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9036. }
  9037. if(sd->state.connect_new) {
  9038. int lv;
  9039. guild_notice = true;
  9040. clif_skillinfoblock(sd);
  9041. clif_hotkeys_send(sd);
  9042. clif_updatestatus(sd,SP_BASEEXP);
  9043. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9044. clif_updatestatus(sd,SP_JOBEXP);
  9045. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9046. clif_updatestatus(sd,SP_SKILLPOINT);
  9047. clif_initialstatus(sd);
  9048. if (sd->sc.option&OPTION_FALCON)
  9049. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9050. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  9051. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9052. else if (sd->sc.option&OPTION_WUGRIDER)
  9053. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9054. else if (sd->sc.data[SC_ALL_RIDING])
  9055. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9056. if(sd->status.manner < 0)
  9057. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9058. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9059. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9060. if(sd->bl.m == sd->feel_map[0].m
  9061. || sd->bl.m == sd->feel_map[1].m
  9062. || sd->bl.m == sd->feel_map[2].m)
  9063. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9064. }
  9065. if(sd->pd && sd->pd->pet.intimate > 900)
  9066. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9067. if(hom_is_active(sd->hd))
  9068. hom_init_timers(sd->hd);
  9069. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9070. sd->state.night = 1;
  9071. clif_status_load(&sd->bl, EFST_SKE, 1);
  9072. }
  9073. // Notify everyone that this char logged in [Skotlex].
  9074. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9075. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9076. //Login Event
  9077. npc_script_event(sd, NPCE_LOGIN);
  9078. }
  9079. } else {
  9080. //For some reason the client "loses" these on warp/map-change.
  9081. clif_updatestatus(sd,SP_STR);
  9082. clif_updatestatus(sd,SP_AGI);
  9083. clif_updatestatus(sd,SP_VIT);
  9084. clif_updatestatus(sd,SP_INT);
  9085. clif_updatestatus(sd,SP_DEX);
  9086. clif_updatestatus(sd,SP_LUK);
  9087. // abort currently running script
  9088. sd->state.using_fake_npc = 0;
  9089. sd->state.menu_or_input = 0;
  9090. sd->npc_menu = 0;
  9091. if(sd->npc_id)
  9092. npc_event_dequeue(sd);
  9093. }
  9094. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9095. #if PACKETVER >= 20070918
  9096. clif_partyinvitationstate(sd);
  9097. clif_equipcheckbox(sd);
  9098. #endif
  9099. #if PACKETVER >= 20141008
  9100. if( battle_config.pet_autofeed_always ){
  9101. // Always send ON or OFF
  9102. if( sd->pd && battle_config.feature_pet_autofeed ){
  9103. clif_configuration( sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed );
  9104. }else{
  9105. clif_configuration( sd, CONFIG_PET_AUTOFEED, false );
  9106. }
  9107. }else{
  9108. // Only send when enabled
  9109. if( sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed ){
  9110. clif_configuration( sd, CONFIG_PET_AUTOFEED, true );
  9111. }
  9112. }
  9113. #endif
  9114. #if PACKETVER >= 20170920
  9115. if( battle_config.homunculus_autofeed_always ){
  9116. // Always send ON or OFF
  9117. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9118. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9119. }else{
  9120. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9121. }
  9122. }else{
  9123. // Only send when enabled
  9124. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9125. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9126. }
  9127. }
  9128. #endif
  9129. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9130. clif_guild_notice(sd); // Displays after VIP
  9131. guild_notice = false; // Do not display it twice
  9132. }
  9133. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9134. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9135. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9136. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9137. }
  9138. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9139. { //Display night.
  9140. if( !sd->state.night )
  9141. {
  9142. sd->state.night = 1;
  9143. clif_status_load(&sd->bl, EFST_SKE, 1);
  9144. }
  9145. }
  9146. else if( sd->state.night )
  9147. { //Clear night display.
  9148. sd->state.night = 0;
  9149. clif_status_load(&sd->bl, EFST_SKE, 0);
  9150. }
  9151. if( mapdata->flag[MF_BATTLEGROUND] )
  9152. {
  9153. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9154. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9155. clif_bg_updatescore_single(sd);
  9156. }
  9157. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9158. {
  9159. char output[128];
  9160. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9161. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9162. }
  9163. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9164. mapdata->hpmeter_visible++;
  9165. sd->state.hpmeter_visible = 1;
  9166. }
  9167. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9168. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9169. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9170. #ifdef VIP_ENABLE
  9171. if (!sd->state.connect_new &&
  9172. !sd->vip.disableshowrate &&
  9173. sd->state.pmap != sd->bl.m &&
  9174. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9175. )
  9176. {
  9177. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9178. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9179. }
  9180. #endif
  9181. // Instances do not need their own channels
  9182. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9183. channel_mjoin(sd); //join new map
  9184. clif_pk_mode_message(sd);
  9185. }
  9186. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9187. clif_guild_notice(sd); // Displays at end
  9188. }
  9189. mail_clear(sd);
  9190. /* Guild Aura Init */
  9191. if( sd->guild && sd->state.gmaster_flag ) {
  9192. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9193. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9194. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9195. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9196. }
  9197. if( sd->state.vending ) { /* show we have a vending */
  9198. clif_openvending(sd,sd->bl.id,sd->vending);
  9199. clif_showvendingboard(&sd->bl,sd->message,0);
  9200. }
  9201. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9202. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9203. npc_script_event(sd, NPCE_LOADMAP);
  9204. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  9205. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9206. if (sd->sc.opt2) //Client loses these on warp.
  9207. clif_changeoption(&sd->bl);
  9208. 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)) {
  9209. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9210. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9211. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9212. }
  9213. clif_weather_check(sd);
  9214. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9215. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9216. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9217. else
  9218. sd->areanpc.clear();
  9219. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9220. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9221. pc_setdead(sd);
  9222. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9223. if(pc_isdead(sd))
  9224. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9225. else {
  9226. skill_usave_trigger(sd);
  9227. if (battle_config.spawn_direction)
  9228. clif_changed_dir(&sd->bl, SELF);
  9229. }
  9230. // Trigger skill effects if you appear standing on them
  9231. if(!battle_config.pc_invincible_time)
  9232. skill_unit_move(&sd->bl,gettick(),1);
  9233. pc_show_questinfo_reinit(sd);
  9234. pc_show_questinfo(sd);
  9235. #if PACKETVER >= 20150513
  9236. if( sd->mail.inbox.unread ){
  9237. clif_Mail_new(sd, 0, NULL, NULL);
  9238. }
  9239. #endif
  9240. sd->state.connect_new = 0;
  9241. sd->state.changemap = false;
  9242. }
  9243. /// Server's tick (ZC_NOTIFY_TIME).
  9244. /// 007f <time>.L
  9245. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9246. {
  9247. int fd = sd->fd;
  9248. WFIFOHEAD(fd,packet_len(0x7f));
  9249. WFIFOW(fd,0) = 0x7f;
  9250. WFIFOL(fd,2) = client_tick(time);
  9251. WFIFOSET(fd,packet_len(0x7f));
  9252. }
  9253. /// Request for server's tick.
  9254. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9255. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9256. /// There are various variants of this packet, some of them have padding between fields.
  9257. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9258. {
  9259. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9260. clif_notify_time(sd, gettick());
  9261. }
  9262. /// Sends hotkey bar.
  9263. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9264. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9265. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9266. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9267. void clif_hotkeys_send(struct map_session_data *sd) {
  9268. #ifdef HOTKEY_SAVING
  9269. const int fd = sd->fd;
  9270. int i;
  9271. int offset = 2;
  9272. #if PACKETVER < 20090603
  9273. const int cmd = 0x2b9;
  9274. #elif PACKETVER < 20141022
  9275. const int cmd = 0x7d9;
  9276. #else
  9277. char Rotate = sd->status.hotkey_rowshift;
  9278. const int cmd = 0xa00;
  9279. offset = 3;
  9280. #endif
  9281. if (!fd) return;
  9282. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9283. WFIFOW(fd, 0) = cmd;
  9284. #if PACKETVER >= 20141022
  9285. WFIFOB(fd, 2) = Rotate;
  9286. #endif
  9287. for(i = 0; i < MAX_HOTKEYS; i++) {
  9288. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9289. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9290. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9291. }
  9292. WFIFOSET(fd, packet_len(cmd));
  9293. #endif
  9294. }
  9295. /// Request to update a position on the hotkey row bar
  9296. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9297. int cmd = RFIFOW(fd, 0);
  9298. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  9299. }
  9300. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9301. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9302. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9303. #ifdef HOTKEY_SAVING
  9304. unsigned short idx;
  9305. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9306. idx = RFIFOW(fd, info->pos[0]);
  9307. if (idx >= MAX_HOTKEYS) return;
  9308. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9309. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9310. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9311. #endif
  9312. }
  9313. /// Displays cast-like progress bar (ZC_PROGRESS).
  9314. /// 02f0 <color>.L <time>.L
  9315. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9316. {
  9317. int fd = sd->fd;
  9318. WFIFOHEAD(fd,packet_len(0x2f0));
  9319. WFIFOW(fd,0) = 0x2f0;
  9320. WFIFOL(fd,2) = color;
  9321. WFIFOL(fd,6) = second;
  9322. WFIFOSET(fd,packet_len(0x2f0));
  9323. }
  9324. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9325. /// 02f2
  9326. void clif_progressbar_abort(struct map_session_data * sd)
  9327. {
  9328. int fd = sd->fd;
  9329. WFIFOHEAD(fd,packet_len(0x2f2));
  9330. WFIFOW(fd,0) = 0x2f2;
  9331. WFIFOSET(fd,packet_len(0x2f2));
  9332. }
  9333. /// Notification from the client, that the progress bar has reached 100%.
  9334. /// 02f1 (CZ_PROGRESS)
  9335. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9336. // No progressbar active, ignore it
  9337. if( !sd->progressbar.npc_id ){
  9338. return;
  9339. }
  9340. int npc_id = sd->progressbar.npc_id;
  9341. bool closing = false;
  9342. // Check if the progress was canceled
  9343. if( gettick() < sd->progressbar.timeout && sd->st ){
  9344. closing = true;
  9345. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9346. // If a message window was open, offer a close button to the user
  9347. if( sd->st->mes_active ){
  9348. clif_scriptclose( sd, npc_id );
  9349. }
  9350. }
  9351. sd->progressbar.npc_id = 0;
  9352. sd->progressbar.timeout = 0;
  9353. sd->state.workinprogress = WIP_DISABLE_NONE;
  9354. npc_scriptcont(sd, npc_id, closing);
  9355. }
  9356. /// Displays cast-like progress bar on a NPC
  9357. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9358. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9359. #if PACKETVER >= 20130821
  9360. unsigned char buf[14];
  9361. if( nd->progressbar.timeout > 0 ){
  9362. WBUFW(buf,0) = 0x9d1;
  9363. WBUFL(buf,2) = nd->bl.id;
  9364. WBUFL(buf,6) = nd->progressbar.color;
  9365. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9366. if( sd ){
  9367. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9368. }else{
  9369. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9370. }
  9371. }
  9372. #endif
  9373. }
  9374. /// Request to walk to a certain position on the current map.
  9375. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9376. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9377. /// There are various variants of this packet, some of them have padding between fields.
  9378. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9379. {
  9380. short x, y;
  9381. if (pc_isdead(sd)) {
  9382. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9383. return;
  9384. }
  9385. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9386. ; //You CAN walk on this OPT1 value.
  9387. else if (sd->progressbar.npc_id) {
  9388. clif_progressbar_abort(sd);
  9389. return; // First walk attempt cancels the progress bar
  9390. } else if (pc_cant_act(sd))
  9391. return;
  9392. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9393. return;
  9394. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9395. //A move command one cell west is only valid if the target cell is free
  9396. if(battle_config.official_cell_stack_limit > 0
  9397. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9398. return;
  9399. // Cloaking wall check is actually updated when you click to process next movement
  9400. // not when you move each cell. This is official behaviour.
  9401. if (sd->sc.data[SC_CLOAKING])
  9402. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9403. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9404. pc_delinvincibletimer(sd);
  9405. //Set last idle time... [Skotlex]
  9406. if (battle_config.idletime_option&IDLE_WALK)
  9407. sd->idletime = last_tick;
  9408. unit_walktoxy(&sd->bl, x, y, 4);
  9409. }
  9410. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9411. /// 018b <result>.W
  9412. /// result:
  9413. /// 0 = disconnect (quit)
  9414. /// 1 = cannot disconnect (wait 10 seconds)
  9415. /// ? = ignored
  9416. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9417. {
  9418. int fd = sd->fd;
  9419. WFIFOHEAD(fd,packet_len(0x18b));
  9420. WFIFOW(fd,0) = 0x18b;
  9421. WFIFOW(fd,2) = result;
  9422. WFIFOSET(fd,packet_len(0x18b));
  9423. }
  9424. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9425. /// 018a <type>.W
  9426. /// type:
  9427. /// 0 = quit
  9428. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9429. {
  9430. /* Rovert's prevent logout option fixed [Valaris] */
  9431. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9432. 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] &&
  9433. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9434. {
  9435. set_eof(fd);
  9436. pc_damage_log_clear(sd,0);
  9437. clif_disconnect_ack(sd, 0);
  9438. } else {
  9439. clif_disconnect_ack(sd, 1);
  9440. }
  9441. }
  9442. /// Requesting unit's name.
  9443. /// 0094 <id>.L (CZ_REQNAME)
  9444. /// 0368 <id>.L (CZ_REQNAME2)
  9445. /// There are various variants of this packet, some of them have padding between fields.
  9446. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9447. {
  9448. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9449. struct block_list* bl;
  9450. //struct status_change *sc;
  9451. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9452. id = sd->bl.id;
  9453. bl = map_id2bl(id);
  9454. if( bl == NULL )
  9455. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9456. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9457. return; // Block namerequests past view range
  9458. // 'see people in GM hide' cheat detection
  9459. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9460. sc = status_get_sc(bl);
  9461. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9462. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9463. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9464. ) {
  9465. char gm_msg[256];
  9466. 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);
  9467. ShowWarning(gm_msg);
  9468. // information is sent to all online GMs
  9469. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9470. return;
  9471. }
  9472. */
  9473. clif_name(&sd->bl,bl,SELF);
  9474. }
  9475. /// Validates and processes global messages
  9476. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9477. /// There are various variants of this packet.
  9478. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9479. {
  9480. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9481. size_t length;
  9482. // validate packet and retrieve name and message
  9483. if( !clif_process_message(sd, false, name, message, output ) )
  9484. return;
  9485. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9486. channel_send(sd->gcbind,sd,message);
  9487. return;
  9488. }
  9489. // send message to others (using the send buffer for temp. storage)
  9490. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9491. length = strlen(output) + 1;
  9492. // send back message to the speaker
  9493. WFIFOHEAD(fd,4+length);
  9494. WFIFOW(fd,0) = 0x8e;
  9495. WFIFOW(fd,2) = (uint16)(4+length);
  9496. safestrncpy(WFIFOCP(fd,4), output, length );
  9497. WFIFOSET(fd, WFIFOW(fd,2));
  9498. #ifdef PCRE_SUPPORT
  9499. // trigger listening npcs
  9500. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9501. #endif
  9502. // Chat logging type 'O' / Global Chat
  9503. 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);
  9504. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9505. }
  9506. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9507. /// Request to warp to a map on given coordinates.
  9508. /// 0140 <map name>.16B <x>.W <y>.W
  9509. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9510. {
  9511. char command[MAP_NAME_LENGTH_EXT+25];
  9512. char* map_name;
  9513. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9514. map_name = RFIFOCP(fd,info->pos[0]);
  9515. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9516. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9517. RFIFOW(fd,info->pos[1]), //x
  9518. RFIFOW(fd,info->pos[2])); //y
  9519. is_atcommand(fd, sd, command, 1);
  9520. }
  9521. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9522. /// 009c <id>.L <head dir>.W <dir>.B
  9523. /// head dir:
  9524. /// 0 = straight
  9525. /// 1 = turned CW
  9526. /// 2 = turned CCW
  9527. /// dir:
  9528. /// 0 = north
  9529. /// 1 = northwest
  9530. /// 2 = west
  9531. /// 3 = southwest
  9532. /// 4 = south
  9533. /// 5 = southeast
  9534. /// 6 = east
  9535. /// 7 = northeast
  9536. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9537. {
  9538. unsigned char buf[64];
  9539. WBUFW(buf,0) = 0x9c;
  9540. WBUFL(buf,2) = bl->id;
  9541. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9542. WBUFB(buf,8) = unit_getdir(bl);
  9543. clif_send(buf, packet_len(0x9c), bl, target);
  9544. if (disguised(bl)) {
  9545. WBUFL(buf,2) = -bl->id;
  9546. WBUFW(buf,6) = 0;
  9547. clif_send(buf, packet_len(0x9c), bl, SELF);
  9548. }
  9549. }
  9550. /// Request to change own body and head direction.
  9551. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9552. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9553. /// There are various variants of this packet, some of them have padding between fields.
  9554. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9555. {
  9556. unsigned char headdir, dir;
  9557. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9558. headdir = RFIFOB(fd,info->pos[0]);
  9559. dir = RFIFOB(fd,info->pos[1]);
  9560. pc_setdir(sd, dir, headdir);
  9561. clif_changed_dir(&sd->bl, AREA_WOS);
  9562. }
  9563. /// Request to show an emotion (CZ_REQ_EMOTION).
  9564. /// 00bf <type>.B
  9565. /// type:
  9566. /// @see enum emotion_type
  9567. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9568. {
  9569. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9570. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9571. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9572. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9573. return;
  9574. }
  9575. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9576. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9577. sd->emotionlasttime = time(NULL);
  9578. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9579. return;
  9580. }
  9581. sd->emotionlasttime = time(NULL);
  9582. if (battle_config.idletime_option&IDLE_EMOTION)
  9583. sd->idletime = last_tick;
  9584. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9585. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9586. return;
  9587. }
  9588. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9589. emoticon = rnd()%6+ET_DICE1;
  9590. }
  9591. clif_emotion(&sd->bl, emoticon);
  9592. } else
  9593. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9594. }
  9595. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9596. /// 00c2 <count>.L
  9597. void clif_user_count(struct map_session_data* sd, int count)
  9598. {
  9599. int fd = sd->fd;
  9600. WFIFOHEAD(fd,packet_len(0xc2));
  9601. WFIFOW(fd,0) = 0xc2;
  9602. WFIFOL(fd,2) = count;
  9603. WFIFOSET(fd,packet_len(0xc2));
  9604. }
  9605. /// /w /who (CZ_REQ_USER_COUNT).
  9606. /// Request to display amount of currently connected players.
  9607. /// 00c1
  9608. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9609. {
  9610. clif_user_count(sd, map_getusers());
  9611. }
  9612. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9613. {
  9614. if (pc_isdead(sd)) {
  9615. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9616. return;
  9617. }
  9618. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9619. // (not all are included in pc_can_attack)
  9620. if (sd->sc.count &&
  9621. (sd->sc.data[SC_TRICKDEAD] ||
  9622. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9623. sd->sc.data[SC_BLADESTOP] ||
  9624. sd->sc.data[SC__MANHOLE] ||
  9625. sd->sc.data[SC_SUHIDE] ))
  9626. return;
  9627. if(action_type != 0x00 && action_type != 0x07)
  9628. pc_stop_walking(sd, 1);
  9629. pc_stop_attack(sd);
  9630. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9631. target_id = sd->bl.id;
  9632. switch(action_type)
  9633. {
  9634. case 0x00: // once attack
  9635. case 0x07: // continuous attack
  9636. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9637. return;
  9638. if( sd->sc.option&OPTION_COSTUME )
  9639. return;
  9640. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9641. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9642. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9643. return;
  9644. }
  9645. }
  9646. pc_delinvincibletimer(sd);
  9647. if (battle_config.idletime_option&IDLE_ATTACK)
  9648. sd->idletime = last_tick;
  9649. unit_attack(&sd->bl, target_id, action_type != 0);
  9650. break;
  9651. case 0x02: // sitdown
  9652. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9653. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9654. break;
  9655. }
  9656. if(pc_issit(sd)) {
  9657. //Bugged client? Just refresh them.
  9658. clif_sitting(&sd->bl);
  9659. return;
  9660. }
  9661. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9662. break;
  9663. if (sd->sc.count && (
  9664. sd->sc.data[SC_DANCING] ||
  9665. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9666. )) //No sitting during these states either.
  9667. break;
  9668. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9669. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9670. break;
  9671. }
  9672. if (battle_config.idletime_option&IDLE_SIT)
  9673. sd->idletime = last_tick;
  9674. pc_setsit(sd);
  9675. skill_sit(sd, true);
  9676. clif_sitting(&sd->bl);
  9677. break;
  9678. case 0x03: // standup
  9679. if (!pc_issit(sd)) {
  9680. //Bugged client? Just refresh them.
  9681. clif_standing(&sd->bl);
  9682. return;
  9683. }
  9684. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9685. break;
  9686. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9687. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9688. break;
  9689. }
  9690. if (pc_setstand(sd, false)) {
  9691. if (battle_config.idletime_option&IDLE_SIT)
  9692. sd->idletime = last_tick;
  9693. skill_sit(sd, false);
  9694. clif_standing(&sd->bl);
  9695. }
  9696. break;
  9697. }
  9698. }
  9699. /// Request for an action.
  9700. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9701. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9702. /// action:
  9703. /// 0 = attack
  9704. /// 1 = pick up item
  9705. /// 2 = sit down
  9706. /// 3 = stand up
  9707. /// 7 = continous attack
  9708. /// 12 = (touch skill?)
  9709. /// There are various variants of this packet, some of them have padding between fields.
  9710. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9711. {
  9712. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9713. clif_parse_ActionRequest_sub(sd,
  9714. RFIFOB(fd,info->pos[1]),
  9715. RFIFOL(fd,info->pos[0]),
  9716. gettick()
  9717. );
  9718. }
  9719. /// Response to the death/system menu (CZ_RESTART).
  9720. /// 00b2 <type>.B
  9721. /// type:
  9722. /// 0 = restart (respawn)
  9723. /// 1 = char-select (disconnect)
  9724. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9725. {
  9726. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9727. case 0x00:
  9728. pc_respawn(sd,CLR_OUTSIGHT);
  9729. break;
  9730. case 0x01:
  9731. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9732. 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] &&
  9733. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9734. { //Send to char-server for character selection.
  9735. pc_damage_log_clear(sd,0);
  9736. chrif_charselectreq(sd, session[fd]->client_addr);
  9737. } else {
  9738. clif_disconnect_ack(sd, 1);
  9739. }
  9740. break;
  9741. }
  9742. }
  9743. /// Validates and processes whispered messages (CZ_WHISPER).
  9744. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9745. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9746. {
  9747. struct map_session_data* dstsd;
  9748. int i;
  9749. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9750. // validate packet and retrieve name and message
  9751. if( !clif_process_message( sd, true, target, message, output ) )
  9752. return;
  9753. // Chat logging type 'W' / Whisper
  9754. 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);
  9755. //-------------------------------------------------------//
  9756. // Lordalfa - Paperboy - To whisper NPC commands //
  9757. //-------------------------------------------------------//
  9758. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9759. {
  9760. char* str = target+4; //Skip the NPC: string part.
  9761. struct npc_data* npc;
  9762. if ((npc = npc_name2id(str))) {
  9763. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9764. char *split;
  9765. char event[EVENT_NAME_LENGTH];
  9766. str = message;
  9767. // skip codepage indicator, if detected
  9768. if( str[0] == '|' && strlen(str) >= 4 )
  9769. str += 3;
  9770. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9771. split = strchr(str,'#');
  9772. if( split == NULL ) { // use the remaining string
  9773. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9774. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9775. split_data[i][0] = '\0';
  9776. break;
  9777. }
  9778. *split = '\0';
  9779. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9780. str = split+1;
  9781. }
  9782. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9783. char variablename[CHAT_SIZE_MAX];
  9784. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9785. set_var_str( sd, variablename, split_data[i] );
  9786. }
  9787. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9788. npc_event(sd,event,0); // Calls the NPC label
  9789. return;
  9790. }
  9791. } else if( target[0] == '#' ) {
  9792. struct Channel *channel = NULL;
  9793. char* chname = target;
  9794. channel = channel_name2channel(chname,sd,3);
  9795. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9796. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9797. channel_send(channel,sd,message);
  9798. }
  9799. else if( channel->pass[0] == '\0') { //no pass needed
  9800. if (channel_join(channel,sd)==0)
  9801. channel_send(channel,sd,message); //join success
  9802. }
  9803. else {
  9804. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9805. }
  9806. return;
  9807. }
  9808. }
  9809. // searching destination character
  9810. dstsd = map_nick2sd(target,false);
  9811. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9812. // player is not on this map-server
  9813. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9814. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9815. // and if we ask for 'Test', we must not contact 'test' player
  9816. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9817. intif_wis_message(sd, target, message, strlen(message) + 1);
  9818. return;
  9819. }
  9820. // if player ignores everyone
  9821. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9822. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9823. clif_wis_end(fd, 1); // 1: target character is not logged in
  9824. else
  9825. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9826. return;
  9827. }
  9828. // if player is autotrading
  9829. if (dstsd->state.autotrade == 1){
  9830. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9831. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9832. return;
  9833. }
  9834. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9835. // if player ignores the source character
  9836. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9837. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9838. clif_wis_end(fd, 2); // 2: ignored by target
  9839. return;
  9840. }
  9841. }
  9842. // notify sender of success
  9843. clif_wis_end(fd, 0); // 0: success to send wisper
  9844. // Normal message
  9845. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9846. }
  9847. /// /b /nb (CZ_BROADCAST).
  9848. /// Request to broadcast a message on whole server.
  9849. /// 0099 <packet len>.W <text>.?B 00
  9850. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9851. char command[CHAT_SIZE_MAX+11];
  9852. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9853. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9854. char* msg = RFIFOCP(fd,info->pos[1]);
  9855. // as the length varies depending on the command used, just block unreasonably long strings
  9856. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9857. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9858. is_atcommand(fd, sd, command, 1);
  9859. }
  9860. /// Request to pick up an item.
  9861. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9862. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9863. /// There are various variants of this packet, some of them have padding between fields.
  9864. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9865. {
  9866. struct flooritem_data *fitem;
  9867. int map_object_id;
  9868. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9869. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9870. do {
  9871. if (pc_isdead(sd)) {
  9872. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9873. break;
  9874. }
  9875. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9876. break;
  9877. if (pc_cant_act(sd))
  9878. break;
  9879. if (!pc_takeitem(sd, fitem))
  9880. break;
  9881. return;
  9882. } while (0);
  9883. // Client REQUIRES a fail packet or you can no longer pick items.
  9884. clif_additem(sd,0,0,6);
  9885. }
  9886. /// Request to drop an item.
  9887. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9888. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9889. /// There are various variants of this packet, some of them have padding between fields.
  9890. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9891. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9892. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9893. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9894. for(;;) {
  9895. if (pc_isdead(sd))
  9896. break;
  9897. if (pc_cant_act2(sd) || sd->npc_id)
  9898. break;
  9899. if (sd->sc.count && (
  9900. sd->sc.data[SC_AUTOCOUNTER] ||
  9901. sd->sc.data[SC_BLADESTOP] ||
  9902. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9903. ))
  9904. break;
  9905. if (!pc_dropitem(sd, item_index, item_amount))
  9906. break;
  9907. if (battle_config.idletime_option&IDLE_DROPITEM)
  9908. sd->idletime = last_tick;
  9909. return;
  9910. }
  9911. //Because the client does not like being ignored.
  9912. clif_dropitem(sd, item_index,0);
  9913. }
  9914. /// Request to use an item.
  9915. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9916. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9917. /// There are various variants of this packet, some of them have padding between fields.
  9918. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9919. {
  9920. int n;
  9921. if (pc_isdead(sd)) {
  9922. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9923. return;
  9924. }
  9925. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9926. clif_msg(sd, WORK_IN_PROGRESS);
  9927. return;
  9928. }
  9929. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9930. if (battle_config.idletime_option&IDLE_USEITEM)
  9931. sd->idletime = last_tick;
  9932. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9933. if(n <0 || n >= MAX_INVENTORY)
  9934. return;
  9935. if (!pc_useitem(sd,n))
  9936. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9937. }
  9938. /// Request to equip an item
  9939. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9940. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9941. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9942. {
  9943. int index;
  9944. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9945. if(pc_isdead(sd)) {
  9946. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9947. return;
  9948. }
  9949. index = RFIFOW(fd,info->pos[0])-2;
  9950. if (index < 0 || index >= MAX_INVENTORY)
  9951. return; //Out of bounds check.
  9952. if(sd->npc_id && !sd->npc_item_flag) {
  9953. return;
  9954. } else if (sd->state.storage_flag || sd->sc.opt1)
  9955. ; //You can equip/unequip stuff while storage is open/under status changes
  9956. else if (pc_cant_act2(sd))
  9957. return;
  9958. if(!sd->inventory.u.items_inventory[index].identify) {
  9959. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9960. return;
  9961. }
  9962. if(!sd->inventory_data[index])
  9963. return;
  9964. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9965. pet_equipitem(sd,index);
  9966. return;
  9967. }
  9968. if (battle_config.idletime_option&IDLE_USEITEM)
  9969. sd->idletime = last_tick;
  9970. //Client doesn't send the position for ammo.
  9971. if(sd->inventory_data[index]->type == IT_AMMO)
  9972. pc_equipitem(sd,index,EQP_AMMO);
  9973. else {
  9974. int req_pos;
  9975. #if PACKETVER >= 20120925
  9976. req_pos = RFIFOL(fd,info->pos[1]);
  9977. #else
  9978. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9979. #endif
  9980. pc_equipitem(sd,index,req_pos);
  9981. }
  9982. }
  9983. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9984. /// 00ab <index>.W
  9985. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9986. {
  9987. int index;
  9988. if(pc_isdead(sd)) {
  9989. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9990. return;
  9991. }
  9992. if (sd->npc_id && !sd->npc_item_flag) {
  9993. return;
  9994. } else if (sd->state.storage_flag || sd->sc.opt1)
  9995. ; //You can equip/unequip stuff while storage is open/under status changes
  9996. else if (pc_cant_act2(sd))
  9997. return;
  9998. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9999. if (battle_config.idletime_option&IDLE_USEITEM)
  10000. sd->idletime = last_tick;
  10001. pc_unequipitem(sd,index,1);
  10002. }
  10003. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10004. /// 0090 <id>.L <type>.B
  10005. /// type:
  10006. /// 1 = click
  10007. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10008. {
  10009. struct block_list *bl;
  10010. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10011. if(pc_isdead(sd)) {
  10012. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10013. return;
  10014. }
  10015. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10016. #ifdef RENEWAL
  10017. clif_msg( sd, WORK_IN_PROGRESS );
  10018. #endif
  10019. return;
  10020. }
  10021. if( sd->state.mail_writing )
  10022. return;
  10023. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10024. //type = RFIFOB(fd,info->pos[1]);
  10025. if (!bl) return;
  10026. switch (bl->type) {
  10027. case BL_MOB:
  10028. case BL_PC:
  10029. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10030. break;
  10031. case BL_NPC:
  10032. #ifdef RENEWAL
  10033. 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
  10034. clif_msg(sd, WORK_IN_PROGRESS);
  10035. break;
  10036. }
  10037. #endif
  10038. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10039. struct npc_data* nd = (struct npc_data*)bl;
  10040. // Progressbar is running
  10041. if( nd->progressbar.timeout > 0 ){
  10042. return;
  10043. }
  10044. npc_click(sd,nd);
  10045. }
  10046. break;
  10047. }
  10048. }
  10049. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10050. /// 00c5 <id>.L <type>.B
  10051. /// type:
  10052. /// 0 = buy
  10053. /// 1 = sell
  10054. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10055. {
  10056. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10057. if (sd->state.trading)
  10058. return;
  10059. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10060. }
  10061. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10062. /// 00ca <result>.B
  10063. /// result:
  10064. /// 0 = "The deal has successfully completed."
  10065. /// 1 = "You do not have enough zeny."
  10066. /// 2 = "You are over your Weight Limit."
  10067. /// 3 = "Out of the maximum capacity, you have too many items."
  10068. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  10069. {
  10070. int fd = sd->fd;
  10071. WFIFOHEAD(fd,packet_len(0xca));
  10072. WFIFOW(fd,0) = 0xca;
  10073. WFIFOB(fd,2) = result;
  10074. WFIFOSET(fd,packet_len(0xca));
  10075. }
  10076. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10077. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10078. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  10079. {
  10080. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10081. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  10082. int result;
  10083. if( sd->state.trading || !sd->npc_shopid )
  10084. result = 1;
  10085. else
  10086. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  10087. sd->npc_shopid = 0; //Clear shop data.
  10088. clif_npc_buy_result(sd, result);
  10089. }
  10090. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10091. /// 00cb <result>.B
  10092. /// result:
  10093. /// 0 = "The deal has successfully completed."
  10094. /// 1 = "The deal has failed."
  10095. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10096. {
  10097. int fd = sd->fd;
  10098. WFIFOHEAD(fd,packet_len(0xcb));
  10099. WFIFOW(fd,0) = 0xcb;
  10100. WFIFOB(fd,2) = result;
  10101. WFIFOSET(fd,packet_len(0xcb));
  10102. }
  10103. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10104. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10105. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10106. {
  10107. int fail=0,n;
  10108. unsigned short *item_list;
  10109. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10110. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10111. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10112. if (sd->state.trading || !sd->npc_shopid)
  10113. fail = 1;
  10114. else
  10115. fail = npc_selllist(sd,n,item_list);
  10116. sd->npc_shopid = 0; //Clear shop data.
  10117. clif_npc_sell_result(sd, fail);
  10118. }
  10119. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10120. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10121. /// type:
  10122. /// 0 = private
  10123. /// 1 = public
  10124. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10125. {
  10126. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10127. int len = RFIFOW(fd,info->pos[0])-15;
  10128. int limit = RFIFOW(fd,info->pos[1]);
  10129. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10130. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10131. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10132. char s_password[CHATROOM_PASS_SIZE];
  10133. char s_title[CHATROOM_TITLE_SIZE];
  10134. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10135. return;
  10136. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10137. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10138. return;
  10139. }
  10140. if( npc_isnear(&sd->bl) ) {
  10141. // uncomment to send msg_txt.
  10142. //char output[150];
  10143. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10144. //clif_displaymessage(sd->fd, output);
  10145. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10146. return;
  10147. }
  10148. if( len <= 0 )
  10149. return; // invalid input
  10150. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10151. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10152. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10153. }
  10154. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10155. /// 00d9 <chat ID>.L <passwd>.8B
  10156. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10157. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10158. int chatid = RFIFOL(fd,info->pos[0]);
  10159. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10160. chat_joinchat(sd,chatid,password);
  10161. }
  10162. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10163. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10164. /// type:
  10165. /// 0 = private
  10166. /// 1 = public
  10167. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10168. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10169. int len = RFIFOW(fd,info->pos[0])-15;
  10170. int limit = RFIFOW(fd,info->pos[1]);
  10171. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10172. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10173. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10174. char s_password[CHATROOM_PASS_SIZE];
  10175. char s_title[CHATROOM_TITLE_SIZE];
  10176. if( len <= 0 )
  10177. return; // invalid input
  10178. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10179. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10180. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10181. }
  10182. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10183. /// 00e0 <role>.L <nick>.24B
  10184. /// role:
  10185. /// 0 = owner
  10186. /// 1 = normal
  10187. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10188. {
  10189. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10190. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10191. }
  10192. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10193. /// 00e2 <name>.24B
  10194. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10195. {
  10196. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10197. }
  10198. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10199. /// 00e3
  10200. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10201. {
  10202. chat_leavechat(sd,0);
  10203. }
  10204. //Handles notifying asker and rejecter of what has just ocurred.
  10205. //Type is used to determine the correct msg_txt to use:
  10206. //0:
  10207. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10208. {
  10209. const char* msg;
  10210. char output[256];
  10211. // Your request has been rejected by autoreject option.
  10212. msg = msg_txt(sd,392);
  10213. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10214. //Notice that a request was rejected.
  10215. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10216. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10217. }
  10218. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10219. /// 00e4 <account id>.L
  10220. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10221. {
  10222. struct map_session_data *t_sd;
  10223. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10224. if(!sd->chatID && pc_cant_act(sd))
  10225. return; //You can trade while in a chatroom.
  10226. if(t_sd){
  10227. // @noask [LuzZza]
  10228. if(t_sd->state.noask) {
  10229. clif_noask_sub(sd, t_sd, 0);
  10230. return;
  10231. }
  10232. if (t_sd->state.mail_writing) {
  10233. int old = sd->trade_partner;
  10234. // Fake trading
  10235. sd->trade_partner = t_sd->status.account_id;
  10236. clif_tradestart(sd, 5);
  10237. // Restore old state
  10238. sd->trade_partner = old;
  10239. return;
  10240. }
  10241. }
  10242. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10243. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10244. return;
  10245. }
  10246. trade_traderequest(sd,t_sd);
  10247. }
  10248. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10249. /// 00e6 <result>.B
  10250. /// result:
  10251. /// 3 = accepted
  10252. /// 4 = rejected
  10253. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10254. {
  10255. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10256. }
  10257. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10258. /// 00e8 <index>.W <amount>.L
  10259. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10260. {
  10261. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10262. short index = RFIFOW(fd,info->pos[0]);
  10263. int amount = RFIFOL(fd,info->pos[1]);
  10264. if( index == 0 )
  10265. trade_tradeaddzeny(sd, amount);
  10266. else
  10267. trade_tradeadditem(sd, index, (short)amount);
  10268. }
  10269. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10270. /// 00eb
  10271. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10272. {
  10273. trade_tradeok(sd);
  10274. }
  10275. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10276. /// 00ed
  10277. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10278. {
  10279. trade_tradecancel(sd);
  10280. }
  10281. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10282. /// 00ef
  10283. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10284. {
  10285. trade_tradecommit(sd);
  10286. }
  10287. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10288. /// 0118
  10289. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10290. {
  10291. pc_stop_attack(sd);
  10292. if (sd) sd->ud.state.attack_continue = 0;
  10293. }
  10294. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10295. /// 0126 <index>.W <amount>.L
  10296. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10297. {
  10298. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10299. if (pc_istrading(sd))
  10300. return;
  10301. if (!pc_iscarton(sd))
  10302. return;
  10303. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10304. }
  10305. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10306. /// 0127 <index>.W <amount>.L
  10307. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10308. {
  10309. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10310. if (!pc_iscarton(sd))
  10311. return;
  10312. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10313. }
  10314. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10315. /// 012a
  10316. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10317. {
  10318. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10319. #ifdef NEW_CARTS
  10320. && sd->sc.data[SC_PUSH_CART] )
  10321. pc_setcart(sd,0);
  10322. #else
  10323. )
  10324. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10325. #endif
  10326. else // priority to remove this option before we can clear cart
  10327. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10328. }
  10329. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10330. /// 097f <Length>.W <identity>.L <type>.B
  10331. void clif_SelectCart(struct map_session_data *sd) {
  10332. #if PACKETVER >= 20150826
  10333. int i = 0, carts = 3;
  10334. int fd = sd->fd;
  10335. WFIFOHEAD(fd,8 + carts);
  10336. WFIFOW(fd,0) = 0x97f;
  10337. WFIFOW(fd,2) = 8 + carts;
  10338. WFIFOL(fd,4) = sd->status.account_id;
  10339. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10340. for( i = 0; i < carts; i++ ) {
  10341. WFIFOB(fd,8 + i) = 10 + i;
  10342. }
  10343. WFIFOSET(fd,8 + carts);
  10344. #endif
  10345. }
  10346. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10347. /// 0980 <identity>.L <type>.B
  10348. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10349. #if PACKETVER >= 20150826
  10350. int type;
  10351. // Check identity
  10352. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10353. return;
  10354. type = (int)RFIFOB(fd,6);
  10355. // Check type
  10356. if( type < 10 || type > MAX_CARTS )
  10357. return;
  10358. pc_setcart(sd, type);
  10359. #endif
  10360. }
  10361. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10362. /// 01af <num>.W
  10363. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10364. {// TODO: State tracking?
  10365. int type;
  10366. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10367. return;
  10368. #ifdef RENEWAL
  10369. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10370. clif_msg(sd, WORK_IN_PROGRESS);
  10371. return;
  10372. }
  10373. #endif
  10374. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10375. if(
  10376. #ifdef NEW_CARTS
  10377. (type == 9 && sd->status.base_level > 130) ||
  10378. (type == 8 && sd->status.base_level > 120) ||
  10379. (type == 7 && sd->status.base_level > 110) ||
  10380. (type == 6 && sd->status.base_level > 100) ||
  10381. #endif
  10382. (type == 5 && sd->status.base_level > 90) ||
  10383. (type == 4 && sd->status.base_level > 80) ||
  10384. (type == 3 && sd->status.base_level > 65) ||
  10385. (type == 2 && sd->status.base_level > 40) ||
  10386. (type == 1))
  10387. pc_setcart(sd, type);
  10388. }
  10389. /// Request to increase status (CZ_STATUS_CHANGE).
  10390. /// 00bb <status id>.W <amount>.B
  10391. /// status id:
  10392. /// SP_STR ~ SP_LUK
  10393. /// amount:
  10394. /// Old clients always send 1 for this, even when using /str+ and the like.
  10395. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10396. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10397. {
  10398. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10399. if( increase_amount < 0 ) {
  10400. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10401. fd, increase_amount);
  10402. }
  10403. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10404. }
  10405. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10406. /// 0112 <skill id>.W
  10407. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10408. {
  10409. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10410. }
  10411. 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)
  10412. {
  10413. int lv;
  10414. if( !hd )
  10415. return;
  10416. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10417. clif_emotion(&hd->bl, ET_THINK);
  10418. return;
  10419. }
  10420. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10421. target_id = hd->bl.id;
  10422. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10423. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10424. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10425. clif_emotion(&hd->bl, ET_THINK);
  10426. if (hd->master)
  10427. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10428. return;
  10429. }
  10430. lv = hom_checkskill(hd, skill_id);
  10431. if( skill_lv > lv )
  10432. skill_lv = lv;
  10433. if( skill_lv )
  10434. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10435. }
  10436. 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)
  10437. {
  10438. int lv;
  10439. if( !hd )
  10440. return;
  10441. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10442. clif_emotion(&hd->bl, ET_THINK);
  10443. return;
  10444. }
  10445. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10446. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10447. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10448. clif_emotion(&hd->bl, ET_THINK);
  10449. if (hd->master)
  10450. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10451. return;
  10452. }
  10453. if( hd->sc.data[SC_BASILICA] )
  10454. return;
  10455. lv = hom_checkskill(hd, skill_id);
  10456. if( skill_lv > lv )
  10457. skill_lv = lv;
  10458. if( skill_lv )
  10459. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10460. }
  10461. 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)
  10462. {
  10463. int lv;
  10464. if( !md )
  10465. return;
  10466. if( skill_isNotOk_mercenary(skill_id, md) )
  10467. return;
  10468. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10469. target_id = md->bl.id;
  10470. if( md->ud.skilltimer != INVALID_TIMER )
  10471. {
  10472. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10473. }
  10474. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10475. return;
  10476. lv = mercenary_checkskill(md, skill_id);
  10477. if( skill_lv > lv )
  10478. skill_lv = lv;
  10479. if( skill_lv )
  10480. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10481. }
  10482. 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)
  10483. {
  10484. int lv;
  10485. if( !md )
  10486. return;
  10487. if( skill_isNotOk_mercenary(skill_id, md) )
  10488. return;
  10489. if( md->ud.skilltimer != INVALID_TIMER )
  10490. return;
  10491. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10492. {
  10493. if (md->master)
  10494. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10495. return;
  10496. }
  10497. if( md->sc.data[SC_BASILICA] )
  10498. return;
  10499. lv = mercenary_checkskill(md, skill_id);
  10500. if( skill_lv > lv )
  10501. skill_lv = lv;
  10502. if( skill_lv )
  10503. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10504. }
  10505. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10506. t_tick tick = gettick();
  10507. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10508. int inf = skill_get_inf(skill_id);
  10509. if (inf&INF_GROUND_SKILL || !inf)
  10510. return; //Using a ground/passive skill on a target? WRONG.
  10511. if (sd->state.block_action & PCBLOCK_SKILL) {
  10512. clif_msg(sd, WORK_IN_PROGRESS);
  10513. return;
  10514. }
  10515. if( SKILL_CHK_HOMUN(skill_id) ) {
  10516. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10517. return;
  10518. }
  10519. if( SKILL_CHK_MERC(skill_id) ) {
  10520. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10521. return;
  10522. }
  10523. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10524. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10525. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10526. sd->idletime = last_tick;
  10527. if( sd->npc_id ){
  10528. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10529. #ifdef RENEWAL
  10530. clif_msg( sd, WORK_IN_PROGRESS );
  10531. #endif
  10532. return;
  10533. }
  10534. }
  10535. if ((pc_cant_act2(sd) || sd->chatID) &&
  10536. skill_id != RK_REFRESH &&
  10537. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10538. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10539. return;
  10540. if( pc_issit(sd) )
  10541. return;
  10542. if( skill_isNotOk(skill_id, sd) )
  10543. return;
  10544. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10545. target_id = sd->bl.id; // never trust the client
  10546. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10547. target_id = sd->bl.id;
  10548. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10549. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10550. return;
  10551. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10552. if( sd->skillitem != skill_id ) {
  10553. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10554. return;
  10555. }
  10556. }
  10557. if( sd->sc.option&OPTION_COSTUME )
  10558. return;
  10559. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10560. return; // On basilica only caster can use Basilica again to stop it.
  10561. if( sd->menuskill_id ) {
  10562. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10563. clif_menuskill_clear(sd); //Cancel pet capture.
  10564. }else if( sd->menuskill_id == SG_FEEL ){
  10565. clif_menuskill_clear( sd ); // Cancel selection
  10566. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10567. return; //Can't use skills while a menu is open.
  10568. }
  10569. if( sd->skillitem == skill_id ) {
  10570. if( skill_lv != sd->skillitemlv )
  10571. skill_lv = sd->skillitemlv;
  10572. if( !(inf&INF_SELF_SKILL) )
  10573. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10574. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10575. return;
  10576. }
  10577. sd->skillitem = sd->skillitemlv = 0;
  10578. if( SKILL_CHK_GUILD(skill_id) ) {
  10579. if( sd->state.gmaster_flag )
  10580. skill_lv = guild_checkskill(sd->guild, skill_id);
  10581. else
  10582. skill_lv = 0;
  10583. } else {
  10584. if( skill_id != ALL_EQSWITCH ){
  10585. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10586. }
  10587. }
  10588. pc_delinvincibletimer(sd);
  10589. if( skill_lv )
  10590. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10591. }
  10592. /// Request to use a targeted skill.
  10593. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10594. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10595. /// There are various variants of this packet, some of them have padding between fields.
  10596. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10597. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10598. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10599. }
  10600. /*==========================================
  10601. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10602. *------------------------------------------*/
  10603. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10604. {
  10605. t_tick tick = gettick();
  10606. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10607. return; //Using a target skill on the ground? WRONG.
  10608. if (sd->state.block_action & PCBLOCK_SKILL) {
  10609. clif_msg(sd, WORK_IN_PROGRESS);
  10610. return;
  10611. }
  10612. if( SKILL_CHK_HOMUN(skill_id) ) {
  10613. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10614. return;
  10615. }
  10616. if( SKILL_CHK_MERC(skill_id) ) {
  10617. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10618. return;
  10619. }
  10620. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10621. #ifdef RENEWAL
  10622. clif_msg( sd, WORK_IN_PROGRESS );
  10623. #endif
  10624. return;
  10625. }
  10626. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10627. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10628. sd->idletime = last_tick;
  10629. if( skill_isNotOk(skill_id, sd) )
  10630. return;
  10631. if( skillmoreinfo != -1 ) {
  10632. if( pc_issit(sd) ) {
  10633. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10634. return;
  10635. }
  10636. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10637. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10638. }
  10639. if( sd->ud.skilltimer != INVALID_TIMER )
  10640. return;
  10641. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10642. if( sd->skillitem != skill_id ) {
  10643. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10644. return;
  10645. }
  10646. }
  10647. if( sd->sc.option&OPTION_COSTUME )
  10648. return;
  10649. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10650. return; // On basilica only caster can use Basilica again to stop it.
  10651. if( sd->menuskill_id ) {
  10652. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10653. clif_menuskill_clear(sd); //Cancel pet capture.
  10654. }else if( sd->menuskill_id == SG_FEEL ){
  10655. clif_menuskill_clear( sd ); // Cancel selection
  10656. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10657. return; //Can't use skills while a menu is open.
  10658. }
  10659. pc_delinvincibletimer(sd);
  10660. if( sd->skillitem == skill_id ) {
  10661. if( skill_lv != sd->skillitemlv )
  10662. skill_lv = sd->skillitemlv;
  10663. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10664. } else {
  10665. int lv;
  10666. sd->skillitem = sd->skillitemlv = 0;
  10667. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10668. if( skill_lv > lv )
  10669. skill_lv = lv;
  10670. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10671. }
  10672. }
  10673. }
  10674. /// Request to use a ground skill.
  10675. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10676. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10677. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10678. /// There are various variants of this packet, some of them have padding between fields.
  10679. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10680. {
  10681. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10682. if (pc_cant_act(sd))
  10683. return;
  10684. if (pc_issit(sd))
  10685. return;
  10686. clif_parse_UseSkillToPosSub(fd, sd,
  10687. RFIFOW(fd,info->pos[0]), //skill lv
  10688. RFIFOW(fd,info->pos[1]), //skill num
  10689. RFIFOW(fd,info->pos[2]), //pos x
  10690. RFIFOW(fd,info->pos[3]), //pos y
  10691. // TODO: find out what this is intended to do
  10692. //RFIFOB(fd, info->pos[4])
  10693. -1 //Skill more info.
  10694. );
  10695. }
  10696. /// Request to use a ground skill with text.
  10697. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10698. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10699. /// There are various variants of this packet, some of them have padding between fields.
  10700. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10701. {
  10702. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10703. if (pc_cant_act(sd))
  10704. return;
  10705. if (pc_issit(sd))
  10706. return;
  10707. clif_parse_UseSkillToPosSub(fd, sd,
  10708. RFIFOW(fd,info->pos[0]), //Skill lv
  10709. RFIFOW(fd,info->pos[1]), //Skill num
  10710. RFIFOW(fd,info->pos[2]), //pos x
  10711. RFIFOW(fd,info->pos[3]), //pos y
  10712. info->pos[4] //skill more info
  10713. );
  10714. }
  10715. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10716. /// 011b <skill id>.W <map name>.16B
  10717. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10718. {
  10719. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10720. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10721. char map_name[MAP_NAME_LENGTH];
  10722. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10723. sd->state.workinprogress = WIP_DISABLE_NONE;
  10724. if(skill_id != sd->menuskill_id)
  10725. return;
  10726. //It is possible to use teleport with the storage window open bugreport:8027
  10727. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10728. clif_menuskill_clear(sd);
  10729. return;
  10730. }
  10731. pc_delinvincibletimer(sd);
  10732. skill_castend_map(sd,skill_id,map_name);
  10733. }
  10734. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10735. /// 011d
  10736. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10737. {
  10738. if (!pc_isdead(sd))
  10739. pc_memo(sd,-1);
  10740. }
  10741. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10742. /// 018e <name id>.W { <material id>.W }*3
  10743. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10744. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10745. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10746. int slot1 = RFIFOW(fd,info->pos[1]);
  10747. int slot2 = RFIFOW(fd,info->pos[2]);
  10748. int slot3 = RFIFOW(fd,info->pos[3]);
  10749. short produce_idx = -1;
  10750. switch( sd->menuskill_id ) {
  10751. case -1:
  10752. case AM_PHARMACY:
  10753. case RK_RUNEMASTERY:
  10754. case GC_RESEARCHNEWPOISON:
  10755. break;
  10756. default:
  10757. return;
  10758. }
  10759. if (pc_istrading(sd)) {
  10760. //Make it fail to avoid shop exploits where you sell something different than you see.
  10761. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10762. clif_menuskill_clear(sd);
  10763. return;
  10764. }
  10765. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10766. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10767. clif_menuskill_clear(sd);
  10768. }
  10769. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10770. /// 025b <mk type>.W <name id>.W
  10771. /// mk type:
  10772. /// 1 = cooking
  10773. /// 2 = arrow
  10774. /// 3 = elemental
  10775. /// 4 = GN_MIX_COOKING
  10776. /// 5 = GN_MAKEBOMB
  10777. /// 6 = GN_S_PHARMACY
  10778. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10779. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10780. int type = RFIFOW(fd,info->pos[0]);
  10781. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10782. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10783. short food_idx = -1;
  10784. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10785. return;
  10786. if (pc_istrading(sd)) {
  10787. //Make it fail to avoid shop exploits where you sell something different than you see.
  10788. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10789. clif_menuskill_clear(sd);
  10790. return;
  10791. }
  10792. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10793. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10794. clif_menuskill_clear(sd);
  10795. }
  10796. /// Answer to repair weapon item selection dialog
  10797. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10798. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10799. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10800. {
  10801. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10802. return;
  10803. if (pc_istrading(sd)) {
  10804. //Make it fail to avoid shop exploits where you sell something different than you see.
  10805. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10806. clif_menuskill_clear(sd);
  10807. return;
  10808. }
  10809. skill_repairweapon(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10810. //nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10811. //refine = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  10812. //for(i = 0; i<MAX_SLOTS; i++)
  10813. // card[i] = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3+i]);
  10814. clif_menuskill_clear(sd);
  10815. }
  10816. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10817. /// 0222 <index>.L
  10818. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10819. {
  10820. int idx;
  10821. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10822. return;
  10823. if (pc_istrading(sd)) {
  10824. //Make it fail to avoid shop exploits where you sell something different than you see.
  10825. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10826. clif_menuskill_clear(sd);
  10827. return;
  10828. }
  10829. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10830. skill_weaponrefine(sd, idx-2);
  10831. clif_menuskill_clear(sd);
  10832. }
  10833. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10834. /// 00b8 <npc id>.L <choice>.B
  10835. /// choice:
  10836. /// 1~254 = menu item
  10837. /// 255 = cancel
  10838. /// NOTE: If there were more than 254 items in the list, choice
  10839. /// overflows to choice%256.
  10840. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10841. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10842. int npc_id = RFIFOL(fd,info->pos[0]);
  10843. uint8 select = RFIFOB(fd,info->pos[1]);
  10844. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10845. #ifdef SECURE_NPCTIMEOUT
  10846. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10847. #endif
  10848. TBL_NPC* nd = map_id2nd(npc_id);
  10849. 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);
  10850. clif_GM_kick(NULL,sd);
  10851. #ifdef SECURE_NPCTIMEOUT
  10852. }
  10853. #endif
  10854. return;
  10855. }
  10856. sd->npc_menu = select;
  10857. npc_scriptcont(sd,npc_id, false);
  10858. }
  10859. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10860. /// 00b9 <npc id>.L
  10861. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10862. {
  10863. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10864. }
  10865. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10866. /// 0143 <npc id>.L <value>.L
  10867. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10868. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10869. int npcid = RFIFOL(fd,info->pos[0]);
  10870. int amount = (int)RFIFOL(fd,info->pos[1]);
  10871. sd->npc_amount = amount;
  10872. npc_scriptcont(sd, npcid, false);
  10873. }
  10874. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10875. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10876. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10877. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10878. int message_len = RFIFOW(fd,info->pos[0])-8;
  10879. int npcid = RFIFOL(fd,info->pos[1]);
  10880. const char* message = RFIFOCP(fd,info->pos[2]);
  10881. if( message_len <= 0 )
  10882. return; // invalid input
  10883. #if PACKETVER >= 20151001
  10884. message_len++;
  10885. #endif
  10886. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10887. npc_scriptcont(sd, npcid, false);
  10888. }
  10889. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10890. /// 0146 <npc id>.L
  10891. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10892. {
  10893. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10894. return;
  10895. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10896. }
  10897. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10898. /// 0178 <index>.W
  10899. /// index:
  10900. /// -1 = cancel
  10901. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10902. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10903. if (sd->menuskill_id != MC_IDENTIFY)
  10904. return;
  10905. // Ignore the request
  10906. // - Invalid item index
  10907. // - Invalid item ID or item doesn't exist
  10908. // - Item is already identified
  10909. if (idx < 0 || idx >= MAX_INVENTORY ||
  10910. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10911. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10912. sd->state.workinprogress = WIP_DISABLE_NONE;
  10913. clif_menuskill_clear(sd);
  10914. return;
  10915. }
  10916. skill_identify(sd, idx);
  10917. clif_menuskill_clear(sd);
  10918. }
  10919. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10920. /// 01ae <name id>.W
  10921. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10922. unsigned short nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10923. if (pc_istrading(sd)) {
  10924. //Make it fail to avoid shop exploits where you sell something different than you see.
  10925. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10926. clif_menuskill_clear(sd);
  10927. return;
  10928. }
  10929. switch (sd->menuskill_id) {
  10930. case AC_MAKINGARROW:
  10931. skill_arrow_create(sd,nameid);
  10932. break;
  10933. case SA_CREATECON:
  10934. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10935. break;
  10936. case WL_READING_SB:
  10937. skill_spellbook(sd,nameid);
  10938. break;
  10939. case GC_POISONINGWEAPON:
  10940. skill_poisoningweapon(sd,nameid);
  10941. break;
  10942. case NC_MAGICDECOY:
  10943. skill_magicdecoy(sd,nameid);
  10944. break;
  10945. }
  10946. clif_menuskill_clear(sd);
  10947. }
  10948. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10949. /// 01ce <skill id>.L
  10950. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10951. {
  10952. if (sd->menuskill_id != SA_AUTOSPELL)
  10953. return;
  10954. sd->state.workinprogress = WIP_DISABLE_NONE;
  10955. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10956. clif_menuskill_clear(sd);
  10957. }
  10958. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10959. /// 017a <card index>.W
  10960. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10961. {
  10962. if (sd->state.trading != 0)
  10963. return;
  10964. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10965. }
  10966. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10967. /// 017c <card index>.W <equip index>.W
  10968. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10969. {
  10970. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10971. if (sd->state.trading != 0)
  10972. return;
  10973. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10974. }
  10975. /// Request of character's name by char ID.
  10976. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10977. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10978. /// There are various variants of this packet, some of them have padding between fields.
  10979. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10980. {
  10981. int charid;
  10982. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10983. map_reqnickdb(sd, charid);
  10984. }
  10985. /// /resetskill /resetstate (CZ_RESET).
  10986. /// Request to reset stats or skills.
  10987. /// 0197 <type>.W
  10988. /// type:
  10989. /// 0 = state
  10990. /// 1 = skill
  10991. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10992. char cmd[15];
  10993. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10994. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10995. else
  10996. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10997. is_atcommand(fd, sd, cmd, 1);
  10998. }
  10999. /// /lb /nlb (CZ_LOCALBROADCAST).
  11000. /// Request to broadcast a message on current map.
  11001. /// 019c <packet len>.W <text>.?B
  11002. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11003. {
  11004. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11005. char command[CHAT_SIZE_MAX+16];
  11006. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11007. char* msg = RFIFOCP(fd,info->pos[1]);
  11008. // as the length varies depending on the command used, just block unreasonably long strings
  11009. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11010. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11011. is_atcommand(fd, sd, command, 1);
  11012. }
  11013. /// Request to move an item from inventory to storage.
  11014. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11015. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11016. /// There are various variants of this packet, some of them have padding between fields.
  11017. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11018. {
  11019. int item_index, item_amount;
  11020. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11021. if (pc_istrading(sd))
  11022. return;
  11023. item_index = RFIFOW(fd,info->pos[0])-2;
  11024. item_amount = RFIFOL(fd,info->pos[1]);
  11025. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11026. return;
  11027. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11028. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11029. return;
  11030. }
  11031. if (sd->state.storage_flag == 1)
  11032. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11033. else
  11034. if (sd->state.storage_flag == 2)
  11035. storage_guild_storageadd(sd, item_index, item_amount);
  11036. else if (sd->state.storage_flag == 3)
  11037. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11038. }
  11039. /// Request to move an item from storage to inventory.
  11040. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11041. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11042. /// There are various variants of this packet, some of them have padding between fields.
  11043. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11044. {
  11045. int item_index, item_amount;
  11046. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11047. item_index = RFIFOW(fd,info->pos[0])-1;
  11048. item_amount = RFIFOL(fd,info->pos[1]);
  11049. if (sd->state.storage_flag == 1)
  11050. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11051. else if(sd->state.storage_flag == 2)
  11052. storage_guild_storageget(sd, item_index, item_amount);
  11053. else if(sd->state.storage_flag == 3)
  11054. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11055. }
  11056. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11057. /// 0129 <index>.W <amount>.L
  11058. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11059. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11060. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11061. int amount = RFIFOL(fd,info->pos[1]);
  11062. if( sd->state.vending )
  11063. return;
  11064. if (!pc_iscarton(sd))
  11065. return;
  11066. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11067. return;
  11068. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11069. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11070. return;
  11071. }
  11072. if (sd->state.storage_flag == 1)
  11073. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11074. else if (sd->state.storage_flag == 2)
  11075. storage_guild_storageaddfromcart(sd, idx, amount);
  11076. else if (sd->state.storage_flag == 3)
  11077. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11078. }
  11079. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11080. /// 0128 <index>.W <amount>.L
  11081. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11082. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11083. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11084. int amount = RFIFOL(fd,info->pos[1]);
  11085. if( sd->state.vending )
  11086. return;
  11087. if (!pc_iscarton(sd))
  11088. return;
  11089. if (sd->state.storage_flag == 1)
  11090. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11091. else
  11092. if (sd->state.storage_flag == 2)
  11093. storage_guild_storagegettocart(sd, idx, amount);
  11094. else if (sd->state.storage_flag == 3)
  11095. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11096. }
  11097. /// Request to close storage (CZ_CLOSE_STORE).
  11098. /// 00f7
  11099. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11100. {
  11101. if( sd->state.storage_flag == 1 )
  11102. storage_storageclose(sd);
  11103. else
  11104. if( sd->state.storage_flag == 2 )
  11105. storage_guild_storageclose(sd);
  11106. else if( sd->state.storage_flag == 3 )
  11107. storage_premiumStorage_close(sd);
  11108. }
  11109. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11110. /// 023a <info>.W
  11111. /// info:
  11112. /// 0 = password has not been set yet
  11113. /// 1 = storage is password-protected
  11114. /// 8 = too many wrong passwords
  11115. /// ? = ignored
  11116. /// NOTE: This packet is only available on certain non-kRO clients.
  11117. void clif_storagepassword(struct map_session_data* sd, short info)
  11118. {
  11119. int fd = sd->fd;
  11120. WFIFOHEAD(fd,packet_len(0x23a));
  11121. WFIFOW(fd,0) = 0x23a;
  11122. WFIFOW(fd,2) = info;
  11123. WFIFOSET(fd,packet_len(0x23a));
  11124. }
  11125. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11126. /// 023b <type>.W <password>.16B <new password>.16B
  11127. /// type:
  11128. /// 2 = change password
  11129. /// 3 = check password
  11130. /// NOTE: This packet is only available on certain non-kRO clients.
  11131. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11132. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11133. // int type = RFIFOW(fd,info->pos[0]);
  11134. // char* password = RFIFOP(fd,info->pos[1]);
  11135. // char* new_password = RFIFOP(fd,info->pos[2]);
  11136. // storage_changepass(sd,password,new_password);
  11137. }
  11138. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11139. /// 023c <result>.W <error count>.W
  11140. /// result:
  11141. /// 4 = password change success
  11142. /// 5 = password change failure
  11143. /// 6 = password check success
  11144. /// 7 = password check failure
  11145. /// 8 = too many wrong passwords
  11146. /// ? = ignored
  11147. /// NOTE: This packet is only available on certain non-kRO clients.
  11148. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11149. {
  11150. int fd = sd->fd;
  11151. WFIFOHEAD(fd,packet_len(0x23c));
  11152. WFIFOW(fd,0) = 0x23c;
  11153. WFIFOW(fd,2) = result;
  11154. WFIFOW(fd,4) = error_count;
  11155. WFIFOSET(fd,packet_len(0x23c));
  11156. }
  11157. /// Party creation request
  11158. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11159. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11160. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11161. name[NAME_LENGTH-1] = '\0';
  11162. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11163. clif_displaymessage(fd, msg_txt(sd,227));
  11164. return;
  11165. }
  11166. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11167. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11168. return;
  11169. }
  11170. party_create(sd,name,0,0);
  11171. }
  11172. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11173. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11174. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11175. char* name = RFIFOCP(fd,info->pos[0]);
  11176. int item1 = RFIFOB(fd,info->pos[1]);
  11177. int item2 = RFIFOB(fd,info->pos[2]);
  11178. name[NAME_LENGTH-1] = '\0';
  11179. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11180. clif_displaymessage(fd, msg_txt(sd,227));
  11181. return;
  11182. }
  11183. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11184. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11185. return;
  11186. }
  11187. party_create(sd,name,item1,item2);
  11188. }
  11189. /// Party invitation request
  11190. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11191. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11192. {
  11193. struct map_session_data *t_sd;
  11194. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11195. clif_displaymessage(fd, msg_txt(sd,227));
  11196. return;
  11197. }
  11198. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11199. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11200. clif_noask_sub(sd, t_sd, 1);
  11201. return;
  11202. }
  11203. party_invite(sd, t_sd);
  11204. }
  11205. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11206. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11207. struct map_session_data *t_sd;
  11208. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11209. name[NAME_LENGTH-1] = '\0';
  11210. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11211. clif_displaymessage(fd, msg_txt(sd,227));
  11212. return;
  11213. }
  11214. t_sd = map_nick2sd(name,false);
  11215. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11216. clif_noask_sub(sd, t_sd, 1);
  11217. return;
  11218. }
  11219. party_invite(sd, t_sd);
  11220. }
  11221. /// Party invitation reply
  11222. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11223. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11224. /// flag:
  11225. /// 0 = reject
  11226. /// 1 = accept
  11227. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11228. {
  11229. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11230. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11231. RFIFOL(fd,info->pos[1]));
  11232. }
  11233. //(CZ_PARTY_JOIN_REQ_ACK)
  11234. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11235. {
  11236. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11237. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11238. RFIFOB(fd,info->pos[1]));
  11239. }
  11240. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11241. /// 0100
  11242. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11243. {
  11244. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11245. clif_displaymessage(fd, msg_txt(sd,227));
  11246. return;
  11247. }
  11248. party_leave(sd);
  11249. }
  11250. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11251. /// 0103 <account id>.L <char name>.24B
  11252. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11253. {
  11254. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11255. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11256. clif_displaymessage(fd, msg_txt(sd,227));
  11257. return;
  11258. }
  11259. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11260. RFIFOCP(fd,info->pos[1]));
  11261. }
  11262. /// Request to change party options.
  11263. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11264. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11265. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11266. {
  11267. struct party_data *p;
  11268. int i,expflag;
  11269. int cmd = RFIFOW(fd,0);
  11270. struct s_packet_db* info = &packet_db[cmd];
  11271. if( !sd->status.party_id )
  11272. return;
  11273. p = party_search(sd->status.party_id);
  11274. if( p == NULL )
  11275. return;
  11276. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11277. if( i == MAX_PARTY )
  11278. return; //Shouldn't happen
  11279. if( !p->party.member[i].leader )
  11280. return;
  11281. expflag = RFIFOL(fd,info->pos[0]);
  11282. if(cmd == 0x0102){ //Client can't change the item-field
  11283. party_changeoption(sd, expflag, p->party.item);
  11284. }
  11285. else {
  11286. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11287. party_changeoption(sd, expflag, itemflag);
  11288. }
  11289. }
  11290. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11291. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11292. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11293. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11294. // validate packet and retrieve name and message
  11295. if( !clif_process_message( sd, false, name, message, output ) )
  11296. return;
  11297. party_send_message(sd, output, strlen(output) + 1 );
  11298. }
  11299. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11300. /// 07da <account id>.L
  11301. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11302. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11303. }
  11304. /// Party Booking in KRO [Spiria]
  11305. ///
  11306. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11307. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11308. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11309. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11310. short level = RFIFOW(fd,info->pos[0]);
  11311. short mapid = RFIFOW(fd,info->pos[1]);
  11312. int idxpbj = info->pos[2];
  11313. short job[MAX_PARTY_BOOKING_JOBS];
  11314. int i;
  11315. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11316. job[i] = RFIFOB(fd,idxpbj+i*2);
  11317. party_booking_register(sd, level, mapid, job);
  11318. }
  11319. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11320. /// 0803 <result>.W
  11321. /// result:
  11322. /// 0 = success
  11323. /// 1 = failure
  11324. /// 2 = already registered
  11325. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11326. {
  11327. int fd = sd->fd;
  11328. WFIFOHEAD(fd,packet_len(0x803));
  11329. WFIFOW(fd,0) = 0x803;
  11330. WFIFOW(fd,2) = flag;
  11331. WFIFOSET(fd,packet_len(0x803));
  11332. }
  11333. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11334. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11335. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11336. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11337. short level = RFIFOW(fd,info->pos[0]);
  11338. short mapid = RFIFOW(fd,info->pos[1]);
  11339. short job = RFIFOW(fd,info->pos[2]);
  11340. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11341. short resultcount = RFIFOW(fd,info->pos[4]);
  11342. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11343. }
  11344. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11345. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11346. /// more results:
  11347. /// 0 = no
  11348. /// 1 = yes
  11349. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11350. {
  11351. int i, j;
  11352. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11353. struct party_booking_ad_info *pb_ad;
  11354. WFIFOHEAD(fd,size*count + 5);
  11355. WFIFOW(fd,0) = 0x805;
  11356. WFIFOW(fd,2) = size*count + 5;
  11357. WFIFOB(fd,4) = more_result;
  11358. for(i=0; i<count; i++)
  11359. {
  11360. pb_ad = results[i];
  11361. WFIFOL(fd,i*size+5) = pb_ad->index;
  11362. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11363. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11364. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11365. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11366. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11367. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11368. }
  11369. WFIFOSET(fd,WFIFOW(fd,2));
  11370. }
  11371. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11372. /// 0806
  11373. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11374. {
  11375. if(party_booking_delete(sd))
  11376. clif_PartyBookingDeleteAck(sd, 0);
  11377. }
  11378. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11379. /// 0807 <result>.W
  11380. /// result:
  11381. /// 0 = success
  11382. /// 1 = success (auto-removed expired ad)
  11383. /// 2 = failure
  11384. /// 3 = nothing registered
  11385. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11386. {
  11387. int fd = sd->fd;
  11388. WFIFOHEAD(fd,packet_len(0x807));
  11389. WFIFOW(fd,0) = 0x807;
  11390. WFIFOW(fd,2) = flag;
  11391. WFIFOSET(fd,packet_len(0x807));
  11392. }
  11393. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11394. /// 0808 { <job>.W }*6
  11395. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11396. {
  11397. short job[MAX_PARTY_BOOKING_JOBS];
  11398. int i;
  11399. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11400. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11401. job[i] = RFIFOW(fd,idxpbu+i*2);
  11402. party_booking_update(sd, job);
  11403. }
  11404. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11405. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11406. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11407. {
  11408. int i;
  11409. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11410. if(pb_ad == NULL) return;
  11411. WBUFW(buf,0) = 0x809;
  11412. WBUFL(buf,2) = pb_ad->index;
  11413. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11414. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11415. WBUFW(buf,34) = pb_ad->p_detail.level;
  11416. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11417. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11418. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11419. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11420. }
  11421. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11422. /// 080a <index>.L { <job>.W }*6
  11423. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11424. {
  11425. int i;
  11426. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11427. if(pb_ad == NULL) return;
  11428. WBUFW(buf,0) = 0x80a;
  11429. WBUFL(buf,2) = pb_ad->index;
  11430. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11431. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11432. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11433. }
  11434. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11435. /// 080b <index>.L
  11436. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11437. {
  11438. uint8 buf[6];
  11439. WBUFW(buf,0) = 0x80b;
  11440. WBUFL(buf,2) = index;
  11441. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11442. }
  11443. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11444. /// 012e
  11445. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11446. {
  11447. vending_closevending(sd);
  11448. }
  11449. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11450. /// 0130 <account id>.L
  11451. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11452. {
  11453. if( sd->npc_id ) {// using an NPC
  11454. return;
  11455. }
  11456. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11457. }
  11458. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11459. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11460. void clif_parse_PurchaseReq(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]) - 8;
  11463. int id = (int)RFIFOL(fd,info->pos[1]);
  11464. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11465. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11466. // whether it fails or not, the buy window is closed
  11467. sd->vended_id = 0;
  11468. }
  11469. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11470. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11471. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11472. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11473. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11474. int aid = (int)RFIFOL(fd,info->pos[1]);
  11475. int uid = (int)RFIFOL(fd,info->pos[2]);
  11476. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11477. vending_purchasereq(sd, aid, uid, data, len/4);
  11478. // whether it fails or not, the buy window is closed
  11479. sd->vended_id = 0;
  11480. }
  11481. /// Confirm or cancel the shop preparation window.
  11482. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11483. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11484. /// result:
  11485. /// 0 = canceled
  11486. /// 1 = open
  11487. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11488. int cmd = RFIFOW(fd,0);
  11489. struct s_packet_db* info = &packet_db[cmd];
  11490. short len = (short)RFIFOW(fd,info->pos[0]);
  11491. const char* message = RFIFOCP(fd,info->pos[1]);
  11492. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11493. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11494. len -= 84;
  11495. }
  11496. else { //(CZ_REQ_OPENSTORE2)
  11497. bool flag;
  11498. len -= 85;
  11499. flag = RFIFOB(fd,info->pos[2]) != 0;
  11500. if (!flag) {
  11501. sd->state.prevend = 0;
  11502. sd->state.workinprogress = WIP_DISABLE_NONE;
  11503. }
  11504. }
  11505. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11506. return;
  11507. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11508. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11509. return;
  11510. }
  11511. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11512. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11513. return;
  11514. }
  11515. if( message[0] == '\0' ) // invalid input
  11516. return;
  11517. vending_openvending(sd, message, data, len/8, NULL);
  11518. }
  11519. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11520. /// 0165 <char id>.L <guild name>.24B
  11521. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11522. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11523. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11524. name[NAME_LENGTH-1] = '\0';
  11525. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11526. clif_displaymessage(fd, msg_txt(sd,228));
  11527. return;
  11528. }
  11529. if(sd->clan){
  11530. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11531. return;
  11532. }
  11533. guild_create(sd, name);
  11534. }
  11535. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11536. /// 014d
  11537. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11538. {
  11539. clif_guild_masterormember(sd);
  11540. }
  11541. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11542. /// 014f <type>.L
  11543. /// type:
  11544. /// 0 = basic info
  11545. /// 1 = member manager
  11546. /// 2 = positions
  11547. /// 3 = skills
  11548. /// 4 = expulsion list
  11549. /// 5 = unknown (GM_ALLGUILDLIST)
  11550. /// 6 = notice
  11551. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11552. {
  11553. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11554. if( !sd->status.guild_id && !sd->bg_id )
  11555. return;
  11556. switch( type )
  11557. {
  11558. case 0: // Basic Information Guild, hostile alliance information
  11559. clif_guild_basicinfo(sd);
  11560. clif_guild_allianceinfo(sd);
  11561. break;
  11562. case 1: // Members list, list job title
  11563. clif_guild_positionnamelist(sd);
  11564. clif_guild_memberlist(sd);
  11565. break;
  11566. case 2: // List job title, title information list
  11567. clif_guild_positionnamelist(sd);
  11568. clif_guild_positioninfolist(sd);
  11569. break;
  11570. case 3: // Skill list
  11571. clif_guild_skillinfo(sd);
  11572. break;
  11573. case 4: // Expulsion list
  11574. clif_guild_expulsionlist(sd);
  11575. break;
  11576. default:
  11577. ShowError("clif: guild request info: unknown type %d\n", type);
  11578. break;
  11579. }
  11580. }
  11581. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11582. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11583. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11584. {
  11585. int i;
  11586. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11587. int len = RFIFOW(fd,info->pos[0]);
  11588. int idxgpos = info->pos[1];
  11589. if(!sd->state.gmaster_flag)
  11590. return;
  11591. for(i = idxgpos; i < len; i += 40 ){
  11592. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11593. }
  11594. }
  11595. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11596. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11597. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11598. {
  11599. int i;
  11600. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11601. int len = RFIFOW(fd,info->pos[0]);
  11602. int idxgpos = info->pos[1];
  11603. if(!sd->state.gmaster_flag)
  11604. return;
  11605. // Guild leadership change
  11606. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11607. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11608. clif_msg(sd, GUILD_MASTER_WOE);
  11609. return;
  11610. }
  11611. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11612. clif_msg(sd, GUILD_MASTER_DELAY);
  11613. return;
  11614. }
  11615. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11616. return;
  11617. }
  11618. for(i=idxgpos;i<len;i+=12){
  11619. int position = RFIFOL(fd,i+8);
  11620. if( position > 0 ){
  11621. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11622. }
  11623. }
  11624. }
  11625. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11626. /// 0151 <guild id>.L
  11627. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11628. {
  11629. struct guild* g;
  11630. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11631. if( (g = guild_search(guild_id)) != NULL )
  11632. clif_guild_emblem(sd,g);
  11633. }
  11634. /// Validates data of a guild emblem (compressed bitmap)
  11635. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11636. EMBVALIDATE_SUCCESS = 0,
  11637. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11638. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11639. };
  11640. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11641. {
  11642. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11643. unsigned long buf_len = sizeof(buf);
  11644. int offset = 0;
  11645. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11646. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11647. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11648. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11649. ))
  11650. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11651. if(battle_config.emblem_transparency_limit != 100) {
  11652. int i, transcount = 1, tmp[3];
  11653. for(i = offset; i < buf_len-1; i++) {
  11654. int j = i%3;
  11655. tmp[j] = RBUFL(buf,i);
  11656. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11657. transcount++;
  11658. }
  11659. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11660. return EMBVALIDATE_ERR_TRANSPARENCY;
  11661. }
  11662. return EMBVALIDATE_SUCCESS;
  11663. }
  11664. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11665. /// 0153 <packet len>.W <emblem data>.?B
  11666. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11667. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11668. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11669. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11670. int emb_val=0;
  11671. if( !emblem_len || !sd->state.gmaster_flag )
  11672. return;
  11673. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11674. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11675. return;
  11676. }
  11677. emb_val = clif_validate_emblem(emblem, emblem_len);
  11678. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11679. 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);
  11680. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11681. return;
  11682. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11683. char output[128];
  11684. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11685. 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"
  11686. return;
  11687. }
  11688. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11689. }
  11690. /// Guild notice update request (CZ_GUILD_NOTICE).
  11691. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11692. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11693. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11694. int guild_id = RFIFOL(fd,info->pos[0]);
  11695. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11696. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11697. if(!sd->state.gmaster_flag)
  11698. return;
  11699. // compensate for some client defects when using multilanguage mode
  11700. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11701. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11702. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11703. guild_change_notice(sd, guild_id, msg1, msg2);
  11704. }
  11705. // Helper function for guild invite functions
  11706. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11707. {
  11708. if (t_sd == NULL) // not online or does not exist
  11709. return 1;
  11710. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11711. clif_displaymessage(fd, msg_txt(sd,228));
  11712. return 1;
  11713. }
  11714. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11715. clif_noask_sub(sd, t_sd, 2);
  11716. return 1;
  11717. }
  11718. // Players in a clan can not join a guild
  11719. if(t_sd && t_sd->clan){
  11720. return 1;
  11721. }
  11722. guild_invite(sd, t_sd);
  11723. return 0;
  11724. }
  11725. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11726. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11727. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11728. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11729. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11730. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11731. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11732. if (clif_sub_guild_invite(fd, sd, t_sd))
  11733. return;
  11734. }
  11735. /// Guild invite request (/guildinvite)
  11736. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11737. void
  11738. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11739. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11740. if (clif_sub_guild_invite(fd, sd, t_sd))
  11741. return;
  11742. }
  11743. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11744. /// 016b <guild id>.L <answer>.L
  11745. /// answer:
  11746. /// 0 = refuse
  11747. /// 1 = accept
  11748. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11749. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11750. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11751. RFIFOL(fd,info->pos[1]));
  11752. }
  11753. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11754. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11755. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11756. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11757. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11758. clif_displaymessage(fd, msg_txt(sd,228));
  11759. return;
  11760. }
  11761. if( sd->bg_id ) {
  11762. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11763. return;
  11764. }
  11765. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11766. RFIFOL(fd,info->pos[1]),
  11767. RFIFOL(fd,info->pos[2]),
  11768. RFIFOCP(fd,info->pos[3]));
  11769. }
  11770. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11771. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11772. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11773. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11774. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11775. { // Guild locked.
  11776. clif_displaymessage(fd, msg_txt(sd,228));
  11777. return;
  11778. }
  11779. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11780. RFIFOL(fd,info->pos[1]),
  11781. RFIFOL(fd,info->pos[2]),
  11782. RFIFOCP(fd,info->pos[3]));
  11783. }
  11784. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11785. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11786. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11787. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11788. // validate packet and retrieve name and message
  11789. if( !clif_process_message( sd, false, name, message, output ) )
  11790. return;
  11791. if( sd->bg_id )
  11792. bg_send_message(sd, output, strlen(output) );
  11793. else
  11794. guild_send_message(sd, output, strlen(output) );
  11795. }
  11796. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11797. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11798. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11799. {
  11800. struct map_session_data *t_sd;
  11801. if(!sd->state.gmaster_flag)
  11802. return;
  11803. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11804. clif_displaymessage(fd, msg_txt(sd,228));
  11805. return;
  11806. }
  11807. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11808. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11809. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11810. // @noask [LuzZza]
  11811. if(t_sd && t_sd->state.noask) {
  11812. clif_noask_sub(sd, t_sd, 3);
  11813. return;
  11814. }
  11815. guild_reqalliance(sd,t_sd);
  11816. }
  11817. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11818. /// 0172 <inviter account id>.L <answer>.L
  11819. /// answer:
  11820. /// 0 = refuse
  11821. /// 1 = accept
  11822. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11823. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11824. guild_reply_reqalliance(sd,
  11825. RFIFOL(fd,info->pos[0]),
  11826. RFIFOL(fd,info->pos[1]));
  11827. }
  11828. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11829. /// 0183 <opponent guild id>.L <relation>.L
  11830. /// relation:
  11831. /// 0 = Ally
  11832. /// 1 = Enemy
  11833. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11834. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11835. if(!sd->state.gmaster_flag)
  11836. return;
  11837. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11838. clif_displaymessage(fd, msg_txt(sd,228));
  11839. return;
  11840. }
  11841. guild_delalliance(sd,
  11842. RFIFOL(fd,info->pos[0]),
  11843. RFIFOL(fd,info->pos[1]));
  11844. }
  11845. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11846. /// 0180 <account id>.L
  11847. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11848. {
  11849. struct map_session_data *t_sd;
  11850. if(!sd->state.gmaster_flag)
  11851. return;
  11852. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11853. clif_displaymessage(fd, msg_txt(sd,228));
  11854. return;
  11855. }
  11856. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11857. // @noask [LuzZza]
  11858. if(t_sd && t_sd->state.noask) {
  11859. clif_noask_sub(sd, t_sd, 4);
  11860. return;
  11861. }
  11862. guild_opposition(sd,t_sd);
  11863. }
  11864. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11865. /// 015d <key>.40B
  11866. /// key:
  11867. /// now guild name; might have been (intended) email, since the
  11868. /// field name and size is same as the one in CH_DELETE_CHAR.
  11869. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11870. {
  11871. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11872. clif_displaymessage(fd, msg_txt(sd,228));
  11873. return;
  11874. }
  11875. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11876. }
  11877. /// Pet
  11878. ///
  11879. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11880. /// 01a1 <type>.B
  11881. /// type:
  11882. /// 0 = pet information
  11883. /// 1 = feed
  11884. /// 2 = performance
  11885. /// 3 = return to egg
  11886. /// 4 = unequip accessory
  11887. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11888. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11889. }
  11890. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11891. /// 019f <id>.L
  11892. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11893. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11894. }
  11895. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11896. /// 01a7 <index>.W
  11897. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11898. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11899. return;
  11900. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11901. clif_menuskill_clear(sd);
  11902. }
  11903. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11904. /// 01a9 <data>.L
  11905. /// data:
  11906. /// is either emotion (@see enum emotion_type) or a compound value
  11907. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11908. /// entry (given in parentheses) in data\pettalktable.xml
  11909. /// act id:
  11910. /// 0 = feeding
  11911. /// 1 = hunting
  11912. /// 2 = danger
  11913. /// 3 = dead
  11914. /// 4 = normal (stand)
  11915. /// 5 = special performance (perfor_s)
  11916. /// 6 = level up (levelup)
  11917. /// 7 = performance 1 (perfor_1)
  11918. /// 8 = performance 2 (perfor_2)
  11919. /// 9 = performance 3 (perfor_3)
  11920. /// 10 = log-in greeting (connect)
  11921. /// hungry value:
  11922. /// 0 = very hungry (hungry)
  11923. /// 1 = hungry (bit_hungry)
  11924. /// 2 = satisfied (noting)
  11925. /// 3 = stuffed (full)
  11926. /// 4 = full (so_full)
  11927. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11928. {
  11929. if(sd->pd)
  11930. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11931. }
  11932. /// Request to change pet's name (CZ_RENAME_PET).
  11933. /// 01a5 <name>.24B
  11934. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11935. {
  11936. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11937. }
  11938. /// /kill (CZ_DISCONNECT_CHARACTER).
  11939. /// Request to disconnect a character.
  11940. /// 00cc <account id>.L
  11941. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11942. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11943. {
  11944. struct block_list *target;
  11945. int tid;
  11946. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11947. target = map_id2bl(tid);
  11948. if (!target) {
  11949. clif_GM_kickack(sd, 0);
  11950. return;
  11951. }
  11952. switch (target->type) {
  11953. case BL_PC:
  11954. {
  11955. char command[NAME_LENGTH+6];
  11956. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11957. is_atcommand(fd, sd, command, 1);
  11958. }
  11959. break;
  11960. /**
  11961. * This one does not invoke any atcommand, so we need to check for permissions.
  11962. */
  11963. case BL_MOB:
  11964. {
  11965. char command[100];
  11966. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11967. clif_GM_kickack(sd, 0);
  11968. return;
  11969. }
  11970. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11971. log_atcommand(sd, command);
  11972. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11973. }
  11974. break;
  11975. case BL_NPC:
  11976. {
  11977. struct npc_data* nd = (struct npc_data *)target;
  11978. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11979. npc_unload_duplicates(nd);
  11980. npc_unload(nd,true);
  11981. npc_read_event_script();
  11982. }
  11983. }
  11984. break;
  11985. default:
  11986. clif_GM_kickack(sd, 0);
  11987. }
  11988. }
  11989. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11990. /// Request to disconnect all characters.
  11991. /// 00ce
  11992. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11993. char cmd[15];
  11994. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11995. is_atcommand(fd, sd, cmd, 1);
  11996. }
  11997. /// /remove (CZ_REMOVE_AID).
  11998. /// Request to warp to a character with given login ID.
  11999. /// 01ba <account name>.24B
  12000. /// /shift (CZ_SHIFT).
  12001. /// Request to warp to a character with given name.
  12002. /// 01bb <char name>.24B
  12003. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12004. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12005. char *player_name;
  12006. char command[NAME_LENGTH+8];
  12007. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12008. player_name[NAME_LENGTH-1] = '\0';
  12009. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12010. is_atcommand(fd, sd, command, 1);
  12011. }
  12012. /// /remove (CZ_REMOVE_AID_SSO).
  12013. /// Request to warp to a character with given account ID.
  12014. /// 0843 <account id>.L
  12015. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12016. {
  12017. uint32 account_id;
  12018. struct map_session_data* pl_sd;
  12019. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12020. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12021. char command[NAME_LENGTH+8];
  12022. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12023. is_atcommand(fd, sd, command, 1);
  12024. }
  12025. }
  12026. /// /recall (CZ_RECALL).
  12027. /// Request to summon a player with given login ID to own position.
  12028. /// 01bc <account name>.24B
  12029. /// /summon (CZ_RECALL_GID).
  12030. /// Request to summon a player with given name to own position.
  12031. /// 01bd <char name>.24B
  12032. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12033. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12034. char *player_name;
  12035. char command [NAME_LENGTH+8];
  12036. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12037. player_name[NAME_LENGTH-1] = '\0';
  12038. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12039. is_atcommand(fd, sd, command, 1);
  12040. }
  12041. /// /recall (CZ_RECALL_SSO).
  12042. /// Request to summon a player with given account ID to own position.
  12043. /// 0842 <account id>.L
  12044. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12045. {
  12046. uint32 account_id;
  12047. struct map_session_data* pl_sd;
  12048. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12049. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12050. char command[NAME_LENGTH+8];
  12051. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12052. is_atcommand(fd, sd, command, 1);
  12053. }
  12054. }
  12055. /// /item /monster (CZ_ITEM_CREATE).
  12056. /// Request to execute GM commands.
  12057. /// Usage:
  12058. /// /item n - summon n monster or acquire n item/s
  12059. /// /item money - grants 2147483647 zenies
  12060. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12061. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12062. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12063. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12064. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12065. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12066. /// 013f <item/mob name>.24B
  12067. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12068. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12069. {
  12070. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12071. int mob_id = 0;
  12072. struct item_data *id = NULL;
  12073. struct mob_db *mob = NULL;
  12074. StringBuf command;
  12075. char *str;
  12076. //#if PACKETVER >= 20131218
  12077. // char str[100];
  12078. //#else
  12079. // char str[24];
  12080. //#endif
  12081. str = RFIFOCP(fd,info->pos[0]);
  12082. if (!str || str[0] == '\0')
  12083. return;
  12084. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12085. return;
  12086. trim(str);
  12087. // Zeny
  12088. if( strcmpi(str, "money") == 0 ) {
  12089. StringBuf_Init(&command);
  12090. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12091. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12092. StringBuf_Destroy(&command);
  12093. return;
  12094. }
  12095. // Item
  12096. if( (id = itemdb_searchname(str)) ) {
  12097. StringBuf_Init(&command);
  12098. if( !itemdb_isstackable2(id) ) //Nonstackable
  12099. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12100. else {
  12101. if (id->flag.guid)
  12102. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  12103. else
  12104. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  12105. }
  12106. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12107. StringBuf_Destroy(&command);
  12108. return;
  12109. }
  12110. // Monster
  12111. if ((mob_id = mobdb_searchname(str)) == 0)
  12112. mob_id = mobdb_checkid(atoi(str));
  12113. if( (mob = mob_db(mob_id)) ) {
  12114. StringBuf_Init(&command);
  12115. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12116. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12117. StringBuf_Destroy(&command);
  12118. return;
  12119. }
  12120. }
  12121. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12122. /// 019d <effect state>.L
  12123. /// effect state:
  12124. /// TODO: Any OPTION_* ?
  12125. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12126. char cmd[6];
  12127. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12128. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12129. is_atcommand(fd, sd, cmd, 1);
  12130. }
  12131. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12132. /// 0149 <account id>.L <type>.B <value>.W
  12133. /// type:
  12134. /// 0 = positive points
  12135. /// 1 = negative points
  12136. /// 2 = self mute (+10 minutes)
  12137. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12138. {
  12139. int id, type, value;
  12140. struct map_session_data *dstsd;
  12141. char command[NAME_LENGTH+15];
  12142. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12143. id = RFIFOL(fd,info->pos[0]);
  12144. type = RFIFOB(fd,info->pos[1]);
  12145. value = RFIFOW(fd,info->pos[2]);
  12146. if( type == 0 )
  12147. value = -value;
  12148. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12149. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12150. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12151. return;
  12152. dstsd = map_id2sd(id);
  12153. if( dstsd == NULL )
  12154. return;
  12155. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12156. is_atcommand(fd, sd, command, 1);
  12157. }
  12158. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12159. /// GM adjustment of a player's manner value by -60.
  12160. /// 0212 <char name>.24B
  12161. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12162. {
  12163. char command[NAME_LENGTH+15];
  12164. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12165. name[NAME_LENGTH-1] = '\0';
  12166. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12167. is_atcommand(fd, sd, command, 1);
  12168. }
  12169. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12170. /// 01e0 <account id>.L <account name>.24B
  12171. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12172. {
  12173. WFIFOHEAD(fd,packet_len(0x1e0));
  12174. WFIFOW(fd,0) = 0x1e0;
  12175. WFIFOL(fd,2) = account_id;
  12176. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12177. WFIFOSET(fd,packet_len(0x1e0));
  12178. }
  12179. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12180. /// 01df <account id>.L
  12181. //! TODO: Figure out how does this actually work
  12182. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12183. {
  12184. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12185. /*
  12186. char query[30];
  12187. safesnprintf(query,sizeof(query),"%d", account_id);
  12188. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12189. */
  12190. clif_account_name(fd, account_id, "");
  12191. }
  12192. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12193. /// GM single cell type change request.
  12194. /// 0198 <x>.W <y>.W <type>.W
  12195. /// type:
  12196. /// 0 = not walkable
  12197. /// 1 = walkable
  12198. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12199. {
  12200. int x,y,type;
  12201. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12202. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12203. return;
  12204. x = RFIFOW(fd,info->pos[0]);
  12205. y = RFIFOW(fd,info->pos[1]);
  12206. type = RFIFOW(fd,info->pos[2]);
  12207. map_setgatcell(sd->bl.m,x,y,type);
  12208. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12209. //FIXME: once players leave the map, the client 'forgets' this information.
  12210. }
  12211. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12212. /// Request to allow/deny whispers from a nick.
  12213. /// 00cf <nick>.24B <type>.B
  12214. /// type:
  12215. /// 0 = (/ex nick) deny speech from nick
  12216. /// 1 = (/in nick) allow speech from nick
  12217. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12218. {
  12219. char* nick;
  12220. uint8 type;
  12221. int i;
  12222. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12223. nick = RFIFOCP(fd,info->pos[0]);
  12224. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12225. type = RFIFOB(fd,info->pos[1]);
  12226. if( type == 0 ) { // Add name to ignore list (block)
  12227. if (strcmp(wisp_server_name, nick) == 0) {
  12228. clif_wisexin(sd, type, 1); // fail
  12229. return;
  12230. }
  12231. // try to find a free spot, while checking for duplicates at the same time
  12232. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12233. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12234. clif_wisexin(sd, type, 2); // too many blocks
  12235. return;
  12236. }
  12237. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12238. clif_wisexin(sd, type, 0); // Aegis reports success.
  12239. return;
  12240. }
  12241. //Insert in position i
  12242. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12243. } else { // Remove name from ignore list (unblock)
  12244. // find entry
  12245. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12246. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12247. clif_wisexin(sd, type, 1); // fail
  12248. return;
  12249. }
  12250. // move everything one place down to overwrite removed entry
  12251. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12252. // wipe last entry
  12253. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12254. }
  12255. clif_wisexin(sd, type, 0); // success
  12256. }
  12257. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12258. /// Request to allow/deny all whispers.
  12259. /// 00d0 <type>.B
  12260. /// type:
  12261. /// 0 = (/exall) deny all speech
  12262. /// 1 = (/inall) allow all speech
  12263. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12264. {
  12265. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12266. if( type == 0 ) {// Deny all
  12267. if( sd->state.ignoreAll ) {
  12268. flag = 1; // fail
  12269. } else {
  12270. sd->state.ignoreAll = 1;
  12271. flag = 0; // success
  12272. }
  12273. } else {//Unblock everyone
  12274. if( sd->state.ignoreAll ) {
  12275. sd->state.ignoreAll = 0;
  12276. flag = 0; // success
  12277. } else {
  12278. if (sd->ignore[0].name[0] != '\0')
  12279. { //Wipe the ignore list.
  12280. memset(sd->ignore, 0, sizeof(sd->ignore));
  12281. flag = 0; // success
  12282. } else {
  12283. flag = 1; // fail
  12284. }
  12285. }
  12286. }
  12287. clif_wisall(sd, type, flag);
  12288. }
  12289. /// Whisper ignore list (ZC_WHISPER_LIST).
  12290. /// 00d4 <packet len>.W { <char name>.24B }*
  12291. void clif_PMIgnoreList(struct map_session_data* sd)
  12292. {
  12293. int i, fd = sd->fd;
  12294. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12295. WFIFOW(fd,0) = 0xd4;
  12296. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12297. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12298. }
  12299. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12300. WFIFOSET(fd,WFIFOW(fd,2));
  12301. }
  12302. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12303. /// 00d3
  12304. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12305. {
  12306. clif_PMIgnoreList(sd);
  12307. }
  12308. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12309. /// 01e7
  12310. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12311. {
  12312. if (sd->state.doridori) return;
  12313. switch (sd->class_&MAPID_UPPERMASK) {
  12314. case MAPID_SOUL_LINKER:
  12315. case MAPID_STAR_GLADIATOR:
  12316. case MAPID_TAEKWON:
  12317. if (!sd->state.rest)
  12318. break;
  12319. case MAPID_SUPER_NOVICE:
  12320. case MAPID_SUPER_BABY:
  12321. case MAPID_SUPER_NOVICE_E:
  12322. case MAPID_SUPER_BABY_E:
  12323. sd->state.doridori=1;
  12324. break;
  12325. }
  12326. }
  12327. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12328. /// 01ed
  12329. /// Note: This packet is caused by 7 lines of any text, followed by
  12330. /// the prayer and an another line of any text. The prayer is
  12331. /// defined by lines 790~793 in data\msgstringtable.txt
  12332. /// "Dear angel, can you hear my voice?"
  12333. /// "I am" (space separated player name) "Super Novice~"
  12334. /// "Help me out~ Please~ T_T"
  12335. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12336. {
  12337. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12338. unsigned int next = pc_nextbaseexp(sd);
  12339. if( next ) {
  12340. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12341. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12342. 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]
  12343. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12344. }
  12345. }
  12346. }
  12347. }
  12348. /// Friends List
  12349. ///
  12350. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12351. /// 0206 <account id>.L <char id>.L <state>.B
  12352. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12353. /// state:
  12354. /// 0 = online
  12355. /// 1 = offline
  12356. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12357. {
  12358. int i, fd = sd->fd;
  12359. //Seek friend.
  12360. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12361. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12362. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12363. return; //Not found
  12364. WFIFOHEAD(fd,packet_len(0x206));
  12365. WFIFOW(fd, 0) = 0x206;
  12366. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12367. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12368. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12369. #if PACKETVER >= 20180221
  12370. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12371. #endif
  12372. WFIFOSET(fd, packet_len(0x206));
  12373. }
  12374. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12375. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12376. {
  12377. uint32 account_id, char_id, online;
  12378. account_id = va_arg(ap, int);
  12379. char_id = va_arg(ap, int);
  12380. online = va_arg(ap, int);
  12381. clif_friendslist_toggle(sd, account_id, char_id, online);
  12382. return 0;
  12383. }
  12384. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12385. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12386. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12387. void clif_friendslist_send(struct map_session_data *sd)
  12388. {
  12389. int i = 0, n, fd = sd->fd;
  12390. #if PACKETVER >= 20180221
  12391. const int size = 8;
  12392. #else
  12393. const int size = 8 + NAME_LENGTH;
  12394. #endif
  12395. // Send friends list
  12396. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12397. WFIFOW(fd, 0) = 0x201;
  12398. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12399. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12400. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12401. #if PACKETVER < 20180221
  12402. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12403. #endif
  12404. }
  12405. if (i) {
  12406. WFIFOW(fd,2) = 4 + size * i;
  12407. WFIFOSET(fd, WFIFOW(fd,2));
  12408. }
  12409. for (n = 0; n < i; n++) { //Sending the online players
  12410. if (map_charid2sd(sd->status.friends[n].char_id))
  12411. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12412. }
  12413. }
  12414. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12415. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12416. /// result:
  12417. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12418. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12419. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12420. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12421. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12422. {
  12423. int fd;
  12424. nullpo_retv(sd);
  12425. fd = sd->fd;
  12426. WFIFOHEAD(fd,packet_len(0x209));
  12427. WFIFOW(fd,0) = 0x209;
  12428. WFIFOW(fd,2) = type;
  12429. if (f_sd) {
  12430. WFIFOL(fd,4) = f_sd->status.account_id;
  12431. WFIFOL(fd,8) = f_sd->status.char_id;
  12432. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12433. }
  12434. WFIFOSET(fd, packet_len(0x209));
  12435. }
  12436. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12437. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12438. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12439. {
  12440. int fd = sd->fd;
  12441. WFIFOHEAD(fd,packet_len(0x207));
  12442. WFIFOW(fd,0) = 0x207;
  12443. WFIFOL(fd,2) = account_id;
  12444. WFIFOL(fd,6) = char_id;
  12445. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12446. WFIFOSET(fd,packet_len(0x207));
  12447. }
  12448. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12449. /// 0202 <name>.24B
  12450. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12451. {
  12452. struct map_session_data *f_sd;
  12453. int i;
  12454. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12455. // Friend doesn't exist (no player with this name)
  12456. if (f_sd == NULL) {
  12457. clif_displaymessage(fd, msg_txt(sd,3));
  12458. return;
  12459. }
  12460. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12461. return;
  12462. }
  12463. // ensure that the request player's friend list is not full
  12464. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12465. if( i == MAX_FRIENDS ){
  12466. clif_friendslist_reqack(sd, f_sd, 2);
  12467. return;
  12468. }
  12469. // @noask [LuzZza]
  12470. if(f_sd->state.noask) {
  12471. clif_noask_sub(sd, f_sd, 5);
  12472. return;
  12473. }
  12474. // Friend already exists
  12475. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12476. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12477. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12478. return;
  12479. }
  12480. }
  12481. f_sd->friend_req = sd->status.char_id;
  12482. sd->friend_req = f_sd->status.char_id;
  12483. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12484. }
  12485. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12486. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12487. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12488. /// reply:
  12489. /// 0 = rejected
  12490. /// 1 = accepted
  12491. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12492. {
  12493. struct map_session_data *f_sd;
  12494. uint32 account_id;
  12495. char reply;
  12496. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12497. account_id = RFIFOL(fd,info->pos[0]);
  12498. //char_id = RFIFOL(fd,info->pos[1]);
  12499. #if PACKETVER < 6
  12500. reply = RFIFOB(fd,info->pos[2]);
  12501. #else
  12502. reply = RFIFOL(fd,info->pos[2]);
  12503. #endif
  12504. if( sd->bl.id == account_id ) {// adding oneself as friend
  12505. return;
  12506. }
  12507. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12508. if (f_sd == NULL)
  12509. return;
  12510. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12511. clif_friendslist_reqack(f_sd, sd, 1);
  12512. else {
  12513. int i;
  12514. // Find an empty slot
  12515. for (i = 0; i < MAX_FRIENDS; i++)
  12516. if (f_sd->status.friends[i].char_id == 0)
  12517. break;
  12518. if (i == MAX_FRIENDS) {
  12519. clif_friendslist_reqack(f_sd, sd, 2);
  12520. return;
  12521. }
  12522. f_sd->status.friends[i].account_id = sd->status.account_id;
  12523. f_sd->status.friends[i].char_id = sd->status.char_id;
  12524. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12525. clif_friendslist_reqack(f_sd, sd, 0);
  12526. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12527. if (battle_config.friend_auto_add) {
  12528. // Also add f_sd to sd's friendlist.
  12529. for (i = 0; i < MAX_FRIENDS; i++) {
  12530. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12531. return; //No need to add anything.
  12532. if (sd->status.friends[i].char_id == 0)
  12533. break;
  12534. }
  12535. if (i == MAX_FRIENDS) {
  12536. clif_friendslist_reqack(sd, f_sd, 2);
  12537. return;
  12538. }
  12539. sd->status.friends[i].account_id = f_sd->status.account_id;
  12540. sd->status.friends[i].char_id = f_sd->status.char_id;
  12541. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12542. clif_friendslist_reqack(sd, f_sd, 0);
  12543. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12544. }
  12545. }
  12546. }
  12547. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12548. /// 0203 <account id>.L <char id>.L
  12549. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12550. {
  12551. struct map_session_data *f_sd = NULL;
  12552. uint32 account_id, char_id;
  12553. int i, j;
  12554. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12555. account_id = RFIFOL(fd,info->pos[0]);
  12556. char_id = RFIFOL(fd,info->pos[1]);
  12557. // Search friend
  12558. for (i = 0; i < MAX_FRIENDS &&
  12559. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12560. if (i == MAX_FRIENDS) {
  12561. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12562. return;
  12563. }
  12564. //remove from friend's list first
  12565. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12566. for (i = 0; i < MAX_FRIENDS &&
  12567. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12568. if (i != MAX_FRIENDS) {
  12569. // move all chars up
  12570. for(j = i + 1; j < MAX_FRIENDS; j++)
  12571. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12572. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12573. //should the guy be notified of some message? we should add it here if so
  12574. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12575. WFIFOW(f_sd->fd,0) = 0x20a;
  12576. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12577. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12578. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12579. }
  12580. } else { //friend not online -- ask char server to delete from his friendlist
  12581. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12582. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12583. return;
  12584. }
  12585. }
  12586. // We can now delete from original requester
  12587. for (i = 0; i < MAX_FRIENDS &&
  12588. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12589. // move all chars up
  12590. for(j = i + 1; j < MAX_FRIENDS; j++)
  12591. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12592. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12593. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12594. WFIFOHEAD(fd,packet_len(0x20a));
  12595. WFIFOW(fd,0) = 0x20a;
  12596. WFIFOL(fd,2) = account_id;
  12597. WFIFOL(fd,6) = char_id;
  12598. WFIFOSET(fd, packet_len(0x20a));
  12599. }
  12600. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12601. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12602. void clif_PVPInfo(struct map_session_data* sd)
  12603. {
  12604. int fd = sd->fd;
  12605. WFIFOHEAD(fd,packet_len(0x210));
  12606. WFIFOW(fd,0) = 0x210;
  12607. WFIFOL(fd,2) = sd->status.char_id;
  12608. WFIFOL(fd,6) = sd->status.account_id;
  12609. WFIFOL(fd,10) = sd->pvp_won; // times won
  12610. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12611. WFIFOL(fd,18) = sd->pvp_point;
  12612. WFIFOSET(fd, packet_len(0x210));
  12613. }
  12614. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12615. /// 020f <char id>.L <account id>.L
  12616. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12617. {
  12618. // TODO: Is there a way to use this on an another player (char/acc id)?
  12619. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12620. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12621. clif_PVPInfo(sd);
  12622. }
  12623. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12624. /// 0254 <which>.B
  12625. /// which: (unused atm for security purpose)
  12626. /// 0 = sun
  12627. /// 1 = moon
  12628. /// 2 = star
  12629. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12630. {
  12631. int i;
  12632. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12633. if (sd->menuskill_id != SG_FEEL)
  12634. return;
  12635. i = sd->menuskill_val-1;
  12636. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12637. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12638. sd->feel_map[i].m = sd->bl.m;
  12639. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12640. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12641. // clif_misceffect2(&sd->bl, 0x1b0);
  12642. // clif_misceffect2(&sd->bl, 0x21f);
  12643. clif_feel_info(sd, i, 0);
  12644. clif_menuskill_clear(sd);
  12645. }
  12646. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12647. /// 0253 <which>.B
  12648. /// which:
  12649. /// 0 = sun
  12650. /// 1 = moon
  12651. /// 2 = star
  12652. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12653. {
  12654. WFIFOHEAD(fd,packet_len(0x253));
  12655. WFIFOW(fd,0)=0x253;
  12656. WFIFOB(fd,2)=TOB(skill_lv-1);
  12657. WFIFOSET(fd, packet_len(0x253));
  12658. sd->menuskill_id = SG_FEEL;
  12659. sd->menuskill_val = skill_lv;
  12660. }
  12661. /// Request to change homunculus' name (CZ_RENAME_MER).
  12662. /// 0231 <name>.24B
  12663. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12664. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12665. }
  12666. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12667. /// 0234 <id>.L
  12668. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12669. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12670. struct block_list *bl = NULL;
  12671. struct unit_data *ud = NULL;
  12672. if( sd->md && sd->md->bl.id == id )
  12673. bl = &sd->md->bl;
  12674. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12675. bl = &sd->hd->bl; // Moving Homunculus
  12676. else
  12677. return;
  12678. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12679. ud = unit_bl2ud(bl);
  12680. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12681. }
  12682. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12683. /// 0232 <id>.L <position data>.3B
  12684. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12685. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12686. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12687. struct block_list *bl = NULL;
  12688. short x, y;
  12689. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12690. if( sd->md && sd->md->bl.id == id )
  12691. bl = &sd->md->bl; // Moving Mercenary
  12692. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12693. bl = &sd->hd->bl; // Moving Homunculus
  12694. else
  12695. return;
  12696. unit_walktoxy(bl, x, y, 4);
  12697. }
  12698. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12699. /// 0233 <id>.L <target id>.L <action>.B
  12700. /// action:
  12701. /// always 0
  12702. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12703. {
  12704. struct block_list *bl = NULL;
  12705. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12706. int id = RFIFOL(fd,info->pos[0]);
  12707. int target_id = RFIFOL(fd,info->pos[1]);
  12708. int action_type = RFIFOB(fd,info->pos[2]);
  12709. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12710. bl = &sd->hd->bl;
  12711. else if( sd->md && sd->md->bl.id == id )
  12712. bl = &sd->md->bl;
  12713. else return;
  12714. unit_stop_attack(bl);
  12715. unit_attack(bl, target_id, action_type != 0);
  12716. }
  12717. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12718. /// 022d <type>.W <command>.B
  12719. /// type:
  12720. /// always 0
  12721. /// command:
  12722. /// 0 = homunculus information
  12723. /// 1 = feed
  12724. /// 2 = delete
  12725. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12726. { //[orn]
  12727. int cmd = RFIFOW(fd,0);
  12728. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12729. if(!hom_is_active(sd->hd))
  12730. return;
  12731. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12732. }
  12733. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12734. /// 0292
  12735. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12736. {
  12737. pc_revive_item(sd);
  12738. }
  12739. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12740. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12741. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12742. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12743. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12744. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12745. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12746. void clif_check(int fd, struct map_session_data* pl_sd)
  12747. {
  12748. WFIFOHEAD(fd,packet_len(0x214));
  12749. WFIFOW(fd, 0) = 0x214;
  12750. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12751. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12752. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12753. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12754. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12755. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12756. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12757. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12758. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12759. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12760. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12761. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12762. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12763. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12764. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12765. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12766. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12767. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12768. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12769. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12770. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12771. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12772. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12773. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12774. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12775. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12776. WFIFOSET(fd,packet_len(0x214));
  12777. }
  12778. /// /check (CZ_REQ_STATUS_GM).
  12779. /// Request character's status values.
  12780. /// 0213 <char name>.24B
  12781. void clif_parse_Check(int fd, struct map_session_data *sd)
  12782. {
  12783. char charname[NAME_LENGTH];
  12784. struct map_session_data* pl_sd;
  12785. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12786. return;
  12787. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12788. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12789. {
  12790. return;
  12791. }
  12792. clif_check(fd, pl_sd);
  12793. }
  12794. /// MAIL SYSTEM
  12795. /// By Zephyrus
  12796. ///
  12797. /// Notification about the result of adding an item to mail
  12798. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12799. /// result:
  12800. /// 0 = success
  12801. /// 1 = failure
  12802. /// 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)
  12803. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12804. /// result:
  12805. /// 0 = success
  12806. /// 1 = over weight
  12807. /// 2 = fatal error
  12808. void clif_Mail_setattachment(struct map_session_data* sd, int index, int amount, uint8 flag)
  12809. {
  12810. int fd = sd->fd;
  12811. #if PACKETVER < 20150513
  12812. WFIFOHEAD(fd,packet_len(0x255));
  12813. WFIFOW(fd,0) = 0x255;
  12814. WFIFOW(fd,2) = index;
  12815. WFIFOB(fd,4) = flag;
  12816. WFIFOSET(fd,packet_len(0x255));
  12817. #else
  12818. struct item* item = &sd->inventory.u.items_inventory[index-2];
  12819. int i, total = 0;
  12820. WFIFOHEAD(fd, 53);
  12821. WFIFOW(fd, 0) = 0xa05;
  12822. WFIFOB(fd, 2) = flag;
  12823. WFIFOW(fd, 3) = index;
  12824. WFIFOW(fd, 5) = amount;
  12825. WFIFOW(fd, 7) = item->nameid;
  12826. WFIFOB(fd, 9) = itemtype(item->nameid);
  12827. WFIFOB(fd, 10) = item->identify;
  12828. WFIFOB(fd, 11) = item->attribute;
  12829. WFIFOB(fd, 12) = item->refine;
  12830. clif_addcards(WFIFOP(fd,13), item);
  12831. clif_add_random_options(WFIFOP(fd,21), item);
  12832. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  12833. if( sd->mail.item[i].nameid == 0 ){
  12834. break;
  12835. }
  12836. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12837. }
  12838. WFIFOW(fd, 46) = total;
  12839. // 5 empty unknown bytes
  12840. memset(WFIFOP(fd, 48), 0, 5);
  12841. WFIFOSET(fd, 53);
  12842. #endif
  12843. }
  12844. /// Notification about the result of retrieving a mail attachment
  12845. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12846. /// result:
  12847. /// 0 = success
  12848. /// 1 = failure
  12849. /// 2 = too many items
  12850. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12851. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12852. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12853. int fd = sd->fd;
  12854. #if PACKETVER < 20150513
  12855. WFIFOHEAD(fd,packet_len(0x245));
  12856. WFIFOW(fd,0) = 0x245;
  12857. WFIFOB(fd,2) = result;
  12858. WFIFOSET(fd,packet_len(0x245));
  12859. #else
  12860. switch( type ){
  12861. case MAIL_ATT_ITEM:
  12862. case MAIL_ATT_ZENY:
  12863. break;
  12864. default:
  12865. return;
  12866. }
  12867. WFIFOHEAD(fd, 12);
  12868. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12869. WFIFOQ(fd, 2) = msg->id;
  12870. WFIFOB(fd, 10) = msg->type;
  12871. WFIFOB(fd, 11) = result;
  12872. WFIFOSET(fd, 12);
  12873. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12874. #endif
  12875. }
  12876. /// Notification about the result of sending a mail
  12877. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12878. /// result:
  12879. /// 0 = success
  12880. /// 1 = recipinent does not exist
  12881. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12882. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12883. int fd = sd->fd;
  12884. #if PACKETVER < 20150513
  12885. WFIFOHEAD(fd,packet_len(0x249));
  12886. WFIFOW(fd,0) = 0x249;
  12887. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12888. WFIFOSET(fd,packet_len(0x249));
  12889. #else
  12890. WFIFOHEAD(fd, 3);
  12891. WFIFOW(fd, 0) = 0x9ed;
  12892. WFIFOB(fd, 2) = result;
  12893. WFIFOSET(fd, 3);
  12894. #endif
  12895. }
  12896. /// Notification about the result of deleting a mail.
  12897. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12898. /// result:
  12899. /// 0 = success
  12900. /// 1 = failure
  12901. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12902. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12903. int fd = sd->fd;
  12904. #if PACKETVER < 20150513
  12905. WFIFOHEAD(fd, packet_len(0x257));
  12906. WFIFOW(fd,0) = 0x257;
  12907. WFIFOL(fd,2) = msg->id;
  12908. WFIFOW(fd,6) = !success;
  12909. WFIFOSET(fd, packet_len(0x257));
  12910. #else
  12911. // This is only a success notification
  12912. if( success ){
  12913. WFIFOHEAD(fd, 11);
  12914. WFIFOW(fd, 0) = 0x9f6;
  12915. WFIFOB(fd, 2) = msg->type;
  12916. WFIFOQ(fd, 3) = msg->id;
  12917. WFIFOSET(fd, 11);
  12918. }
  12919. #endif
  12920. }
  12921. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12922. /// 0274 <mail id>.L <result>.W
  12923. /// result:
  12924. /// 0 = success
  12925. /// 1 = failure
  12926. void clif_Mail_return(int fd, int mail_id, short fail)
  12927. {
  12928. WFIFOHEAD(fd,packet_len(0x274));
  12929. WFIFOW(fd,0) = 0x274;
  12930. WFIFOL(fd,2) = mail_id;
  12931. WFIFOW(fd,6) = fail;
  12932. WFIFOSET(fd,packet_len(0x274));
  12933. }
  12934. /// Notification about new mail.
  12935. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12936. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12937. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12938. int fd = sd->fd;
  12939. #if PACKETVER < 20150513
  12940. WFIFOHEAD(fd,packet_len(0x24a));
  12941. WFIFOW(fd,0) = 0x24a;
  12942. WFIFOL(fd,2) = mail_id;
  12943. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12944. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12945. WFIFOSET(fd,packet_len(0x24a));
  12946. #else
  12947. WFIFOHEAD(fd,3);
  12948. WFIFOW(fd,0) = 0x9e7;
  12949. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12950. WFIFOSET(fd,3);
  12951. #endif
  12952. }
  12953. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12954. /// 0260 <type>.L
  12955. /// type:
  12956. /// 0 = open
  12957. /// 1 = close
  12958. void clif_Mail_window(int fd, int flag)
  12959. {
  12960. WFIFOHEAD(fd,packet_len(0x260));
  12961. WFIFOW(fd,0) = 0x260;
  12962. WFIFOL(fd,2) = flag;
  12963. WFIFOSET(fd,packet_len(0x260));
  12964. }
  12965. /// Lists mails stored in inbox.
  12966. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12967. /// read:
  12968. /// 0 = unread
  12969. /// 1 = read
  12970. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12971. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12972. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12973. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12974. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12975. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12976. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12977. #if PACKETVER < 20150513
  12978. int fd = sd->fd;
  12979. struct mail_data *md = &sd->mail.inbox;
  12980. struct mail_message *msg;
  12981. int len, i, j;
  12982. len = 8 + (73 * md->amount);
  12983. WFIFOHEAD(fd,len);
  12984. WFIFOW(fd,0) = 0x240;
  12985. WFIFOW(fd,2) = len;
  12986. WFIFOL(fd,4) = md->amount;
  12987. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12988. {
  12989. msg = &md->msg[i];
  12990. if (msg->id < 1)
  12991. continue;
  12992. WFIFOL(fd,8+73*j) = msg->id;
  12993. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12994. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12995. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12996. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12997. j++;
  12998. }
  12999. WFIFOSET(fd,len);
  13000. if( md->full ) {// TODO: is this official?
  13001. char output[100];
  13002. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13003. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13004. }
  13005. #else
  13006. int fd = sd->fd;
  13007. struct mail_data *md = &sd->mail.inbox;
  13008. struct mail_message *msg;
  13009. int i, j, k, offset, titleLength;
  13010. uint8 mailType, amount, remaining;
  13011. uint32 now = (uint32)time(NULL);
  13012. #if PACKETVER >= 20170419
  13013. int cmd = 0xac2;
  13014. #elif PACKETVER >= 20160601
  13015. int cmd = 0xa7d;
  13016. #else
  13017. int cmd = 0x9f0;
  13018. #endif
  13019. if( battle_config.mail_daily_count ){
  13020. mail_refresh_remaining_amount(sd);
  13021. }
  13022. #if PACKETVER >= 20170419
  13023. // Always send all
  13024. i = md->amount;
  13025. #else
  13026. // If a starting mail id was sent
  13027. if( mailID != 0 ){
  13028. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13029. // Unknown mail
  13030. if( i == md->amount ){
  13031. // Ignore the request for now
  13032. return; // TODO: Should we just show the first page instead?
  13033. }
  13034. // It was actually the oldest/first mail, there is no further page
  13035. if( i == 0 ){
  13036. return;
  13037. }
  13038. // We actually want the next/older mail
  13039. i -= 1;
  13040. }else{
  13041. i = md->amount;
  13042. }
  13043. #endif
  13044. // Count the remaining mails from the starting mail or the beginning
  13045. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13046. for( j = i, remaining = 0; j >= 0; j-- ){
  13047. msg = &md->msg[j];
  13048. if (msg->id < 1)
  13049. continue;
  13050. #if PACKETVER < 20170419
  13051. if (msg->type != type)
  13052. continue;
  13053. #endif
  13054. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13055. continue;
  13056. remaining++;
  13057. }
  13058. #if PACKETVER >= 20170419
  13059. // Always send all
  13060. amount = remaining;
  13061. #else
  13062. if( remaining > MAIL_PAGE_SIZE ){
  13063. amount = MAIL_PAGE_SIZE;
  13064. }else{
  13065. amount = remaining;
  13066. }
  13067. #endif
  13068. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13069. WFIFOW(fd, 0) = cmd;
  13070. #if PACKETVER >= 20170419
  13071. WFIFOB(fd, 4) = 1; // Unknown
  13072. offset = 5;
  13073. #else
  13074. WFIFOB(fd, 4) = type;
  13075. WFIFOB(fd, 5) = amount;
  13076. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13077. offset = 7;
  13078. #endif
  13079. for( amount = 0; i >= 0; i-- ){
  13080. msg = &md->msg[i];
  13081. if (msg->id < 1)
  13082. continue;
  13083. #if PACKETVER < 20170419
  13084. if (msg->type != type)
  13085. continue;
  13086. #endif
  13087. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13088. continue;
  13089. #if PACKETVER >= 20170419
  13090. WFIFOB(fd, offset) = msg->type;
  13091. offset += 1;
  13092. #endif
  13093. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13094. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13095. mailType = MAIL_TYPE_TEXT; // Normal letter
  13096. if( msg->zeny > 0 ){
  13097. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13098. }
  13099. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13100. if( msg->item[k].nameid > 0 ){
  13101. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13102. break;
  13103. }
  13104. }
  13105. #if PACKETVER >= 20170419
  13106. // If it came from an npc?
  13107. if( !msg->send_id ){
  13108. mailType |= MAIL_TYPE_NPC;
  13109. }
  13110. #endif
  13111. WFIFOB(fd, offset + 9) = mailType;
  13112. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13113. #if PACKETVER < 20170419
  13114. // How much time has passed since you received the mail
  13115. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13116. offset += 4;
  13117. #endif
  13118. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13119. if( msg->scheduled_deletion > 0 ){
  13120. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13121. }else{
  13122. // Fake the scheduled deletion to one year in the future
  13123. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13124. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13125. }
  13126. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13127. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13128. offset += 40 + titleLength;
  13129. }
  13130. WFIFOW(fd, 2) = (int16)offset;
  13131. WFIFOSET(fd, offset);
  13132. #endif
  13133. }
  13134. /// Mail inbox list request.
  13135. /// 023f (CZ_MAIL_GET_LIST)
  13136. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13137. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13138. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13139. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13140. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13141. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13142. #if PACKETVER < 20150513
  13143. struct mail_data* md = &sd->mail.inbox;
  13144. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13145. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13146. else
  13147. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13148. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13149. mail_removezeny(sd, false);
  13150. #else
  13151. int cmd = RFIFOW(fd, 0);
  13152. #if PACKETVER < 20170419
  13153. uint8 openType = RFIFOB(fd, 2);
  13154. uint64 mailId = RFIFOQ(fd, 3);
  13155. #else
  13156. uint8 openType;
  13157. uint64 mailId = RFIFOQ(fd, 2);
  13158. int i;
  13159. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13160. if( i == MAIL_MAX_INBOX ){
  13161. openType = MAIL_INBOX_NORMAL;
  13162. mailId = 0;
  13163. }else{
  13164. openType = sd->mail.inbox.msg[i].type;
  13165. mailId = 0;
  13166. }
  13167. #endif
  13168. switch( openType ){
  13169. case MAIL_INBOX_NORMAL:
  13170. case MAIL_INBOX_ACCOUNT:
  13171. case MAIL_INBOX_RETURNED:
  13172. break;
  13173. default:
  13174. // Unknown type: ignore request
  13175. return;
  13176. }
  13177. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13178. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13179. return;
  13180. }
  13181. // If it is not a next page request
  13182. if( cmd != 0x9ee ){
  13183. mailId = 0;
  13184. }
  13185. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13186. #endif
  13187. }
  13188. /// Opens a mail
  13189. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13190. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13191. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13192. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13193. /// { }*n
  13194. // TODO: Packet description => for repeated block
  13195. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  13196. {
  13197. int i, fd = sd->fd;
  13198. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13199. if( i == MAIL_MAX_INBOX ) {
  13200. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13201. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13202. return;
  13203. } else {
  13204. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13205. struct item *item;
  13206. struct item_data *data;
  13207. int msg_len = strlen(msg->body), len;
  13208. #if PACKETVER >= 20150513
  13209. int offset, j, itemsize, count = 0;
  13210. #endif
  13211. if( msg_len == 0 ) {
  13212. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13213. msg_len = strlen(msg->body);
  13214. }
  13215. #if PACKETVER < 20150513
  13216. item = &msg->item[0];
  13217. len = 101 + msg_len;
  13218. WFIFOHEAD(fd,len);
  13219. WFIFOW(fd,0) = 0x242;
  13220. WFIFOW(fd,2) = len;
  13221. WFIFOL(fd,4) = msg->id;
  13222. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13223. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13224. WFIFOL(fd,72) = 0;
  13225. WFIFOL(fd,76) = msg->zeny;
  13226. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13227. WFIFOL(fd,80) = item->amount;
  13228. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  13229. WFIFOW(fd,86) = data->type;
  13230. WFIFOB(fd,88) = item->identify;
  13231. WFIFOB(fd,89) = item->attribute;
  13232. WFIFOB(fd,90) = item->refine;
  13233. WFIFOW(fd,91) = item->card[0];
  13234. WFIFOW(fd,93) = item->card[1];
  13235. WFIFOW(fd,95) = item->card[2];
  13236. WFIFOW(fd,97) = item->card[3];
  13237. } else // no item, set all to zero
  13238. memset(WFIFOP(fd,80), 0x00, 19);
  13239. WFIFOB(fd,99) = (unsigned char)msg_len;
  13240. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13241. WFIFOSET(fd,len);
  13242. #else
  13243. // Count the attached items
  13244. ARR_FIND( 0, MAIL_MAX_ITEM, count, msg->item[count].nameid == 0 );
  13245. msg_len += 1; // Zero Termination
  13246. itemsize = 24 + 5 * 5;
  13247. len = 24 + msg_len+1 + itemsize * count;
  13248. WFIFOHEAD(fd, len);
  13249. WFIFOW(fd, 0) = 0x9eb;
  13250. WFIFOW(fd, 2) = len;
  13251. WFIFOB(fd, 4) = msg->type;
  13252. WFIFOQ(fd, 5) = msg->id;
  13253. WFIFOW(fd, 13) = msg_len;
  13254. WFIFOQ(fd, 15) = msg->zeny;
  13255. WFIFOB(fd, 23) = (uint8)count; // item count
  13256. safestrncpy(WFIFOCP(fd, 24), msg->body, msg_len);
  13257. offset = 24 + msg_len;
  13258. for (j = 0; j < MAIL_MAX_ITEM; j++) {
  13259. item = &msg->item[j];
  13260. if (item->nameid > 0 && item->amount > 0 && (data = itemdb_exists(item->nameid)) != NULL) {
  13261. WFIFOW(fd, offset) = item->amount;
  13262. WFIFOW(fd, offset + 2) = (data->view_id) ? data->view_id : item->nameid;
  13263. WFIFOB(fd, offset + 4) = item->identify;
  13264. WFIFOB(fd, offset + 5) = item->attribute;
  13265. WFIFOB(fd, offset + 6) = item->refine;
  13266. clif_addcards(WFIFOP(fd, offset + 7), item);
  13267. // 4B unsigned long location
  13268. WFIFOB(fd, offset + 15 + 4) = data->type;
  13269. // 2B unsigned short wItemSpriteNumber
  13270. //WFIFOW(fd, offset + 15 + 5) = data->view_id;
  13271. // 2B unsigned short bindOnEquipType
  13272. clif_add_random_options(WFIFOP(fd, offset + 15 + 9 ), item);
  13273. offset += itemsize;
  13274. }
  13275. }
  13276. WFIFOSET(fd, len);
  13277. #endif
  13278. if (msg->status == MAIL_UNREAD) {
  13279. msg->status = MAIL_READ;
  13280. intif_Mail_read(mail_id);
  13281. clif_parse_Mail_refreshinbox(fd, sd);
  13282. sd->mail.inbox.unread--;
  13283. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13284. }
  13285. }
  13286. }
  13287. /// Request to open a mail.
  13288. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13289. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13290. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13291. #if PACKETVER < 20150513
  13292. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13293. #else
  13294. //uint8 openType = RFIFOB(fd, 2);
  13295. int mail_id = (int)RFIFOQ(fd, 3);
  13296. #endif
  13297. if( mail_id <= 0 )
  13298. return;
  13299. if( mail_invalid_operation(sd) )
  13300. return;
  13301. clif_Mail_read(sd, mail_id);
  13302. }
  13303. /// Allow a player to begin writing a mail
  13304. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13305. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13306. int fd = sd->fd;
  13307. WFIFOHEAD(fd, 27);
  13308. WFIFOW(fd, 0) = 0xa12;
  13309. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13310. WFIFOB(fd, 26) = success;
  13311. WFIFOSET(fd, 27);
  13312. }
  13313. /// Request to start writing a mail
  13314. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13315. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13316. char name[NAME_LENGTH];
  13317. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13318. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13319. clif_send_Mail_beginwrite_ack(sd, name, false);
  13320. return;
  13321. }
  13322. mail_clear(sd);
  13323. sd->state.mail_writing = true;
  13324. clif_send_Mail_beginwrite_ack(sd, name,true);
  13325. }
  13326. /// Notification that the client cancelled writing a mail
  13327. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13328. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13329. sd->state.mail_writing = false;
  13330. }
  13331. /// Give the client information about the recipient, if available
  13332. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13333. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13334. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13335. int fd = sd->fd;
  13336. #if PACKETVER <= 20160302
  13337. int cmd = 0xa14;
  13338. #else
  13339. int cmd = 0xa51;
  13340. #endif
  13341. WFIFOHEAD(fd, packet_len(cmd));
  13342. WFIFOW(fd, 0) = cmd;
  13343. WFIFOL(fd, 2) = char_id;
  13344. WFIFOW(fd, 6) = class_;
  13345. WFIFOW(fd, 8) = level;
  13346. #if PACKETVER >= 20160302
  13347. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13348. #endif
  13349. WFIFOSET(fd, packet_len(cmd));
  13350. }
  13351. /// Request information about the recipient
  13352. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13353. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13354. static char name[NAME_LENGTH];
  13355. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13356. intif_mail_checkreceiver(sd, name);
  13357. }
  13358. /// Request to receive mail's attachment.
  13359. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13360. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13361. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13362. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13363. int i;
  13364. struct mail_message* msg;
  13365. #if PACKETVER < 20150513
  13366. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13367. int attachment = MAIL_ATT_ALL;
  13368. #else
  13369. uint16 packet_id = RFIFOW(fd, 0);
  13370. int mail_id = (int)RFIFOQ(fd, 2);
  13371. //int openType = RFIFOB(fd, 10);
  13372. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13373. #endif
  13374. if( !chrif_isconnected() )
  13375. return;
  13376. if( mail_id <= 0 )
  13377. return;
  13378. if( mail_invalid_operation(sd) )
  13379. return;
  13380. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13381. if( i == MAIL_MAX_INBOX )
  13382. return;
  13383. msg = &sd->mail.inbox.msg[i];
  13384. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13385. attachment &= ~MAIL_ATT_ZENY;
  13386. }
  13387. if( attachment&MAIL_ATT_ITEM ){
  13388. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13389. // No items were found
  13390. if( i == MAIL_MAX_ITEM ){
  13391. attachment &= ~MAIL_ATT_ITEM;
  13392. }
  13393. }
  13394. // Either no attachment requested at all or there are no zeny or items in the mail
  13395. if( attachment == MAIL_ATT_NONE ){
  13396. return;
  13397. }
  13398. if( attachment&MAIL_ATT_ZENY ){
  13399. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13400. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13401. return;
  13402. }else{
  13403. // To make sure another request fails
  13404. msg->zeny = 0;
  13405. }
  13406. }
  13407. if( attachment&MAIL_ATT_ITEM ){
  13408. int new_ = 0, totalweight = 0;
  13409. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13410. struct item* item = &msg->item[i];
  13411. if( item->nameid > 0 && item->amount > 0 ){
  13412. struct item_data *data;
  13413. if((data = itemdb_exists(item->nameid)) == NULL)
  13414. continue;
  13415. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13416. case CHKADDITEM_NEW:
  13417. new_++;
  13418. break;
  13419. case CHKADDITEM_OVERAMOUNT:
  13420. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13421. return;
  13422. }
  13423. totalweight += data->weight * item->amount;
  13424. }
  13425. }
  13426. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13427. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13428. return;
  13429. }else if( pc_inventoryblank(sd) < new_ ){
  13430. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13431. return;
  13432. }
  13433. // To make sure another request fails
  13434. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13435. }
  13436. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13437. clif_Mail_read(sd, mail_id);
  13438. }
  13439. /// Request to delete a mail.
  13440. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13441. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13442. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13443. #if PACKETVER < 20150513
  13444. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13445. #else
  13446. //int openType = RFIFOB(fd, 2);
  13447. int mail_id = (int)RFIFOQ(fd, 3);
  13448. #endif
  13449. int i, j;
  13450. if( !chrif_isconnected() )
  13451. return;
  13452. if( mail_id <= 0 )
  13453. return;
  13454. if( mail_invalid_operation(sd) )
  13455. return;
  13456. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13457. if (i < MAIL_MAX_INBOX) {
  13458. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13459. // can't delete mail without removing zeny first
  13460. if( msg->zeny > 0 ){
  13461. clif_mail_delete(sd, msg, false);
  13462. return;
  13463. }
  13464. // can't delete mail without removing attachment(s) first
  13465. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13466. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13467. clif_mail_delete(sd, msg, false);
  13468. return;
  13469. }
  13470. }
  13471. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13472. sd->mail.inbox.unread--;
  13473. clif_Mail_new(sd,0,NULL,NULL);
  13474. }
  13475. }
  13476. }
  13477. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13478. /// 0273 <mail id>.L <receive name>.24B
  13479. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13480. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13481. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13482. int i;
  13483. if( mail_id <= 0 )
  13484. return;
  13485. if( mail_invalid_operation(sd) )
  13486. return;
  13487. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13488. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13489. intif_Mail_return(sd->status.char_id, mail_id);
  13490. else
  13491. clif_Mail_return(sd->fd, mail_id, 1);
  13492. }
  13493. /// Request to add an item or Zeny to mail.
  13494. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13495. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13496. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13497. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13498. int idx = RFIFOW(fd,info->pos[0]);
  13499. #if PACKETVER < 20150513
  13500. int amount = RFIFOL(fd,info->pos[1]);
  13501. #else
  13502. int amount = RFIFOW(fd,info->pos[1]);
  13503. #endif
  13504. unsigned char flag;
  13505. if( !chrif_isconnected() )
  13506. return;
  13507. if (idx < 0 || amount < 0 || idx >= MAX_INVENTORY)
  13508. return;
  13509. flag = mail_setitem(sd, idx, amount);
  13510. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13511. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13512. }else{
  13513. clif_Mail_setattachment(sd,idx,amount,flag);
  13514. }
  13515. }
  13516. /// Remove an item from a mail
  13517. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13518. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13519. int fd = sd->fd;
  13520. WFIFOHEAD(fd, 9);
  13521. WFIFOW(fd, 0) = 0xa07;
  13522. WFIFOB(fd, 2) = success;
  13523. WFIFOW(fd, 3) = index;
  13524. WFIFOW(fd, 5) = amount;
  13525. int total = 0;
  13526. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13527. if( sd->mail.item[i].nameid == 0 ){
  13528. break;
  13529. }
  13530. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13531. }
  13532. WFIFOW(fd, 7) = total;
  13533. WFIFOSET(fd, 9);
  13534. }
  13535. /// Request to reset mail item and/or Zeny
  13536. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13537. /// type:
  13538. /// 0 = reset all
  13539. /// 1 = remove item
  13540. /// 2 = remove zeny
  13541. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13542. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13543. {
  13544. #if PACKETVER < 20150513
  13545. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13546. if (type == 0 || type == 1)
  13547. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13548. if (type == 0 || type == 2)
  13549. mail_removezeny(sd, false);
  13550. #else
  13551. uint16 index = RFIFOW(fd, 2);
  13552. uint16 count = RFIFOW(fd, 4);
  13553. mail_removeitem(sd,0,index,count);
  13554. #endif
  13555. }
  13556. /// Request to send mail
  13557. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13558. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13559. /// 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)
  13560. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13561. #if PACKETVER < 20150513
  13562. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13563. if( !chrif_isconnected() )
  13564. return;
  13565. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13566. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13567. return;
  13568. }
  13569. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13570. #else
  13571. uint16 length = RFIFOW(fd, 2);
  13572. if( length < 0x3e ){
  13573. ShowWarning("Too short...\n");
  13574. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13575. return;
  13576. }
  13577. // Forged request without a begin writing packet?
  13578. if( !sd->state.mail_writing ){
  13579. return; // Ignore it
  13580. }
  13581. char receiver[NAME_LENGTH];
  13582. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13583. // char sender[NAME_LENGTH];
  13584. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13585. uint64 zeny = RFIFOQ(fd, 52);
  13586. uint16 titleLength = RFIFOW(fd, 60);
  13587. uint16 textLength = RFIFOW(fd, 62);
  13588. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13589. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13590. char title[MAIL_TITLE_LENGTH];
  13591. char text[MAIL_BODY_LENGTH];
  13592. #if PACKETVER <= 20160330
  13593. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13594. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13595. #else
  13596. // 64 = <char id>.L
  13597. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13598. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13599. #endif
  13600. if( zeny > 0 ){
  13601. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13602. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13603. return;
  13604. }
  13605. }
  13606. mail_send(sd, receiver, title, text, realTextLength);
  13607. #endif
  13608. }
  13609. /// AUCTION SYSTEM
  13610. /// By Zephyrus
  13611. ///
  13612. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13613. /// 025f <type>.L
  13614. /// type:
  13615. /// 0 = open
  13616. /// 1 = close
  13617. void clif_Auction_openwindow(struct map_session_data *sd)
  13618. {
  13619. int fd = sd->fd;
  13620. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13621. return;
  13622. if( !battle_config.feature_auction )
  13623. return;
  13624. WFIFOHEAD(fd,packet_len(0x25f));
  13625. WFIFOW(fd,0) = 0x25f;
  13626. WFIFOL(fd,2) = 0;
  13627. WFIFOSET(fd,packet_len(0x25f));
  13628. }
  13629. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13630. /// 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 }*
  13631. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13632. {
  13633. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13634. struct auction_data auction;
  13635. struct item_data *item;
  13636. WFIFOHEAD(fd,12 + (count * 83));
  13637. WFIFOW(fd,0) = 0x252;
  13638. WFIFOW(fd,2) = 12 + (count * 83);
  13639. WFIFOL(fd,4) = pages;
  13640. WFIFOL(fd,8) = count;
  13641. for( i = 0; i < count; i++ ) {
  13642. int k = 12 + (i * 83);
  13643. memcpy(&auction, RBUFP(buf,i * len), len);
  13644. WFIFOL(fd,k) = auction.auction_id;
  13645. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13646. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  13647. WFIFOW(fd,28+k) = item->view_id;
  13648. else
  13649. WFIFOW(fd,28+k) = auction.item.nameid;
  13650. WFIFOL(fd,30+k) = auction.type;
  13651. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13652. WFIFOB(fd,36+k) = auction.item.identify;
  13653. WFIFOB(fd,37+k) = auction.item.attribute;
  13654. WFIFOB(fd,38+k) = auction.item.refine;
  13655. WFIFOW(fd,39+k) = auction.item.card[0];
  13656. WFIFOW(fd,41+k) = auction.item.card[1];
  13657. WFIFOW(fd,43+k) = auction.item.card[2];
  13658. WFIFOW(fd,45+k) = auction.item.card[3];
  13659. WFIFOL(fd,47+k) = auction.price;
  13660. WFIFOL(fd,51+k) = auction.buynow;
  13661. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13662. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13663. }
  13664. WFIFOSET(fd,WFIFOW(fd,2));
  13665. }
  13666. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13667. /// 0256 <index>.W <result>.B
  13668. /// result:
  13669. /// 0 = success
  13670. /// 1 = failure
  13671. static void clif_Auction_setitem(int fd, int index, bool fail)
  13672. {
  13673. WFIFOHEAD(fd,packet_len(0x256));
  13674. WFIFOW(fd,0) = 0x256;
  13675. WFIFOW(fd,2) = index;
  13676. WFIFOB(fd,4) = fail;
  13677. WFIFOSET(fd,packet_len(0x256));
  13678. }
  13679. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13680. /// 024b <type>.W
  13681. /// type:
  13682. /// 0 = create (any other action in auction window)
  13683. /// 1 = cancel (cancel pressed on register tab)
  13684. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13685. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13686. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13687. if( sd->auction.amount > 0 )
  13688. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13689. sd->auction.amount = 0;
  13690. }
  13691. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13692. /// 024c <index>.W <count>.L
  13693. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13694. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13695. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13696. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13697. struct item_data *item;
  13698. if( !battle_config.feature_auction )
  13699. return;
  13700. if( sd->auction.amount > 0 )
  13701. sd->auction.amount = 0;
  13702. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13703. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13704. return;
  13705. }
  13706. 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.
  13707. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13708. return;
  13709. }
  13710. 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) )
  13711. { // Consumable or pets are not allowed
  13712. clif_Auction_setitem(sd->fd, idx, true);
  13713. return;
  13714. }
  13715. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13716. !sd->inventory.u.items_inventory[idx].identify ||
  13717. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13718. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13719. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13720. clif_Auction_setitem(sd->fd, idx, true);
  13721. return;
  13722. }
  13723. sd->auction.index = idx;
  13724. sd->auction.amount = amount;
  13725. clif_Auction_setitem(fd, idx + 2, false);
  13726. }
  13727. /// Result from an auction action (ZC_AUCTION_RESULT).
  13728. /// 0250 <result>.B
  13729. /// result:
  13730. /// 0 = You have failed to bid into the auction
  13731. /// 1 = You have successfully bid in the auction
  13732. /// 2 = The auction has been canceled
  13733. /// 3 = An auction with at least one bidder cannot be canceled
  13734. /// 4 = You cannot register more than 5 items in an auction at a time
  13735. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13736. /// 6 = You have won the auction
  13737. /// 7 = You have failed to win the auction
  13738. /// 8 = You do not have enough Zeny
  13739. /// 9 = You cannot place more than 5 bids at a time
  13740. void clif_Auction_message(int fd, unsigned char flag)
  13741. {
  13742. WFIFOHEAD(fd,packet_len(0x250));
  13743. WFIFOW(fd,0) = 0x250;
  13744. WFIFOB(fd,2) = flag;
  13745. WFIFOSET(fd,packet_len(0x250));
  13746. }
  13747. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13748. /// 025e <result>.W
  13749. /// result:
  13750. /// 0 = You have ended the auction
  13751. /// 1 = You cannot end the auction
  13752. /// 2 = Auction ID is incorrect
  13753. void clif_Auction_close(int fd, unsigned char flag)
  13754. {
  13755. WFIFOHEAD(fd,packet_len(0x25e));
  13756. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13757. WFIFOW(fd,2) = flag;
  13758. WFIFOSET(fd,packet_len(0x25e));
  13759. }
  13760. /// Request to add an auction (CZ_AUCTION_ADD).
  13761. /// 024d <now money>.L <max money>.L <delete hour>.W
  13762. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13763. {
  13764. struct auction_data auction;
  13765. struct item_data *item;
  13766. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13767. if( !battle_config.feature_auction )
  13768. return;
  13769. auction.price = RFIFOL(fd,info->pos[0]);
  13770. auction.buynow = RFIFOL(fd,info->pos[1]);
  13771. auction.hours = RFIFOW(fd,info->pos[2]);
  13772. // Invalid Situations...
  13773. if( sd->auction.amount < 1 ) {
  13774. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13775. return;
  13776. }
  13777. if( auction.price >= auction.buynow ) {
  13778. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13779. return;
  13780. }
  13781. if( auction.hours < 1 || auction.hours > 48 ) {
  13782. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13783. return;
  13784. }
  13785. // Auction checks...
  13786. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13787. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13788. clif_Auction_message(fd, 2); // The auction has been canceled
  13789. return;
  13790. }
  13791. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13792. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13793. return;
  13794. }
  13795. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13796. auction.buynow = battle_config.auction_maximumprice;
  13797. if( auction.price >= auction.buynow )
  13798. auction.price = auction.buynow - 1;
  13799. }
  13800. auction.auction_id = 0;
  13801. auction.seller_id = sd->status.char_id;
  13802. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13803. auction.buyer_id = 0;
  13804. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13805. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13806. {
  13807. clif_Auction_message(fd, 2); // The auction has been canceled
  13808. return;
  13809. }
  13810. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13811. { // Just in case
  13812. clif_Auction_message(fd, 2); // The auction has been canceled
  13813. return;
  13814. }
  13815. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13816. auction.type = item->type;
  13817. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13818. auction.item.amount = 1;
  13819. auction.timestamp = 0;
  13820. if( !intif_Auction_register(&auction) )
  13821. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13822. else
  13823. {
  13824. int zeny = auction.hours*battle_config.auction_feeperhour;
  13825. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13826. sd->auction.amount = 0;
  13827. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13828. }
  13829. }
  13830. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13831. /// 024e <auction id>.L
  13832. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13833. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13834. intif_Auction_cancel(sd->status.char_id, auction_id);
  13835. }
  13836. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13837. /// 025d <auction id>.L
  13838. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13839. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13840. intif_Auction_close(sd->status.char_id, auction_id);
  13841. }
  13842. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13843. /// 024f <auction id>.L <money>.L
  13844. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13845. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13846. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13847. int bid = RFIFOL(fd,info->pos[1]);
  13848. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13849. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13850. return;
  13851. }
  13852. if( bid <= 0 )
  13853. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13854. else if( bid > sd->status.zeny )
  13855. clif_Auction_message(fd, 8); // You do not have enough zeny
  13856. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13857. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13858. else {
  13859. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13860. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13861. }
  13862. }
  13863. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13864. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13865. /// search type:
  13866. /// 0 = armor
  13867. /// 1 = weapon
  13868. /// 2 = card
  13869. /// 3 = misc
  13870. /// 4 = name search
  13871. /// 5 = auction id search
  13872. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13873. char search_text[NAME_LENGTH];
  13874. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13875. short type = RFIFOW(fd,info->pos[0]);
  13876. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13877. int page = RFIFOW(fd,info->pos[3]);
  13878. if( !battle_config.feature_auction )
  13879. return;
  13880. clif_parse_Auction_cancelreg(fd, sd);
  13881. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13882. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13883. }
  13884. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13885. /// 025c <type>.W
  13886. /// type:
  13887. /// 0 = sell (own auctions)
  13888. /// 1 = buy (own bids)
  13889. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13890. {
  13891. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13892. if( !battle_config.feature_auction )
  13893. return;
  13894. clif_parse_Auction_cancelreg(fd, sd);
  13895. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13896. }
  13897. /// CASH/POINT SHOP
  13898. ///
  13899. void clif_cashshop_open( struct map_session_data* sd ){
  13900. WFIFOHEAD( sd->fd, 10 );
  13901. WFIFOW( sd->fd, 0 ) = 0x845;
  13902. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13903. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13904. WFIFOSET( sd->fd, 10 );
  13905. }
  13906. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13907. sd->state.cashshop_open = true;
  13908. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13909. clif_cashshop_open( sd );
  13910. }
  13911. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13912. sd->state.cashshop_open = false;
  13913. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13914. // No need to do anything here
  13915. }
  13916. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13917. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13918. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13919. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13920. int j;
  13921. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13922. return;
  13923. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13924. WFIFOW(fd, 0) = 0x8c0;
  13925. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13926. WFIFOL(fd, 4) = tab;
  13927. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13928. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13929. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13930. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13931. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13932. }
  13933. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13934. }
  13935. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13936. void clif_cashshop_list( int fd ){
  13937. int tab;
  13938. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13939. int length = 8 + cash_shop_items[tab].count * 6;
  13940. int i, offset;
  13941. WFIFOHEAD( fd, length );
  13942. WFIFOW( fd, 0 ) = 0x8ca;
  13943. WFIFOW( fd, 2 ) = length;
  13944. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13945. WFIFOW( fd, 6 ) = tab;
  13946. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13947. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13948. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13949. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13950. }
  13951. WFIFOSET( fd, length );
  13952. }
  13953. }
  13954. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13955. if( !sd->status.cashshop_sent ) {
  13956. clif_cashshop_list( fd );
  13957. #if PACKETVER_SUPPORTS_SALES
  13958. sale_notify_login(sd);
  13959. #endif
  13960. sd->status.cashshop_sent = true;
  13961. }
  13962. }
  13963. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13964. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13965. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13966. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13967. {
  13968. int fd, i, cost[2] = { 0, 0 };
  13969. #if PACKETVER < 20070711
  13970. const int offset = 8;
  13971. #else
  13972. const int offset = 12;
  13973. #endif
  13974. nullpo_retv(sd);
  13975. nullpo_retv(nd);
  13976. fd = sd->fd;
  13977. sd->npc_shopid = nd->bl.id;
  13978. npc_shop_currency_type(sd, nd, cost, true);
  13979. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13980. WFIFOW(fd,0) = 0x287;
  13981. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13982. WFIFOL(fd,4) = cost[0];
  13983. #if PACKETVER >= 20070711
  13984. WFIFOL(fd,8) = cost[1];
  13985. #endif
  13986. for( i = 0; i < nd->u.shop.count; i++ ) {
  13987. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13988. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13989. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13990. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13991. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13992. }
  13993. WFIFOSET(fd,WFIFOW(fd,2));
  13994. }
  13995. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13996. /// 0289 <cash point>.L <error>.W
  13997. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13998. /// error:
  13999. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14000. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14001. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14002. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14003. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14004. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14005. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14006. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14007. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14008. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14009. {
  14010. int fd, cost[2] = { 0, 0 };
  14011. struct npc_data *nd;
  14012. nullpo_retv(sd);
  14013. fd = sd->fd;
  14014. nd = map_id2nd(sd->npc_shopid);
  14015. npc_shop_currency_type(sd, nd, cost, false);
  14016. WFIFOHEAD(fd, packet_len(0x289));
  14017. WFIFOW(fd,0) = 0x289;
  14018. WFIFOL(fd,2) = cost[0];
  14019. #if PACKETVER < 20070711
  14020. WFIFOW(fd,6) = TOW(error);
  14021. #else
  14022. WFIFOL(fd,6) = cost[1];
  14023. WFIFOW(fd,10) = TOW(error);
  14024. #endif
  14025. WFIFOSET(fd, packet_len(0x289));
  14026. }
  14027. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  14028. WFIFOHEAD( sd->fd, 16 );
  14029. WFIFOW( sd->fd, 0 ) = 0x849;
  14030. WFIFOL( sd->fd, 2 ) = item_id;
  14031. WFIFOW( sd->fd, 6 ) = result;
  14032. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  14033. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  14034. WFIFOSET( sd->fd, 16 );
  14035. }
  14036. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  14037. /// 0288 <name id>.W <amount>.W
  14038. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14039. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14040. /// 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)
  14041. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  14042. struct s_packet_db* info;
  14043. int cmd = RFIFOW(fd,0);
  14044. nullpo_retv(sd);
  14045. info = &packet_db[cmd];
  14046. if( sd->state.trading || !sd->npc_shopid ) {
  14047. clif_cashshop_ack(sd,1);
  14048. return;
  14049. }
  14050. else {
  14051. #if PACKETVER < 20101116
  14052. short nameid = RFIFOW(fd,info->pos[0]);
  14053. short amount = RFIFOW(fd,info->pos[1]);
  14054. int points = RFIFOL(fd,info->pos[2]);
  14055. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  14056. #else
  14057. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  14058. int len = RFIFOW(fd,info->pos[0]);
  14059. int points = RFIFOL(fd,info->pos[1]);
  14060. int count = RFIFOW(fd,info->pos[2]);
  14061. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14062. if( len < 10 || len != 10 + count * s_itl){
  14063. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  14064. return;
  14065. }
  14066. if(cmd==0x848){
  14067. if (cashshop_buylist( sd, points, count, item_list))
  14068. clif_cashshop_ack(sd,0);
  14069. return;
  14070. } else {
  14071. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  14072. return;
  14073. }
  14074. #endif
  14075. }
  14076. }
  14077. /// Adoption System
  14078. ///
  14079. /// Adoption message (ZC_BABYMSG).
  14080. /// 0216 <msg>.L
  14081. /// msg:
  14082. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14083. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14084. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14085. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14086. {
  14087. int fd = sd->fd;
  14088. WFIFOHEAD(fd,6);
  14089. WFIFOW(fd,0) = 0x216;
  14090. WFIFOL(fd,2) = type;
  14091. WFIFOSET(fd,6);
  14092. }
  14093. /// Adoption confirmation (ZC_REQ_BABY).
  14094. /// 01f6 <account id>.L <char id>.L <name>.B
  14095. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14096. {
  14097. int fd = sd->fd;
  14098. WFIFOHEAD(fd,34);
  14099. WFIFOW(fd,0) = 0x1f6;
  14100. WFIFOL(fd,2) = src->status.account_id;
  14101. WFIFOL(fd,6) = p_id;
  14102. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14103. WFIFOSET(fd,34);
  14104. }
  14105. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14106. /// 01f9 <account id>.L
  14107. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14108. {
  14109. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14110. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14111. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14112. {
  14113. tsd->adopt_invite = sd->status.account_id;
  14114. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14115. }
  14116. }
  14117. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14118. /// 01f7 <account id>.L <char id>.L <answer>.L
  14119. /// answer:
  14120. /// 0 = rejected
  14121. /// 1 = accepted
  14122. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14123. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14124. int p1_id = RFIFOL(fd,info->pos[0]);
  14125. int p2_id = RFIFOL(fd,info->pos[1]);
  14126. int result = RFIFOL(fd,info->pos[2]);
  14127. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14128. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14129. int pid = sd->adopt_invite;
  14130. sd->adopt_invite = 0;
  14131. if( p1_sd == NULL || p2_sd == NULL )
  14132. return; // Both players need to be online
  14133. if( pid != p1_sd->status.account_id )
  14134. return; // Incorrect values
  14135. if( result == 0 )
  14136. return; // Rejected
  14137. pc_adoption(p1_sd, p2_sd, sd);
  14138. }
  14139. /// Convex Mirror (ZC_BOSS_INFO).
  14140. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14141. /// infoType:
  14142. /// BOSS_INFO_NOT = No boss on this map.
  14143. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14144. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14145. /// BOSS_INFO_DEAD = Boss is dead.
  14146. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14147. {
  14148. int fd = sd->fd;
  14149. WFIFOHEAD(fd,70);
  14150. memset(WFIFOP(fd,0),0,70);
  14151. WFIFOW(fd,0) = 0x293;
  14152. switch (flag) {
  14153. case BOSS_INFO_NOT:
  14154. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14155. // No data required
  14156. break;
  14157. case BOSS_INFO_ALIVE:
  14158. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14159. // Update X/Y
  14160. WFIFOL(fd,3) = md->bl.x;
  14161. WFIFOL(fd,7) = md->bl.y;
  14162. break;
  14163. case BOSS_INFO_ALIVE_WITHMSG:
  14164. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14165. // Current X/Y
  14166. WFIFOL(fd,3) = md->bl.x;
  14167. WFIFOL(fd,7) = md->bl.y;
  14168. break;
  14169. case BOSS_INFO_DEAD:
  14170. {
  14171. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14172. unsigned int seconds;
  14173. int hours, minutes;
  14174. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14175. hours = seconds / (60 * 60);
  14176. seconds = seconds - (60 * 60 * hours);
  14177. minutes = seconds / 60;
  14178. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14179. // Add respawn info
  14180. WFIFOW(fd,11) = hours; // Hours
  14181. WFIFOW(fd,13) = minutes; // Minutes
  14182. }
  14183. break;
  14184. }
  14185. if (md != NULL)
  14186. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14187. WFIFOSET(fd,70);
  14188. }
  14189. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14190. /// 02d6 <account id>.L
  14191. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14192. {
  14193. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14194. struct map_session_data* tsd = map_id2sd(aid);
  14195. if (!tsd)
  14196. return;
  14197. if (sd->bl.m != tsd->bl.m)
  14198. return;
  14199. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14200. clif_viewequip_ack(sd, tsd);
  14201. else
  14202. clif_msg(sd, VIEW_EQUIP_FAIL);
  14203. }
  14204. /// Request to a configuration.
  14205. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14206. /// type: see enum e_config_type
  14207. /// flag:
  14208. /// false = disabled
  14209. /// true = enabled
  14210. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14211. int cmd = RFIFOW(fd,0);
  14212. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14213. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14214. switch( type ){
  14215. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14216. sd->status.show_equip = flag;
  14217. break;
  14218. case CONFIG_PET_AUTOFEED:
  14219. // Player can not click this if he does not have a pet
  14220. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14221. return;
  14222. }
  14223. sd->pd->pet.autofeed = flag;
  14224. break;
  14225. case CONFIG_HOMUNCULUS_AUTOFEED:
  14226. // Player can not click this if he does not have a homunculus or it is vaporized
  14227. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14228. return;
  14229. }
  14230. sd->hd->homunculus.autofeed = flag;
  14231. break;
  14232. default:
  14233. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14234. return;
  14235. }
  14236. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14237. }
  14238. /// Request to change party invitation tick.
  14239. /// value:
  14240. /// 0 = disabled
  14241. /// 1 = enabled
  14242. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14243. {
  14244. bool flag = RFIFOB(fd,6) ? true : false;
  14245. sd->status.allow_party = flag;
  14246. clif_partytickack(sd, flag);
  14247. }
  14248. /// Questlog System [Kevin] [Inkfish]
  14249. ///
  14250. /**
  14251. * Safe check to init packet len & quest num for player.
  14252. * @param def_len
  14253. * @param info_len Length of each quest info.
  14254. * @param avail_quests Avail quests that player has.
  14255. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14256. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14257. **/
  14258. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14259. (*limit_out) = (0xFFFF - def_len) / info_len;
  14260. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14261. (*len_out) = ((*limit_out) * info_len) + def_len;
  14262. }
  14263. /// Sends list of all quest states
  14264. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14265. /// 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)
  14266. /// 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)
  14267. void clif_quest_send_list(struct map_session_data *sd)
  14268. {
  14269. int fd = sd->fd;
  14270. int i;
  14271. int offset = 8;
  14272. int limit = 0;
  14273. #if PACKETVER >= 20141022
  14274. #if PACKETVER >= 20150513
  14275. int size = 22 + NAME_LENGTH;
  14276. #else
  14277. int size = 10 + NAME_LENGTH;
  14278. #endif
  14279. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14280. WFIFOHEAD(fd,i);
  14281. #if PACKETVER >= 20150513
  14282. WFIFOW(fd, 0) = 0x9f8;
  14283. #else
  14284. WFIFOW(fd, 0) = 0x97a;
  14285. #endif
  14286. WFIFOL(fd, 4) = limit;
  14287. for (i = 0; i < limit; i++) {
  14288. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14289. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14290. offset += 4;
  14291. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14292. offset++;
  14293. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  14294. offset += 4;
  14295. WFIFOL(fd, offset) = sd->quest_log[i].time;
  14296. offset += 4;
  14297. WFIFOW(fd, offset) = qi->objectives_count;
  14298. offset += 2;
  14299. if( qi->objectives_count > 0 ){
  14300. int j;
  14301. struct mob_db *mob;
  14302. for( j = 0; j < qi->objectives_count; j++ ){
  14303. mob = mob_db(qi->objectives[j].mob);
  14304. #if PACKETVER >= 20150513
  14305. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14306. offset += 4;
  14307. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14308. offset += 4;
  14309. #endif
  14310. WFIFOL(fd, offset) = qi->objectives[j].mob;
  14311. offset += 4;
  14312. #if PACKETVER >= 20150513
  14313. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14314. offset += 2;
  14315. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14316. offset += 2;
  14317. #endif
  14318. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14319. offset += 2;
  14320. WFIFOW(fd, offset) = qi->objectives[j].count;
  14321. offset += 2;
  14322. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14323. offset += NAME_LENGTH;
  14324. }
  14325. }
  14326. }
  14327. WFIFOW(fd, 2) = offset;
  14328. WFIFOSET(fd, offset);
  14329. #else
  14330. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14331. WFIFOHEAD(fd,i);
  14332. WFIFOW(fd, 0) = 0x2b1;
  14333. WFIFOL(fd, 4) = limit;
  14334. for (i = 0; i < limit; i++) {
  14335. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14336. offset += 4;
  14337. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14338. offset += 1;
  14339. }
  14340. WFIFOW(fd, 2) = offset;
  14341. WFIFOSET(fd, offset);
  14342. #endif
  14343. }
  14344. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14345. /// 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
  14346. void clif_quest_send_mission(struct map_session_data *sd)
  14347. {
  14348. int fd = sd->fd;
  14349. int i, j, limit = 0;
  14350. int len = sd->avail_quests*104+8;
  14351. struct mob_db *mob;
  14352. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14353. WFIFOHEAD(fd, len);
  14354. WFIFOW(fd, 0) = 0x2b2;
  14355. WFIFOW(fd, 2) = len;
  14356. WFIFOL(fd, 4) = limit;
  14357. for (i = 0; i < limit; i++) {
  14358. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14359. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14360. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  14361. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  14362. WFIFOW(fd, i*104+20) = qi->objectives_count;
  14363. for (j = 0 ; j < qi->objectives_count; j++) {
  14364. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  14365. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14366. mob = mob_db(qi->objectives[j].mob);
  14367. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14368. }
  14369. }
  14370. WFIFOSET(fd, len);
  14371. }
  14372. /// Notification about a new quest
  14373. /// 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)
  14374. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14375. /// 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)
  14376. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14377. {
  14378. int fd = sd->fd;
  14379. int i, offset;
  14380. struct quest_db *qi = quest_search(qd->quest_id);
  14381. #if PACKETVER >= 20150513
  14382. int cmd = 0x9f9;
  14383. #else
  14384. int cmd = 0x2b3;
  14385. #endif
  14386. WFIFOHEAD(fd, packet_len(cmd));
  14387. WFIFOW(fd, 0) = cmd;
  14388. WFIFOL(fd, 2) = qd->quest_id;
  14389. WFIFOB(fd, 6) = qd->state;
  14390. WFIFOB(fd, 7) = qd->time - qi->time;
  14391. WFIFOL(fd, 11) = qd->time;
  14392. WFIFOW(fd, 15) = qi->objectives_count;
  14393. for (i = 0, offset = 17; i < qi->objectives_count; i++) {
  14394. struct mob_db *mob;
  14395. #if PACKETVER >= 20150513
  14396. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14397. offset += 4;
  14398. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14399. offset += 4;
  14400. #endif
  14401. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14402. offset += 4;
  14403. #if PACKETVER >= 20150513
  14404. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14405. offset += 2;
  14406. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14407. offset += 2;
  14408. #endif
  14409. WFIFOW(fd, offset) = qd->count[i];
  14410. offset += 2;
  14411. mob = mob_db(qi->objectives[i].mob);
  14412. safestrncpy(WFIFOCP(fd, offset), mob->jname, NAME_LENGTH);
  14413. offset += NAME_LENGTH;
  14414. }
  14415. WFIFOSET(fd, packet_len(cmd));
  14416. #if PACKETVER >= 20150513
  14417. int len = 4 + qi->objectives_count * 12;
  14418. WFIFOHEAD(fd, len);
  14419. WFIFOW(fd, 0) = 0x8fe;
  14420. WFIFOW(fd, 2) = len;
  14421. for( i = 0, offset = 4; i < qi->objectives_count; i++, offset += 12 ){
  14422. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14423. WFIFOL(fd, offset+4) = qi->objectives[i].mob;
  14424. WFIFOW(fd, offset + 10) = qi->objectives[i].count;
  14425. WFIFOW(fd, offset + 12) = qd->count[i];
  14426. }
  14427. WFIFOSET(fd, len);
  14428. #endif
  14429. }
  14430. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14431. /// 02b4 <quest id>.L
  14432. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14433. {
  14434. int fd = sd->fd;
  14435. WFIFOHEAD(fd, packet_len(0x2b4));
  14436. WFIFOW(fd, 0) = 0x2b4;
  14437. WFIFOL(fd, 2) = quest_id;
  14438. WFIFOSET(fd, packet_len(0x2b4));
  14439. }
  14440. /// Notification of an update to the hunting mission counter
  14441. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14442. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14443. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14444. {
  14445. int fd = sd->fd;
  14446. int i, offset;
  14447. struct quest_db *qi = quest_search(qd->quest_id);
  14448. int len = qi->objectives_count * 12 + 6;
  14449. #if PACKETVER >= 20150513
  14450. int cmd = 0x9fa;
  14451. #else
  14452. int cmd = 0x2b5;
  14453. #endif
  14454. WFIFOHEAD(fd, len);
  14455. WFIFOW(fd, 0) = cmd;
  14456. WFIFOW(fd, 4) = qi->objectives_count;
  14457. for (i = 0, offset = 6; i < qi->objectives_count; i++) {
  14458. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  14459. WFIFOL(fd, offset) = qd->quest_id;
  14460. offset += 4;
  14461. #if PACKETVER >= 20150513
  14462. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14463. offset += 4;
  14464. #else
  14465. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14466. offset += 4;
  14467. #endif
  14468. WFIFOW(fd, offset) = qi->objectives[i].count;
  14469. offset += 2;
  14470. WFIFOW(fd, offset) = qd->count[i];
  14471. offset += 2;
  14472. }
  14473. }
  14474. WFIFOW(fd, 2) = offset;
  14475. WFIFOSET(fd, offset);
  14476. }
  14477. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14478. /// 02b6 <quest id>.L <active>.B
  14479. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14480. {
  14481. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14482. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14483. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14484. }
  14485. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14486. /// 02b7 <quest id>.L <active>.B
  14487. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14488. {
  14489. int fd = sd->fd;
  14490. WFIFOHEAD(fd, packet_len(0x2b7));
  14491. WFIFOW(fd, 0) = 0x2b7;
  14492. WFIFOL(fd, 2) = quest_id;
  14493. WFIFOB(fd, 6) = active;
  14494. WFIFOSET(fd, packet_len(0x2b7));
  14495. }
  14496. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14497. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14498. /// effect:
  14499. /// 0 = none
  14500. /// 1 = exclamation mark icon
  14501. /// 2 = question mark icon
  14502. /// color:
  14503. /// 0 = yellow
  14504. /// 1 = orange
  14505. /// 2 = green
  14506. /// 3 = purple
  14507. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14508. {
  14509. #if PACKETVER >= 20090218
  14510. nullpo_retv(sd);
  14511. nullpo_retv(bl);
  14512. int fd = sd->fd;
  14513. WFIFOHEAD(fd, packet_len(0x446));
  14514. WFIFOW(fd, 0) = 0x446;
  14515. WFIFOL(fd, 2) = bl->id;
  14516. WFIFOW(fd, 6) = bl->x;
  14517. WFIFOW(fd, 8) = bl->y;
  14518. WFIFOW(fd, 10) = effect;
  14519. WFIFOW(fd, 12) = color;
  14520. WFIFOSET(fd, packet_len(0x446));
  14521. #endif
  14522. }
  14523. /// Mercenary System
  14524. ///
  14525. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14526. /// 02a2 <var id>.W <value>.L
  14527. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14528. {
  14529. struct mercenary_data *md;
  14530. struct status_data *status;
  14531. int fd;
  14532. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14533. return;
  14534. fd = sd->fd;
  14535. status = &md->battle_status;
  14536. WFIFOHEAD(fd,packet_len(0x2a2));
  14537. WFIFOW(fd,0) = 0x2a2;
  14538. WFIFOW(fd,2) = type;
  14539. switch( type ) {
  14540. case SP_ATK1:
  14541. {
  14542. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14543. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14544. }
  14545. break;
  14546. case SP_MATK1:
  14547. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14548. break;
  14549. case SP_HIT:
  14550. WFIFOL(fd,4) = status->hit;
  14551. break;
  14552. case SP_CRITICAL:
  14553. WFIFOL(fd,4) = status->cri/10;
  14554. break;
  14555. case SP_DEF1:
  14556. WFIFOL(fd,4) = status->def;
  14557. break;
  14558. case SP_MDEF1:
  14559. WFIFOL(fd,4) = status->mdef;
  14560. break;
  14561. case SP_MERCFLEE:
  14562. WFIFOL(fd,4) = status->flee;
  14563. break;
  14564. case SP_ASPD:
  14565. WFIFOL(fd,4) = status->amotion;
  14566. break;
  14567. case SP_HP:
  14568. WFIFOL(fd,4) = status->hp;
  14569. break;
  14570. case SP_MAXHP:
  14571. WFIFOL(fd,4) = status->max_hp;
  14572. break;
  14573. case SP_SP:
  14574. WFIFOL(fd,4) = status->sp;
  14575. break;
  14576. case SP_MAXSP:
  14577. WFIFOL(fd,4) = status->max_sp;
  14578. break;
  14579. case SP_MERCKILLS:
  14580. WFIFOL(fd,4) = md->mercenary.kill_count;
  14581. break;
  14582. case SP_MERCFAITH:
  14583. WFIFOL(fd,4) = mercenary_get_faith(md);
  14584. break;
  14585. }
  14586. WFIFOSET(fd,packet_len(0x2a2));
  14587. }
  14588. /// Mercenary base status data (ZC_MER_INIT).
  14589. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14590. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14591. /// <calls>.L <kills>.L <atk range>.W
  14592. void clif_mercenary_info(struct map_session_data *sd)
  14593. {
  14594. int fd;
  14595. struct mercenary_data *md;
  14596. struct status_data *status;
  14597. int atk;
  14598. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14599. return;
  14600. fd = sd->fd;
  14601. status = &md->battle_status;
  14602. WFIFOHEAD(fd,packet_len(0x29b));
  14603. WFIFOW(fd,0) = 0x29b;
  14604. WFIFOL(fd,2) = md->bl.id;
  14605. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14606. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14607. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14608. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14609. WFIFOW(fd,10) = status->hit;
  14610. WFIFOW(fd,12) = status->cri/10;
  14611. WFIFOW(fd,14) = status->def;
  14612. WFIFOW(fd,16) = status->mdef;
  14613. WFIFOW(fd,18) = status->flee;
  14614. WFIFOW(fd,20) = status->amotion;
  14615. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14616. WFIFOW(fd,46) = md->db->lv;
  14617. WFIFOL(fd,48) = status->hp;
  14618. WFIFOL(fd,52) = status->max_hp;
  14619. WFIFOL(fd,56) = status->sp;
  14620. WFIFOL(fd,60) = status->max_sp;
  14621. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  14622. WFIFOW(fd,68) = mercenary_get_faith(md);
  14623. WFIFOL(fd,70) = mercenary_get_calls(md);
  14624. WFIFOL(fd,74) = md->mercenary.kill_count;
  14625. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14626. WFIFOSET(fd,packet_len(0x29b));
  14627. }
  14628. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14629. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14630. void clif_mercenary_skillblock(struct map_session_data *sd)
  14631. {
  14632. struct mercenary_data *md;
  14633. int fd, i, len = 4;
  14634. if( sd == NULL || (md = sd->md) == NULL )
  14635. return;
  14636. fd = sd->fd;
  14637. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14638. WFIFOW(fd,0) = 0x29d;
  14639. for( i = 0; i < MAX_MERCSKILL; i++ )
  14640. {
  14641. uint16 id;
  14642. short idx = -1;
  14643. if( (id = md->db->skill[i].id) == 0 )
  14644. continue;
  14645. if ((idx = mercenary_skill_get_index(id)) == -1)
  14646. continue;
  14647. WFIFOW(fd,len) = id;
  14648. WFIFOL(fd,len+2) = skill_get_inf(id);
  14649. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14650. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14651. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14652. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14653. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14654. len += 37;
  14655. }
  14656. WFIFOW(fd,2) = len;
  14657. WFIFOSET(fd,len);
  14658. }
  14659. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14660. /// 029f <command>.B
  14661. /// 1 = mercenary information
  14662. /// 2 = delete
  14663. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14664. {
  14665. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14666. if( sd->md == NULL )
  14667. return;
  14668. if( option == 2 ) mercenary_delete(sd->md, 2);
  14669. }
  14670. /// Mercenary Message
  14671. /// message:
  14672. /// 0 = Mercenary soldier's duty hour is over.
  14673. /// 1 = Your mercenary soldier has been killed.
  14674. /// 2 = Your mercenary soldier has been fired.
  14675. /// 3 = Your mercenary soldier has ran away.
  14676. void clif_mercenary_message(struct map_session_data* sd, int message){
  14677. clif_msg(sd, MERC_MSG_BASE + message);
  14678. }
  14679. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  14680. /// 0298 <name id>.W <seconds>.L
  14681. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  14682. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  14683. WFIFOHEAD(fd,packet_len(0x298));
  14684. WFIFOW(fd,0) = 0x298;
  14685. WFIFOW(fd,2) = nameid;
  14686. WFIFOL(fd,4) = seconds;
  14687. WFIFOSET(fd,packet_len(0x298));
  14688. }
  14689. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  14690. /// 0299 <index>.W <name id>.W
  14691. void clif_rental_expired(int fd, int index, unsigned short nameid)
  14692. { // '<ItemName>' item has been deleted from the Inventory
  14693. WFIFOHEAD(fd,packet_len(0x299));
  14694. WFIFOW(fd,0) = 0x299;
  14695. WFIFOW(fd,2) = index+2;
  14696. WFIFOW(fd,4) = nameid;
  14697. WFIFOSET(fd,packet_len(0x299));
  14698. }
  14699. /// Book Reading (ZC_READ_BOOK).
  14700. /// 0294 <book id>.L <page>.L
  14701. void clif_readbook(int fd, int book_id, int page)
  14702. {
  14703. WFIFOHEAD(fd,packet_len(0x294));
  14704. WFIFOW(fd,0) = 0x294;
  14705. WFIFOL(fd,2) = book_id;
  14706. WFIFOL(fd,6) = page;
  14707. WFIFOSET(fd,packet_len(0x294));
  14708. }
  14709. /// Battlegrounds
  14710. ///
  14711. /// Updates HP bar of a camp member.
  14712. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14713. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14714. void clif_bg_hp(struct map_session_data *sd) {
  14715. #if PACKETVER < 20140613
  14716. unsigned char buf[34];
  14717. const int cmd = 0x2e0;
  14718. #else
  14719. unsigned char buf[14];
  14720. const int cmd = 0xa0e;
  14721. #endif
  14722. nullpo_retv(sd);
  14723. WBUFW(buf,0) = cmd;
  14724. WBUFL(buf,2) = sd->status.account_id;
  14725. #if PACKETVER < 20140613
  14726. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14727. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14728. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14729. WBUFW(buf,32) = 100;
  14730. } else {
  14731. WBUFW(buf,30) = sd->battle_status.hp;
  14732. WBUFW(buf,32) = sd->battle_status.max_hp;
  14733. }
  14734. #else
  14735. if( sd->battle_status.max_hp > INT32_MAX ) {
  14736. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14737. WBUFL(buf,10) = 100;
  14738. } else {
  14739. WBUFL(buf,6) = sd->battle_status.hp;
  14740. WBUFL(buf,10) = sd->battle_status.max_hp;
  14741. }
  14742. #endif
  14743. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14744. }
  14745. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14746. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14747. void clif_bg_xy(struct map_session_data *sd)
  14748. {
  14749. unsigned char buf[36];
  14750. nullpo_retv(sd);
  14751. WBUFW(buf,0)=0x2df;
  14752. WBUFL(buf,2)=sd->status.account_id;
  14753. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14754. WBUFW(buf,30)=sd->status.class_;
  14755. WBUFW(buf,32)=sd->bl.x;
  14756. WBUFW(buf,34)=sd->bl.y;
  14757. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14758. }
  14759. void clif_bg_xy_remove(struct map_session_data *sd)
  14760. {
  14761. unsigned char buf[36];
  14762. nullpo_retv(sd);
  14763. WBUFW(buf,0)=0x2df;
  14764. WBUFL(buf,2)=sd->status.account_id;
  14765. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14766. WBUFW(buf,30)=0;
  14767. WBUFW(buf,32)=-1;
  14768. WBUFW(buf,34)=-1;
  14769. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14770. }
  14771. /// Notifies clients of a battleground message.
  14772. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  14773. void clif_bg_message( struct battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  14774. struct map_session_data *sd = bg_getavailablesd( bg );
  14775. if( sd == nullptr ){
  14776. return;
  14777. }
  14778. // limit length
  14779. len = min( len + 1, CHAT_SIZE_MAX );
  14780. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  14781. WBUFW(buf,0) = 0x2dc;
  14782. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14783. WBUFL(buf,4) = src_id;
  14784. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14785. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  14786. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14787. }
  14788. /// Validates and processes battlechat messages.
  14789. /// All messages that are sent after enabling battleground chat with /battlechat.
  14790. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  14791. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14792. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14793. if( !clif_process_message( sd, false, name, message, output ) )
  14794. return;
  14795. bg_send_message(sd, output, strlen(output) );
  14796. }
  14797. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14798. /// 02de <camp A points>.W <camp B points>.W
  14799. void clif_bg_updatescore(int16 m)
  14800. {
  14801. struct block_list bl;
  14802. unsigned char buf[6];
  14803. struct map_data *mapdata = map_getmapdata(m);
  14804. bl.id = 0;
  14805. bl.type = BL_NUL;
  14806. bl.m = m;
  14807. WBUFW(buf,0) = 0x2de;
  14808. WBUFW(buf,2) = mapdata->bgscore_lion;
  14809. WBUFW(buf,4) = mapdata->bgscore_eagle;
  14810. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14811. }
  14812. void clif_bg_updatescore_single(struct map_session_data *sd)
  14813. {
  14814. int fd;
  14815. nullpo_retv(sd);
  14816. fd = sd->fd;
  14817. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  14818. WFIFOHEAD(fd,packet_len(0x2de));
  14819. WFIFOW(fd,0) = 0x2de;
  14820. WFIFOW(fd,2) = mapdata->bgscore_lion;
  14821. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  14822. WFIFOSET(fd,packet_len(0x2de));
  14823. }
  14824. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14825. /// 02dd <account id>.L <name>.24B <camp>.W
  14826. void clif_sendbgemblem_area(struct map_session_data *sd)
  14827. {
  14828. unsigned char buf[33];
  14829. nullpo_retv(sd);
  14830. WBUFW(buf, 0) = 0x2dd;
  14831. WBUFL(buf,2) = sd->bl.id;
  14832. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14833. WBUFW(buf,30) = sd->bg_id;
  14834. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14835. }
  14836. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14837. {
  14838. nullpo_retv(sd);
  14839. WFIFOHEAD(fd,32);
  14840. WFIFOW(fd,0) = 0x2dd;
  14841. WFIFOL(fd,2) = sd->bl.id;
  14842. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14843. WFIFOW(fd,30) = sd->bg_id;
  14844. WFIFOSET(fd,packet_len(0x2dd));
  14845. }
  14846. /// Custom Fonts (ZC_NOTIFY_FONT).
  14847. /// 02ef <account_id>.L <font id>.W
  14848. void clif_font(struct map_session_data *sd)
  14849. {
  14850. #if PACKETVER >= 20080102
  14851. unsigned char buf[8];
  14852. nullpo_retv(sd);
  14853. WBUFW(buf,0) = 0x2ef;
  14854. WBUFL(buf,2) = sd->bl.id;
  14855. WBUFW(buf,6) = sd->status.font;
  14856. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14857. #endif
  14858. }
  14859. /// Required to start the instancing information window on Client
  14860. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14861. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14862. void clif_instance_create(unsigned short instance_id, int num)
  14863. {
  14864. #if PACKETVER >= 20071128
  14865. struct instance_db *db = NULL;
  14866. struct map_session_data *sd = NULL;
  14867. enum send_target target = PARTY;
  14868. unsigned char buf[65];
  14869. instance_getsd(instance_id, &sd, &target);
  14870. if (!sd)
  14871. return;
  14872. db = instance_searchtype_db(instance_data[instance_id].type);
  14873. if (!db)
  14874. return;
  14875. WBUFW(buf,0) = 0x2cb;
  14876. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14877. WBUFW(buf,63) = num;
  14878. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14879. #endif
  14880. return;
  14881. }
  14882. /// To announce Instancing queue creation if no maps available
  14883. /// S 0x2cc <Standby Position>.W
  14884. void clif_instance_changewait(unsigned short instance_id, int num)
  14885. {
  14886. #if PACKETVER >= 20071128
  14887. struct map_session_data *sd = NULL;
  14888. enum send_target target = PARTY;
  14889. unsigned char buf[4];
  14890. instance_getsd(instance_id, &sd, &target);
  14891. if (!sd)
  14892. return;
  14893. WBUFW(buf,0) = 0x2cc;
  14894. WBUFW(buf,2) = num;
  14895. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14896. #endif
  14897. return;
  14898. }
  14899. /// Notify the current status to members
  14900. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14901. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14902. {
  14903. #if PACKETVER >= 20071128
  14904. struct instance_db *db = NULL;
  14905. struct map_session_data *sd = NULL;
  14906. enum send_target target = PARTY;
  14907. unsigned char buf[71];
  14908. instance_getsd(instance_id, &sd, &target);
  14909. if (!sd)
  14910. return;
  14911. db = instance_searchtype_db(instance_data[instance_id].type);
  14912. if (!db)
  14913. return;
  14914. WBUFW(buf,0) = 0x2cd;
  14915. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14916. WBUFL(buf,63) = limit1;
  14917. WBUFL(buf,67) = limit2;
  14918. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14919. #endif
  14920. return;
  14921. }
  14922. /// Notify a status change to members
  14923. /// S 0x2ce <Message ID>.L
  14924. /// 0 = Notification (EnterLimitDate update?)
  14925. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14926. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14927. /// 3 = The Memorial Dungeon has been removed.
  14928. /// 4 = Create failure (removes the instance window)
  14929. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14930. {
  14931. #if PACKETVER >= 20071128
  14932. struct map_session_data *sd = NULL;
  14933. enum send_target target = PARTY;
  14934. unsigned char buf[10];
  14935. instance_getsd(instance_id, &sd, &target);
  14936. if (!sd)
  14937. return;
  14938. WBUFW(buf,0) = 0x2ce;
  14939. WBUFL(buf,2) = type;
  14940. WBUFL(buf,6) = limit;
  14941. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14942. #endif
  14943. return;
  14944. }
  14945. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14946. /// 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
  14947. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14948. {
  14949. #if PACKETVER >= 20071002
  14950. unsigned char buf[22];
  14951. struct item_data* id = itemdb_search(item_data->nameid);
  14952. WBUFW(buf,0) = 0x2b8;
  14953. WBUFL(buf,2) = sd->status.account_id;
  14954. WBUFW(buf,6) = item_data->nameid;
  14955. WBUFB(buf,8) = item_data->identify;
  14956. WBUFB(buf,9) = item_data->attribute;
  14957. WBUFB(buf,10) = item_data->refine;
  14958. clif_addcards(WBUFP(buf,11), item_data);
  14959. WBUFW(buf,19) = id->equip; // equip location
  14960. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14961. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14962. #endif
  14963. }
  14964. /** Display gained exp.
  14965. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  14966. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  14967. * amount: INT32_MIN ~ INT32_MAX
  14968. * var id:
  14969. * SP_BASEEXP, SP_JOBEXP
  14970. * exp type:
  14971. * 0 = normal exp gained/lost
  14972. * 1 = quest exp gained/lost
  14973. * @param sd Player
  14974. * @param exp EXP value gained/loss
  14975. * @param type SP_BASEEXP, SP_JOBEXP
  14976. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14977. * @param lost True:if lossing EXP
  14978. */
  14979. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14980. {
  14981. int fd;
  14982. int offset;
  14983. #if PACKETVER >= 20170830
  14984. int cmd = 0xacc;
  14985. #else
  14986. int cmd = 0x7f6;
  14987. #endif
  14988. nullpo_retv(sd);
  14989. fd = sd->fd;
  14990. WFIFOHEAD(fd, packet_len(cmd));
  14991. WFIFOW(fd,0) = cmd;
  14992. WFIFOL(fd,2) = sd->bl.id;
  14993. #if PACKETVER >= 20170830
  14994. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  14995. offset = 4;
  14996. #else
  14997. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14998. offset = 0;
  14999. #endif
  15000. WFIFOW(fd,10+offset) = type;
  15001. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15002. WFIFOSET(fd,packet_len(cmd));
  15003. }
  15004. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15005. /// type:
  15006. /// 0 = Displays 'value' for 5 seconds.
  15007. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15008. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15009. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15010. /// value:
  15011. /// 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).
  15012. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15013. {
  15014. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15015. WFIFOW(sd->fd,0) = 0x1b1;
  15016. WFIFOB(sd->fd,2) = type;
  15017. WFIFOL(sd->fd,3) = value;
  15018. WFIFOSET(sd->fd, packet_len(0x1b1));
  15019. }
  15020. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15021. /// 021d <state>.L
  15022. /// state:
  15023. /// 0 = Full effects
  15024. /// 1 = Reduced effects
  15025. ///
  15026. /// NOTE: The state is used on Aegis for sending skill unit packet
  15027. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15028. /// whenever possible. Due to the way the decision check is
  15029. /// constructed, this state tracking was rendered useless,
  15030. /// as the only skill unit, that is sent with 0x1c9 is
  15031. /// Graffiti.
  15032. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15033. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15034. sd->state.lesseffect = ( isLess != 0 );
  15035. }
  15036. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15037. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15038. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15039. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15040. int type = RFIFOL(fd,info->pos[1]);
  15041. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15042. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15043. if( sd->state.trading || sd->npc_shopid )
  15044. return;
  15045. if( flag == 0 || n == 0) {
  15046. clif_menuskill_clear(sd);
  15047. return; // Canceled by player.
  15048. }
  15049. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15050. clif_menuskill_clear(sd);
  15051. return; // Prevent hacking.
  15052. }
  15053. switch( type ) {
  15054. case 0: // Change Material
  15055. skill_changematerial(sd,n,item_list);
  15056. break;
  15057. case 1: // Level 1: Pure to Rough
  15058. case 2: // Level 2: Rough to Pure
  15059. skill_elementalanalysis(sd,n,type,item_list);
  15060. break;
  15061. }
  15062. clif_menuskill_clear(sd);
  15063. return;
  15064. }
  15065. /*==========================================
  15066. * Elemental System
  15067. *==========================================*/
  15068. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15069. struct elemental_data *ed;
  15070. struct status_data *status;
  15071. int fd;
  15072. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15073. return;
  15074. fd = sd->fd;
  15075. status = &ed->battle_status;
  15076. WFIFOHEAD(fd,8);
  15077. WFIFOW(fd,0) = 0x81e;
  15078. WFIFOW(fd,2) = type;
  15079. switch( type ) {
  15080. case SP_HP:
  15081. WFIFOL(fd,4) = status->hp;
  15082. break;
  15083. case SP_MAXHP:
  15084. WFIFOL(fd,4) = status->max_hp;
  15085. break;
  15086. case SP_SP:
  15087. WFIFOL(fd,4) = status->sp;
  15088. break;
  15089. case SP_MAXSP:
  15090. WFIFOL(fd,4) = status->max_sp;
  15091. break;
  15092. }
  15093. WFIFOSET(fd,8);
  15094. }
  15095. void clif_elemental_info(struct map_session_data *sd) {
  15096. int fd;
  15097. struct elemental_data *ed;
  15098. struct status_data *status;
  15099. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15100. return;
  15101. fd = sd->fd;
  15102. status = &ed->battle_status;
  15103. WFIFOHEAD(fd,22);
  15104. WFIFOW(fd, 0) = 0x81d;
  15105. WFIFOL(fd, 2) = ed->bl.id;
  15106. WFIFOL(fd, 6) = status->hp;
  15107. WFIFOL(fd,10) = status->max_hp;
  15108. WFIFOL(fd,14) = status->sp;
  15109. WFIFOL(fd,18) = status->max_sp;
  15110. WFIFOSET(fd,22);
  15111. }
  15112. /// Buying Store System
  15113. ///
  15114. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15115. /// 0810 <slots>.B
  15116. void clif_buyingstore_open(struct map_session_data* sd)
  15117. {
  15118. int fd = sd->fd;
  15119. WFIFOHEAD(fd,packet_len(0x810));
  15120. WFIFOW(fd,0) = 0x810;
  15121. WFIFOB(fd,2) = sd->buyingstore.slots;
  15122. WFIFOSET(fd,packet_len(0x810));
  15123. }
  15124. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15125. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15126. /// result:
  15127. /// 0 = cancel
  15128. /// 1 = open
  15129. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  15130. {
  15131. const unsigned int blocksize = 8;
  15132. uint8* itemlist;
  15133. char storename[MESSAGE_SIZE];
  15134. unsigned char result;
  15135. int zenylimit;
  15136. unsigned int count, packet_len;
  15137. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15138. packet_len = RFIFOW(fd,info->pos[0]);
  15139. // TODO: Make this check global for all variable length packets.
  15140. if( packet_len < 89 )
  15141. {// minimum packet length
  15142. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  15143. return;
  15144. }
  15145. zenylimit = RFIFOL(fd,info->pos[1]);
  15146. result = RFIFOL(fd,info->pos[2]);
  15147. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  15148. itemlist = RFIFOP(fd,info->pos[4]);
  15149. // so that buyingstore_create knows, how many elements it has access to
  15150. packet_len-= info->pos[4];
  15151. if( packet_len%blocksize )
  15152. {
  15153. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15154. return;
  15155. }
  15156. count = packet_len/blocksize;
  15157. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  15158. }
  15159. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15160. /// 0812 <result>.W <total weight>.L
  15161. /// result:
  15162. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15163. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15164. /// 8 = "No sale (purchase) information available." (0x705)
  15165. /// ? = nothing
  15166. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15167. {
  15168. int fd = sd->fd;
  15169. WFIFOHEAD(fd,packet_len(0x812));
  15170. WFIFOW(fd,0) = 0x812;
  15171. WFIFOW(fd,2) = result;
  15172. WFIFOL(fd,4) = weight;
  15173. WFIFOSET(fd,packet_len(0x812));
  15174. }
  15175. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15176. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15177. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  15178. {
  15179. int fd = sd->fd;
  15180. unsigned int i;
  15181. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  15182. WFIFOW(fd,0) = 0x813;
  15183. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  15184. WFIFOL(fd,4) = sd->bl.id;
  15185. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  15186. for( i = 0; i < sd->buyingstore.slots; i++ )
  15187. {
  15188. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  15189. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  15190. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  15191. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  15192. }
  15193. WFIFOSET(fd,WFIFOW(fd,2));
  15194. }
  15195. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15196. /// 0814 <account id>.L <store name>.80B
  15197. void clif_buyingstore_entry(struct map_session_data* sd)
  15198. {
  15199. uint8 buf[MESSAGE_SIZE+6];
  15200. WBUFW(buf,0) = 0x814;
  15201. WBUFL(buf,2) = sd->bl.id;
  15202. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15203. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15204. }
  15205. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15206. {
  15207. int fd = sd->fd;
  15208. WFIFOHEAD(fd,packet_len(0x814));
  15209. WFIFOW(fd,0) = 0x814;
  15210. WFIFOL(fd,2) = pl_sd->bl.id;
  15211. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15212. WFIFOSET(fd,packet_len(0x814));
  15213. }
  15214. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15215. /// 0815
  15216. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15217. {
  15218. buyingstore_close(sd);
  15219. }
  15220. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15221. /// 0816 <account id>.L
  15222. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15223. {
  15224. uint8 buf[6];
  15225. WBUFW(buf,0) = 0x816;
  15226. WBUFL(buf,2) = sd->bl.id;
  15227. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15228. }
  15229. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15230. {
  15231. int fd = sd->fd;
  15232. WFIFOHEAD(fd,packet_len(0x816));
  15233. WFIFOW(fd,0) = 0x816;
  15234. WFIFOL(fd,2) = pl_sd->bl.id;
  15235. WFIFOSET(fd,packet_len(0x816));
  15236. }
  15237. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15238. /// 0817 <account id>.L
  15239. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15240. {
  15241. uint32 account_id;
  15242. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15243. buyingstore_open(sd, account_id);
  15244. }
  15245. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  15246. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  15247. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  15248. {
  15249. int fd = sd->fd;
  15250. unsigned int i;
  15251. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  15252. WFIFOW(fd,0) = 0x818;
  15253. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  15254. WFIFOL(fd,4) = pl_sd->bl.id;
  15255. WFIFOL(fd,8) = pl_sd->buyer_id;
  15256. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  15257. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  15258. {
  15259. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  15260. 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.
  15261. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  15262. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  15263. }
  15264. WFIFOSET(fd,WFIFOW(fd,2));
  15265. }
  15266. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  15267. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  15268. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  15269. {
  15270. const unsigned int blocksize = 6;
  15271. uint8* itemlist;
  15272. uint32 account_id;
  15273. unsigned int count, packet_len, buyer_id;
  15274. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15275. packet_len = RFIFOW(fd,info->pos[0]);
  15276. if( packet_len < 12 )
  15277. {// minimum packet length
  15278. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  15279. return;
  15280. }
  15281. account_id = RFIFOL(fd,info->pos[1]);
  15282. buyer_id = RFIFOL(fd,info->pos[2]);
  15283. itemlist = RFIFOP(fd,info->pos[3]);
  15284. // so that buyingstore_trade knows, how many elements it has access to
  15285. packet_len-= info->pos[3];
  15286. if( packet_len%blocksize )
  15287. {
  15288. 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);
  15289. return;
  15290. }
  15291. count = packet_len/blocksize;
  15292. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  15293. }
  15294. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15295. /// 081a <result>.W
  15296. /// result:
  15297. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15298. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15299. /// ? = nothing
  15300. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15301. {
  15302. int fd = sd->fd;
  15303. WFIFOHEAD(fd,packet_len(0x81a));
  15304. WFIFOW(fd,0) = 0x81a;
  15305. WFIFOW(fd,2) = result;
  15306. WFIFOSET(fd,packet_len(0x81a));
  15307. }
  15308. /// Updates the zeny limit and an item in the buying store item list.
  15309. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15310. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15311. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  15312. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  15313. const int cmd = 0x81b;
  15314. #else
  15315. const int cmd = 0x9e6;
  15316. #endif
  15317. int offset = 0;
  15318. int fd = sd->fd;
  15319. WFIFOHEAD(fd,packet_len(cmd));
  15320. WFIFOW(fd,0) = cmd;
  15321. WFIFOW(fd,2) = nameid;
  15322. WFIFOW(fd,4) = amount; // amount of nameid received
  15323. #if PACKETVER >= 20141016
  15324. WFIFOL(fd,6) = zeny; // zeny
  15325. offset += 4;
  15326. #endif
  15327. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  15328. #if PACKETVER >= 20141016
  15329. WFIFOL(fd,10+offset) = char_id; // GID
  15330. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  15331. #endif
  15332. WFIFOSET(fd,packet_len(cmd));
  15333. }
  15334. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15335. /// 081c <index>.W <amount>.W <price>.L
  15336. /// message:
  15337. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15338. ///
  15339. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15340. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15341. {
  15342. int fd = sd->fd;
  15343. WFIFOHEAD(fd,packet_len(0x81c));
  15344. WFIFOW(fd,0) = 0x81c;
  15345. WFIFOW(fd,2) = index+2;
  15346. WFIFOW(fd,4) = amount;
  15347. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15348. WFIFOSET(fd,packet_len(0x81c));
  15349. }
  15350. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15351. /// 0824 <result>.W <name id>.W
  15352. /// result:
  15353. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15354. /// 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)
  15355. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15356. /// ? = nothing
  15357. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  15358. {
  15359. int fd = sd->fd;
  15360. WFIFOHEAD(fd,packet_len(0x824));
  15361. WFIFOW(fd,0) = 0x824;
  15362. WFIFOW(fd,2) = result;
  15363. WFIFOW(fd,4) = nameid;
  15364. WFIFOSET(fd,packet_len(0x824));
  15365. }
  15366. /// Search Store Info System
  15367. ///
  15368. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15369. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15370. /// type:
  15371. /// 0 = Vending
  15372. /// 1 = Buying Store
  15373. ///
  15374. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15375. /// amount of card slots. If the client does not know about the item it
  15376. /// cannot be searched.
  15377. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  15378. {
  15379. const unsigned int blocksize = 2;
  15380. const uint8* itemlist;
  15381. const uint8* cardlist;
  15382. unsigned char type;
  15383. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  15384. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15385. packet_len = RFIFOW(fd,info->pos[0]);
  15386. if( packet_len < 15 )
  15387. {// minimum packet length
  15388. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  15389. return;
  15390. }
  15391. type = RFIFOB(fd,info->pos[1]);
  15392. max_price = RFIFOL(fd,info->pos[2]);
  15393. min_price = RFIFOL(fd,info->pos[3]);
  15394. item_count = RFIFOB(fd,info->pos[4]);
  15395. card_count = RFIFOB(fd,info->pos[5]);
  15396. itemlist = RFIFOP(fd,info->pos[6]);
  15397. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  15398. // check, if there is enough data for the claimed count of items
  15399. packet_len-= info->pos[6];
  15400. if( packet_len%blocksize )
  15401. {
  15402. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15403. return;
  15404. }
  15405. count = packet_len/blocksize;
  15406. if( count < item_count+card_count )
  15407. {
  15408. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  15409. return;
  15410. }
  15411. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  15412. }
  15413. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15414. /// 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 }*
  15415. /// is first page:
  15416. /// 0 = appends to existing results
  15417. /// 1 = clears previous results before displaying this result set
  15418. /// is next page:
  15419. /// 0 = no "next" label
  15420. /// 1 = "next" label to retrieve more results
  15421. void clif_search_store_info_ack(struct map_session_data* sd)
  15422. {
  15423. #if PACKETVER >= 20150225
  15424. const unsigned int blocksize = MESSAGE_SIZE+26+5*5;
  15425. #else
  15426. const unsigned int blocksize = MESSAGE_SIZE+26;
  15427. #endif
  15428. int fd = sd->fd;
  15429. unsigned int i, start, end;
  15430. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  15431. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  15432. WFIFOHEAD(fd,7+(end-start)*blocksize);
  15433. WFIFOW(fd,0) = 0x836;
  15434. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  15435. WFIFOB(fd,4) = !sd->searchstore.pages;
  15436. WFIFOB(fd,5) = searchstore_querynext(sd);
  15437. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15438. for( i = start; i < end; i++ ) {
  15439. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15440. struct item it;
  15441. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  15442. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  15443. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  15444. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  15445. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  15446. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  15447. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  15448. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  15449. // make-up an item for clif_addcards
  15450. memset(&it, 0, sizeof(it));
  15451. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  15452. it.nameid = ssitem->nameid;
  15453. it.amount = ssitem->amount;
  15454. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  15455. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  15456. }
  15457. WFIFOSET(fd,WFIFOW(fd,2));
  15458. }
  15459. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15460. /// 0837 <reason>.B
  15461. /// reason:
  15462. /// 0 = "No matching stores were found." (0x70b)
  15463. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15464. /// 2 = "You cannot search anymore." (0x706)
  15465. /// 3 = "You cannot search yet." (0x708)
  15466. /// 4 = "No sale (purchase) information available." (0x705)
  15467. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15468. {
  15469. int fd = sd->fd;
  15470. WFIFOHEAD(fd,packet_len(0x837));
  15471. WFIFOW(fd,0) = 0x837;
  15472. WFIFOB(fd,2) = reason;
  15473. WFIFOSET(fd,packet_len(0x837));
  15474. }
  15475. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15476. /// 0838
  15477. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15478. {
  15479. searchstore_next(sd);
  15480. }
  15481. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15482. /// 083a <type>.W <remaining uses>.B
  15483. /// type:
  15484. /// 0 = Search Stores
  15485. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15486. void clif_open_search_store_info(struct map_session_data* sd)
  15487. {
  15488. int fd = sd->fd;
  15489. WFIFOHEAD(fd,packet_len(0x83a));
  15490. WFIFOW(fd,0) = 0x83a;
  15491. WFIFOW(fd,2) = sd->searchstore.effect;
  15492. #if PACKETVER > 20100701
  15493. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15494. #endif
  15495. WFIFOSET(fd,packet_len(0x83a));
  15496. }
  15497. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15498. /// 083b
  15499. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15500. {
  15501. searchstore_close(sd);
  15502. }
  15503. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15504. /// 083c <account id>.L <store id>.L <nameid>.W
  15505. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  15506. {
  15507. unsigned short nameid;
  15508. uint32 account_id, store_id;
  15509. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15510. account_id = RFIFOL(fd,info->pos[0]);
  15511. store_id = RFIFOL(fd,info->pos[1]);
  15512. nameid = RFIFOW(fd,info->pos[2]);
  15513. searchstore_click(sd, account_id, store_id, nameid);
  15514. }
  15515. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15516. /// 083d <xPos>.W <yPos>.W
  15517. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15518. {
  15519. int fd = sd->fd;
  15520. WFIFOHEAD(fd,packet_len(0x83d));
  15521. WFIFOW(fd,0) = 0x83d;
  15522. WFIFOW(fd,2) = x;
  15523. WFIFOW(fd,4) = y;
  15524. WFIFOSET(fd,packet_len(0x83d));
  15525. }
  15526. /// Parse function for packet debugging.
  15527. void clif_parse_debug(int fd,struct map_session_data *sd)
  15528. {
  15529. int cmd, packet_len;
  15530. // clif_parse ensures, that there is at least 2 bytes of data
  15531. cmd = RFIFOW(fd,0);
  15532. if( sd ) {
  15533. packet_len = packet_db[cmd].len;
  15534. if( packet_len == 0 )
  15535. {// unknown
  15536. packet_len = RFIFOREST(fd);
  15537. }
  15538. else if( packet_len == -1 )
  15539. {// variable length
  15540. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15541. }
  15542. 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);
  15543. }
  15544. else
  15545. {
  15546. packet_len = RFIFOREST(fd);
  15547. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15548. }
  15549. ShowDump(RFIFOP(fd,0), packet_len);
  15550. }
  15551. /*==========================================
  15552. * Server tells client to display a window similar to Magnifier (item) one
  15553. * Server populates the window with avilable elemental converter options according to player's inventory
  15554. *------------------------------------------*/
  15555. int clif_elementalconverter_list(struct map_session_data *sd) {
  15556. int i,c,view,fd;
  15557. nullpo_ret(sd);
  15558. /// Main client packet processing function
  15559. fd=sd->fd;
  15560. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  15561. WFIFOW(fd, 0)=0x1ad;
  15562. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  15563. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  15564. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  15565. WFIFOW(fd,c*2+ 4)= view;
  15566. else
  15567. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  15568. c++;
  15569. }
  15570. }
  15571. WFIFOW(fd,2) = c*2+4;
  15572. WFIFOSET(fd, WFIFOW(fd,2));
  15573. if (c > 0) {
  15574. sd->menuskill_id = SA_CREATECON;
  15575. sd->menuskill_val = c;
  15576. }
  15577. return 0;
  15578. }
  15579. /**
  15580. * Rune Knight
  15581. **/
  15582. void clif_millenniumshield(struct block_list *bl, short shields) {
  15583. #if PACKETVER >= 20081217
  15584. unsigned char buf[10];
  15585. WBUFW(buf,0) = 0x440;
  15586. WBUFL(buf,2) = bl->id;
  15587. WBUFW(buf,6) = shields;
  15588. WBUFW(buf,8) = 0;
  15589. clif_send(buf,packet_len(0x440),bl,AREA);
  15590. #endif
  15591. }
  15592. /**
  15593. * Warlock
  15594. **/
  15595. /*==========================================
  15596. * Spellbook list [LimitLine/3CeAM]
  15597. *------------------------------------------*/
  15598. int clif_spellbook_list(struct map_session_data *sd)
  15599. {
  15600. int i, c;
  15601. int fd;
  15602. nullpo_ret(sd);
  15603. fd = sd->fd;
  15604. WFIFOHEAD(fd, 8 * 8 + 8);
  15605. WFIFOW(fd,0) = 0x1ad;
  15606. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  15607. {
  15608. if( reading_spellbook_db.findBook(sd->inventory.u.items_inventory[i].nameid) )
  15609. {
  15610. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15611. c++;
  15612. }
  15613. }
  15614. if( c > 0 )
  15615. {
  15616. WFIFOW(fd,2) = c * 2 + 4;
  15617. WFIFOSET(fd, WFIFOW(fd, 2));
  15618. sd->menuskill_id = WL_READING_SB;
  15619. sd->menuskill_val = c;
  15620. }
  15621. else{
  15622. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15623. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  15624. }
  15625. return 1;
  15626. }
  15627. /**
  15628. * Mechanic
  15629. **/
  15630. /*==========================================
  15631. * Magic Decoy Material List
  15632. *------------------------------------------*/
  15633. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  15634. int i, c;
  15635. int fd;
  15636. nullpo_ret(sd);
  15637. fd = sd->fd;
  15638. WFIFOHEAD(fd, 8 * 8 + 8);
  15639. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15640. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15641. if( itemdb_group_item_exists(IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid) ) {
  15642. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15643. c ++;
  15644. }
  15645. }
  15646. if( c > 0 ) {
  15647. sd->menuskill_id = NC_MAGICDECOY;
  15648. sd->menuskill_val = skill_lv;
  15649. sd->sc.comet_x = x;
  15650. sd->sc.comet_y = y;
  15651. WFIFOW(fd,2) = c * 2 + 4;
  15652. WFIFOSET(fd, WFIFOW(fd, 2));
  15653. } else {
  15654. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  15655. return 0;
  15656. }
  15657. return 1;
  15658. }
  15659. /*==========================================
  15660. * Guillotine Cross Poisons List
  15661. *------------------------------------------*/
  15662. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  15663. int i, c;
  15664. int fd;
  15665. nullpo_ret(sd);
  15666. fd = sd->fd;
  15667. WFIFOHEAD(fd, 8 * 8 + 8);
  15668. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15669. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15670. if( itemdb_group_item_exists(IG_POISON, sd->inventory.u.items_inventory[i].nameid) ) {
  15671. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15672. c ++;
  15673. }
  15674. }
  15675. if( c > 0 ) {
  15676. sd->menuskill_id = GC_POISONINGWEAPON;
  15677. sd->menuskill_val = skill_lv;
  15678. WFIFOW(fd,2) = c * 2 + 4;
  15679. WFIFOSET(fd, WFIFOW(fd, 2));
  15680. } else {
  15681. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  15682. return 0;
  15683. }
  15684. return 1;
  15685. }
  15686. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15687. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15688. int fd, i, c;
  15689. nullpo_ret(sd);
  15690. fd = sd->fd;
  15691. if( !fd )
  15692. return 0;
  15693. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15694. return 0;
  15695. WFIFOHEAD(fd, 2 * 6 + 4);
  15696. WFIFOW(fd,0) = 0x442;
  15697. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15698. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15699. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15700. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  15701. {
  15702. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15703. c++;
  15704. }
  15705. if( c > 0 ) {
  15706. WFIFOW(fd,2) = 8 + c * 2;
  15707. WFIFOL(fd,4) = c;
  15708. WFIFOSET(fd,WFIFOW(fd,2));
  15709. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15710. sd->menuskill_val = c;
  15711. } else {
  15712. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15713. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15714. }
  15715. return 1;
  15716. }
  15717. /*===========================================
  15718. * Skill list for Four Elemental Analysis
  15719. * and Change Material skills.
  15720. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15721. *------------------------------------------*/
  15722. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15723. #if PACKETVER >= 20090922
  15724. int fd = sd->fd;
  15725. nullpo_ret(sd);
  15726. sd->menuskill_id = skill_id; // To prevent hacking.
  15727. sd->menuskill_val = skill_lv;
  15728. if( skill_id == GN_CHANGEMATERIAL )
  15729. skill_lv = 0; // Changematerial
  15730. WFIFOHEAD(fd, packet_len(0x7e3));
  15731. WFIFOW(fd,0) = 0x7e3;
  15732. WFIFOL(fd,2) = skill_lv;
  15733. WFIFOL(fd,4) = 0;
  15734. WFIFOSET(fd, packet_len(0x7e3));
  15735. #endif
  15736. return 1;
  15737. }
  15738. /*==========================================
  15739. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  15740. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15741. * RFIFOL(fd,2) - type (currently not used)
  15742. *------------------------------------------*/
  15743. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15744. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15745. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15746. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  15747. return;
  15748. if( pc_istrading(sd) ) {
  15749. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  15750. clif_menuskill_clear(sd);
  15751. return;
  15752. }
  15753. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  15754. clif_menuskill_clear(sd);
  15755. }
  15756. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15757. /// 08cf <id>.L <type>.W <num>.W
  15758. void clif_spiritcharm(struct map_session_data *sd) {
  15759. unsigned char buf[10];
  15760. nullpo_retv(sd);
  15761. WBUFW(buf,0) = 0x08cf;
  15762. WBUFL(buf,2) = sd->bl.id;
  15763. WBUFW(buf,6) = sd->spiritcharm_type;
  15764. WBUFW(buf,8) = sd->spiritcharm;
  15765. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15766. }
  15767. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15768. /// 0907 <index>.W
  15769. ///
  15770. /// R 0908 <index>.w <type>.b
  15771. /// type:
  15772. /// 0 = move item to personal tab
  15773. /// 1 = move item to normal tab
  15774. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15775. #if PACKETVER >= 20111122
  15776. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15777. int index = RFIFOW(fd,info->pos[0]) - 2;
  15778. int type = RFIFOB(fd, info->pos[1]);
  15779. /* can't move while dead. */
  15780. if(pc_isdead(sd)) {
  15781. return;
  15782. }
  15783. if (index < 0 || index >= MAX_INVENTORY)
  15784. return;
  15785. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15786. sd->inventory.u.items_inventory[index].favorite = 0;
  15787. else if( type == 0 )
  15788. sd->inventory.u.items_inventory[index].favorite = 1;
  15789. else
  15790. return;/* nothing to do. */
  15791. clif_favorite_item(sd, index);
  15792. #endif
  15793. }
  15794. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15795. /// 0900 <index>.W <favorite>.B
  15796. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15797. int fd = sd->fd;
  15798. WFIFOHEAD(fd,packet_len(0x908));
  15799. WFIFOW(fd,0) = 0x908;
  15800. WFIFOW(fd,2) = index+2;
  15801. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15802. WFIFOSET(fd,packet_len(0x908));
  15803. }
  15804. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15805. void clif_snap( struct block_list *bl, short x, short y ) {
  15806. unsigned char buf[10];
  15807. WBUFW(buf,0) = 0x8d2;
  15808. WBUFL(buf,2) = bl->id;
  15809. WBUFW(buf,6) = x;
  15810. WBUFW(buf,8) = y;
  15811. if( disguised(bl) )
  15812. {
  15813. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15814. WBUFL(buf,2) = -bl->id;
  15815. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15816. } else
  15817. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15818. }
  15819. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15820. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15821. #if PACKETVER >= 20120404
  15822. WFIFOHEAD(fd,packet_len(0x977));
  15823. WFIFOW(fd,0) = 0x977;
  15824. WFIFOL(fd,2) = md->bl.id;
  15825. WFIFOL(fd,6) = md->status.hp;
  15826. WFIFOL(fd,10) = md->status.max_hp;
  15827. WFIFOSET(fd,packet_len(0x977));
  15828. #endif
  15829. }
  15830. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15831. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15832. return;
  15833. }
  15834. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15835. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15836. WFIFOW(sd->fd,0) = 0x2c9;
  15837. WFIFOB(sd->fd,2) = flag;
  15838. WFIFOSET(sd->fd, packet_len(0x2c9));
  15839. }
  15840. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15841. /// 0979 <world name>.24B <char name>.24B
  15842. void clif_ackworldinfo(struct map_session_data* sd) {
  15843. int fd;
  15844. nullpo_retv(sd);
  15845. fd = sd->fd;
  15846. WFIFOHEAD(fd,packet_len(0x979));
  15847. WFIFOW(fd,0)=0x979;
  15848. //AID -> world name ?
  15849. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15850. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15851. WFIFOSET(fd,packet_len(0x979));
  15852. }
  15853. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15854. /// 0978 <AID>.L
  15855. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15856. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15857. if(sd)
  15858. clif_ackworldinfo(sd);
  15859. }
  15860. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15861. /// 0447
  15862. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15863. //if(sd)
  15864. ;
  15865. }
  15866. /// req world info (CZ_CLIENT_VERSION)
  15867. /// 044A <version>.L
  15868. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15869. //if(sd)
  15870. ;
  15871. }
  15872. /// Ranking list
  15873. /// ranking pointlist { <name>.24B <point>.L }*10
  15874. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15875. struct fame_list* list;
  15876. int i, size = MAX_FAME_LIST;
  15877. switch(rankingtype) {
  15878. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15879. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15880. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15881. // PK currently unsupported
  15882. case RANK_KILLER: list = NULL; size = 0; break;
  15883. default:
  15884. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15885. return;
  15886. }
  15887. //Packet size limits this list to 10 elements. [Skotlex]
  15888. for (i = 0; i < min(10,size); i++) {
  15889. if (list[i].id > 0) {
  15890. const char* name;
  15891. if (strcmp(list[i].name, "-") == 0 &&
  15892. (name = map_charid2nick(list[i].id)) != NULL)
  15893. {
  15894. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15895. } else {
  15896. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15897. }
  15898. } else {
  15899. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15900. }
  15901. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15902. }
  15903. for(;i < 10; i++) { //In case the MAX is less than 10.
  15904. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15905. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15906. }
  15907. }
  15908. /// Request for the blacksmith ranklist.
  15909. /// /blacksmith command sends this packet to the server.
  15910. /// 0217 (CZ_BLACKSMITH_RANK)
  15911. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15912. clif_ranklist(sd,RANK_BLACKSMITH);
  15913. }
  15914. /// Request for the alchemist ranklist.
  15915. /// /alchemist command sends this packet to the server.
  15916. /// 0218 (CZ_ALCHEMIST_RANK)
  15917. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15918. clif_ranklist(sd,RANK_ALCHEMIST);
  15919. }
  15920. /// Request for the taekwon ranklist.
  15921. /// /taekwon command sends this packet to the server.
  15922. /// 0225 (CZ_TAEKWON_RANK)
  15923. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15924. clif_ranklist(sd,RANK_TAEKWON);
  15925. }
  15926. /// Request for the killer ranklist.
  15927. /// /pk command sends this packet to the server.
  15928. /// 0237 (CZ_KILLER_RANK)
  15929. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15930. clif_ranklist(sd,RANK_KILLER);
  15931. }
  15932. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15933. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15934. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15935. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15936. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15937. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15938. enum e_rank rank;
  15939. #if PACKETVER < 20130710
  15940. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15941. short cmd;
  15942. switch( rankingType ){
  15943. case RANK_BLACKSMITH: cmd = 0x219; break;
  15944. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15945. case RANK_TAEKWON: cmd = 0x226; break;
  15946. case RANK_KILLER: cmd = 0x238; break;
  15947. default:
  15948. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15949. return;
  15950. }
  15951. // Can be safely casted here, since we validated it before
  15952. rank = (enum e_rank)rankingType;
  15953. WBUFW(buf,0) = cmd;
  15954. clif_sub_ranklist(buf,2,sd,rank);
  15955. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  15956. #else
  15957. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  15958. int mypoint = 0;
  15959. switch( rankingType ){
  15960. case RANK_BLACKSMITH:
  15961. case RANK_ALCHEMIST:
  15962. case RANK_TAEKWON:
  15963. case RANK_KILLER:
  15964. break;
  15965. default:
  15966. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15967. return;
  15968. }
  15969. // Can be safely casted here, since we validated it before
  15970. rank = (enum e_rank)rankingType;
  15971. WBUFW(buf,0) = 0x97d;
  15972. WBUFW(buf,2) = rank;
  15973. clif_sub_ranklist(buf,4,sd,rank);
  15974. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15975. case MAPID_BLACKSMITH:
  15976. case MAPID_ALCHEMIST:
  15977. case MAPID_TAEKWON:
  15978. mypoint = sd->status.fame;
  15979. }
  15980. WBUFL(buf,284) = mypoint; //mypoint
  15981. clif_send(buf, 288, &sd->bl, SELF);
  15982. #endif
  15983. }
  15984. /*
  15985. * 097c <type> (CZ_REQ_RANKING)
  15986. * type
  15987. * 0: /blacksmith
  15988. * 1: /alchemist
  15989. * 2: /taekwon
  15990. * 3: /pk
  15991. * */
  15992. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15993. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15994. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15995. clif_ranklist(sd,rankingtype);
  15996. }
  15997. /// Updates the fame rank points for the given ranking.
  15998. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  15999. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16000. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16001. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16002. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  16003. int fd=sd->fd;
  16004. #if PACKETVER < 20130710
  16005. short cmd;
  16006. switch(rankingtype){
  16007. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16008. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16009. case RANK_TAEKWON: cmd = 0x224; break;
  16010. default:
  16011. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16012. return;
  16013. }
  16014. WFIFOHEAD(fd,packet_len(cmd));
  16015. WFIFOW(fd,0) = cmd;
  16016. WFIFOL(fd,2) = point;
  16017. WFIFOL(fd,6) = sd->status.fame;
  16018. WFIFOSET(fd, packet_len(cmd));
  16019. #else
  16020. WFIFOHEAD(fd,packet_len(0x97e));
  16021. WFIFOW(fd,0) = 0x97e;
  16022. WFIFOW(fd,2) = rankingtype;
  16023. WFIFOL(fd,4) = point;
  16024. WFIFOL(fd,8) = sd->status.fame;
  16025. WFIFOSET(fd,packet_len(0x97e));
  16026. #endif
  16027. }
  16028. /**
  16029. * Transmit personal information to player. (rates)
  16030. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16031. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16032. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16033. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16034. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16035. * FIXME!
  16036. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16037. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16038. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16039. */
  16040. #ifdef VIP_ENABLE
  16041. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16042. if (sd) {
  16043. struct s_packet_db* info;
  16044. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16045. int cmd = 0, fd, i = 0;
  16046. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16047. int details_bexp[PINFO_MAX];
  16048. int details_drop[PINFO_MAX];
  16049. int details_penalty[PINFO_MAX];
  16050. /**
  16051. * Set for EXP
  16052. */
  16053. //0:PCRoom
  16054. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16055. if (details_bexp[0] == 100 || !details_bexp[0])
  16056. details_bexp[0] = 0;
  16057. else {
  16058. if (details_bexp[0] < 100) {
  16059. details_bexp[0] = 100 - details_bexp[0];
  16060. details_bexp[0] = 0 - details_bexp[0];
  16061. }
  16062. else
  16063. details_bexp[0] = details_bexp[0] - 100;
  16064. }
  16065. //1:Premium
  16066. if (pc_isvip(sd)) {
  16067. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16068. if (details_bexp[1] < 0)
  16069. details_bexp[1] = 0 - details_bexp[1];
  16070. }
  16071. else
  16072. details_bexp[1] = 0;
  16073. //2:Server
  16074. details_bexp[2] = battle_config.base_exp_rate;
  16075. if (details_bexp[2] == 100)
  16076. details_bexp[2] = 0;
  16077. else {
  16078. if (details_bexp[2] < 100) {
  16079. details_bexp[2] = 100 - details_bexp[2];
  16080. details_bexp[2] = 0 - details_bexp[2];
  16081. }
  16082. else
  16083. details_bexp[2] = details_bexp[2] - 100;
  16084. }
  16085. //3:TPLUS
  16086. details_bexp[3] = 0;
  16087. /* End - EXP set*/
  16088. /**
  16089. * Set for Drop rate
  16090. */
  16091. //0:PCRoom
  16092. details_drop[0] = 0;
  16093. //1:Premium
  16094. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16095. if (pc_isvip(sd)) {
  16096. if (details_drop[1] < 0)
  16097. details_drop[1] = 0 - details_drop[1];
  16098. }
  16099. else
  16100. details_drop[1] = 0;
  16101. //2:Server
  16102. details_drop[2] = battle_config.item_rate_common;
  16103. if (details_drop[2] == 100)
  16104. details_drop[2] = 0;
  16105. else {
  16106. if (details_drop[2] < 100) {
  16107. details_drop[2] = 100 - details_drop[2];
  16108. details_drop[2] = 0 - details_drop[2];
  16109. }
  16110. else
  16111. details_drop[2] = details_drop[2] - 100;
  16112. }
  16113. //3:TPLUS
  16114. details_drop[3] = 0;
  16115. /* End - Drop set*/
  16116. /**
  16117. * Set for Penalty rate
  16118. */
  16119. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16120. //0:PCRoom
  16121. details_penalty[0] = 0;
  16122. //1:Premium
  16123. if (pc_isvip(sd)) {
  16124. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16125. if (details_penalty[1] == 100)
  16126. details_penalty[1] = 0;
  16127. else {
  16128. if (details_penalty[1] < 100) {
  16129. details_penalty[1] = 100 - details_penalty[1];
  16130. details_penalty[1] = 0 - details_penalty[1];
  16131. }
  16132. else
  16133. details_penalty[1] = details_penalty[1] - 100;
  16134. }
  16135. }
  16136. else
  16137. details_penalty[1] = 0;
  16138. //2:Server
  16139. details_penalty[2] = battle_config.death_penalty_base;
  16140. if (details_penalty[2] == 100)
  16141. details_penalty[2] = 0;
  16142. else {
  16143. if (details_penalty[2] < 100) {
  16144. details_penalty[2] = 100 - details_penalty[2];
  16145. details_penalty[2] = 0 - details_penalty[2];
  16146. }
  16147. else
  16148. details_penalty[2] = details_penalty[2] - 100;
  16149. }
  16150. //3:TPLUS
  16151. details_penalty[3] = 0;
  16152. /* End - Penalty set*/
  16153. cmd = packet_db_ack[cmdtype];
  16154. info = &packet_db[cmd];
  16155. len = info->len; //this is the base len without details
  16156. if(!len) return; //version as packet disable
  16157. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16158. szdetails = 7;
  16159. factor = 1;
  16160. }
  16161. else if (cmd == 0x097b) {
  16162. tot_baseexp *= factor;
  16163. tot_drop *= factor;
  16164. tot_penalty *= factor;
  16165. }
  16166. fd = sd->fd;
  16167. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16168. WFIFOW(fd,0) = cmd;
  16169. for (i = 0; i < maxinfotype; i++) {
  16170. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16171. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16172. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16173. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16174. tot_baseexp += details_bexp[i]*factor;
  16175. tot_drop += details_penalty[i]*factor;
  16176. tot_penalty += details_drop[i]*factor;
  16177. len += szdetails;
  16178. }
  16179. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16180. if (cmd == 0x08cb) { //0x08cb version
  16181. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16182. WFIFOW(fd,info->pos[2]) = tot_drop;
  16183. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16184. }
  16185. else { //2013-08-07aRagexe uses 0x097b
  16186. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16187. WFIFOL(fd,info->pos[2]) = tot_drop;
  16188. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16189. }
  16190. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16191. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16192. WFIFOSET(fd,len);
  16193. }
  16194. }
  16195. #endif
  16196. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16197. char cmd[30];
  16198. int t_aid = RFIFOL(fd,2);
  16199. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16200. is_atcommand(fd, sd, cmd, 1);
  16201. }
  16202. /**
  16203. * Marks Crimson Marker target on mini-map to the caster
  16204. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16205. * @param fd
  16206. * @param bl Crimson Marker target
  16207. **/
  16208. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16209. struct s_packet_db* info;
  16210. int cmd = 0;
  16211. int16 len;
  16212. unsigned char buf[11];
  16213. nullpo_retv(sd);
  16214. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16215. if (!cmd)
  16216. cmd = 0x09C1; //default
  16217. info = &packet_db[cmd];
  16218. if (!(len = info->len))
  16219. return;
  16220. WBUFW(buf, 0) = cmd;
  16221. WBUFL(buf, info->pos[0]) = bl->id;
  16222. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16223. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16224. clif_send(buf, len, &sd->bl, SELF);
  16225. }
  16226. /**
  16227. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16228. **/
  16229. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16230. struct s_packet_db *info = NULL;
  16231. int cmd = 0;
  16232. nullpo_retv(sd);
  16233. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16234. info = &packet_db[cmd];
  16235. if (!cmd || !info->len)
  16236. return;
  16237. WFIFOHEAD(sd->fd, info->len);
  16238. WFIFOW(sd->fd, 0) = cmd;
  16239. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16240. WFIFOSET(sd->fd, info->len);
  16241. }
  16242. /**
  16243. * [Ind/Hercules]
  16244. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16245. **/
  16246. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16247. char buf[256];
  16248. size_t len;
  16249. nullpo_retv(bl);
  16250. if(!message)
  16251. return;
  16252. len = strlen(message)+1;
  16253. if( len > sizeof(buf)-8 ) {
  16254. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16255. len = sizeof(buf)-8;
  16256. }
  16257. WBUFW(buf,0) = 0x8b3;
  16258. WBUFW(buf,2) = (uint16)(len+8);
  16259. WBUFL(buf,4) = bl->id;
  16260. safestrncpy(WBUFCP(buf,8), message, len);
  16261. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16262. }
  16263. /**
  16264. * [Ind/Hercules]
  16265. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16266. **/
  16267. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16268. unsigned char buf[10];
  16269. nullpo_retv(sd);
  16270. WBUFW(buf,0) = 0x7fc;
  16271. WBUFL(buf,2) = prev_leader_aid;
  16272. WBUFL(buf,6) = new_leader_aid;
  16273. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16274. }
  16275. /**
  16276. * Sends a clan message to a player
  16277. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16278. **/
  16279. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16280. #if PACKETVER >= 20131223
  16281. struct map_session_data *sd;
  16282. uint8 buf[256];
  16283. if( len == 0 ){
  16284. return;
  16285. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16286. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16287. len = sizeof(buf)-5-NAME_LENGTH;
  16288. }
  16289. WBUFW(buf, 0) = 0x98e;
  16290. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16291. // 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
  16292. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16293. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16294. if((sd = clan_getavailablesd(clan)) != NULL)
  16295. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16296. #endif
  16297. }
  16298. /**
  16299. * Parses a clan message from a player.
  16300. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16301. **/
  16302. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16303. #if PACKETVER >= 20131223
  16304. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16305. // validate packet and retrieve name and message
  16306. if( !clif_process_message(sd, false, name, message, output ) )
  16307. return;
  16308. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16309. #endif
  16310. }
  16311. /**
  16312. * Sends the basic clan informations to the client.
  16313. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16314. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16315. **/
  16316. void clif_clan_basicinfo( struct map_session_data *sd ){
  16317. #if PACKETVER >= 20131223
  16318. int fd, offset, length, i, flag;
  16319. struct clan* clan;
  16320. char mapname[MAP_NAME_LENGTH_EXT];
  16321. nullpo_retv( sd );
  16322. nullpo_retv( clan = sd->clan );
  16323. // Check if the player has a valid session and is not autotrading
  16324. if( !clif_session_isValid( sd ) ){
  16325. return;
  16326. }
  16327. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16328. fd = sd->fd;
  16329. WFIFOHEAD(fd,length);
  16330. memset( WFIFOP(fd, 0), 0, length );
  16331. WFIFOW( fd, 0 ) = 0x98a;
  16332. WFIFOL( fd, 4 ) = clan->id;
  16333. offset = 8;
  16334. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16335. offset += NAME_LENGTH;
  16336. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16337. offset += NAME_LENGTH;
  16338. mapindex_getmapname_ext( clan->map, mapname );
  16339. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16340. offset += MAP_NAME_LENGTH_EXT;
  16341. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16342. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16343. for( flag = 0; flag < 2; flag++ ){
  16344. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16345. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16346. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16347. offset += NAME_LENGTH;
  16348. }
  16349. }
  16350. }
  16351. WFIFOW( fd, 2 ) = offset;
  16352. WFIFOSET(fd,offset);
  16353. #endif
  16354. }
  16355. /**
  16356. * Updates the online and maximum player count of a clan.
  16357. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16358. **/
  16359. void clif_clan_onlinecount( struct clan* clan ){
  16360. #if PACKETVER >= 20131223
  16361. uint8 buf[6];
  16362. struct map_session_data *sd;
  16363. WBUFW(buf,0) = 0x988;
  16364. WBUFW(buf,2) = clan->connect_member;
  16365. WBUFW(buf,4) = clan->max_member;
  16366. if((sd = clan_getavailablesd(clan)) != NULL)
  16367. clif_send(buf, 6, &sd->bl, CLAN);
  16368. #endif
  16369. }
  16370. /**
  16371. * Notifies the client that the player has left his clan.
  16372. * 0989 (ZC_ACK_CLAN_LEAVE)
  16373. **/
  16374. void clif_clan_leave( struct map_session_data* sd ){
  16375. #if PACKETVER >= 20131223
  16376. int fd;
  16377. nullpo_retv( sd );
  16378. if( !clif_session_isValid( sd ) ){
  16379. return;
  16380. }
  16381. fd = sd->fd;
  16382. WFIFOHEAD(fd,2);
  16383. WFIFOW(fd,0) = 0x989;
  16384. WFIFOSET(fd,2);
  16385. #endif
  16386. }
  16387. /**
  16388. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16389. * 0A2F <result>.B <title_id>.L
  16390. */
  16391. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16392. {
  16393. #if PACKETVER >= 20150513
  16394. int fd;
  16395. nullpo_retv(sd);
  16396. if (!clif_session_isValid(sd))
  16397. return;
  16398. fd = sd->fd;
  16399. WFIFOHEAD(fd, packet_len(0xa2f));
  16400. WFIFOW(fd, 0) = 0xa2f;
  16401. WFIFOB(fd, 2) = result;
  16402. WFIFOL(fd, 3) = title_id;
  16403. WFIFOSET(fd, packet_len(0xa2f));
  16404. #endif
  16405. }
  16406. /**
  16407. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16408. * 0A2E <title_id>.L
  16409. */
  16410. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16411. {
  16412. int title_id;
  16413. nullpo_retv(sd);
  16414. title_id = RFIFOL(fd, 2);
  16415. if( title_id == sd->status.title_id ){
  16416. // It is exactly the same as the old one
  16417. return;
  16418. }else if( title_id <= 0 ){
  16419. sd->status.title_id = 0;
  16420. }else{
  16421. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16422. clif_change_title_ack(sd, 1, title_id);
  16423. return;
  16424. }
  16425. sd->status.title_id = title_id;
  16426. }
  16427. clif_name_area(&sd->bl);
  16428. clif_change_title_ack(sd, 0, title_id);
  16429. }
  16430. #ifdef DUMP_UNKNOWN_PACKET
  16431. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16432. {
  16433. const char* packet_txt = "save/packet.txt";
  16434. FILE* fp;
  16435. time_t time_server;
  16436. struct tm *datetime;
  16437. char datestr[512];
  16438. time(&time_server); // get time in seconds since 1/1/1970
  16439. datetime = localtime(&time_server); // convert seconds in structure
  16440. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16441. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16442. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16443. if( sd ) {
  16444. 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);
  16445. } else {
  16446. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16447. }
  16448. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16449. fprintf(fp, "\n");
  16450. fclose(fp);
  16451. } else {
  16452. ShowError("Failed to write '%s'.\n", packet_txt);
  16453. // Dump on console instead
  16454. if( sd ) {
  16455. 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);
  16456. } else {
  16457. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16458. }
  16459. ShowDump(RFIFOP(fd,0), packet_len);
  16460. }
  16461. }
  16462. #endif
  16463. /// Roulette System
  16464. /// Author: Yommy
  16465. /// Opens the roulette window
  16466. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16467. void clif_roulette_open( struct map_session_data* sd ){
  16468. nullpo_retv(sd);
  16469. int fd = sd->fd;
  16470. WFIFOHEAD(fd,packet_len(0xa1a));
  16471. WFIFOW(fd,0) = 0xa1a;
  16472. WFIFOB(fd,2) = 0; // result
  16473. WFIFOL(fd,3) = 0; // serial
  16474. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16475. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16476. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  16477. WFIFOL(fd,11) = sd->roulette_point.gold;
  16478. WFIFOL(fd,15) = sd->roulette_point.silver;
  16479. WFIFOL(fd,19) = sd->roulette_point.bronze;
  16480. WFIFOSET(fd,packet_len(0xa1a));
  16481. }
  16482. /// Request to open the roulette window
  16483. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16484. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16485. nullpo_retv(sd);
  16486. if (!battle_config.feature_roulette) {
  16487. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16488. return;
  16489. }
  16490. clif_roulette_open(sd);
  16491. }
  16492. /// Sends the info about the available roulette rewards to the client
  16493. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16494. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16495. void clif_roulette_info( struct map_session_data* sd ){
  16496. nullpo_retv(sd);
  16497. int fd = sd->fd;
  16498. int len = 8; // Initialize to header size
  16499. #if PACKETVER < 20180516
  16500. int size = 8;
  16501. #else
  16502. int size = 12;
  16503. #endif
  16504. for( int i = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16505. len += (MAX_ROULETTE_COLUMNS - i) * size;
  16506. }
  16507. WFIFOHEAD(fd,len);
  16508. WFIFOW(fd,0) = 0xa1c;
  16509. WFIFOW(fd,2) = len;
  16510. WFIFOL(fd,4) = 1; // serial
  16511. for(int i = 0, offset = 8; i < MAX_ROULETTE_LEVEL; i++) {
  16512. for(int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  16513. WFIFOW(fd,offset + 0) = i;
  16514. WFIFOW(fd,offset + 2) = j;
  16515. #if PACKETVER < 20180516
  16516. WFIFOW(fd,offset + 4) = rd.nameid[i][j];
  16517. WFIFOW(fd,offset + 6) = rd.qty[i][j];
  16518. #else
  16519. WFIFOL(fd,offset + 4) = rd.nameid[i][j];
  16520. WFIFOL(fd,offset + 8) = rd.qty[i][j];
  16521. #endif
  16522. offset += size;
  16523. }
  16524. }
  16525. WFIFOSET(fd,len);
  16526. }
  16527. /// Request the roulette reward data
  16528. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16529. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16530. nullpo_retv(sd);
  16531. if (!battle_config.feature_roulette) {
  16532. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16533. return;
  16534. }
  16535. clif_roulette_info(sd);
  16536. }
  16537. /// Notification of the client that the roulette window was closed
  16538. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16539. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16540. nullpo_retv(sd);
  16541. if (!battle_config.feature_roulette) {
  16542. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16543. return;
  16544. }
  16545. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16546. }
  16547. /// Response to a item reward request
  16548. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16549. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16550. #if PACKETVER >= 20141016
  16551. nullpo_retv(sd);
  16552. int fd = sd->fd;
  16553. WFIFOHEAD(fd,packet_len(0xa22));
  16554. WFIFOW(fd,0) = 0xa22;
  16555. WFIFOB(fd,2) = type;
  16556. WFIFOW(fd,3) = 0; //! TODO: Additional item
  16557. WFIFOSET(fd,packet_len(0xa22));
  16558. #endif
  16559. }
  16560. /**
  16561. * Claim roulette reward
  16562. * @param sd Player
  16563. * @return 0:Success
  16564. **/
  16565. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16566. struct item it;
  16567. uint8 res = 1;
  16568. nullpo_retr(1, sd);
  16569. if (sd->roulette.prizeIdx < 0)
  16570. return RECV_ITEM_FAILED;
  16571. memset(&it, 0, sizeof(it));
  16572. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16573. it.identify = 1;
  16574. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16575. ; // onSuccess
  16576. }
  16577. sd->roulette.claimPrize = false;
  16578. sd->roulette.prizeStage = 0;
  16579. sd->roulette.prizeIdx = -1;
  16580. sd->roulette.stage = 0;
  16581. return res;
  16582. }
  16583. /// Update Roulette window with current stats
  16584. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16585. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID ){
  16586. nullpo_retv(sd);
  16587. int fd = sd->fd;
  16588. WFIFOHEAD(fd,packet_len(0xa20));
  16589. WFIFOW(fd,0) = 0xa20;
  16590. WFIFOB(fd,2) = result;
  16591. WFIFOW(fd,3) = stage;
  16592. WFIFOW(fd,5) = prizeIdx;
  16593. WFIFOW(fd,7) = bonusItemID;
  16594. WFIFOL(fd,9) = sd->roulette_point.gold;
  16595. WFIFOL(fd,13) = sd->roulette_point.silver;
  16596. WFIFOL(fd,17) = sd->roulette_point.bronze;
  16597. WFIFOSET(fd,packet_len(0xa20));
  16598. }
  16599. /// Request to start the roulette
  16600. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16601. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16602. enum GENERATE_ROULETTE_ACK result;
  16603. nullpo_retv(sd);
  16604. if (!battle_config.feature_roulette) {
  16605. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16606. return;
  16607. }
  16608. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16609. return;
  16610. }
  16611. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16612. sd->roulette.stage = 0;
  16613. sd->roulette.claimPrize = false;
  16614. sd->roulette.prizeStage = 0;
  16615. sd->roulette.prizeIdx = -1;
  16616. }
  16617. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16618. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16619. }else{
  16620. if (!sd->roulette.stage) {
  16621. if (sd->roulette_point.bronze > 0) {
  16622. sd->roulette_point.bronze -= 1;
  16623. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16624. } else if (sd->roulette_point.silver > 9) {
  16625. sd->roulette_point.silver -= 10;
  16626. sd->roulette.stage = 2;
  16627. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16628. } else if (sd->roulette_point.gold > 9) {
  16629. sd->roulette_point.gold -= 10;
  16630. sd->roulette.stage = 4;
  16631. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16632. }
  16633. }
  16634. sd->roulette.prizeStage = sd->roulette.stage;
  16635. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16636. sd->roulette.claimPrize = true;
  16637. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16638. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16639. result = GENERATE_ROULETTE_LOSING;
  16640. sd->roulette.stage = 0;
  16641. }else{
  16642. result = GENERATE_ROULETTE_SUCCESS;
  16643. sd->roulette.stage++;
  16644. }
  16645. }
  16646. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16647. }
  16648. /// Request to claim a prize
  16649. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16650. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16651. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16652. nullpo_retv(sd);
  16653. if (!battle_config.feature_roulette) {
  16654. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16655. return;
  16656. }
  16657. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16658. return;
  16659. }
  16660. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16661. switch (clif_roulette_getitem(sd)) {
  16662. case ADDITEM_SUCCESS:
  16663. type = RECV_ITEM_SUCCESS;
  16664. break;
  16665. case ADDITEM_INVALID:
  16666. case ADDITEM_OVERITEM:
  16667. case ADDITEM_OVERAMOUNT:
  16668. type = RECV_ITEM_OVERCOUNT;
  16669. break;
  16670. case ADDITEM_OVERWEIGHT:
  16671. type = RECV_ITEM_OVERWEIGHT;
  16672. break;
  16673. case ADDITEM_STACKLIMIT:
  16674. default:
  16675. type = RECV_ITEM_FAILED;
  16676. break;
  16677. }
  16678. }
  16679. clif_roulette_recvitem_ack(sd,type);
  16680. }
  16681. /// MERGE ITEM
  16682. /**
  16683. * Acknowledge the client about item merger result
  16684. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16685. * @param fd
  16686. * @param sd
  16687. **/
  16688. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16689. unsigned char buf[9];
  16690. struct s_packet_db *info = NULL;
  16691. short cmd = 0;
  16692. nullpo_retv(sd);
  16693. if (!clif_session_isValid(sd))
  16694. return;
  16695. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16696. return;
  16697. if (!(info = &packet_db[cmd]) || info->len == 0)
  16698. return;
  16699. WBUFW(buf, 0) = cmd;
  16700. WBUFW(buf, info->pos[0]) = index;
  16701. WBUFW(buf, info->pos[1]) = count;
  16702. WBUFB(buf, info->pos[2]) = type;
  16703. clif_send(buf, info->len, &sd->bl, SELF);
  16704. }
  16705. /**
  16706. * Check if item has the pair to be merged
  16707. * @param sd
  16708. * @param it Item
  16709. * @return True if has pair, False if not
  16710. **/
  16711. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16712. struct item *it_;
  16713. unsigned short i;
  16714. nullpo_retr(false, sd);
  16715. 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);
  16716. if (i < MAX_INVENTORY)
  16717. return true;
  16718. return false;
  16719. }
  16720. /**
  16721. * Check if item can be merged
  16722. * @param id Item Data
  16723. * @param it Item
  16724. * @return True if can be merged, False if not
  16725. **/
  16726. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16727. if (!id || !it)
  16728. return false;
  16729. if (id->type == IT_CASH)
  16730. return false;
  16731. if (!itemdb_isstackable2(id))
  16732. return false;
  16733. if (itemdb_isspecial(it->card[0]))
  16734. return false;
  16735. if (!it->unique_id)
  16736. return false;
  16737. return true;
  16738. }
  16739. /**
  16740. * Open available item to be merged.
  16741. * Only show 1 item in 1 process.
  16742. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16743. * @param sd
  16744. **/
  16745. void clif_merge_item_open(struct map_session_data *sd) {
  16746. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16747. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16748. int len = 0;
  16749. struct s_packet_db *info = NULL;
  16750. struct item *it;
  16751. nullpo_retv(sd);
  16752. if (!clif_session_isValid(sd))
  16753. return;
  16754. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16755. return;
  16756. if (!(info = &packet_db[cmd]) || info->len == 0)
  16757. return;
  16758. // Get entries
  16759. for (i = 0; i < MAX_INVENTORY; i++) {
  16760. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16761. continue;
  16762. if (clif_merge_item_has_pair(sd, it))
  16763. indexes[n++] = i;
  16764. }
  16765. if (n < 2) { // No item need to be merged
  16766. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16767. return;
  16768. }
  16769. WBUFW(buf, 0) = cmd;
  16770. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16771. for (i = 0; i < n; i++) {
  16772. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16773. }
  16774. clif_send(buf, len, &sd->bl, SELF);
  16775. }
  16776. /**
  16777. * Process item merger
  16778. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16779. * @param fd
  16780. * @param sd
  16781. **/
  16782. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16783. struct s_packet_db *info = NULL;
  16784. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16785. unsigned int count = 0;
  16786. struct item_data *id = NULL;
  16787. nullpo_retv(sd);
  16788. if (!clif_session_isValid(sd))
  16789. return;
  16790. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16791. return;
  16792. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16793. if (n < 2) { // No item need to be merged
  16794. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16795. return;
  16796. }
  16797. for (i = 0, j = 0; i < n; i++) {
  16798. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16799. if( idx < 0 || idx >= MAX_INVENTORY ){
  16800. return;
  16801. }
  16802. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16803. continue;
  16804. indexes[j] = idx;
  16805. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16806. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16807. return;
  16808. }
  16809. count += sd->inventory.u.items_inventory[idx].amount;
  16810. j++;
  16811. }
  16812. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16813. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16814. return;
  16815. }
  16816. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16817. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16818. return;
  16819. }
  16820. // Merrrrge!!!!
  16821. for (i = 1; i < n; i++) {
  16822. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16823. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16824. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16825. sd->inventory_data[idx] = NULL;
  16826. clif_delitem(sd, idx, amt, 0);
  16827. }
  16828. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16829. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16830. }
  16831. /**
  16832. * Cancel item merge
  16833. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16834. * @param fd
  16835. * @param sd
  16836. **/
  16837. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16838. return; // Nothing todo yet
  16839. }
  16840. /**
  16841. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16842. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16843. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  16844. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16845. **/
  16846. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type) {
  16847. unsigned char buf[9 + NAME_LENGTH * 2];
  16848. unsigned short cmd = 0;
  16849. struct s_packet_db *info = NULL;
  16850. if (!(cmd = packet_db_ack[ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  16851. return;
  16852. if (!(info = &packet_db[cmd]) || info->len == 0)
  16853. return;
  16854. WBUFW(buf, 0) = 0x7fd;
  16855. WBUFB(buf, 4) = type;
  16856. WBUFW(buf, 5) = nameid;
  16857. WBUFB(buf, 7) = NAME_LENGTH;
  16858. if (battle_config.broadcast_hide_name) {
  16859. std::string dispname = std::string(char_name);
  16860. int hide = min(battle_config.broadcast_hide_name, dispname.length() - 1);
  16861. dispname.replace(dispname.length() - hide, hide, hide, '*');
  16862. safestrncpy(WBUFCP(buf, 8), dispname.c_str(), NAME_LENGTH);
  16863. }
  16864. else
  16865. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  16866. switch (type) {
  16867. case ITEMOBTAIN_TYPE_BOXITEM:
  16868. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  16869. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  16870. WBUFW(buf, 9 + NAME_LENGTH) = container;
  16871. break;
  16872. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16873. {
  16874. struct mob_db *db = mob_db(container);
  16875. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  16876. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  16877. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  16878. }
  16879. break;
  16880. case ITEMOBTAIN_TYPE_NPC:
  16881. default:
  16882. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  16883. break;
  16884. }
  16885. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  16886. }
  16887. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16888. /// 0A02 <view>.W
  16889. /// Value <flag> has the following effects:
  16890. /// 1: Open a Dress Room window.
  16891. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16892. #if PACKETVER >= 20150513
  16893. int fd = sd->fd;
  16894. nullpo_retv(sd);
  16895. WFIFOHEAD(fd, packet_len(0xa02));
  16896. WFIFOW(fd,0) = 0xa02;
  16897. WFIFOW(fd,2) = flag;
  16898. WFIFOSET(fd, packet_len(0xa02));
  16899. #endif
  16900. }
  16901. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16902. /// 0A35 <result>.W
  16903. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16904. #if PACKETVER >= 20150513
  16905. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16906. // Ignore the request
  16907. // - Invalid item index
  16908. // - Invalid item ID or item doesn't exist
  16909. // - Item is already identified
  16910. if (idx < 0 || idx >= MAX_INVENTORY ||
  16911. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16912. sd->inventory.u.items_inventory[idx].identify)
  16913. return;
  16914. // Ignore the request - No magnifiers in inventory
  16915. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16916. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16917. return;
  16918. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16919. return;
  16920. skill_identify(sd, idx);
  16921. #endif
  16922. }
  16923. /// Starts navigation to the given target on client side
  16924. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16925. #if PACKETVER >= 20111010
  16926. int fd = sd->fd;
  16927. WFIFOHEAD(fd,27);
  16928. WFIFOW(fd,0) = 0x08e2;
  16929. // How detailed will our navigation be?
  16930. if( mob_id > 0 ){
  16931. x = 0;
  16932. y = 0;
  16933. WFIFOB(fd,2) = 3; // monster with destination field
  16934. }else if( x > 0 && y > 0 ){
  16935. WFIFOB(fd,2) = 0; // with coordinates
  16936. }else{
  16937. x = 0;
  16938. y = 0;
  16939. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16940. }
  16941. // Which services can be used for transportation?
  16942. WFIFOB(fd,3) = flag;
  16943. // If this flag is set, the navigation window will not be opened up
  16944. WFIFOB(fd,4) = hideWindow;
  16945. // Target map
  16946. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  16947. // Target x
  16948. WFIFOW(fd,21) = x;
  16949. // Target y
  16950. WFIFOW(fd,23) = y;
  16951. // Target monster ID
  16952. WFIFOW(fd,25) = mob_id;
  16953. WFIFOSET(fd,27);
  16954. #endif
  16955. }
  16956. /// Send hat effects to the client (ZC_HAT_EFFECT).
  16957. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  16958. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  16959. #if PACKETVER >= 20150513
  16960. unsigned char* buf;
  16961. int len,i;
  16962. struct map_session_data *tsd;
  16963. struct block_list* tbl;
  16964. if( target == SELF ){
  16965. tsd = BL_CAST(BL_PC,bl);
  16966. tbl = &sd->bl;
  16967. }else{
  16968. tsd = sd;
  16969. tbl = bl;
  16970. }
  16971. if( !tsd->hatEffectCount )
  16972. return;
  16973. len = 9 + tsd->hatEffectCount * 2;
  16974. buf = (unsigned char*)aMalloc( len );
  16975. WBUFW(buf,0) = 0xa3b;
  16976. WBUFW(buf,2) = len;
  16977. WBUFL(buf,4) = tsd->bl.id;
  16978. WBUFB(buf,8) = 1;
  16979. for( i = 0; i < tsd->hatEffectCount; i++ ){
  16980. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  16981. }
  16982. clif_send(buf, len,tbl,target);
  16983. aFree(buf);
  16984. #endif
  16985. }
  16986. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  16987. #if PACKETVER >= 20150513
  16988. unsigned char buf[13];
  16989. WBUFW(buf,0) = 0xa3b;
  16990. WBUFW(buf,2) = 13;
  16991. WBUFL(buf,4) = sd->bl.id;
  16992. WBUFB(buf,8) = enable;
  16993. WBUFL(buf,9) = effectId;
  16994. clif_send(buf,13,&sd->bl,AREA);
  16995. #endif
  16996. }
  16997. /// Notify the client that a sale has started
  16998. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  16999. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17000. #if PACKETVER_SUPPORTS_SALES
  17001. unsigned char buf[8];
  17002. WBUFW(buf, 0) = 0x9b2;
  17003. WBUFW(buf, 2) = sale_item->nameid;
  17004. WBUFL(buf, 4) = (uint32)(sale_item->end - time(NULL)); // time in S
  17005. clif_send(buf, 8, bl, target);
  17006. #endif
  17007. }
  17008. /// Notify the clien that a sale has ended
  17009. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17010. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17011. #if PACKETVER_SUPPORTS_SALES
  17012. unsigned char buf[4];
  17013. WBUFW(buf, 0) = 0x9b3;
  17014. WBUFW(buf, 2) = sale_item->nameid;
  17015. clif_send(buf, 4, bl, target);
  17016. #endif
  17017. }
  17018. /// Update the remaining amount of a sale item.
  17019. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17020. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17021. #if PACKETVER_SUPPORTS_SALES
  17022. unsigned char buf[8];
  17023. WBUFW(buf, 0) = 0x9c4;
  17024. WBUFW(buf, 2) = sale_item->nameid;
  17025. WBUFL(buf, 4) = sale_item->amount;
  17026. clif_send(buf, 8, bl, target);
  17027. #endif
  17028. }
  17029. /// The client requested a refresh of the current remaining count of a sale item
  17030. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17031. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17032. #if PACKETVER_SUPPORTS_SALES
  17033. struct sale_item_data* sale;
  17034. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17035. return;
  17036. }
  17037. sale = sale_find_item( RFIFOW(fd, 6), true );
  17038. if( sale == NULL ){
  17039. return;
  17040. }
  17041. clif_sale_amount(sale, &sd->bl, SELF);
  17042. #endif
  17043. }
  17044. /// Opens the sale administration window on the client
  17045. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17046. void clif_sale_open( struct map_session_data* sd ){
  17047. #if PACKETVER_SUPPORTS_SALES
  17048. nullpo_retv(sd);
  17049. if( sd->state.sale_open ){
  17050. return;
  17051. }
  17052. sd->state.sale_open = true;
  17053. int fd = sd->fd;
  17054. WFIFOHEAD(fd, 2);
  17055. WFIFOW(fd, 0) = 0x9b5;
  17056. WFIFOSET(fd, 2);
  17057. #endif
  17058. }
  17059. /// Client request to open the sale administration window.
  17060. /// This is sent by /limitedsale
  17061. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17062. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17063. #if PACKETVER_SUPPORTS_SALES
  17064. nullpo_retv(sd);
  17065. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17066. return;
  17067. }
  17068. char command[CHAT_SIZE_MAX];
  17069. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17070. is_atcommand(fd, sd, command, 1);
  17071. #endif
  17072. }
  17073. /// Closes the sale administration window on the client.
  17074. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17075. void clif_sale_close(struct map_session_data* sd) {
  17076. #if PACKETVER_SUPPORTS_SALES
  17077. nullpo_retv(sd);
  17078. if( !sd->state.sale_open ){
  17079. return;
  17080. }
  17081. sd->state.sale_open = false;
  17082. int fd = sd->fd;
  17083. WFIFOHEAD(fd, 2);
  17084. WFIFOW(fd, 0) = 0x9bd;
  17085. WFIFOSET(fd, 2);
  17086. #endif
  17087. }
  17088. /// Client request to close the sale administration window.
  17089. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17090. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17091. #if PACKETVER_SUPPORTS_SALES
  17092. nullpo_retv(sd);
  17093. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17094. return;
  17095. }
  17096. clif_sale_close(sd);
  17097. #endif
  17098. }
  17099. /// Reply to a item search request for item sale administration.
  17100. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17101. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17102. #if PACKETVER_SUPPORTS_SALES
  17103. int fd = sd->fd;
  17104. WFIFOHEAD(fd, 10);
  17105. WFIFOW(fd, 0) = 0x9ad;
  17106. if( item != NULL ){
  17107. WFIFOW(fd, 2) = 0;
  17108. WFIFOW(fd, 4) = item->nameid;
  17109. WFIFOL(fd, 6) = item->price;
  17110. }else{
  17111. WFIFOW(fd, 2) = 1;
  17112. WFIFOW(fd, 4) = 0;
  17113. WFIFOL(fd, 6) = 0;
  17114. }
  17115. WFIFOSET(fd, 10);
  17116. #endif
  17117. }
  17118. /// Search request for an item sale administration.
  17119. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17120. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17121. #if PACKETVER_SUPPORTS_SALES
  17122. char item_name[ITEM_NAME_LENGTH];
  17123. struct item_data *id = NULL;
  17124. nullpo_retv(sd);
  17125. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17126. return;
  17127. }
  17128. if( !sd->state.sale_open ){
  17129. return;
  17130. }
  17131. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17132. id = itemdb_searchname(item_name);
  17133. if( id ){
  17134. int i;
  17135. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17136. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17137. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17138. return;
  17139. }
  17140. }
  17141. }
  17142. // not found
  17143. clif_sale_search_reply( sd, NULL );
  17144. #endif
  17145. }
  17146. /// Reply if an item was successfully put on sale or not.
  17147. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17148. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17149. #if PACKETVER_SUPPORTS_SALES
  17150. int fd = sd->fd;
  17151. WFIFOHEAD(fd, 4);
  17152. WFIFOW(fd, 0) = 0x9af;
  17153. WFIFOW(fd, 2) = (uint16)result;
  17154. WFIFOSET(fd, 4);
  17155. #endif
  17156. }
  17157. /// A client request to put an item on sale.
  17158. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17159. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W
  17160. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17161. #if PACKETVER_SUPPORTS_SALES
  17162. int32 count;
  17163. int16 nameid;
  17164. int startTime;
  17165. int endTime;
  17166. uint16 sellingHours;
  17167. nullpo_retv(sd);
  17168. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17169. return;
  17170. }
  17171. if( !sd->state.sale_open ){
  17172. return;
  17173. }
  17174. nameid = RFIFOW(fd, 6);
  17175. count = RFIFOL(fd, 8);
  17176. startTime = RFIFOL(fd, 12);
  17177. #if PACKETVER >= 20150520
  17178. if( RFIFOW(fd,0) == 0xa3d )
  17179. sellingHours = RFIFOW(fd, 16);
  17180. else
  17181. #endif
  17182. sellingHours = RFIFOB(fd, 16);
  17183. endTime = startTime + sellingHours * 60 * 60;
  17184. clif_sale_add_reply( sd, sale_add_item(nameid,count,startTime,endTime) );
  17185. #endif
  17186. }
  17187. /// Reply to an item removal from sale.
  17188. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17189. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17190. #if PACKETVER_SUPPORTS_SALES
  17191. int fd = sd->fd;
  17192. WFIFOHEAD(fd, 4);
  17193. WFIFOW(fd, 0) = 0x9b1;
  17194. WFIFOW(fd, 2) = failed;
  17195. WFIFOSET(fd, 4);
  17196. #endif
  17197. }
  17198. /// Request to remove an item from sale.
  17199. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17200. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17201. #if PACKETVER_SUPPORTS_SALES
  17202. nullpo_retv(sd);
  17203. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17204. return;
  17205. }
  17206. if( !sd->state.sale_open ){
  17207. return;
  17208. }
  17209. clif_sale_remove_reply(sd, !sale_remove_item(RFIFOW(fd, 6)));
  17210. #endif
  17211. }
  17212. /// Achievement System
  17213. /// Author: Luxuri, Aleos
  17214. /**
  17215. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17216. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17217. */
  17218. void clif_achievement_list_all(struct map_session_data *sd)
  17219. {
  17220. nullpo_retv(sd);
  17221. if (!battle_config.feature_achievement) {
  17222. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17223. return;
  17224. }
  17225. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17226. if (count == 0)
  17227. return;
  17228. int len = (50 * count) + 22;
  17229. int fd = sd->fd;
  17230. int *info = achievement_level(sd, true);
  17231. WFIFOHEAD(fd,len);
  17232. WFIFOW(fd, 0) = 0xa23;
  17233. WFIFOW(fd, 2) = len;
  17234. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17235. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17236. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17237. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17238. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17239. for (int i = 0; i < count; i++) {
  17240. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17241. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17242. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17243. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17244. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17245. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17246. }
  17247. WFIFOSET(fd, len);
  17248. }
  17249. /**
  17250. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17251. * 0a24 <packetType>.W <ACHPoint>.L
  17252. */
  17253. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17254. {
  17255. nullpo_retv(sd);
  17256. if (!battle_config.feature_achievement) {
  17257. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17258. return;
  17259. }
  17260. int fd = sd->fd;
  17261. int *info = achievement_level(sd, true);
  17262. WFIFOHEAD(fd, packet_len(0xa24));
  17263. WFIFOW(fd, 0) = 0xa24;
  17264. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17265. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17266. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17267. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17268. if (ach) {
  17269. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17270. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17271. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17272. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17273. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17274. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17275. } else
  17276. memset(WFIFOP(fd, 16), 0, 40);
  17277. WFIFOSET(fd, packet_len(0xa24));
  17278. }
  17279. /**
  17280. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17281. * 0a25 <packetType>.W <achievementID>.L
  17282. */
  17283. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17284. {
  17285. nullpo_retv(sd);
  17286. if( sd->achievement_data.save )
  17287. intif_achievement_save(sd);
  17288. achievement_check_reward(sd, RFIFOL(fd,2));
  17289. }
  17290. /**
  17291. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17292. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17293. */
  17294. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17295. {
  17296. WFIFOHEAD(fd, packet_len(0xa26));
  17297. WFIFOW(fd, 0) = 0xa26;
  17298. WFIFOB(fd, 2) = result;
  17299. WFIFOL(fd, 3) = achievement_id;
  17300. WFIFOSET(fd, packet_len(0xa26));
  17301. }
  17302. /// Process the pet evolution request
  17303. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17304. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17305. #if PACKETVER >= 20141008
  17306. auto pet = pet_db_search(RFIFOW(fd, 4), PET_EGG);
  17307. if (!pet) {
  17308. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17309. return;
  17310. }
  17311. pet_evolution(sd, pet->class_);
  17312. #endif
  17313. }
  17314. /// Sends the result of the evolution to the client.
  17315. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17316. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17317. #if PACKETVER >= 20141008
  17318. int fd = sd->fd;
  17319. WFIFOHEAD(fd, packet_len(0x9fc));
  17320. WFIFOW(fd, 0) = 0x9fc;
  17321. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17322. WFIFOSET(fd, packet_len(0x9fc));
  17323. #endif
  17324. }
  17325. /*
  17326. * This packet is sent by /changedress or /nocosplay
  17327. *
  17328. * 0ae8
  17329. */
  17330. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17331. #if PACKETVER >= 20180103
  17332. char command[CHAT_SIZE_MAX];
  17333. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17334. is_atcommand( fd, sd, command, 1 );
  17335. #endif
  17336. }
  17337. /// Opens an UI window of the given type and initializes it with the given data
  17338. /// 0AE2 <type>.B <data>.L
  17339. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17340. nullpo_retv(sd);
  17341. int fd = sd->fd;
  17342. WFIFOHEAD(fd,packet_len(0xae2));
  17343. WFIFOW(fd,0) = 0xae2;
  17344. WFIFOB(fd,2) = ui_type;
  17345. WFIFOL(fd,3) = data;
  17346. WFIFOSET(fd,packet_len(0xae2));
  17347. }
  17348. /// Request to open an UI window of the given type
  17349. /// 0A68 <type>.B
  17350. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17351. switch( RFIFOB(fd,2) ){
  17352. case IN_UI_ATTENDANCE:
  17353. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17354. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17355. }else if( pc_attendance_enabled() ){
  17356. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17357. }else{
  17358. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17359. }
  17360. break;
  17361. }
  17362. }
  17363. /// Response for attedance request
  17364. /// 0AF0 <unknown>.L <data>.L
  17365. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17366. nullpo_retv(sd);
  17367. int fd = sd->fd;
  17368. WFIFOHEAD(fd,packet_len(0xAF0));
  17369. WFIFOW(fd,0) = 0xAF0;
  17370. WFIFOL(fd,2) = 0;
  17371. WFIFOL(fd,6) = data;
  17372. WFIFOSET(fd,packet_len(0xAF0));
  17373. }
  17374. /// Request from the client to retrieve today's attendance reward
  17375. /// 0AEF
  17376. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17377. pc_attendance_claim_reward(sd);
  17378. }
  17379. /// Send out the percentage of weight that causes it to be displayed in red.
  17380. /// 0ADE <percentage>.L
  17381. void clif_weight_limit( struct map_session_data* sd ){
  17382. #if PACKETVER >= 20171025
  17383. nullpo_retv(sd);
  17384. int fd = sd->fd;
  17385. WFIFOHEAD(fd, packet_len(0xADE));
  17386. WFIFOW(fd, 0) = 0xADE;
  17387. #ifdef RENEWAL
  17388. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17389. #else
  17390. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17391. #endif
  17392. WFIFOSET(fd, packet_len(0xADE));
  17393. #endif
  17394. }
  17395. enum e_private_airship_response : uint32{
  17396. PRIVATEAIRSHIP_OK,
  17397. PRIVATEAIRSHIP_RETRY,
  17398. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17399. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17400. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17401. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17402. };
  17403. /// Send out the response to a private airship request
  17404. /// 0A4A <response>.L
  17405. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17406. #if PACKETVER >= 20180321
  17407. nullpo_retv( sd );
  17408. int fd = sd->fd;
  17409. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17410. WFIFOW( fd, 0 ) = 0xA4A;
  17411. WFIFOL( fd, 2 ) = response;
  17412. WFIFOSET( fd, packet_len( 0xA4A ) );
  17413. #endif
  17414. }
  17415. /// Parses a request for a private airship
  17416. /// 0A49 <mapname>.16B <itemid>.W
  17417. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17418. #if PACKETVER >= 20180321
  17419. // Check if the feature is enabled
  17420. if( !battle_config.feature_privateairship ){
  17421. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17422. return;
  17423. }
  17424. // Check if the player is allowed to warp from the source map
  17425. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17426. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17427. return;
  17428. }
  17429. char mapname[MAP_NAME_LENGTH_EXT];
  17430. safestrncpy( mapname, RFIFOCP( fd, 2 ), MAP_NAME_LENGTH_EXT );
  17431. int16 mapindex = mapindex_name2id( mapname );
  17432. // Check if we know the mapname
  17433. if( mapindex < 0 ){
  17434. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17435. return;
  17436. }
  17437. int16 mapid = map_mapindex2mapid( mapindex );
  17438. // Check if the map is available on this server
  17439. if( mapid < 0 ){
  17440. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17441. return;
  17442. }
  17443. // Check if the player tried to warp to the map he is on
  17444. if( sd->bl.m == mapid ){
  17445. // This is blocked by the client, but just to be sure
  17446. return;
  17447. }
  17448. // This can only be a hack, so we prevent it
  17449. if( map_getmapdata( mapid )->instance_id ){
  17450. // Ignore requests to warp directly into a running instance
  17451. return;
  17452. }
  17453. // Check if the player is allowed to warp to the target map
  17454. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17455. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17456. return;
  17457. }
  17458. uint16 item_id = RFIFOW( fd, 2 + MAP_NAME_LENGTH_EXT );
  17459. // Check if the item sent by the client is known to us
  17460. if( !itemdb_group_item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17461. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17462. return;
  17463. }
  17464. int idx = pc_search_inventory( sd, item_id );
  17465. // Check if the player has the item at all
  17466. if( idx < 0 ){
  17467. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17468. return;
  17469. }
  17470. // Delete the chosen item
  17471. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17472. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17473. return;
  17474. }
  17475. // Warp the player to a random spot on the destination map
  17476. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17477. #endif
  17478. }
  17479. /// Sends out the usage history of the guild storage
  17480. /// 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
  17481. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17482. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17483. #if PACKETVER >= 20140205
  17484. nullpo_retv( sd );
  17485. int fd = sd->fd;
  17486. int size = 8;
  17487. int sub = 83;
  17488. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17489. size += log.size() * sub;
  17490. }else{
  17491. log.clear();
  17492. }
  17493. WFIFOHEAD(fd, size);
  17494. WFIFOW(fd, 0) = 0x9DA;
  17495. WFIFOW(fd, 2) = size;
  17496. WFIFOW(fd, 4) = result;
  17497. WFIFOW(fd, 6) = (uint16)log.size();
  17498. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17499. for (int offset = 8, i = 0; i < log.size(); i++, offset += sub) {
  17500. struct guild_log_entry& entry = log[i];
  17501. uint16 viewid = itemdb_viewid( entry.item.nameid );
  17502. WFIFOL(fd, offset) = entry.id;
  17503. WFIFOW(fd, offset + 4) = viewid > 0 ? viewid : entry.item.nameid;
  17504. WFIFOL(fd, offset + 6) = (uint16)(entry.amount > 0 ? entry.amount : (entry.amount * -1));
  17505. WFIFOB(fd, offset + 10) = entry.amount > 0; // action = true(put), false(get)
  17506. WFIFOL(fd, offset + 11) = entry.item.refine;
  17507. WFIFOQ(fd, offset + 15) = entry.item.unique_id;
  17508. WFIFOB(fd, offset + 23) = entry.item.identify;
  17509. WFIFOW(fd, offset + 24) = itemtype(entry.item.nameid);
  17510. clif_addcards(WFIFOP(fd, offset + 26), &entry.item);
  17511. safestrncpy(WFIFOCP(fd, offset + 34), entry.name, NAME_LENGTH);
  17512. safestrncpy(WFIFOCP(fd, offset + 34 + NAME_LENGTH), entry.time, NAME_LENGTH);
  17513. WFIFOB(fd, offset + 34 + 2 * NAME_LENGTH) = entry.item.attribute;
  17514. }
  17515. }
  17516. WFIFOSET(fd, size);
  17517. #endif
  17518. }
  17519. /// Activates the client camera info or updates the client camera with the given values.
  17520. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  17521. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  17522. #if PACKETVER >= 20160525
  17523. int fd = sd->fd;
  17524. WFIFOHEAD(fd, packet_len(0xa78));
  17525. WFIFOW(fd, 0) = 0xa78;
  17526. WFIFOB(fd, 2) = show;
  17527. WFIFOF(fd, 3) = range;
  17528. WFIFOF(fd, 7) = rotation;
  17529. WFIFOF(fd, 11) = latitude;
  17530. WFIFOSET(fd, packet_len(0xa78));
  17531. #endif
  17532. }
  17533. /// Activates or deactives the client camera info or updates the camera settings.
  17534. /// This packet is triggered by /viewpointvalue or /setcamera
  17535. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  17536. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  17537. char command[CHAT_SIZE_MAX];
  17538. // /viewpointvalue
  17539. if( RFIFOB( fd, 2 ) == 1 ){
  17540. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  17541. // /setcamera
  17542. }else{
  17543. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  17544. }
  17545. is_atcommand( fd, sd, command, 1 );
  17546. }
  17547. /// Send the full list of items in the equip switch window
  17548. /// 0a9b <length>.W { <index>.W <position>.L }*
  17549. void clif_equipswitch_list( struct map_session_data* sd ){
  17550. #if PACKETVER >= 20170208
  17551. int fd = sd->fd;
  17552. int offset, i, position;
  17553. WFIFOW(fd, 0) = 0xa9b;
  17554. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  17555. short index = sd->equip_switch_index[i];
  17556. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  17557. WFIFOW(fd, offset) = index + 2;
  17558. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  17559. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  17560. offset += 6;
  17561. }
  17562. }
  17563. WFIFOW(fd, 2) = offset;
  17564. WFIFOSET(fd, offset);
  17565. #endif
  17566. }
  17567. /// Acknowledgement for removing an equip to the equip switch window
  17568. /// 0a9a <index>.W <position.>.L <failure>.W
  17569. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17570. #if PACKETVER >= 20170208
  17571. int fd = sd->fd;
  17572. WFIFOHEAD(fd, packet_len(0xa9a));
  17573. WFIFOW(fd, 0) = 0xa9a;
  17574. WFIFOW(fd, 2) = index + 2;
  17575. WFIFOL(fd, 4) = pos;
  17576. WFIFOW(fd, 8) = failed;
  17577. WFIFOSET(fd, packet_len(0xa9a));
  17578. #endif
  17579. }
  17580. /// Request to remove an equip from the equip switch window
  17581. /// 0a99 <index>.W <position>.L <= 20170502
  17582. /// 0a99 <index>.W
  17583. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  17584. #if PACKETVER >= 20170208
  17585. uint16 index = RFIFOW(fd, 2) - 2;
  17586. bool removed = false;
  17587. if( !battle_config.feature_equipswitch ){
  17588. return;
  17589. }
  17590. // Check if the index is valid
  17591. if( index >= MAX_INVENTORY ){
  17592. return;
  17593. }
  17594. pc_equipswitch_remove( sd, index );
  17595. #endif
  17596. }
  17597. /// Acknowledgement for adding an equip to the equip switch window
  17598. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  17599. /// 0a98 <index>.W <position.>.L <flag>.W
  17600. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  17601. #if PACKETVER >= 20170208
  17602. int fd = sd->fd;
  17603. WFIFOHEAD(fd, packet_len(0xa98));
  17604. WFIFOW(fd, 0) = 0xa98;
  17605. WFIFOW(fd, 2) = index + 2;
  17606. WFIFOL(fd, 4) = pos;
  17607. #if PACKETVER <= 20170502
  17608. WFIFOL(fd, 8) = flag;
  17609. #else
  17610. WFIFOW(fd, 8) = flag;
  17611. #endif
  17612. WFIFOSET(fd,packet_len(0xa98));
  17613. #endif
  17614. }
  17615. /// Request to add an equip to the equip switch window
  17616. /// 0a97 <index>.W <position>.L
  17617. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  17618. #if PACKETVER >= 20170208
  17619. uint16 index = RFIFOW(fd, 2) - 2;
  17620. uint32 position = RFIFOL(fd, 4);
  17621. if( !battle_config.feature_equipswitch ){
  17622. return;
  17623. }
  17624. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  17625. return;
  17626. }
  17627. if( sd->state.trading || sd->npc_shopid ){
  17628. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  17629. return;
  17630. }
  17631. if( sd->inventory_data[index]->type == IT_AMMO ){
  17632. position = EQP_AMMO;
  17633. }
  17634. pc_equipitem( sd, index, position, true );
  17635. #endif
  17636. }
  17637. /// Acknowledgement packet for the full equip switch
  17638. /// 0a9d <failed>.W
  17639. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  17640. #if PACKETVER >= 20170208
  17641. int fd = sd->fd;
  17642. WFIFOHEAD(fd, packet_len(0xa9d));
  17643. WFIFOW(fd, 0) = 0xa9d;
  17644. WFIFOW(fd, 2) = failed;
  17645. WFIFOSET(fd, packet_len(0xa9d));
  17646. #endif
  17647. }
  17648. /// Request to do a full equip switch
  17649. /// 0a9c
  17650. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  17651. #if PACKETVER >= 20170208
  17652. int i;
  17653. t_tick tick = gettick();
  17654. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  17655. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  17656. // Client will not let you send a request
  17657. return;
  17658. }
  17659. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  17660. if( !battle_config.feature_equipswitch ){
  17661. return;
  17662. }
  17663. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  17664. if( i == EQI_MAX ){
  17665. // client will show: "There is no item to replace." and should not even come here
  17666. clif_equipswitch_reply( sd, false );
  17667. return;
  17668. }
  17669. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  17670. return;
  17671. }
  17672. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  17673. #endif
  17674. }
  17675. /// Request to do a single equip switch
  17676. /// 0ace <index>.W
  17677. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  17678. #if PACKETVER >= 20170502
  17679. uint16 index = RFIFOW(fd, 2) - 2;
  17680. if( !battle_config.feature_equipswitch ){
  17681. return;
  17682. }
  17683. // Check if the index is valid
  17684. if( index >= MAX_INVENTORY ){
  17685. return;
  17686. }
  17687. // Check if the item exists
  17688. if (sd->inventory_data[index] == nullptr)
  17689. return;
  17690. // Check if the item was already added to equip switch
  17691. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  17692. if( sd->npc_id ){
  17693. #ifdef RENEWAL
  17694. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  17695. clif_msg( sd, WORK_IN_PROGRESS );
  17696. return;
  17697. }
  17698. #endif
  17699. if( !sd->npc_item_flag ){
  17700. return;
  17701. }
  17702. }
  17703. pc_equipswitch( sd, index );
  17704. return;
  17705. }
  17706. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  17707. #endif
  17708. }
  17709. /*==========================================
  17710. * Main client packet processing function
  17711. *------------------------------------------*/
  17712. static int clif_parse(int fd)
  17713. {
  17714. int cmd, packet_len;
  17715. TBL_PC* sd;
  17716. int pnum;
  17717. #ifdef PACKET_OBFUSCATION
  17718. int cmd2;
  17719. #endif
  17720. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17721. // Note: "click masters" can do 80+ clicks in 10 seconds
  17722. 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]
  17723. { // begin main client packet processing loop
  17724. sd = (TBL_PC *)session[fd]->session_data;
  17725. if (session[fd]->flag.eof) {
  17726. if (sd) {
  17727. if (sd->state.autotrade) {
  17728. //Disassociate character from the socket connection.
  17729. session[fd]->session_data = NULL;
  17730. sd->fd = 0;
  17731. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17732. } else
  17733. if (sd->state.active) {
  17734. // Player logout display [Valaris]
  17735. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17736. clif_quitsave(fd, sd);
  17737. } else {
  17738. //Unusual logout (during log on/off/map-changer procedure)
  17739. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17740. map_quit(sd);
  17741. }
  17742. } else {
  17743. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17744. }
  17745. do_close(fd);
  17746. return 0;
  17747. }
  17748. if (RFIFOREST(fd) < 2)
  17749. return 0;
  17750. cmd = RFIFOW(fd, 0);
  17751. #ifdef PACKET_OBFUSCATION
  17752. // Check if it is a player that tries to connect to the map server.
  17753. if( sd ){
  17754. // Decrypt the current packet ID with the last key stored in the session.
  17755. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17756. }else{
  17757. // Store the original value for checking
  17758. cmd2 = cmd;
  17759. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17760. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17761. }
  17762. #endif
  17763. // filter out invalid / unsupported packets
  17764. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17765. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17766. #ifdef DUMP_INVALID_PACKET
  17767. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17768. #endif
  17769. #ifdef PACKET_OBFUSCATION_WARN
  17770. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17771. if( !sd ){
  17772. #ifdef PACKET_OBFUSCATION
  17773. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17774. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17775. }
  17776. #else
  17777. // Try to use the initial keys for the decryption of the packet ID.
  17778. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17779. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17780. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17781. }
  17782. #endif
  17783. }
  17784. #endif
  17785. set_eof(fd);
  17786. return 0;
  17787. }
  17788. // determine real packet length
  17789. packet_len = packet_db[cmd].len;
  17790. if (packet_len == -1) { // variable-length packet
  17791. if (RFIFOREST(fd) < 4)
  17792. return 0;
  17793. packet_len = RFIFOW(fd,2);
  17794. if (packet_len < 4 || packet_len > 32768) {
  17795. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17796. #ifdef DUMP_INVALID_PACKET
  17797. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17798. #endif
  17799. set_eof(fd);
  17800. return 0;
  17801. }
  17802. }
  17803. if ((int)RFIFOREST(fd) < packet_len)
  17804. return 0; // not enough data received to form the packet
  17805. #ifdef PACKET_OBFUSCATION
  17806. RFIFOW(fd, 0) = cmd;
  17807. if (sd)
  17808. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17809. #endif
  17810. if( packet_db[cmd].func == clif_parse_debug )
  17811. packet_db[cmd].func(fd, sd);
  17812. else if( packet_db[cmd].func != NULL ) {
  17813. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17814. ; //Only valid packet when there is no session
  17815. else
  17816. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17817. ; //Only valid packet when player is not on a map
  17818. else
  17819. packet_db[cmd].func(fd, sd);
  17820. }
  17821. #ifdef DUMP_UNKNOWN_PACKET
  17822. else DumpUnknown(fd,sd,cmd,packet_len);
  17823. #endif
  17824. RFIFOSKIP(fd, packet_len);
  17825. }; // main loop end
  17826. return 0;
  17827. }
  17828. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17829. va_list argp;
  17830. int i;
  17831. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17832. return;
  17833. packet_db[cmd].len = length;
  17834. packet_db[cmd].func = func;
  17835. va_start(argp, func);
  17836. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17837. int offset = va_arg(argp, int);
  17838. if( offset == 0 ){
  17839. break;
  17840. }
  17841. packet_db[cmd].pos[i] = offset;
  17842. }
  17843. if( i == MAX_PACKET_POS ){
  17844. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17845. }
  17846. va_end(argp);
  17847. }
  17848. /*==========================================
  17849. * Reads packets and setups its array reference
  17850. *------------------------------------------*/
  17851. void packetdb_readdb(){
  17852. memset(packet_db,0,sizeof(packet_db));
  17853. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17854. #include "clif_packetdb.hpp"
  17855. #include "clif_shuffle.hpp"
  17856. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17857. #ifdef PACKET_OBFUSCATION
  17858. 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]);
  17859. #else
  17860. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17861. #endif
  17862. }
  17863. /*==========================================
  17864. *
  17865. *------------------------------------------*/
  17866. void do_init_clif(void) {
  17867. const char* colors[COLOR_MAX] = {
  17868. "0x00FF00",
  17869. "0xFF0000",
  17870. "0xFFFFFF",
  17871. "0xFFFF00",
  17872. "0x00FFFF",
  17873. "0xB5FFB5",
  17874. };
  17875. int i;
  17876. /**
  17877. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17878. **/
  17879. for(i = 0; i < COLOR_MAX; i++) {
  17880. color_table[i] = strtoul(colors[i],NULL,0);
  17881. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17882. }
  17883. packetdb_readdb();
  17884. set_defaultparse(clif_parse);
  17885. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  17886. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  17887. exit(EXIT_FAILURE);
  17888. }
  17889. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  17890. add_timer_func_list(clif_delayquit, "clif_delayquit");
  17891. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  17892. }
  17893. void do_final_clif(void) {
  17894. ers_destroy(delay_clearunit_ers);
  17895. }