clif.cpp 585 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772
  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. /* for clif_clearunit_delayed */
  56. static struct eri *delay_clearunit_ers;
  57. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  58. int packet_db_ack[MAX_ACK_FUNC + 1];
  59. unsigned long color_table[COLOR_MAX];
  60. #include "clif_obfuscation.hpp"
  61. static bool clif_session_isValid(struct map_session_data *sd);
  62. #if PACKETVER >= 20150513
  63. enum mail_type {
  64. MAIL_TYPE_TEXT = 0x0,
  65. MAIL_TYPE_ZENY = 0x2,
  66. MAIL_TYPE_ITEM = 0x4,
  67. MAIL_TYPE_NPC = 0x8
  68. };
  69. #endif
  70. /** Converts item type to display it on client if necessary.
  71. * @param nameid: Item ID
  72. * @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
  73. */
  74. static inline int itemtype(unsigned short nameid) {
  75. 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
  76. int type = id->type;
  77. if( type == IT_SHADOWGEAR ) {
  78. if( id->equip&EQP_SHADOW_WEAPON )
  79. return IT_WEAPON;
  80. else
  81. return IT_ARMOR;
  82. }
  83. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  84. }
  85. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  86. p += pos;
  87. p[0] = (uint8)(x>>2);
  88. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  89. p[2] = (uint8)((y<<4) | (dir&0xf));
  90. }
  91. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  92. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  93. p += pos;
  94. p[0] = (uint8)(x0>>2);
  95. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  96. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  97. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  98. p[4] = (uint8)y1;
  99. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  100. }
  101. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  102. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  103. }
  104. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  105. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  106. }
  107. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  108. p += pos;
  109. if( x ) {
  110. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  111. }
  112. if( y ) {
  113. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  114. }
  115. if( dir ) {
  116. dir[0] = ( p[2] & 0x0f );
  117. }
  118. }
  119. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  120. p += pos;
  121. if( x0 ) {
  122. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  123. }
  124. if( y0 ) {
  125. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  126. }
  127. if( x1 ) {
  128. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  129. }
  130. if( y1 ) {
  131. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  132. }
  133. if( sx0 ) {
  134. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  135. }
  136. if( sy0 ) {
  137. sy0[0] = ( p[5] & 0x0f ) >> 0;
  138. }
  139. }
  140. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  141. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  142. }
  143. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  144. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  145. }
  146. //To idenfity disguised characters.
  147. static inline bool disguised(struct block_list* bl) {
  148. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  149. }
  150. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  151. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  152. if( len > max )
  153. len = max;
  154. mes[len-1] = '\0';
  155. return len;
  156. }
  157. static char map_ip_str[128];
  158. static uint32 map_ip;
  159. static uint32 bind_ip = INADDR_ANY;
  160. static uint16 map_port = 5121;
  161. static bool clif_ally_only = false;
  162. int map_fd;
  163. static int clif_parse (int fd);
  164. /*==========================================
  165. * Ip setting of map-server
  166. *------------------------------------------*/
  167. int clif_setip(const char* ip) {
  168. char ip_str[16];
  169. map_ip = host2ip(ip);
  170. if (!map_ip) {
  171. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  172. return 0;
  173. }
  174. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  175. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  176. return 1;
  177. }
  178. void clif_setbindip(const char* ip)
  179. {
  180. bind_ip = host2ip(ip);
  181. if (bind_ip) {
  182. char ip_str[16];
  183. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  184. } else {
  185. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  186. }
  187. }
  188. /*==========================================
  189. * Sets map port to 'port'
  190. * is run from map.c upon loading map server configuration
  191. *------------------------------------------*/
  192. void clif_setport(uint16 port)
  193. {
  194. map_port = port;
  195. }
  196. /*==========================================
  197. * Returns map server IP
  198. *------------------------------------------*/
  199. uint32 clif_getip(void)
  200. {
  201. return map_ip;
  202. }
  203. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  204. uint32 clif_refresh_ip(void)
  205. {
  206. uint32 new_ip;
  207. new_ip = host2ip(map_ip_str);
  208. if (new_ip && new_ip != map_ip) {
  209. map_ip = new_ip;
  210. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  211. return map_ip;
  212. }
  213. return 0;
  214. }
  215. /*==========================================
  216. * Returns map port which is set by clif_setport()
  217. *------------------------------------------*/
  218. uint16 clif_getport(void)
  219. {
  220. return map_port;
  221. }
  222. #if PACKETVER >= 20071106
  223. static inline unsigned char clif_bl_type(struct block_list *bl) {
  224. switch (bl->type) {
  225. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  226. case BL_ITEM: return 0x2; //ITEM_TYPE
  227. case BL_SKILL: return 0x3; //SKILL_TYPE
  228. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  229. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  230. case BL_NPC: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
  231. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  232. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  233. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  234. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  235. default: return 0x1; //NPC_TYPE
  236. }
  237. }
  238. #endif
  239. static bool clif_session_isValid(struct map_session_data *sd) {
  240. return ( sd != NULL && session_isActive(sd->fd) );
  241. }
  242. /*==========================================
  243. * sub process of clif_send
  244. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  245. * In order to send area-wise packets, such as:
  246. * - AREA : everyone nearby your area
  247. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  248. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  249. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  250. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  251. *------------------------------------------*/
  252. static int clif_send_sub(struct block_list *bl, va_list ap)
  253. {
  254. struct block_list *src_bl;
  255. struct map_session_data *sd;
  256. unsigned char *buf;
  257. int len, type, fd;
  258. nullpo_ret(bl);
  259. nullpo_ret(sd = (struct map_session_data *)bl);
  260. fd = sd->fd;
  261. if (!fd) //Don't send to disconnected clients.
  262. return 0;
  263. buf = va_arg(ap,unsigned char*);
  264. len = va_arg(ap,int);
  265. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  266. type = va_arg(ap,int);
  267. switch(type) {
  268. case AREA_WOS:
  269. if (bl == src_bl)
  270. return 0;
  271. break;
  272. case AREA_WOC:
  273. if (sd->chatID || bl == src_bl)
  274. return 0;
  275. break;
  276. case AREA_WOSC:
  277. {
  278. if(src_bl->type == BL_PC) {
  279. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  280. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  281. return 0;
  282. }
  283. else if(src_bl->type == BL_NPC) {
  284. struct npc_data *nd = (struct npc_data *)src_bl;
  285. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  286. return 0;
  287. }
  288. }
  289. break;
  290. }
  291. if (session[fd] == NULL)
  292. return 0;
  293. /* unless visible, hold it here */
  294. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  295. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  296. return 0;
  297. WFIFOHEAD(fd, len);
  298. if (WFIFOP(fd,0) == buf) {
  299. ShowError("WARNING: Invalid use of clif_send function\n");
  300. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  301. ShowError(" Please correct your code.\n");
  302. // don't send to not move the pointer of the packet for next sessions in the loop
  303. //WFIFOSET(fd,0);//## TODO is this ok?
  304. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  305. return 0;
  306. }
  307. memcpy(WFIFOP(fd,0), buf, len);
  308. WFIFOSET(fd,len);
  309. return 0;
  310. }
  311. /*==========================================
  312. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  313. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  314. *------------------------------------------*/
  315. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  316. {
  317. int i;
  318. struct map_session_data *sd, *tsd;
  319. struct party_data *p = NULL;
  320. struct guild *g = NULL;
  321. struct battleground_data *bg = NULL;
  322. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  323. struct s_mapiterator* iter;
  324. if( type != ALL_CLIENT )
  325. nullpo_ret(bl);
  326. sd = BL_CAST(BL_PC, bl);
  327. switch(type) {
  328. case ALL_CLIENT: //All player clients.
  329. iter = mapit_getallusers();
  330. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ){
  331. WFIFOHEAD(tsd->fd, len);
  332. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  333. WFIFOSET(tsd->fd, len);
  334. }
  335. mapit_free(iter);
  336. break;
  337. case ALL_SAMEMAP: //All players on the same map
  338. iter = mapit_getallusers();
  339. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  340. {
  341. if( bl->m == tsd->bl.m ){
  342. WFIFOHEAD(tsd->fd, len);
  343. memcpy(WFIFOP(tsd->fd,0), buf, len);
  344. WFIFOSET(tsd->fd,len);
  345. }
  346. }
  347. mapit_free(iter);
  348. break;
  349. case AREA:
  350. case AREA_WOSC:
  351. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  352. clif_send (buf, len, bl, SELF);
  353. case AREA_WOC:
  354. case AREA_WOS:
  355. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  356. BL_PC, buf, len, bl, type);
  357. break;
  358. case AREA_CHAT_WOC:
  359. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  360. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  361. break;
  362. case CHAT:
  363. case CHAT_WOS:
  364. {
  365. struct chat_data *cd;
  366. if (sd) {
  367. cd = (struct chat_data*)map_id2bl(sd->chatID);
  368. } else if (bl->type == BL_CHAT) {
  369. cd = (struct chat_data*)bl;
  370. } else break;
  371. if (cd == NULL)
  372. break;
  373. for(i = 0; i < cd->users; i++) {
  374. if (type == CHAT_WOS && cd->usersd[i] == sd)
  375. continue;
  376. if ((fd=cd->usersd[i]->fd) >0 && session[fd]){ // Added check to see if session exists [PoW]
  377. WFIFOHEAD(fd,len);
  378. memcpy(WFIFOP(fd,0), buf, len);
  379. WFIFOSET(fd,len);
  380. }
  381. }
  382. }
  383. break;
  384. case PARTY_AREA:
  385. case PARTY_AREA_WOS:
  386. x0 = bl->x - AREA_SIZE;
  387. y0 = bl->y - AREA_SIZE;
  388. x1 = bl->x + AREA_SIZE;
  389. y1 = bl->y + AREA_SIZE;
  390. case PARTY:
  391. case PARTY_WOS:
  392. case PARTY_SAMEMAP:
  393. case PARTY_SAMEMAP_WOS:
  394. if (sd && sd->status.party_id)
  395. p = party_search(sd->status.party_id);
  396. if (p) {
  397. for(i=0;i<MAX_PARTY;i++){
  398. if( (sd = p->data[i].sd) == NULL )
  399. continue;
  400. if( !(fd=sd->fd) )
  401. continue;
  402. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  403. continue;
  404. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  405. continue;
  406. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  407. continue;
  408. WFIFOHEAD(fd, len);
  409. memcpy(WFIFOP(fd, 0), buf, len);
  410. WFIFOSET(fd, len);
  411. }
  412. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  413. break;
  414. iter = mapit_getallusers();
  415. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  416. {
  417. if( tsd->partyspy == p->party.party_id ){
  418. WFIFOHEAD(tsd->fd, len);
  419. memcpy(WFIFOP(tsd->fd,0), buf, len);
  420. WFIFOSET(tsd->fd,len);
  421. }
  422. }
  423. mapit_free(iter);
  424. }
  425. break;
  426. case DUEL:
  427. case DUEL_WOS:
  428. if (!sd || !sd->duel_group) break; //Invalid usage.
  429. iter = mapit_getallusers();
  430. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  431. {
  432. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  433. continue;
  434. if( sd->duel_group == tsd->duel_group ){
  435. WFIFOHEAD(tsd->fd, len);
  436. memcpy(WFIFOP(tsd->fd,0), buf, len);
  437. WFIFOSET(tsd->fd,len);
  438. }
  439. }
  440. mapit_free(iter);
  441. break;
  442. case SELF:
  443. if (sd && (fd=sd->fd)) {
  444. WFIFOHEAD(fd,len);
  445. memcpy(WFIFOP(fd,0), buf, len);
  446. WFIFOSET(fd,len);
  447. }
  448. break;
  449. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  450. case GUILD_AREA:
  451. case GUILD_AREA_WOS:
  452. x0 = bl->x - AREA_SIZE;
  453. y0 = bl->y - AREA_SIZE;
  454. x1 = bl->x + AREA_SIZE;
  455. y1 = bl->y + AREA_SIZE;
  456. case GUILD_SAMEMAP:
  457. case GUILD_SAMEMAP_WOS:
  458. case GUILD:
  459. case GUILD_WOS:
  460. case GUILD_NOBG:
  461. if (sd && sd->status.guild_id)
  462. g = sd->guild;
  463. if (g) {
  464. for(i = 0; i < g->max_member; i++) {
  465. if( (sd = g->member[i].sd) != NULL )
  466. {
  467. if( !(fd=sd->fd) )
  468. continue;
  469. if( type == GUILD_NOBG && sd->bg_id )
  470. continue;
  471. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  472. continue;
  473. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  474. continue;
  475. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  476. continue;
  477. WFIFOHEAD(fd,len);
  478. memcpy(WFIFOP(fd,0), buf, len);
  479. WFIFOSET(fd,len);
  480. }
  481. }
  482. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  483. break;
  484. iter = mapit_getallusers();
  485. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  486. {
  487. if( tsd->guildspy == g->guild_id ){
  488. WFIFOHEAD(tsd->fd, len);
  489. memcpy(WFIFOP(tsd->fd,0), buf, len);
  490. WFIFOSET(tsd->fd,len);
  491. }
  492. }
  493. mapit_free(iter);
  494. }
  495. break;
  496. case BG_AREA:
  497. case BG_AREA_WOS:
  498. x0 = bl->x - AREA_SIZE;
  499. y0 = bl->y - AREA_SIZE;
  500. x1 = bl->x + AREA_SIZE;
  501. y1 = bl->y + AREA_SIZE;
  502. case BG_SAMEMAP:
  503. case BG_SAMEMAP_WOS:
  504. case BG:
  505. case BG_WOS:
  506. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  507. {
  508. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  509. {
  510. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  511. continue;
  512. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  513. continue;
  514. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  515. continue;
  516. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  517. continue;
  518. WFIFOHEAD(fd,len);
  519. memcpy(WFIFOP(fd,0), buf, len);
  520. WFIFOSET(fd,len);
  521. }
  522. }
  523. break;
  524. case CLAN:
  525. if( sd && sd->clan ){
  526. struct clan* clan = sd->clan;
  527. for( i = 0; i < clan->max_member; i++ ){
  528. if( ( sd = clan->members[i] ) == NULL || !(fd = sd->fd) ){
  529. continue;
  530. }
  531. WFIFOHEAD(fd,len);
  532. memcpy(WFIFOP(fd,0), buf, len);
  533. WFIFOSET(fd,len);
  534. }
  535. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  536. break;
  537. iter = mapit_getallusers();
  538. while ((tsd = (TBL_PC*)mapit_next(iter)) != NULL){
  539. if (tsd->clanspy == clan->id){
  540. WFIFOHEAD(tsd->fd, len);
  541. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  542. WFIFOSET(tsd->fd, len);
  543. }
  544. }
  545. mapit_free(iter);
  546. }
  547. break;
  548. default:
  549. ShowError("clif_send: Unrecognized type %d\n",type);
  550. return -1;
  551. }
  552. return 0;
  553. }
  554. /// Notifies the client, that it's connection attempt was accepted.
  555. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  556. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  557. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  558. void clif_authok(struct map_session_data *sd)
  559. {
  560. #if PACKETVER < 20080102
  561. const int cmd = 0x73;
  562. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  563. const int cmd = 0x2eb;
  564. #else
  565. const int cmd = 0xa18;
  566. #endif
  567. int fd = sd->fd;
  568. WFIFOHEAD(fd,packet_len(cmd));
  569. WFIFOW(fd, 0) = cmd;
  570. WFIFOL(fd, 2) = gettick();
  571. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  572. WFIFOB(fd, 9) = 5; // ignored
  573. WFIFOB(fd,10) = 5; // ignored
  574. #if PACKETVER >= 20080102
  575. WFIFOW(fd,11) = sd->status.font;
  576. #endif
  577. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  578. WFIFOB(fd,13) = sd->status.sex;
  579. #endif
  580. WFIFOSET(fd,packet_len(cmd));
  581. }
  582. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  583. /// 0074 <error code>.B
  584. /// error code:
  585. /// 0 = client type mismatch
  586. /// 1 = ID mismatch
  587. /// 2 = mobile - out of available time
  588. /// 3 = mobile - already logged in
  589. /// 4 = mobile - waiting state
  590. void clif_authrefuse(int fd, uint8 error_code)
  591. {
  592. WFIFOHEAD(fd,packet_len(0x74));
  593. WFIFOW(fd,0) = 0x74;
  594. WFIFOB(fd,2) = error_code;
  595. WFIFOSET(fd,packet_len(0x74));
  596. }
  597. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  598. /// 0081 <error code>.B
  599. /// error code:
  600. /// 0 = BAN_UNFAIR
  601. /// 1 = server closed -> MsgStringTable[4]
  602. /// 2 = ID already logged in -> MsgStringTable[5]
  603. /// 3 = timeout/too much lag -> MsgStringTable[241]
  604. /// 4 = server full -> MsgStringTable[264]
  605. /// 5 = underaged -> MsgStringTable[305]
  606. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  607. /// 9 = too many connections from this ip -> MsgStringTable[529]
  608. /// 10 = out of available time paid for -> MsgStringTable[530]
  609. /// 11 = BAN_PAY_SUSPEND
  610. /// 12 = BAN_PAY_CHANGE
  611. /// 13 = BAN_PAY_WRONGIP
  612. /// 14 = BAN_PAY_PNGAMEROOM
  613. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  614. /// 16 = BAN_JAPAN_REFUSE1
  615. /// 17 = BAN_JAPAN_REFUSE2
  616. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  617. /// 100 = BAN_PC_IP_UNFAIR
  618. /// 101 = BAN_PC_IP_COUNT_ALL
  619. /// 102 = BAN_PC_IP_COUNT
  620. /// 103 = BAN_GRAVITY_MEM_AGREE
  621. /// 104 = BAN_GAME_MEM_AGREE
  622. /// 105 = BAN_HAN_VALID
  623. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  624. /// 107 = BAN_OVER_CHARACTER_LIST
  625. /// 108 = BAN_IP_BLOCK
  626. /// 109 = BAN_INVALID_PWD_CNT
  627. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  628. /// ? = disconnected -> MsgStringTable[3]
  629. void clif_authfail_fd(int fd, int type)
  630. {
  631. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  632. return;
  633. WFIFOHEAD(fd, packet_len(0x81));
  634. WFIFOW(fd,0) = 0x81;
  635. WFIFOB(fd,2) = type;
  636. WFIFOSET(fd,packet_len(0x81));
  637. set_eof(fd);
  638. }
  639. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  640. /// 00b3 <type>.B
  641. /// type:
  642. /// 1 = disconnect, char-select
  643. /// ? = nothing
  644. void clif_charselectok(int id, uint8 ok)
  645. {
  646. struct map_session_data* sd;
  647. int fd;
  648. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  649. return;
  650. fd = sd->fd;
  651. WFIFOHEAD(fd,packet_len(0xb3));
  652. WFIFOW(fd,0) = 0xb3;
  653. WFIFOB(fd,2) = ok;
  654. WFIFOSET(fd,packet_len(0xb3));
  655. }
  656. /// Makes an item appear on the ground.
  657. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  658. /// 084b <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  659. void clif_dropflooritem(struct flooritem_data* fitem)
  660. {
  661. #if PACKETVER >= 20130000
  662. uint8 buf[19];
  663. uint32 header=0x84b;
  664. #else
  665. uint8 buf[17];
  666. uint32 header=0x09e;
  667. #endif
  668. int view, offset=0;
  669. nullpo_retv(fitem);
  670. if (fitem->item.nameid == 0)
  671. return;
  672. WBUFW(buf, offset+0) = header;
  673. WBUFL(buf, offset+2) = fitem->bl.id;
  674. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item.nameid)) > 0) ? view : fitem->item.nameid;
  675. #if PACKETVER >= 20130000
  676. WBUFW(buf, offset+8) = itemtype(fitem->item.nameid);
  677. offset +=2;
  678. #endif
  679. WBUFB(buf, offset+8) = fitem->item.identify;
  680. WBUFW(buf, offset+9) = fitem->bl.x;
  681. WBUFW(buf, offset+11) = fitem->bl.y;
  682. WBUFB(buf, offset+13) = fitem->subx;
  683. WBUFB(buf, offset+14) = fitem->suby;
  684. WBUFW(buf, offset+15) = fitem->item.amount;
  685. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  686. }
  687. /// Makes an item disappear from the ground.
  688. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  689. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  690. {
  691. unsigned char buf[16];
  692. nullpo_retv(fitem);
  693. WBUFW(buf,0) = 0xa1;
  694. WBUFL(buf,2) = fitem->bl.id;
  695. if (fd == 0) {
  696. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  697. } else {
  698. WFIFOHEAD(fd,packet_len(0xa1));
  699. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  700. WFIFOSET(fd,packet_len(0xa1));
  701. }
  702. }
  703. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  704. /// 0080 <id>.L <type>.B
  705. /// type:
  706. /// 0 = out of sight
  707. /// 1 = died
  708. /// 2 = logged out
  709. /// 3 = teleport
  710. /// 4 = trickdead
  711. void clif_clearunit_single(int id, clr_type type, int fd)
  712. {
  713. WFIFOHEAD(fd, packet_len(0x80));
  714. WFIFOW(fd,0) = 0x80;
  715. WFIFOL(fd,2) = id;
  716. WFIFOB(fd,6) = type;
  717. WFIFOSET(fd, packet_len(0x80));
  718. }
  719. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  720. /// 0080 <id>.L <type>.B
  721. /// type:
  722. /// 0 = out of sight
  723. /// 1 = died
  724. /// 2 = logged out
  725. /// 3 = teleport
  726. /// 4 = trickdead
  727. void clif_clearunit_area(struct block_list* bl, clr_type type)
  728. {
  729. unsigned char buf[8];
  730. nullpo_retv(bl);
  731. WBUFW(buf,0) = 0x80;
  732. WBUFL(buf,2) = bl->id;
  733. WBUFB(buf,6) = type;
  734. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  735. if(disguised(bl)) {
  736. WBUFL(buf,2) = -bl->id;
  737. clif_send(buf, packet_len(0x80), bl, SELF);
  738. }
  739. }
  740. /// Used to make monsters with player-sprites disappear after dying
  741. /// like normal monsters, because the client does not remove those
  742. /// automatically.
  743. static TIMER_FUNC(clif_clearunit_delayed_sub){
  744. struct block_list *bl = (struct block_list *)data;
  745. clif_clearunit_area(bl, (clr_type) id);
  746. ers_free(delay_clearunit_ers,bl);
  747. return 0;
  748. }
  749. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  750. {
  751. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  752. memcpy (tbl, bl, sizeof (struct block_list));
  753. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  754. }
  755. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  756. {
  757. if(sd->sc.option&OPTION_COSTUME)
  758. {
  759. *rhand = *lhand = 0;
  760. return;
  761. }
  762. #if PACKETVER < 4
  763. *rhand = sd->status.weapon;
  764. *lhand = sd->status.shield;
  765. #else
  766. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  767. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  768. {
  769. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  770. if (id->view_id > 0)
  771. *rhand = id->view_id;
  772. else
  773. *rhand = id->nameid;
  774. } else
  775. *rhand = 0;
  776. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  777. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  778. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  779. {
  780. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  781. if (id->view_id > 0)
  782. *lhand = id->view_id;
  783. else
  784. *lhand = id->nameid;
  785. } else
  786. *lhand = 0;
  787. #endif
  788. }
  789. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  790. static int clif_setlevel_sub(int lv) {
  791. if( lv < battle_config.max_lv ) {
  792. ;
  793. } else if( lv < battle_config.aura_lv ) {
  794. lv = battle_config.max_lv - 1;
  795. } else {
  796. lv = battle_config.max_lv;
  797. }
  798. return lv;
  799. }
  800. static int clif_setlevel(struct block_list* bl) {
  801. int lv = status_get_lv(bl);
  802. if( battle_config.client_limit_unit_lv&bl->type )
  803. return clif_setlevel_sub(lv);
  804. switch( bl->type ) {
  805. case BL_NPC:
  806. case BL_PET:
  807. // npcs and pets do not have level
  808. return 0;
  809. }
  810. return lv;
  811. }
  812. /*==========================================
  813. * Prepares 'unit standing/spawning' packet
  814. *------------------------------------------*/
  815. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  816. {
  817. struct map_session_data* sd;
  818. struct status_change* sc = status_get_sc(bl);
  819. struct view_data* vd = status_get_viewdata(bl);
  820. unsigned char *buf = WBUFP(buffer, 0);
  821. #if PACKETVER < 20091103
  822. bool type = !pcdb_checkid(vd->class_);
  823. #endif
  824. unsigned short offset = 0;
  825. #if PACKETVER >= 20091103
  826. const char *name;
  827. #endif
  828. sd = BL_CAST(BL_PC, bl);
  829. #if PACKETVER < 20091103
  830. if(type)
  831. WBUFW(buf,0) = spawn ? 0x7c : 0x78;
  832. else
  833. #endif
  834. #if PACKETVER < 4
  835. WBUFW(buf,0) = spawn ? 0x79 : 0x78;
  836. #elif PACKETVER < 7
  837. WBUFW(buf,0) = spawn ? 0x1d9 : 0x1d8;
  838. #elif PACKETVER < 20080102
  839. WBUFW(buf,0) = spawn ? 0x22b : 0x22a;
  840. #elif PACKETVER < 20091103
  841. WBUFW(buf,0) = spawn ? 0x2ed : 0x2ee;
  842. #elif PACKETVER < 20101124
  843. WBUFW(buf,0) = spawn ? 0x7f8 : 0x7f9;
  844. #elif PACKETVER < 20120221
  845. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  846. #elif PACKETVER < 20131223
  847. WBUFW(buf,0) = spawn ? 0x90f : 0x915;
  848. #elif PACKETVER < 20150513
  849. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  850. #else
  851. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  852. #endif
  853. #if PACKETVER >= 20091103
  854. name = status_get_name(bl);
  855. #if PACKETVER < 20110111
  856. WBUFW(buf,2) = (uint16)((spawn ? 62 : 63)+strlen(name));
  857. #elif PACKETVER < 20120221
  858. WBUFW(buf,2) = (uint16)((spawn ? 64 : 65)+strlen(name));
  859. #elif PACKETVER < 20130807
  860. WBUFW(buf,2) = (uint16)((spawn ? 77 : 78)+strlen(name));
  861. #else
  862. WBUFW(buf,2) = (uint16)((spawn ? 79 : 80)+strlen(name));
  863. #endif
  864. WBUFB(buf,4) = clif_bl_type(bl);
  865. offset+=3;
  866. buf = WBUFP(buffer,offset);
  867. #elif PACKETVER >= 20071106
  868. if (type) { //Non-player packets
  869. WBUFB(buf,2) = clif_bl_type(bl);
  870. offset++;
  871. buf = WBUFP(buffer,offset);
  872. }
  873. #endif
  874. WBUFL(buf, 2) = bl->id;
  875. #if PACKETVER >= 20131223
  876. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  877. offset+=4;
  878. buf = WBUFP(buffer,offset);
  879. #endif
  880. WBUFW(buf, 6) = status_get_speed(bl);
  881. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  882. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  883. #if PACKETVER < 20091103
  884. if (type&&spawn) { //uses an older and different packet structure
  885. WBUFW(buf,12) = (sc)? sc->option : 0;
  886. WBUFW(buf,14) = vd->hair_style;
  887. WBUFW(buf,16) = vd->weapon;
  888. WBUFW(buf,18) = vd->head_bottom;
  889. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  890. WBUFW(buf,22) = vd->shield;
  891. } else {
  892. #endif
  893. #if PACKETVER >= 20091103
  894. WBUFL(buf,12) = (sc)? sc->option : 0;
  895. offset+=2;
  896. buf = WBUFP(buffer,offset);
  897. #elif PACKETVER >= 7
  898. if (!type) {
  899. WBUFL(buf,12) = (sc)? sc->option : 0;
  900. offset+=2;
  901. buf = WBUFP(buffer,offset);
  902. } else
  903. WBUFW(buf,12) = (sc)? sc->option : 0;
  904. #else
  905. WBUFW(buf,12) = (sc)? sc->option : 0;
  906. #endif
  907. WBUFW(buf,14) = vd->class_;
  908. WBUFW(buf,16) = vd->hair_style;
  909. WBUFW(buf,18) = vd->weapon;
  910. #if PACKETVER < 4
  911. WBUFW(buf,20) = vd->head_bottom;
  912. WBUFW(buf,22) = vd->shield;
  913. #else
  914. WBUFW(buf,20) = vd->shield;
  915. WBUFW(buf,22) = vd->head_bottom;
  916. #endif
  917. #if PACKETVER < 20091103
  918. }
  919. #endif
  920. WBUFW(buf,24) = vd->head_top;
  921. WBUFW(buf,26) = vd->head_mid;
  922. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG )
  923. { //The hell, why flags work like this?
  924. WBUFW(buf,22) = status_get_emblem_id(bl);
  925. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  926. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  927. }
  928. WBUFW(buf,28) = vd->hair_color;
  929. WBUFW(buf,30) = vd->cloth_color;
  930. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  931. #if PACKETVER < 20091103
  932. if (type&&spawn) { //End of packet 0x7c
  933. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  934. WBUFB(buf,35) = vd->sex;
  935. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  936. WBUFB(buf,39) = 0;
  937. WBUFB(buf,40) = 0;
  938. return packet_len(0x7c);
  939. }
  940. #endif
  941. #if PACKETVER >= 20110111
  942. WBUFW(buf,34) = vd->robe;
  943. offset+= 2;
  944. buf = WBUFP(buffer,offset);
  945. #endif
  946. WBUFL(buf,34) = status_get_guild_id(bl);
  947. WBUFW(buf,38) = status_get_emblem_id(bl);
  948. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  949. #if PACKETVER >= 20091103
  950. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  951. offset+=2;
  952. buf = WBUFP(buffer,offset);
  953. #elif PACKETVER >= 7
  954. if (!type) {
  955. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  956. offset+=2;
  957. buf = WBUFP(buffer,offset);
  958. } else
  959. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  960. #else
  961. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  962. #endif
  963. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  964. WBUFB(buf,45) = vd->sex;
  965. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  966. WBUFB(buf,49) = (sd)? 5 : 0;
  967. WBUFB(buf,50) = (sd)? 5 : 0;
  968. if (!spawn) {
  969. WBUFB(buf,51) = vd->dead_sit;
  970. offset++;
  971. buf = WBUFP(buffer,offset);
  972. }
  973. WBUFW(buf,51) = clif_setlevel(bl);
  974. #if PACKETVER < 20091103
  975. if (type) //End for non-player packet
  976. return packet_len(WBUFW(buffer,0));
  977. #endif
  978. #if PACKETVER >= 20080102
  979. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  980. #endif
  981. #if PACKETVER >= 20120221
  982. 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)) ) {
  983. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  984. WBUFL(buf,59) = status_get_hp(bl); // HP
  985. } else {
  986. WBUFL(buf,55) = -1; // maxHP
  987. WBUFL(buf,59) = -1; // HP
  988. }
  989. WBUFB(buf,63) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  990. #endif
  991. #if PACKETVER >= 20150513
  992. WBUFW(buf,64) = vd->body_style; // body
  993. offset+= 2;
  994. buf = WBUFP(buffer,offset);
  995. #endif
  996. #if PACKETVER >= 20091103
  997. #if PACKETVER >= 20120221
  998. safestrncpy(WBUFCP(buf,64), name, NAME_LENGTH);
  999. #else
  1000. safestrncpy(WBUFCP(buf,55), name, NAME_LENGTH);
  1001. #endif
  1002. return WBUFW(buffer,2);
  1003. #else
  1004. return packet_len(WBUFW(buffer,0));
  1005. #endif
  1006. }
  1007. /*==========================================
  1008. * Prepares 'unit walking' packet
  1009. *------------------------------------------*/
  1010. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1011. {
  1012. struct map_session_data* sd;
  1013. struct status_change* sc = status_get_sc(bl);
  1014. struct view_data* vd = status_get_viewdata(bl);
  1015. unsigned char* buf = WBUFP(buffer,0);
  1016. #if PACKETVER >= 7
  1017. unsigned short offset = 0;
  1018. #endif
  1019. #if PACKETVER >= 20091103
  1020. const char *name;
  1021. #endif
  1022. sd = BL_CAST(BL_PC, bl);
  1023. #if PACKETVER < 4
  1024. WBUFW(buf, 0) = 0x7b;
  1025. #elif PACKETVER < 7
  1026. WBUFW(buf, 0) = 0x1da;
  1027. #elif PACKETVER < 20080102
  1028. WBUFW(buf, 0) = 0x22c;
  1029. #elif PACKETVER < 20091103
  1030. WBUFW(buf, 0) = 0x2ec;
  1031. #elif PACKETVER < 20101124
  1032. WBUFW(buf, 0) = 0x7f7;
  1033. #elif PACKETVER < 20120221
  1034. WBUFW(buf, 0) = 0x856;
  1035. #elif PACKETVER < 20131223
  1036. WBUFW(buf, 0) = 0x914;
  1037. #elif PACKETVER < 20150513
  1038. WBUFW(buf, 0) = 0x9db;
  1039. #else
  1040. WBUFW(buf, 0) = 0x9fd;
  1041. #endif
  1042. #if PACKETVER >= 20091103
  1043. name = status_get_name(bl);
  1044. #if PACKETVER < 20110111
  1045. WBUFW(buf, 2) = (uint16)(69+strlen(name));
  1046. #elif PACKETVER < 20120221
  1047. WBUFW(buf, 2) = (uint16)(71+strlen(name));
  1048. #elif PACKETVER < 20130807
  1049. WBUFW(buf, 2) = (uint16)(84+strlen(name));
  1050. #else
  1051. WBUFW(buf, 2) = (uint16)(86+strlen(name));
  1052. #endif
  1053. offset+=2;
  1054. buf = WBUFP(buffer,offset);
  1055. #endif
  1056. #if PACKETVER >= 20071106
  1057. WBUFB(buf, 2) = clif_bl_type(bl);
  1058. offset++;
  1059. buf = WBUFP(buffer,offset);
  1060. #endif
  1061. WBUFL(buf, 2) = bl->id;
  1062. #if PACKETVER >= 20131223
  1063. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  1064. offset+=4;
  1065. buf = WBUFP(buffer,offset);
  1066. #endif
  1067. WBUFW(buf, 6) = status_get_speed(bl);
  1068. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1069. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1070. #if PACKETVER < 7
  1071. WBUFW(buf,12) = (sc)? sc->option : 0;
  1072. #else
  1073. WBUFL(buf,12) = (sc)? sc->option : 0;
  1074. offset+=2; //Shift the rest of elements by 2 bytes.
  1075. buf = WBUFP(buffer,offset);
  1076. #endif
  1077. WBUFW(buf,14) = vd->class_;
  1078. WBUFW(buf,16) = vd->hair_style;
  1079. WBUFW(buf,18) = vd->weapon;
  1080. #if PACKETVER < 4
  1081. WBUFW(buf,20) = vd->head_bottom;
  1082. WBUFL(buf,22) = gettick();
  1083. WBUFW(buf,26) = vd->shield;
  1084. #else
  1085. WBUFW(buf,20) = vd->shield;
  1086. WBUFW(buf,22) = vd->head_bottom;
  1087. WBUFL(buf,24) = gettick();
  1088. #endif
  1089. WBUFW(buf,28) = vd->head_top;
  1090. WBUFW(buf,30) = vd->head_mid;
  1091. WBUFW(buf,32) = vd->hair_color;
  1092. WBUFW(buf,34) = vd->cloth_color;
  1093. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1094. #if PACKETVER >= 20110111
  1095. WBUFW(buf,38) = vd->robe;
  1096. offset+= 2;
  1097. buf = WBUFP(buffer,offset);
  1098. #endif
  1099. WBUFL(buf,38) = status_get_guild_id(bl);
  1100. WBUFW(buf,42) = status_get_emblem_id(bl);
  1101. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1102. #if PACKETVER < 7
  1103. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1104. #else
  1105. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1106. offset+=2; //Shift the rest of elements by 2 bytes.
  1107. buf = WBUFP(buffer,offset);
  1108. #endif
  1109. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1110. WBUFB(buf,49) = vd->sex;
  1111. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1112. WBUFB(buf,56) = (sd)? 5 : 0;
  1113. WBUFB(buf,57) = (sd)? 5 : 0;
  1114. WBUFW(buf,58) = clif_setlevel(bl);
  1115. #if PACKETVER >= 20080102
  1116. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1117. #endif
  1118. #if PACKETVER >= 20120221
  1119. 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)) ) {
  1120. WBUFL(buf,62) = status_get_max_hp(bl); // maxHP
  1121. WBUFL(buf,66) = status_get_hp(bl); // HP
  1122. } else {
  1123. WBUFL(buf,62) = -1; // maxHP
  1124. WBUFL(buf,66) = -1; // HP
  1125. }
  1126. WBUFB(buf,70) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1127. #endif
  1128. #if PACKETVER >= 20150513
  1129. WBUFW(buf,71) = vd->body_style; // body
  1130. offset+= 2;
  1131. buf = WBUFP(buffer,offset);
  1132. #endif
  1133. #if PACKETVER >= 20091103
  1134. #if PACKETVER >= 20120221
  1135. safestrncpy(WBUFCP(buf,71), name, NAME_LENGTH);
  1136. #else
  1137. safestrncpy(WBUFCP(buf,62), name, NAME_LENGTH);
  1138. #endif
  1139. return WBUFW(buffer,2);
  1140. #else
  1141. return packet_len(WBUFW(buffer,0));
  1142. #endif
  1143. }
  1144. //Modifies the buffer for disguise characters and sends it to self.
  1145. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1146. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1147. {
  1148. #if PACKETVER >= 20091103
  1149. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1150. WBUFL(buf,5)=-bl->id;
  1151. #elif PACKETVER >= 20071106
  1152. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1153. WBUFL(buf,3)=-bl->id;
  1154. #else
  1155. WBUFL(buf,2)=-bl->id;
  1156. #endif
  1157. clif_send(buf, len, bl, SELF);
  1158. }
  1159. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1160. /// 01b0 <id>.L <type>.B <value>.L
  1161. /// type:
  1162. /// unused
  1163. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1164. {
  1165. nullpo_retv(bl);
  1166. if(!pcdb_checkid(class_))
  1167. {// player classes yield missing sprites
  1168. unsigned char buf[16];
  1169. WBUFW(buf,0)=0x1b0;
  1170. WBUFL(buf,2)=bl->id;
  1171. WBUFB(buf,6)=type;
  1172. WBUFL(buf,7)=class_;
  1173. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1174. }
  1175. }
  1176. /// Notifies the client of an object's spirits.
  1177. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1178. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1179. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1180. {
  1181. WFIFOHEAD(fd, packet_len(0x1e1));
  1182. WFIFOW(fd,0)=0x1e1;
  1183. WFIFOL(fd,2)=sd->bl.id;
  1184. WFIFOW(fd,6)=sd->spiritball;
  1185. WFIFOSET(fd, packet_len(0x1e1));
  1186. }
  1187. /*==========================================
  1188. * Kagerou/Oboro amulet spirit
  1189. *------------------------------------------*/
  1190. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1191. {
  1192. WFIFOHEAD(fd, packet_len(0x08cf));
  1193. WFIFOW(fd,0)=0x08cf;
  1194. WFIFOL(fd,2)=sd->bl.id;
  1195. WFIFOW(fd,6)=sd->spiritcharm_type;
  1196. WFIFOW(fd,8)=sd->spiritcharm;
  1197. WFIFOSET(fd, packet_len(0x08cf));
  1198. }
  1199. /*==========================================
  1200. * Run when player changes map / refreshes
  1201. * Tells its client to display all weather settings being used by this map
  1202. *------------------------------------------*/
  1203. static void clif_weather_check(struct map_session_data *sd)
  1204. {
  1205. int16 m = sd->bl.m;
  1206. int fd = sd->fd;
  1207. if (map_getmapflag(m, MF_SNOW)
  1208. || map_getmapflag(m, MF_CLOUDS)
  1209. || map_getmapflag(m, MF_FOG)
  1210. || map_getmapflag(m, MF_FIREWORKS)
  1211. || map_getmapflag(m, MF_SAKURA)
  1212. || map_getmapflag(m, MF_LEAVES)
  1213. || map_getmapflag(m, MF_CLOUDS2))
  1214. {
  1215. if (map_getmapflag(m, MF_SNOW))
  1216. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1217. if (map_getmapflag(m, MF_CLOUDS))
  1218. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1219. if (map_getmapflag(m, MF_CLOUDS2))
  1220. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1221. if (map_getmapflag(m, MF_FOG))
  1222. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1223. if (map_getmapflag(m, MF_FIREWORKS)) {
  1224. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1225. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1226. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1227. }
  1228. if (map_getmapflag(m, MF_SAKURA))
  1229. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1230. if (map_getmapflag(m, MF_LEAVES))
  1231. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1232. }
  1233. }
  1234. /**
  1235. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1236. **/
  1237. void clif_weather(int16 m)
  1238. {
  1239. struct s_mapiterator* iter;
  1240. struct map_session_data *sd=NULL;
  1241. iter = mapit_getallusers();
  1242. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1243. {
  1244. if( sd->bl.m == m )
  1245. clif_weather_check(sd);
  1246. }
  1247. mapit_free(iter);
  1248. }
  1249. /**
  1250. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1251. **/
  1252. int clif_spawn(struct block_list *bl)
  1253. {
  1254. unsigned char buf[128];
  1255. struct view_data *vd;
  1256. int len;
  1257. vd = status_get_viewdata(bl);
  1258. if( !vd || vd->class_ == JT_INVISIBLE )
  1259. return 0;
  1260. /**
  1261. * Hide NPC from maya purple card.
  1262. **/
  1263. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1264. return 0;
  1265. len = clif_set_unit_idle(bl, buf,true);
  1266. clif_send(buf, len, bl, AREA_WOS);
  1267. if (disguised(bl))
  1268. clif_setdisguise(bl, buf, len);
  1269. if (vd->cloth_color)
  1270. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1271. if (vd->body_style)
  1272. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1273. switch (bl->type)
  1274. {
  1275. case BL_PC:
  1276. {
  1277. TBL_PC *sd = ((TBL_PC*)bl);
  1278. if (sd->spiritball > 0)
  1279. clif_spiritball(&sd->bl);
  1280. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1281. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1282. else if(sd->state.size==SZ_MEDIUM)
  1283. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1284. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1285. clif_sendbgemblem_area(sd);
  1286. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1287. clif_spiritcharm(sd);
  1288. if (sd->status.robe)
  1289. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1290. clif_efst_status_change_sub(bl, bl, AREA);
  1291. clif_hat_effects(sd,bl,AREA);
  1292. }
  1293. break;
  1294. case BL_MOB:
  1295. {
  1296. TBL_MOB *md = ((TBL_MOB*)bl);
  1297. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1298. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1299. else if(md->special_state.size==SZ_MEDIUM)
  1300. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1301. }
  1302. break;
  1303. case BL_NPC:
  1304. {
  1305. TBL_NPC *nd = ((TBL_NPC*)bl);
  1306. if( nd->size == SZ_BIG )
  1307. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1308. else if( nd->size == SZ_MEDIUM )
  1309. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1310. clif_efst_status_change_sub(bl, bl, AREA);
  1311. clif_progressbar_npc_area(nd);
  1312. }
  1313. break;
  1314. case BL_PET:
  1315. if (vd->head_bottom)
  1316. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1317. break;
  1318. }
  1319. return 0;
  1320. }
  1321. /// Sends information about owned homunculus to the client . [orn]
  1322. /// 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)
  1323. /// 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)
  1324. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1325. {
  1326. struct status_data *status;
  1327. unsigned char buf[128];
  1328. int offset;
  1329. #if PACKETVER < 20141016
  1330. const int cmd = 0x22e;
  1331. #else
  1332. const int cmd = 0x9f7;
  1333. #endif
  1334. int htype;
  1335. nullpo_retv(hd);
  1336. if (!clif_session_isValid(sd))
  1337. return;
  1338. status = &hd->battle_status;
  1339. htype = hom_class2type(hd->homunculus.class_);
  1340. memset(buf,0,packet_len(cmd));
  1341. WBUFW(buf,0) = cmd;
  1342. safestrncpy(WBUFCP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1343. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1344. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1345. WBUFW(buf,27) = hd->homunculus.level;
  1346. WBUFW(buf,29) = hd->homunculus.hunger;
  1347. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1348. WBUFW(buf,33) = 0; // equip id
  1349. WBUFW(buf,35) = cap_value(status->rhw.atk2 + status->batk, 0, INT16_MAX);
  1350. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1351. WBUFW(buf,39)=status->hit;
  1352. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1353. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1354. else
  1355. WBUFW(buf,41) = status->cri/10;
  1356. #ifdef RENEWAL
  1357. WBUFW(buf,43) = status->def + status->def2;
  1358. WBUFW(buf,45) = status->mdef + status->mdef2;
  1359. #else
  1360. WBUFW(buf,43) = status->def + status->vit;
  1361. WBUFW(buf,45) = status->mdef;
  1362. #endif
  1363. WBUFW(buf,47) = status->flee;
  1364. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1365. #if PACKETVER >= 20141016
  1366. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1367. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1368. if (status->max_hp > (INT32_MAX/100)) {
  1369. WBUFL(buf,51) = status->hp/(status->max_hp/100);
  1370. WBUFL(buf,55) = 100;
  1371. } else {
  1372. WBUFL(buf,51) = status->hp;
  1373. WBUFL(buf,55) = status->max_hp;
  1374. }
  1375. offset = 4;
  1376. #else
  1377. if (status->max_hp > INT16_MAX) {
  1378. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1379. WBUFW(buf,53) = 100;
  1380. } else {
  1381. WBUFW(buf,51) = status->hp;
  1382. WBUFW(buf,53) = status->max_hp;
  1383. }
  1384. offset = 0;
  1385. #endif
  1386. if (status->max_sp > INT16_MAX) {
  1387. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1388. WBUFW(buf,57+offset) = 100;
  1389. } else {
  1390. WBUFW(buf,55+offset) = status->sp;
  1391. WBUFW(buf,57+offset) = status->max_sp;
  1392. }
  1393. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1394. WBUFL(buf,63+offset) = hd->exp_next;
  1395. switch( htype ) {
  1396. case HT_REG:
  1397. case HT_EVO:
  1398. if( hd->homunculus.level >= battle_config.hom_max_level )
  1399. WBUFL(buf,63+offset) = 0;
  1400. break;
  1401. case HT_S:
  1402. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1403. WBUFL(buf,63+offset) = 0;
  1404. break;
  1405. }
  1406. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1407. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1408. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1409. }
  1410. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1411. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1412. /// type:
  1413. /// unused
  1414. /// state:
  1415. /// 0 = pre-init
  1416. /// 1 = intimacy
  1417. /// 2 = hunger
  1418. /// 3 = accessory?
  1419. /// ? = ignored
  1420. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1421. { //[orn]
  1422. int fd = sd->fd;
  1423. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1424. hom_calc_skilltree(sd->hd, 0);
  1425. WFIFOHEAD(fd, packet_len(0x230));
  1426. WFIFOW(fd,0)=0x230;
  1427. WFIFOB(fd,2)=0;
  1428. WFIFOB(fd,3)=state;
  1429. WFIFOL(fd,4)=sd->hd->bl.id;
  1430. WFIFOL(fd,8)=param;
  1431. WFIFOSET(fd,packet_len(0x230));
  1432. }
  1433. int clif_homskillinfoblock(struct map_session_data *sd)
  1434. { //[orn]
  1435. struct homun_data *hd;
  1436. int fd = sd->fd;
  1437. int i, len=4;
  1438. nullpo_ret(sd);
  1439. hd = sd->hd;
  1440. if ( !hd )
  1441. return 0 ;
  1442. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1443. WFIFOW(fd,0)=0x235;
  1444. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1445. int id = hd->homunculus.hskill[i].id;
  1446. if( id != 0 ){
  1447. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1448. short idx = hom_skill_get_index(id);
  1449. if (idx == -1)
  1450. continue;
  1451. WFIFOW(fd,len ) = id;
  1452. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1453. WFIFOW(fd,len+4) = 0;
  1454. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1455. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1456. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1457. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1458. 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;
  1459. len+=37;
  1460. }
  1461. }
  1462. WFIFOW(fd,2)=len;
  1463. WFIFOSET(fd,len);
  1464. return 0;
  1465. }
  1466. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1467. { //[orn]
  1468. struct homun_data *hd;
  1469. int fd;
  1470. short idx = -1;
  1471. nullpo_retv(sd);
  1472. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1473. return;
  1474. fd = sd->fd;
  1475. hd = sd->hd;
  1476. WFIFOHEAD(fd, packet_len(0x239));
  1477. WFIFOW(fd,0) = 0x239;
  1478. WFIFOW(fd,2) = skill_id;
  1479. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1480. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1481. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1482. 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;
  1483. WFIFOSET(fd,packet_len(0x239));
  1484. }
  1485. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1486. {
  1487. int fd=sd->fd;
  1488. WFIFOHEAD(fd,packet_len(0x22f));
  1489. WFIFOW(fd,0)=0x22f;
  1490. WFIFOB(fd,2)=fail;
  1491. WFIFOW(fd,3)=foodid;
  1492. WFIFOSET(fd,packet_len(0x22f));
  1493. return 0;
  1494. }
  1495. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1496. /// 0087 <walk start time>.L <walk data>.6B
  1497. void clif_walkok(struct map_session_data *sd)
  1498. {
  1499. int fd=sd->fd;
  1500. WFIFOHEAD(fd, packet_len(0x87));
  1501. WFIFOW(fd,0)=0x87;
  1502. WFIFOL(fd,2)=gettick();
  1503. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1504. WFIFOSET(fd,packet_len(0x87));
  1505. }
  1506. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1507. {
  1508. uint8 buf[128];
  1509. int len;
  1510. struct status_change *sc = NULL;
  1511. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1512. clif_ally_only = true;
  1513. len = clif_set_unit_walking(bl,ud,buf);
  1514. clif_send(buf,len,bl,AREA_WOS);
  1515. if (disguised(bl))
  1516. clif_setdisguise(bl, buf, len);
  1517. if(vd->cloth_color)
  1518. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1519. if(vd->body_style)
  1520. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1521. switch(bl->type) {
  1522. case BL_PC:
  1523. {
  1524. TBL_PC *sd = ((TBL_PC*)bl);
  1525. // clif_movepc(sd);
  1526. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1527. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1528. else if(sd->state.size==SZ_MEDIUM)
  1529. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1530. if (sd->status.robe)
  1531. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1532. }
  1533. break;
  1534. case BL_MOB:
  1535. {
  1536. TBL_MOB *md = ((TBL_MOB*)bl);
  1537. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1538. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1539. else if(md->special_state.size==SZ_MEDIUM)
  1540. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1541. }
  1542. break;
  1543. case BL_PET:
  1544. if(vd->head_bottom) // needed to display pet equip properly
  1545. clif_pet_equip_area((TBL_PET*)bl);
  1546. break;
  1547. }
  1548. clif_ally_only = false;
  1549. }
  1550. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1551. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1552. /// Note: unit must not be self
  1553. void clif_move(struct unit_data *ud)
  1554. {
  1555. unsigned char buf[16];
  1556. struct view_data* vd;
  1557. struct block_list* bl = ud->bl;
  1558. struct status_change *sc = NULL;
  1559. vd = status_get_viewdata(bl);
  1560. if (!vd )
  1561. return;
  1562. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1563. else if( vd->class_ == JT_INVISIBLE ){
  1564. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1565. if(disguised(bl)) {
  1566. WBUFW(buf,0)=0x86;
  1567. WBUFL(buf,2)=-bl->id;
  1568. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1569. WBUFL(buf,12)=gettick();
  1570. clif_send(buf, packet_len(0x86), bl, SELF);
  1571. }
  1572. return;
  1573. }
  1574. /**
  1575. * Hide NPC from maya purple card.
  1576. **/
  1577. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1578. return;
  1579. if (ud->state.speed_changed) {
  1580. // Since we don't know how to update the speed of other objects,
  1581. // use the old walk packet to update the data.
  1582. ud->state.speed_changed = 0;
  1583. clif_move2(bl, vd, ud);
  1584. return;
  1585. }
  1586. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1587. clif_ally_only = true;
  1588. WBUFW(buf,0)=0x86;
  1589. WBUFL(buf,2)=bl->id;
  1590. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1591. WBUFL(buf,12)=gettick();
  1592. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1593. if (disguised(bl)) {
  1594. WBUFL(buf,2)=-bl->id;
  1595. clif_send(buf, packet_len(0x86), bl, SELF);
  1596. }
  1597. clif_ally_only = false;
  1598. }
  1599. /*==========================================
  1600. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1601. *------------------------------------------*/
  1602. static TIMER_FUNC(clif_delayquit){
  1603. struct map_session_data *sd = NULL;
  1604. //Remove player from map server
  1605. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1606. map_quit(sd);
  1607. return 0;
  1608. }
  1609. /*==========================================
  1610. *
  1611. *------------------------------------------*/
  1612. void clif_quitsave(int fd,struct map_session_data *sd) {
  1613. if (!battle_config.prevent_logout ||
  1614. sd->canlog_tick == 0 ||
  1615. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1616. map_quit(sd);
  1617. else if (sd->fd) {
  1618. //Disassociate session from player (session is deleted after this function was called)
  1619. //And set a timer to make him quit later.
  1620. session[sd->fd]->session_data = NULL;
  1621. sd->fd = 0;
  1622. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1623. }
  1624. }
  1625. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1626. /// 0091 <map name>.16B <x>.W <y>.W
  1627. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1628. {
  1629. int fd;
  1630. nullpo_retv(sd);
  1631. fd = sd->fd;
  1632. WFIFOHEAD(fd,packet_len(0x91));
  1633. WFIFOW(fd,0) = 0x91;
  1634. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1635. WFIFOW(fd,18) = x;
  1636. WFIFOW(fd,20) = y;
  1637. WFIFOSET(fd,packet_len(0x91));
  1638. }
  1639. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1640. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1641. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1642. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1643. {
  1644. int fd;
  1645. #if PACKETVER >= 20170315
  1646. int cmd = 0xac7;
  1647. #else
  1648. int cmd = 0x92;
  1649. #endif
  1650. nullpo_retv(sd);
  1651. fd = sd->fd;
  1652. WFIFOHEAD(fd,packet_len(cmd));
  1653. WFIFOW(fd,0) = cmd;
  1654. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1655. WFIFOW(fd,18) = x;
  1656. WFIFOW(fd,20) = y;
  1657. WFIFOL(fd,22) = htonl(ip);
  1658. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1659. #if PACKETVER >= 20170315
  1660. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1661. #endif
  1662. WFIFOSET(fd,packet_len(cmd));
  1663. }
  1664. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1665. /// This function combines both calls and allows to simplify the calling code
  1666. void clif_blown(struct block_list *bl)
  1667. {
  1668. clif_slide(bl, bl->x, bl->y);
  1669. clif_fixpos(bl);
  1670. }
  1671. /// Visually moves(slides) a character to x,y. If the target cell
  1672. /// isn't walkable, the char doesn't move at all. If the char is
  1673. /// sitting it will stand up (ZC_STOPMOVE).
  1674. /// 0088 <id>.L <x>.W <y>.W
  1675. void clif_fixpos(struct block_list *bl)
  1676. {
  1677. unsigned char buf[10];
  1678. nullpo_retv(bl);
  1679. WBUFW(buf,0) = 0x88;
  1680. WBUFL(buf,2) = bl->id;
  1681. WBUFW(buf,6) = bl->x;
  1682. WBUFW(buf,8) = bl->y;
  1683. clif_send(buf, packet_len(0x88), bl, AREA);
  1684. if( disguised(bl) ) {
  1685. WBUFL(buf,2) = -bl->id;
  1686. clif_send(buf, packet_len(0x88), bl, SELF);
  1687. }
  1688. }
  1689. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1690. /// 00c4 <shop id>.L
  1691. void clif_npcbuysell(struct map_session_data* sd, int id)
  1692. {
  1693. int fd;
  1694. nullpo_retv(sd);
  1695. fd=sd->fd;
  1696. WFIFOHEAD(fd, packet_len(0xc4));
  1697. WFIFOW(fd,0)=0xc4;
  1698. WFIFOL(fd,2)=id;
  1699. WFIFOSET(fd,packet_len(0xc4));
  1700. }
  1701. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1702. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1703. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1704. {
  1705. int fd,i,c;
  1706. bool discount;
  1707. nullpo_retv(sd);
  1708. nullpo_retv(nd);
  1709. fd = sd->fd;
  1710. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1711. WFIFOW(fd,0) = 0xc6;
  1712. c = 0;
  1713. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1714. for( i = 0; i < nd->u.shop.count; i++ )
  1715. {
  1716. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1717. int val = nd->u.shop.shop_item[i].value;
  1718. if( id == NULL )
  1719. continue;
  1720. WFIFOL(fd, 4+c*11) = val;
  1721. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1722. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1723. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1724. c++;
  1725. }
  1726. WFIFOW(fd,2) = 4 + c*11;
  1727. WFIFOSET(fd,WFIFOW(fd,2));
  1728. }
  1729. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1730. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1731. void clif_selllist(struct map_session_data *sd)
  1732. {
  1733. int fd,i,c=0,val;
  1734. struct npc_data *nd;
  1735. nullpo_retv(sd);
  1736. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1737. return;
  1738. fd=sd->fd;
  1739. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1740. WFIFOW(fd,0)=0xc7;
  1741. for( i = 0; i < MAX_INVENTORY; i++ )
  1742. {
  1743. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1744. {
  1745. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1746. continue;
  1747. val=sd->inventory_data[i]->value_sell;
  1748. if( val < 0 )
  1749. continue;
  1750. WFIFOW(fd,4+c*10)=i+2;
  1751. WFIFOL(fd,6+c*10)=val;
  1752. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1753. c++;
  1754. }
  1755. }
  1756. WFIFOW(fd,2)=c*10+4;
  1757. WFIFOSET(fd,WFIFOW(fd,2));
  1758. }
  1759. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1760. /// 09d4
  1761. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1762. // TODO: State tracking?
  1763. sd->npc_shopid = 0;
  1764. }
  1765. /**
  1766. * Presents list of items, that can be sold to a Market shop.
  1767. * @author: Ind and Yommy
  1768. **/
  1769. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1770. #if PACKETVER >= 20131223
  1771. struct npc_item_list *shop = nd->u.shop.shop_item;
  1772. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1773. struct item_data *id = NULL;
  1774. struct s_packet_db *info;
  1775. int fd;
  1776. nullpo_retv(sd);
  1777. if (sd->state.trading)
  1778. return;
  1779. info = &packet_db[cmd];
  1780. if (!info || info->len == 0)
  1781. return;
  1782. fd = sd->fd;
  1783. WFIFOHEAD(fd, 4 + shop_size * 13);
  1784. WFIFOW(fd,0) = cmd;
  1785. for (i = 0, c = 0; i < shop_size; i++) {
  1786. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1787. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1788. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1789. WFIFOL(fd, 7+c*13) = shop[i].value;
  1790. WFIFOL(fd,11+c*13) = shop[i].qty;
  1791. WFIFOW(fd,15+c*13) = id->weight;
  1792. c++;
  1793. }
  1794. }
  1795. WFIFOW(fd,2) = 4 + c*13;
  1796. WFIFOSET(fd,WFIFOW(fd,2));
  1797. sd->state.trading = 1;
  1798. #endif
  1799. }
  1800. /// Closes the Market shop window.
  1801. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1802. nullpo_retv(sd);
  1803. sd->npc_shopid = 0;
  1804. sd->state.trading = 0;
  1805. }
  1806. /// Purchase item from Market shop.
  1807. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1808. #if PACKETVER >= 20131223
  1809. unsigned short cmd = 0x9d7, len = 0;
  1810. struct npc_data* nd;
  1811. uint8 result = (res == 0 ? 1 : 0);
  1812. int fd = 0;
  1813. struct s_packet_db *info;
  1814. nullpo_retv(sd);
  1815. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1816. info = &packet_db[cmd];
  1817. if (!info || info->len == 0)
  1818. return;
  1819. fd = sd->fd;
  1820. len = 5 + 8*n;
  1821. WFIFOHEAD(fd, len);
  1822. WFIFOW(fd, 0) = cmd;
  1823. WFIFOW(fd, 2) = len;
  1824. if (result) {
  1825. uint8 i, j;
  1826. struct npc_item_list *shop = nd->u.shop.shop_item;
  1827. unsigned short count = nd->u.shop.count;
  1828. for (i = 0; i < n; i++) {
  1829. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1830. WFIFOW(fd, 7+i*8) = list[i].qty;
  1831. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1832. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1833. }
  1834. }
  1835. WFIFOB(fd, 4) = n;
  1836. WFIFOSET(fd, len);
  1837. #endif
  1838. }
  1839. /// Purchase item from Market shop.
  1840. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1841. #if PACKETVER >= 20131223
  1842. struct s_packet_db* info;
  1843. struct s_npc_buy_list *item_list;
  1844. uint16 len = 0, i = 0;
  1845. uint8 res = 0, n = 0;
  1846. nullpo_retv(sd);
  1847. if (!sd->npc_shopid)
  1848. return;
  1849. info = &packet_db[RFIFOW(fd,0)];
  1850. if (!info || info->len == 0)
  1851. return;
  1852. len = RFIFOW(fd,info->pos[0]);
  1853. n = (len-4) / 6;
  1854. CREATE(item_list, struct s_npc_buy_list, n);
  1855. for (i = 0; i < n; i++) {
  1856. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1857. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1858. }
  1859. res = npc_buylist(sd, n, item_list);
  1860. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1861. aFree(item_list);
  1862. #endif
  1863. }
  1864. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1865. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1866. /// Client behavior (dialog window):
  1867. /// - disable mouse targeting
  1868. /// - open the dialog window
  1869. /// - set npcid of dialog window (0 by default)
  1870. /// - if set to clear on next mes, clear contents
  1871. /// - append this text
  1872. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1873. {
  1874. int fd = sd->fd;
  1875. int slen = strlen(mes) + 9;
  1876. WFIFOHEAD(fd, slen);
  1877. WFIFOW(fd,0)=0xb4;
  1878. WFIFOW(fd,2)=slen;
  1879. WFIFOL(fd,4)=npcid;
  1880. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1881. WFIFOSET(fd,WFIFOW(fd,2));
  1882. }
  1883. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1884. /// 00b5 <npc id>.L
  1885. /// Client behavior (dialog window):
  1886. /// - disable mouse targeting
  1887. /// - open the dialog window
  1888. /// - add 'next' button
  1889. /// When 'next' is pressed:
  1890. /// - 00B9 <npcid of dialog window>.L
  1891. /// - set to clear on next mes
  1892. /// - remove 'next' button
  1893. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1894. {
  1895. int fd;
  1896. nullpo_retv(sd);
  1897. fd=sd->fd;
  1898. WFIFOHEAD(fd, packet_len(0xb5));
  1899. WFIFOW(fd,0)=0xb5;
  1900. WFIFOL(fd,2)=npcid;
  1901. WFIFOSET(fd,packet_len(0xb5));
  1902. }
  1903. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1904. /// 00b6 <npc id>.L
  1905. /// Client behavior:
  1906. /// - if dialog window is open:
  1907. /// - remove 'next' button
  1908. /// - add 'close' button
  1909. /// - else:
  1910. /// - enable mouse targeting
  1911. /// - close the dialog window
  1912. /// - close the menu window
  1913. /// When 'close' is pressed:
  1914. /// - enable mouse targeting
  1915. /// - close the dialog window
  1916. /// - close the menu window
  1917. /// - 0146 <npcid of dialog window>.L
  1918. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1919. {
  1920. int fd;
  1921. nullpo_retv(sd);
  1922. fd=sd->fd;
  1923. WFIFOHEAD(fd, packet_len(0xb6));
  1924. WFIFOW(fd,0)=0xb6;
  1925. WFIFOL(fd,2)=npcid;
  1926. WFIFOSET(fd,packet_len(0xb6));
  1927. }
  1928. /**
  1929. * Close script when player is idle
  1930. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1931. * @author [Ind/Hercules]
  1932. * @param sd : player pointer
  1933. * @param npcid : npc gid to close
  1934. */
  1935. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1936. {
  1937. struct s_packet_db* info;
  1938. int16 len;
  1939. int cmd = 0;
  1940. int fd;
  1941. nullpo_retv(sd);
  1942. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  1943. if(!cmd) cmd = 0x8d6; //default
  1944. info = &packet_db[cmd];
  1945. len = info->len;
  1946. fd = sd->fd;
  1947. WFIFOHEAD(fd, len);
  1948. WFIFOW(fd,0)=0x8d6;
  1949. WFIFOL(fd,info->pos[0])=npcid;
  1950. WFIFOSET(fd,len);
  1951. }
  1952. /*==========================================
  1953. *
  1954. *------------------------------------------*/
  1955. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1956. unsigned char *buf;
  1957. int fd = sd->fd;
  1958. sd->state.using_fake_npc = 1;
  1959. WFIFOHEAD(fd, packet_len(0x78));
  1960. buf = WFIFOP(fd,0);
  1961. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1962. WBUFW(buf,0)=0x78;
  1963. #if PACKETVER >= 20071106
  1964. WBUFB(buf,2) = 0; // object type
  1965. buf = WFIFOP(fd,1);
  1966. #endif
  1967. WBUFL(buf,2)=npcid;
  1968. WBUFW(buf,14)=111;
  1969. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1970. WBUFB(buf,49)=5;
  1971. WBUFB(buf,50)=5;
  1972. WFIFOSET(fd, packet_len(0x78));
  1973. }
  1974. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1975. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1976. /// Client behavior:
  1977. /// - disable mouse targeting
  1978. /// - close the menu window
  1979. /// - open the menu window
  1980. /// - add options to the menu (separated in the text by ":")
  1981. /// - set npcid of menu window
  1982. /// - if dialog window is open:
  1983. /// - remove 'next' button
  1984. /// When 'ok' is pressed:
  1985. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1986. /// - close the menu window
  1987. /// When 'cancel' is pressed:
  1988. /// - 00B8 <npcid of menu window>.L <-1>.B
  1989. /// - enable mouse targeting
  1990. /// - close a bunch of windows...
  1991. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1992. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1993. /// TODO investigate behavior of other windows [FlavioJS]
  1994. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1995. {
  1996. int fd = sd->fd;
  1997. int slen = strlen(mes) + 9;
  1998. struct block_list *bl = NULL;
  1999. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2000. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2001. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2002. clif_sendfakenpc(sd, npcid);
  2003. WFIFOHEAD(fd, slen);
  2004. WFIFOW(fd,0)=0xb7;
  2005. WFIFOW(fd,2)=slen;
  2006. WFIFOL(fd,4)=npcid;
  2007. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2008. WFIFOSET(fd,WFIFOW(fd,2));
  2009. }
  2010. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2011. /// 0142 <npc id>.L
  2012. /// Client behavior (inputnum window):
  2013. /// - if npcid exists in the client:
  2014. /// - open the inputnum window
  2015. /// - set npcid of inputnum window
  2016. /// When 'ok' is pressed:
  2017. /// - if inputnum window has text:
  2018. /// - if npcid exists in the client:
  2019. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2020. /// - close inputnum window
  2021. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2022. {
  2023. int fd;
  2024. struct block_list *bl = NULL;
  2025. nullpo_retv(sd);
  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. fd=sd->fd;
  2031. WFIFOHEAD(fd, packet_len(0x142));
  2032. WFIFOW(fd,0)=0x142;
  2033. WFIFOL(fd,2)=npcid;
  2034. WFIFOSET(fd,packet_len(0x142));
  2035. }
  2036. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2037. /// 01d4 <npc id>.L
  2038. /// Client behavior (inputstr window):
  2039. /// - if npcid is 0 or npcid exists in the client:
  2040. /// - open the inputstr window
  2041. /// - set npcid of inputstr window
  2042. /// When 'ok' is pressed:
  2043. /// - if inputstr window has text and isn't an insult(manner.txt):
  2044. /// - if npcid is 0 or npcid exists in the client:
  2045. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2046. /// - close inputstr window
  2047. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2048. {
  2049. int fd;
  2050. struct block_list *bl = NULL;
  2051. nullpo_retv(sd);
  2052. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2053. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2054. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2055. clif_sendfakenpc(sd, npcid);
  2056. fd=sd->fd;
  2057. WFIFOHEAD(fd, packet_len(0x1d4));
  2058. WFIFOW(fd,0)=0x1d4;
  2059. WFIFOL(fd,2)=npcid;
  2060. WFIFOSET(fd,packet_len(0x1d4));
  2061. }
  2062. /// Marks a position on client's minimap (ZC_COMPASS).
  2063. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2064. /// npc id:
  2065. /// is ignored in the client
  2066. /// type:
  2067. /// 0 = display mark for 15 seconds
  2068. /// 1 = display mark until dead or teleported
  2069. /// 2 = remove mark
  2070. /// color:
  2071. /// 0x00RRGGBB
  2072. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2073. {
  2074. int fd;
  2075. nullpo_retv(sd);
  2076. fd=sd->fd;
  2077. WFIFOHEAD(fd, packet_len(0x144));
  2078. WFIFOW(fd,0)=0x144;
  2079. WFIFOL(fd,2)=npc_id;
  2080. WFIFOL(fd,6)=type;
  2081. WFIFOL(fd,10)=x;
  2082. WFIFOL(fd,14)=y;
  2083. WFIFOB(fd,18)=id;
  2084. WFIFOL(fd,19)=color;
  2085. WFIFOSET(fd,packet_len(0x144));
  2086. }
  2087. /// Displays an illustration image.
  2088. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2089. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2090. /// type:
  2091. /// 0 = bottom left corner
  2092. /// 1 = bottom middle
  2093. /// 2 = bottom right corner
  2094. /// 3 = middle of screen, inside a movable window
  2095. /// 4 = middle of screen, movable with a close button, chrome-less
  2096. /// 255 = clear all displayed cutins
  2097. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2098. {
  2099. int fd;
  2100. nullpo_retv(sd);
  2101. fd=sd->fd;
  2102. WFIFOHEAD(fd, packet_len(0x1b3));
  2103. WFIFOW(fd,0)=0x1b3;
  2104. strncpy(WFIFOCP(fd,2),image,64);
  2105. WFIFOB(fd,66)=type;
  2106. WFIFOSET(fd,packet_len(0x1b3));
  2107. }
  2108. /*==========================================
  2109. * Fills in card data from the given item and into the buffer. [Skotlex]
  2110. *------------------------------------------*/
  2111. static void clif_addcards(unsigned char* buf, struct item* item)
  2112. {
  2113. int i=0,j;
  2114. if( item == NULL ) { //Blank data
  2115. WBUFW(buf,0) = 0;
  2116. WBUFW(buf,2) = 0;
  2117. WBUFW(buf,4) = 0;
  2118. WBUFW(buf,6) = 0;
  2119. return;
  2120. }
  2121. if( item->card[0] == CARD0_PET ) { //pet eggs
  2122. WBUFW(buf,0) = 0;
  2123. WBUFW(buf,2) = 0;
  2124. WBUFW(buf,4) = 0;
  2125. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2126. return;
  2127. }
  2128. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2129. WBUFW(buf,0) = item->card[0];
  2130. WBUFW(buf,2) = item->card[1];
  2131. WBUFW(buf,4) = item->card[2];
  2132. WBUFW(buf,6) = item->card[3];
  2133. return;
  2134. }
  2135. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2136. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2137. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2138. //Normal items.
  2139. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2140. WBUFW(buf,0) = j;
  2141. else
  2142. WBUFW(buf,0) = item->card[i];
  2143. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2144. WBUFW(buf,2) = j;
  2145. else
  2146. WBUFW(buf,2) = item->card[i];
  2147. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2148. WBUFW(buf,4) = j;
  2149. else
  2150. WBUFW(buf,4) = item->card[i];
  2151. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2152. WBUFW(buf,6) = j;
  2153. else
  2154. WBUFW(buf,6) = item->card[i];
  2155. }
  2156. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2157. /// A maximum of 5 random options can be supported.
  2158. void clif_add_random_options(unsigned char* buf, struct item *it) {
  2159. #if PACKETVER >= 20150225
  2160. int i;
  2161. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  2162. WBUFW(buf, i*5 + 0) = it->option[i].id; // OptIndex
  2163. WBUFW(buf, i*5 + 2) = it->option[i].value; // Value
  2164. WBUFB(buf, i*5 + 4) = it->option[i].param; // Param1
  2165. }
  2166. #if MAX_ITEM_RDM_OPT < 5
  2167. for ( ; i < 5; i++) {
  2168. WBUFW(buf, i*5 + 0) = 0; // OptIndex
  2169. WBUFW(buf, i*5 + 2) = 0; // Value
  2170. WBUFB(buf, i*5 + 4) = 0; // Param1
  2171. }
  2172. #endif
  2173. #endif
  2174. }
  2175. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2176. /// 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)
  2177. /// 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)
  2178. /// 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)
  2179. /// 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)
  2180. /// 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)
  2181. /// 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)
  2182. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2183. {
  2184. int fd, header, offs=0;
  2185. #if PACKETVER < 20061218
  2186. header = 0xa0;
  2187. #elif PACKETVER < 20071002
  2188. header = 0x29a;
  2189. #elif PACKETVER < 20120925
  2190. header = 0x2d4;
  2191. #elif PACKETVER < 20150225
  2192. header = 0x990;
  2193. #elif PACKETVER < 20160921
  2194. header = 0xa0c;
  2195. #else
  2196. header = 0xa37;
  2197. #endif
  2198. nullpo_retv(sd);
  2199. fd = sd->fd;
  2200. if( !session_isActive(fd) ) //Sasuke-
  2201. return;
  2202. WFIFOHEAD(fd,packet_len(header));
  2203. if( fail )
  2204. {
  2205. WFIFOW(fd,offs+0) = header;
  2206. WFIFOW(fd,offs+2) = n+2;
  2207. WFIFOW(fd,offs+4) = amount;
  2208. WFIFOW(fd,offs+6) = 0;
  2209. WFIFOB(fd,offs+8) = 0;
  2210. WFIFOB(fd,offs+9) = 0;
  2211. WFIFOB(fd,offs+10) = 0;
  2212. WFIFOW(fd,offs+11) = 0;
  2213. WFIFOW(fd,offs+13) = 0;
  2214. WFIFOW(fd,offs+15) = 0;
  2215. WFIFOW(fd,offs+17) = 0;
  2216. #if PACKETVER < 20120925
  2217. WFIFOW(fd,offs+19) = 0;
  2218. #else
  2219. WFIFOL(fd,offs+19) = 0;
  2220. offs += 2;
  2221. #endif
  2222. WFIFOB(fd,offs+21) = 0;
  2223. WFIFOB(fd,offs+22) = fail;
  2224. #if PACKETVER >= 20061218
  2225. WFIFOL(fd,offs+23) = 0;
  2226. #endif
  2227. #if PACKETVER >= 20071002
  2228. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2229. #if PACKETVER >= 20150225
  2230. clif_add_random_options(WFIFOP(fd,offs+31), &sd->inventory.u.items_inventory[n]);
  2231. #if PACKETVER >= 20160921
  2232. WFIFOB(fd,offs+54) = 0; // Favorite
  2233. WFIFOW(fd,offs+55) = 0; // View ID
  2234. #endif
  2235. #endif
  2236. #endif
  2237. }
  2238. else
  2239. {
  2240. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2241. return;
  2242. WFIFOW(fd,offs+0) = header;
  2243. WFIFOW(fd,offs+2) = n+2;
  2244. WFIFOW(fd,offs+4) = amount;
  2245. if (sd->inventory_data[n]->view_id > 0)
  2246. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2247. else
  2248. WFIFOW(fd,offs+6)=sd->inventory.u.items_inventory[n].nameid;
  2249. WFIFOB(fd,offs+8)=sd->inventory.u.items_inventory[n].identify;
  2250. WFIFOB(fd,offs+9)=sd->inventory.u.items_inventory[n].attribute;
  2251. WFIFOB(fd,offs+10)=sd->inventory.u.items_inventory[n].refine;
  2252. clif_addcards(WFIFOP(fd,offs+11), &sd->inventory.u.items_inventory[n]);
  2253. #if PACKETVER < 20120925
  2254. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2255. #else
  2256. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2257. offs += 2;
  2258. #endif
  2259. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2260. WFIFOB(fd,offs+22) = fail;
  2261. #if PACKETVER >= 20061218
  2262. WFIFOL(fd,offs+23)=sd->inventory.u.items_inventory[n].expire_time;
  2263. #endif
  2264. #if PACKETVER >= 20071002
  2265. /* Yellow color only for non-stackable item */
  2266. 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;
  2267. #endif
  2268. #if PACKETVER >= 20150225
  2269. clif_add_random_options(WFIFOP(fd,31), &sd->inventory.u.items_inventory[n]);
  2270. #if PACKETVER >= 20160921
  2271. WFIFOB(fd,offs+54) = sd->inventory.u.items_inventory[n].favorite;
  2272. WFIFOW(fd,offs+55) = sd->inventory_data[n]->look;
  2273. #endif
  2274. #endif
  2275. }
  2276. WFIFOSET(fd,packet_len(header));
  2277. }
  2278. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2279. /// 00af <index>.W <amount>.W
  2280. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2281. {
  2282. int fd;
  2283. nullpo_retv(sd);
  2284. fd=sd->fd;
  2285. WFIFOHEAD(fd, packet_len(0xaf));
  2286. WFIFOW(fd,0)=0xaf;
  2287. WFIFOW(fd,2)=n+2;
  2288. WFIFOW(fd,4)=amount;
  2289. WFIFOSET(fd,packet_len(0xaf));
  2290. }
  2291. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2292. /// 07fa <delete type>.W <index>.W <amount>.W
  2293. /// delete type:
  2294. /// 0 = Normal
  2295. /// 1 = Item used for a skill
  2296. /// 2 = Refine failed
  2297. /// 3 = Material changed
  2298. /// 4 = Moved to storage
  2299. /// 5 = Moved to cart
  2300. /// 6 = Item sold
  2301. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2302. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2303. {
  2304. #if PACKETVER < 20091117
  2305. clif_dropitem(sd,n,amount);
  2306. #else
  2307. int fd;
  2308. nullpo_retv(sd);
  2309. fd=sd->fd;
  2310. WFIFOHEAD(fd, packet_len(0x7fa));
  2311. WFIFOW(fd,0)=0x7fa;
  2312. WFIFOW(fd,2)=reason;
  2313. WFIFOW(fd,4)=n+2;
  2314. WFIFOW(fd,6)=amount;
  2315. WFIFOSET(fd,packet_len(0x7fa));
  2316. #endif
  2317. }
  2318. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2319. char normal = (equip < 0);
  2320. int offset = 0;
  2321. WBUFW(buf,n) = idx; //index
  2322. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2323. WBUFB(buf,n+4) = itemtype(id->nameid);
  2324. if (!normal){ //equip 31B
  2325. WBUFL(buf,n+5) = equip; //location
  2326. WBUFL(buf,n+9) = it->equip; //wear state
  2327. WBUFB(buf,n+13) = it->refine; //refine lvl
  2328. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2329. WBUFL(buf,n+22) = it->expire_time;
  2330. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2331. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2332. #if PACKETVER >= 20150225
  2333. //V6_ITEM_Option
  2334. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2335. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2336. offset += 26;
  2337. #endif
  2338. //V5_ITEM_flag
  2339. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2340. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2341. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2342. }
  2343. else { //normal 24B
  2344. WBUFW(buf,n+5) = it->amount;
  2345. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2346. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2347. WBUFL(buf,n+19) = it->expire_time;
  2348. //V5_ITEM_flag
  2349. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2350. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2351. }
  2352. }
  2353. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2354. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2355. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2356. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2357. #if PACKETVER >= 20120925
  2358. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2359. #else
  2360. WBUFW(buf,n) = idx; //index
  2361. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2362. WBUFB(buf,n+4) = itemtype(id->nameid);
  2363. WBUFB(buf,n+5) = it->identify;
  2364. if (equip >= 0) { //Equippable item 28.B
  2365. WBUFW(buf,n+6) = equip;
  2366. WBUFW(buf,n+8) = it->equip;
  2367. WBUFB(buf,n+10) = it->attribute;
  2368. WBUFB(buf,n+11) = it->refine;
  2369. clif_addcards(WBUFP(buf, n+12), it); //8B
  2370. #if PACKETVER >= 20071002
  2371. WBUFL(buf,n+20) = it->expire_time;
  2372. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2373. #endif
  2374. #if PACKETVER >= 20100629
  2375. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2376. #endif
  2377. } else { //Stackable item. 22.B
  2378. WBUFW(buf,n+6) = it->amount;
  2379. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2380. clif_addcards(WBUFP(buf, n+10), it); //8B
  2381. #if PACKETVER >= 20071002
  2382. WBUFL(buf,n+18) = it->expire_time;
  2383. #endif
  2384. }
  2385. #endif
  2386. }
  2387. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2388. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2389. void clif_inventorylist(struct map_session_data *sd) {
  2390. int i,n,ne,arrow=-1;
  2391. unsigned char *buf;
  2392. unsigned char *bufe;
  2393. #if PACKETVER < 5
  2394. const int s = 10; //Entry size
  2395. #elif PACKETVER < 20080102
  2396. const int s = 18;
  2397. #elif PACKETVER < 20120925
  2398. const int s = 22;
  2399. #else
  2400. const int s = 24;
  2401. #endif
  2402. #if PACKETVER < 20071002
  2403. const int se = 20;
  2404. #elif PACKETVER < 20100629
  2405. const int se = 26;
  2406. #elif PACKETVER < 20120925
  2407. const int se = 28;
  2408. #elif PACKETVER < 20150225
  2409. const int se = 31;
  2410. #else
  2411. const int se = 57;
  2412. #endif
  2413. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2414. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2415. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2416. {
  2417. if( sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2418. continue;
  2419. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2420. { //Non-stackable (Equippable)
  2421. clif_item_sub(bufe, ne*se+4, i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2422. ne++;
  2423. }
  2424. else { //Stackable.
  2425. clif_item_sub(buf, n*s+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], -2);
  2426. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->inventory.u.items_inventory[i].equip )
  2427. arrow=i;
  2428. n++;
  2429. }
  2430. }
  2431. if( n )
  2432. {
  2433. #if PACKETVER < 5
  2434. WBUFW(buf,0)=0xa3;
  2435. #elif PACKETVER < 20080102
  2436. WBUFW(buf,0)=0x1ee;
  2437. #elif PACKETVER < 20120925
  2438. WBUFW(buf,0)=0x2e8;
  2439. #else
  2440. WBUFW(buf,0)=0x991;
  2441. #endif
  2442. WBUFW(buf,2)=4+n*s;
  2443. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2444. }
  2445. if( arrow >= 0 )
  2446. clif_arrowequip(sd,arrow);
  2447. if( ne ) {
  2448. #if PACKETVER < 20071002
  2449. WBUFW(bufe,0)=0xa4;
  2450. #elif PACKETVER < 20120925
  2451. WBUFW(bufe,0)=0x2d0;
  2452. #elif PACKETVER < 20150225
  2453. WBUFW(bufe,0)=0x992;
  2454. #else
  2455. WBUFW(bufe,0)=0xa0d;
  2456. #endif
  2457. WBUFW(bufe,2)=4+ne*se;
  2458. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2459. }
  2460. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2461. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2462. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2463. continue;
  2464. if ( sd->inventory.u.items_inventory[i].favorite )
  2465. clif_favorite_item(sd, i);
  2466. }
  2467. #endif
  2468. if( buf ) aFree(buf);
  2469. if( bufe ) aFree(bufe);
  2470. }
  2471. //Required when items break/get-repaired. Only sends equippable item list.
  2472. void clif_equiplist(struct map_session_data *sd)
  2473. {
  2474. int i,n,fd = sd->fd;
  2475. unsigned char *buf;
  2476. #if PACKETVER < 20071002
  2477. const int cmd = 20;
  2478. #elif PACKETVER < 20100629
  2479. const int cmd = 26;
  2480. #elif PACKETVER < 20120925
  2481. const int cmd = 28;
  2482. #elif PACKETVER < 20150225
  2483. const int cmd = 31;
  2484. #else
  2485. const int cmd = 57;
  2486. #endif
  2487. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2488. buf = WFIFOP(fd,0);
  2489. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2490. if (sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2491. continue;
  2492. if(itemdb_isstackable2(sd->inventory_data[i]))
  2493. continue;
  2494. //Equippable
  2495. clif_item_sub(buf, n*cmd+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2496. n++;
  2497. }
  2498. if (n) {
  2499. #if PACKETVER < 20071002
  2500. WBUFW(buf,0)=0xa4;
  2501. #elif PACKETVER < 20120925
  2502. WBUFW(buf,0)=0x2d0;
  2503. #elif PACKETVER < 20150225
  2504. WBUFW(buf,0)=0x992;
  2505. #else
  2506. WBUFW(buf,0)=0xa0d;
  2507. #endif
  2508. WBUFW(buf,2)=4+n*cmd;
  2509. WFIFOSET(fd,WFIFOW(fd,2));
  2510. }
  2511. }
  2512. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename)
  2513. {
  2514. static const int client_buf = 0x5000; // Max buffer to send
  2515. struct item_data *id;
  2516. int i,n,ne,nn;
  2517. unsigned char *buf;
  2518. unsigned char *bufe;
  2519. #if PACKETVER < 5
  2520. const int s = 10; //Entry size.normal item
  2521. const int sidx=4; //start itemlist idx
  2522. const int cmd = 0xa5;
  2523. #elif PACKETVER < 20080102
  2524. const int s = 18;
  2525. const int sidx=4;
  2526. const int cmd = 0x1f0;
  2527. #elif PACKETVER < 20120925
  2528. const int s = 22;
  2529. const int sidx=4;
  2530. const int cmd = 0x2ea;
  2531. #else
  2532. const int s = 24;
  2533. const int sidx = 4+24;
  2534. const int cmd = 0x995;
  2535. #endif
  2536. #if PACKETVER < 20071002
  2537. const int se = 20; //entry size equip
  2538. const int sidxe = 4; //start itemlist idx
  2539. const int cmde = 0xa6;
  2540. #elif PACKETVER < 20100629
  2541. const int se = 26;
  2542. const int sidxe = 4;
  2543. const int cmde = 0x2d1;
  2544. #elif PACKETVER < 20120925
  2545. const int se = 28;
  2546. const int sidxe = 4;
  2547. const int cmde = 0x2d1;
  2548. #elif PACKETVER < 20150225
  2549. const int se = 31;
  2550. const int sidxe = 4+24;
  2551. const int cmde = 0x996;
  2552. #else
  2553. const int se = 57;
  2554. const int sidxe = 4+24;
  2555. const int cmde = 0xa10;
  2556. #endif
  2557. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2558. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2559. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2560. {
  2561. if( items[i].nameid <= 0 )
  2562. continue;
  2563. id = itemdb_search(items[i].nameid);
  2564. if( !itemdb_isstackable2(id) ) { //Equippable
  2565. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2566. ne++;
  2567. }
  2568. else { //Stackable
  2569. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2570. n++;
  2571. }
  2572. }
  2573. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2574. {
  2575. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2576. WFIFOHEAD(sd->fd,sidx+nn*s);
  2577. WFIFOW(sd->fd,0)=cmd;
  2578. WFIFOW(sd->fd,2)=sidx+nn*s;
  2579. #if PACKETVER >= 20120925
  2580. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2581. #endif
  2582. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2583. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2584. }
  2585. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2586. {
  2587. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2588. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2589. WFIFOW(sd->fd,0)=cmde;
  2590. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2591. #if PACKETVER >= 20120925
  2592. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2593. #endif
  2594. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2595. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2596. }
  2597. // Empty storage
  2598. if (n == 0 && ne == 0) {
  2599. WFIFOHEAD(sd->fd, 4+NAME_LENGTH);
  2600. WFIFOW(sd->fd,0) = cmd;
  2601. WFIFOW(sd->fd,2) = 4+NAME_LENGTH;
  2602. #if PACKETVER >= 20120925
  2603. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2604. #endif
  2605. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2606. }
  2607. if( buf ) aFree(buf);
  2608. if( bufe ) aFree(bufe);
  2609. }
  2610. void clif_cartlist(struct map_session_data *sd)
  2611. {
  2612. struct item_data *id;
  2613. int i,n,ne;
  2614. unsigned char *buf;
  2615. unsigned char *bufe;
  2616. #if PACKETVER < 5
  2617. const int s = 10; //Entry size.
  2618. #elif PACKETVER < 20080102
  2619. const int s = 18;
  2620. #elif PACKETVER < 20120925
  2621. const int s = 22;
  2622. #else
  2623. const int s = 24;
  2624. #endif
  2625. #if PACKETVER < 20071002
  2626. const int cmd = 20;
  2627. #elif PACKETVER < 20100629
  2628. const int cmd = 26;
  2629. #elif PACKETVER < 20120925
  2630. const int cmd = 28;
  2631. #elif PACKETVER < 20150225
  2632. const int cmd = 31;
  2633. #else
  2634. const int cmd = 57;
  2635. #endif
  2636. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2637. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2638. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2639. {
  2640. if( sd->cart.u.items_cart[i].nameid <= 0 )
  2641. continue;
  2642. id = itemdb_search(sd->cart.u.items_cart[i].nameid);
  2643. if( !itemdb_isstackable2(id) ) { //Equippable
  2644. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->cart.u.items_cart[i], id, id->equip);
  2645. ne++;
  2646. }
  2647. else { //Stackable
  2648. clif_item_sub(buf, n*s+4,i+2, &sd->cart.u.items_cart[i], id,-1);
  2649. n++;
  2650. }
  2651. }
  2652. if( n )
  2653. {
  2654. #if PACKETVER < 5
  2655. WBUFW(buf,0)=0x123;
  2656. #elif PACKETVER < 20080102
  2657. WBUFW(buf,0)=0x1ef;
  2658. #elif PACKETVER < 20120925
  2659. WBUFW(buf,0)=0x2e9;
  2660. #else
  2661. WBUFW(buf,0)=0x993;
  2662. #endif
  2663. WBUFW(buf,2)=4+n*s;
  2664. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2665. }
  2666. if( ne )
  2667. {
  2668. #if PACKETVER < 20071002
  2669. WBUFW(bufe,0)=0x122;
  2670. #elif PACKETVER < 20120925
  2671. WBUFW(bufe,0)=0x2d2;
  2672. #elif PACKETVER < 20150225
  2673. WBUFW(bufe,0)=0x994;
  2674. #else
  2675. WBUFW(bufe,0)=0xa0f;
  2676. #endif
  2677. WBUFW(bufe,2)=4+ne*cmd;
  2678. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2679. }
  2680. if( buf ) aFree(buf);
  2681. if( bufe ) aFree(bufe);
  2682. }
  2683. /// Removes cart (ZC_CARTOFF).
  2684. /// 012b
  2685. /// Client behaviour:
  2686. /// Closes the cart storage and removes all it's items from memory.
  2687. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2688. void clif_clearcart(int fd)
  2689. {
  2690. WFIFOHEAD(fd, packet_len(0x12b));
  2691. WFIFOW(fd,0) = 0x12b;
  2692. WFIFOSET(fd, packet_len(0x12b));
  2693. }
  2694. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2695. /// 01eb <account id>.L <x>.W <y>.W
  2696. void clif_guild_xy(struct map_session_data *sd)
  2697. {
  2698. unsigned char buf[10];
  2699. nullpo_retv(sd);
  2700. WBUFW(buf,0)=0x1eb;
  2701. WBUFL(buf,2)=sd->status.account_id;
  2702. WBUFW(buf,6)=sd->bl.x;
  2703. WBUFW(buf,8)=sd->bl.y;
  2704. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2705. }
  2706. /*==========================================
  2707. * Sends x/y dot to a single fd. [Skotlex]
  2708. *------------------------------------------*/
  2709. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2710. {
  2711. if( sd->bg_id )
  2712. return;
  2713. WFIFOHEAD(fd,packet_len(0x1eb));
  2714. WFIFOW(fd,0)=0x1eb;
  2715. WFIFOL(fd,2)=sd->status.account_id;
  2716. WFIFOW(fd,6)=sd->bl.x;
  2717. WFIFOW(fd,8)=sd->bl.y;
  2718. WFIFOSET(fd,packet_len(0x1eb));
  2719. }
  2720. // Guild XY locators [Valaris]
  2721. void clif_guild_xy_remove(struct map_session_data *sd)
  2722. {
  2723. unsigned char buf[10];
  2724. nullpo_retv(sd);
  2725. WBUFW(buf,0)=0x1eb;
  2726. WBUFL(buf,2)=sd->status.account_id;
  2727. WBUFW(buf,6)=-1;
  2728. WBUFW(buf,8)=-1;
  2729. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2730. }
  2731. /*==========================================
  2732. *
  2733. *------------------------------------------*/
  2734. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2735. {
  2736. struct map_session_data *sd, *tsd;
  2737. #if PACKETVER < 20100126
  2738. const int cmd = 0x106;
  2739. #else
  2740. const int cmd = 0x80e;
  2741. #endif
  2742. sd = va_arg(ap, struct map_session_data *);
  2743. tsd = (TBL_PC *)bl;
  2744. nullpo_ret(sd);
  2745. nullpo_ret(tsd);
  2746. if( !tsd->fd || tsd == sd )
  2747. return 0;
  2748. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2749. return 0;
  2750. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2751. WFIFOW(tsd->fd,0) = cmd;
  2752. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2753. #if PACKETVER < 20100126
  2754. if( sd->battle_status.max_hp > INT16_MAX )
  2755. { //To correctly display the %hp bar. [Skotlex]
  2756. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2757. WFIFOW(tsd->fd,8) = 100;
  2758. } else {
  2759. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2760. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2761. }
  2762. #else
  2763. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2764. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2765. #endif
  2766. WFIFOSET(tsd->fd,packet_len(cmd));
  2767. return 0;
  2768. }
  2769. /*==========================================
  2770. * Server tells all players that are allowed to view HP bars
  2771. * and are nearby 'sd' that 'sd' hp bar was updated.
  2772. *------------------------------------------*/
  2773. static int clif_hpmeter(struct map_session_data *sd)
  2774. {
  2775. nullpo_ret(sd);
  2776. 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);
  2777. return 0;
  2778. }
  2779. /// Notifies client of a character parameter change.
  2780. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2781. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2782. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2783. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2784. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2785. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2786. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2787. /// TODO: Extract individual packets.
  2788. /// FIXME: Packet lengths from packet_len(cmd)
  2789. void clif_updatestatus(struct map_session_data *sd,int type)
  2790. {
  2791. int fd,len=8;
  2792. nullpo_retv(sd);
  2793. fd=sd->fd;
  2794. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2795. return;
  2796. WFIFOHEAD(fd, 14);
  2797. WFIFOW(fd,0)=0xb0;
  2798. WFIFOW(fd,2)=type;
  2799. switch(type){
  2800. // 00b0
  2801. case SP_WEIGHT:
  2802. pc_updateweightstatus(sd);
  2803. WFIFOHEAD(fd,14);
  2804. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2805. WFIFOW(fd,2)=type;
  2806. WFIFOL(fd,4)=sd->weight;
  2807. break;
  2808. case SP_MAXWEIGHT:
  2809. WFIFOL(fd,4)=sd->max_weight;
  2810. break;
  2811. case SP_SPEED:
  2812. WFIFOL(fd,4)=sd->battle_status.speed;
  2813. break;
  2814. case SP_BASELEVEL:
  2815. WFIFOL(fd,4)=sd->status.base_level;
  2816. break;
  2817. case SP_JOBLEVEL:
  2818. WFIFOL(fd,4)=sd->status.job_level;
  2819. break;
  2820. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2821. WFIFOL(fd,4)=sd->status.karma;
  2822. break;
  2823. case SP_MANNER:
  2824. WFIFOL(fd,4)=sd->status.manner;
  2825. break;
  2826. case SP_STATUSPOINT:
  2827. WFIFOL(fd,4)=sd->status.status_point;
  2828. break;
  2829. case SP_SKILLPOINT:
  2830. WFIFOL(fd,4)=sd->status.skill_point;
  2831. break;
  2832. case SP_HIT:
  2833. WFIFOL(fd,4)=sd->battle_status.hit;
  2834. break;
  2835. case SP_FLEE1:
  2836. WFIFOL(fd,4)=sd->battle_status.flee;
  2837. break;
  2838. case SP_FLEE2:
  2839. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2840. break;
  2841. case SP_MAXHP:
  2842. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2843. break;
  2844. case SP_MAXSP:
  2845. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2846. break;
  2847. case SP_HP:
  2848. // On officials the HP never go below 1, even if you die [Lemongrass]
  2849. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2850. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2851. break;
  2852. case SP_SP:
  2853. WFIFOL(fd,4)=sd->battle_status.sp;
  2854. break;
  2855. case SP_ASPD:
  2856. WFIFOL(fd,4)=sd->battle_status.amotion;
  2857. break;
  2858. case SP_ATK1:
  2859. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2860. break;
  2861. case SP_DEF1:
  2862. WFIFOL(fd,4)=pc_leftside_def(sd);
  2863. break;
  2864. case SP_MDEF1:
  2865. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2866. break;
  2867. case SP_ATK2:
  2868. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2869. break;
  2870. case SP_DEF2:
  2871. WFIFOL(fd,4)=pc_rightside_def(sd);
  2872. break;
  2873. case SP_MDEF2: {
  2874. //negative check (in case you have something like Berserk active)
  2875. int mdef2 = pc_rightside_mdef(sd);
  2876. WFIFOL(fd,4)=
  2877. #ifndef RENEWAL
  2878. ( mdef2 < 0 ) ? 0 :
  2879. #endif
  2880. mdef2;
  2881. }
  2882. break;
  2883. case SP_CRITICAL:
  2884. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2885. break;
  2886. case SP_MATK1:
  2887. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2888. break;
  2889. case SP_MATK2:
  2890. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2891. break;
  2892. case SP_ZENY:
  2893. WFIFOW(fd,0)=0xb1;
  2894. WFIFOL(fd,4)=sd->status.zeny;
  2895. break;
  2896. #if PACKETVER >= 20170830
  2897. case SP_BASEEXP:
  2898. WFIFOW(fd,0)=0xacb;
  2899. WFIFOQ(fd,4)=sd->status.base_exp;
  2900. len = packet_len(0xacb);
  2901. break;
  2902. case SP_JOBEXP:
  2903. WFIFOW(fd,0)=0xacb;
  2904. WFIFOQ(fd,4)=sd->status.job_exp;
  2905. len = packet_len(0xacb);
  2906. break;
  2907. case SP_NEXTBASEEXP:
  2908. WFIFOW(fd,0)=0xacb;
  2909. WFIFOQ(fd,4)=pc_nextbaseexp(sd);
  2910. len = packet_len(0xacb);
  2911. break;
  2912. case SP_NEXTJOBEXP:
  2913. WFIFOW(fd,0)=0xacb;
  2914. WFIFOQ(fd,4)=pc_nextjobexp(sd);
  2915. len = packet_len(0xacb);
  2916. break;
  2917. #else
  2918. case SP_BASEEXP:
  2919. WFIFOW(fd,0)=0xb1;
  2920. WFIFOL(fd,4)=sd->status.base_exp;
  2921. break;
  2922. case SP_JOBEXP:
  2923. WFIFOW(fd,0)=0xb1;
  2924. WFIFOL(fd,4)=sd->status.job_exp;
  2925. break;
  2926. case SP_NEXTBASEEXP:
  2927. WFIFOW(fd,0)=0xb1;
  2928. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2929. break;
  2930. case SP_NEXTJOBEXP:
  2931. WFIFOW(fd,0)=0xb1;
  2932. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2933. break;
  2934. #endif
  2935. /**
  2936. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2937. **/
  2938. case SP_USTR:
  2939. case SP_UAGI:
  2940. case SP_UVIT:
  2941. case SP_UINT:
  2942. case SP_UDEX:
  2943. case SP_ULUK:
  2944. WFIFOW(fd,0)=0xbe;
  2945. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2946. len=5;
  2947. break;
  2948. /**
  2949. * Tells the client how far it is allowed to attack (weapon range)
  2950. **/
  2951. case SP_ATTACKRANGE:
  2952. WFIFOW(fd,0)=0x13a;
  2953. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2954. len=4;
  2955. break;
  2956. case SP_STR:
  2957. WFIFOW(fd,0)=0x141;
  2958. WFIFOL(fd,2)=type;
  2959. WFIFOL(fd,6)=sd->status.str;
  2960. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2961. len=14;
  2962. break;
  2963. case SP_AGI:
  2964. WFIFOW(fd,0)=0x141;
  2965. WFIFOL(fd,2)=type;
  2966. WFIFOL(fd,6)=sd->status.agi;
  2967. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2968. len=14;
  2969. break;
  2970. case SP_VIT:
  2971. WFIFOW(fd,0)=0x141;
  2972. WFIFOL(fd,2)=type;
  2973. WFIFOL(fd,6)=sd->status.vit;
  2974. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2975. len=14;
  2976. break;
  2977. case SP_INT:
  2978. WFIFOW(fd,0)=0x141;
  2979. WFIFOL(fd,2)=type;
  2980. WFIFOL(fd,6)=sd->status.int_;
  2981. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2982. len=14;
  2983. break;
  2984. case SP_DEX:
  2985. WFIFOW(fd,0)=0x141;
  2986. WFIFOL(fd,2)=type;
  2987. WFIFOL(fd,6)=sd->status.dex;
  2988. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2989. len=14;
  2990. break;
  2991. case SP_LUK:
  2992. WFIFOW(fd,0)=0x141;
  2993. WFIFOL(fd,2)=type;
  2994. WFIFOL(fd,6)=sd->status.luk;
  2995. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2996. len=14;
  2997. break;
  2998. case SP_CARTINFO:
  2999. WFIFOW(fd,0)=0x121;
  3000. WFIFOW(fd,2)=sd->cart_num;
  3001. WFIFOW(fd,4)=MAX_CART;
  3002. WFIFOL(fd,6)=sd->cart_weight;
  3003. WFIFOL(fd,10)=sd->cart_weight_max;
  3004. len=14;
  3005. break;
  3006. default:
  3007. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3008. return;
  3009. }
  3010. WFIFOSET(fd,len);
  3011. // Additional update packets that should be sent right after
  3012. switch( type ){
  3013. case SP_BASELEVEL:
  3014. if( sd->status.party_id ){
  3015. struct party_data* p;
  3016. int i;
  3017. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3018. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3019. if( i < MAX_PARTY ){
  3020. p->party.member[i].lv = sd->status.base_level;
  3021. clif_party_job_and_level(sd);
  3022. }
  3023. }
  3024. }
  3025. break;
  3026. case SP_HP:
  3027. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3028. clif_hpmeter(sd);
  3029. }
  3030. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3031. clif_party_hp(sd);
  3032. }
  3033. if( sd->bg_id ){
  3034. clif_bg_hp(sd);
  3035. }
  3036. break;
  3037. }
  3038. }
  3039. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3040. /// 01ab <account id>.L <var id>.W <value>.L
  3041. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3042. {
  3043. unsigned char buf[12];
  3044. nullpo_retv(sd);
  3045. WBUFW(buf,0)=0x1ab;
  3046. WBUFL(buf,2)=sd->bl.id;
  3047. WBUFW(buf,6)=type;
  3048. switch(type)
  3049. {
  3050. case SP_MANNER:
  3051. WBUFL(buf,8)=val;
  3052. break;
  3053. default:
  3054. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3055. return;
  3056. }
  3057. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3058. }
  3059. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3060. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3061. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  3062. unsigned char buf[32];
  3063. #if PACKETVER < 4
  3064. const int cmd = 0xc3;
  3065. #else
  3066. const int cmd = 0x1d7;
  3067. #endif
  3068. WBUFW(buf,0) = cmd;
  3069. WBUFL(buf,2) = id;
  3070. WBUFB(buf,6) = type;
  3071. WBUFW(buf,7) = val;
  3072. #if PACKETVER >= 4
  3073. WBUFW(buf,9) = val2;
  3074. #endif
  3075. clif_send(buf,packet_len(cmd), bl, target);
  3076. }
  3077. /// Updates sprite/style properties of an object.
  3078. void clif_changelook(struct block_list *bl, int type, int val) {
  3079. struct map_session_data* sd;
  3080. struct status_change* sc;
  3081. struct view_data* vd;
  3082. enum send_target target = AREA;
  3083. int val2 = 0;
  3084. nullpo_retv(bl);
  3085. sd = BL_CAST(BL_PC, bl);
  3086. sc = status_get_sc(bl);
  3087. vd = status_get_viewdata(bl);
  3088. if( vd ) //temp hack to let Warp Portal change appearance
  3089. switch(type) {
  3090. case LOOK_WEAPON:
  3091. if (sd) {
  3092. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3093. val = vd->weapon;
  3094. }
  3095. else
  3096. vd->weapon = val;
  3097. break;
  3098. case LOOK_SHIELD:
  3099. if (sd) {
  3100. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3101. val = vd->shield;
  3102. }
  3103. else
  3104. vd->shield = val;
  3105. break;
  3106. case LOOK_BASE:
  3107. if (!sd)
  3108. break;
  3109. if ( val == JT_INVISIBLE )
  3110. return;
  3111. if (sd->sc.option&OPTION_COSTUME)
  3112. vd->weapon = vd->shield = 0;
  3113. if (!vd->cloth_color)
  3114. break;
  3115. if (sd) {
  3116. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3117. vd->cloth_color = 0;
  3118. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3119. vd->cloth_color = 0;
  3120. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3121. vd->cloth_color = 0;
  3122. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3123. vd->cloth_color = 0;
  3124. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3125. vd->cloth_color = 0;
  3126. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3127. vd->body_style = 0;
  3128. }
  3129. break;
  3130. case LOOK_HAIR:
  3131. vd->hair_style = val;
  3132. break;
  3133. case LOOK_HEAD_BOTTOM:
  3134. vd->head_bottom = val;
  3135. break;
  3136. case LOOK_HEAD_TOP:
  3137. vd->head_top = val;
  3138. break;
  3139. case LOOK_HEAD_MID:
  3140. vd->head_mid = val;
  3141. break;
  3142. case LOOK_HAIR_COLOR:
  3143. vd->hair_color = val;
  3144. break;
  3145. case LOOK_CLOTHES_COLOR:
  3146. if (val && sd) {
  3147. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3148. val = 0;
  3149. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3150. val = 0;
  3151. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3152. val = 0;
  3153. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3154. val = 0;
  3155. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3156. val = 0;
  3157. }
  3158. vd->cloth_color = val;
  3159. break;
  3160. case LOOK_SHOES:
  3161. #if PACKETVER > 3
  3162. if (sd) {
  3163. int n;
  3164. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3165. if(sd->inventory_data[n]->view_id > 0)
  3166. val = sd->inventory_data[n]->view_id;
  3167. else
  3168. val = sd->inventory.u.items_inventory[n].nameid;
  3169. } else
  3170. val = 0;
  3171. }
  3172. #endif
  3173. //Shoes? No packet uses this....
  3174. break;
  3175. case LOOK_BODY:
  3176. // unknown purpose
  3177. break;
  3178. case LOOK_ROBE:
  3179. #if PACKETVER < 20110111
  3180. return;
  3181. #else
  3182. vd->robe = val;
  3183. #endif
  3184. break;
  3185. case LOOK_BODY2:
  3186. #if PACKETVER < 20150513
  3187. return;
  3188. #else
  3189. if (val && sd->sc.option&OPTION_COSTUME)
  3190. val = 0;
  3191. vd->body_style = val;
  3192. #endif
  3193. break;
  3194. }
  3195. // prevent leaking the presence of GM-hidden objects
  3196. if( sc && sc->option&OPTION_INVISIBLE )
  3197. target = SELF;
  3198. #if PACKETVER < 4
  3199. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3200. #else
  3201. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3202. nullpo_retv(vd);
  3203. type = LOOK_WEAPON;
  3204. val = vd->weapon;
  3205. val2 = vd->shield;
  3206. }
  3207. if( disguised(bl) ) {
  3208. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3209. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3210. } else
  3211. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3212. #endif
  3213. }
  3214. //Sends a change-base-look packet required for traps as they are triggered.
  3215. void clif_changetraplook(struct block_list *bl,int val) {
  3216. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3217. }
  3218. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3219. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3220. clif_sprite_change(bl, id, type, val, 0, target);
  3221. }
  3222. /// Character status (ZC_STATUS).
  3223. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3224. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3225. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3226. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3227. void clif_initialstatus(struct map_session_data *sd) {
  3228. int fd, mdef2;
  3229. unsigned char *buf;
  3230. nullpo_retv(sd);
  3231. fd=sd->fd;
  3232. WFIFOHEAD(fd, packet_len(0xbd));
  3233. buf = WFIFOP(fd,0);
  3234. WBUFW(buf,0) = 0xbd;
  3235. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3236. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3237. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3238. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3239. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3240. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3241. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3242. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3243. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3244. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3245. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3246. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3247. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3248. WBUFW(buf,16) = pc_leftside_atk(sd);
  3249. WBUFW(buf,18) = pc_rightside_atk(sd);
  3250. WBUFW(buf,20) = pc_rightside_matk(sd);
  3251. WBUFW(buf,22) = pc_leftside_matk(sd);
  3252. WBUFW(buf,24) = pc_leftside_def(sd);
  3253. WBUFW(buf,26) = pc_rightside_def(sd);
  3254. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3255. mdef2 = pc_rightside_mdef(sd);
  3256. WBUFW(buf,30) =
  3257. #ifndef RENEWAL
  3258. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3259. #endif
  3260. mdef2;
  3261. WBUFW(buf,32) = sd->battle_status.hit;
  3262. WBUFW(buf,34) = sd->battle_status.flee;
  3263. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3264. WBUFW(buf,38) = sd->battle_status.cri/10;
  3265. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3266. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3267. WFIFOSET(fd, packet_len(0xbd));
  3268. clif_updatestatus(sd, SP_STR);
  3269. clif_updatestatus(sd, SP_AGI);
  3270. clif_updatestatus(sd, SP_VIT);
  3271. clif_updatestatus(sd, SP_INT);
  3272. clif_updatestatus(sd, SP_DEX);
  3273. clif_updatestatus(sd, SP_LUK);
  3274. clif_updatestatus(sd, SP_ATTACKRANGE);
  3275. clif_updatestatus(sd, SP_ASPD);
  3276. }
  3277. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3278. /// 013c <index>.W
  3279. void clif_arrowequip(struct map_session_data *sd,int val) {
  3280. int fd;
  3281. nullpo_retv(sd);
  3282. #if PACKETVER >= 20121128
  3283. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3284. #endif
  3285. fd=sd->fd;
  3286. WFIFOHEAD(fd, packet_len(0x013c));
  3287. WFIFOW(fd,0) = 0x013c;
  3288. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3289. WFIFOSET(fd, packet_len(0x013c));
  3290. }
  3291. /// Ammunition action message (ZC_ACTION_FAILURE).
  3292. /// 013b <type>.W
  3293. /// type:
  3294. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3295. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3296. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3297. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3298. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3299. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3300. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3301. int fd;
  3302. nullpo_retv(sd);
  3303. fd=sd->fd;
  3304. WFIFOHEAD(fd, packet_len(0x013b));
  3305. WFIFOW(fd,0) = 0x013b;
  3306. WFIFOW(fd,2) = type;
  3307. WFIFOSET(fd, packet_len(0x013b));
  3308. }
  3309. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3310. /// 01ad <packet len>.W { <name id>.W }*
  3311. void clif_arrow_create_list(struct map_session_data *sd)
  3312. {
  3313. int i, c;
  3314. int fd;
  3315. nullpo_retv(sd);
  3316. fd = sd->fd;
  3317. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3318. WFIFOW(fd,0) = 0x1ad;
  3319. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3320. short j, nameid = skill_arrow_db[i].nameid;
  3321. if (nameid > 0 && itemdb_exists(nameid) &&
  3322. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3323. !sd->inventory.u.items_inventory[j].equip && sd->inventory.u.items_inventory[j].identify)
  3324. {
  3325. if ((j = itemdb_viewid(nameid)) > 0)
  3326. WFIFOW(fd,c*2+4) = j;
  3327. else
  3328. WFIFOW(fd,c*2+4) = nameid;
  3329. c++;
  3330. }
  3331. }
  3332. WFIFOW(fd,2) = c*2+4;
  3333. WFIFOSET(fd, WFIFOW(fd,2));
  3334. if (c > 0) {
  3335. sd->menuskill_id = AC_MAKINGARROW;
  3336. sd->menuskill_val = c;
  3337. }
  3338. }
  3339. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3340. /// 00bc <status id>.W <result>.B <value>.B
  3341. /// status id:
  3342. /// SP_STR ~ SP_LUK
  3343. /// result:
  3344. /// 0 = failure
  3345. /// 1 = success
  3346. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3347. int fd;
  3348. nullpo_retv(sd);
  3349. fd=sd->fd;
  3350. WFIFOHEAD(fd, packet_len(0xbc));
  3351. WFIFOW(fd,0) = 0xbc;
  3352. WFIFOW(fd,2) = type;
  3353. WFIFOB(fd,4) = ok;
  3354. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3355. WFIFOSET(fd, packet_len(0xbc));
  3356. }
  3357. /// Notifies the client about the result of a request to equip an item.
  3358. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3359. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3360. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3361. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3362. /// @ok: //inversed forv2 v5
  3363. /// 0 = failure
  3364. /// 1 = success
  3365. /// 2 = failure due to low level
  3366. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3367. {
  3368. int fd = 0, cmd = 0, look = 0;
  3369. struct s_packet_db *info = NULL;
  3370. nullpo_retv(sd);
  3371. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3372. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3373. return;
  3374. fd = sd->fd;
  3375. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3376. look = sd->inventory_data[n]->look;
  3377. WFIFOHEAD(fd, info->len);
  3378. WFIFOW(fd, 0) = cmd;
  3379. WFIFOW(fd, info->pos[0]) = n+2;
  3380. switch (cmd) {
  3381. case 0xaa:
  3382. WFIFOW(fd, info->pos[1]) = pos;
  3383. #if PACKETVER < 20100629
  3384. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3385. #else
  3386. WFIFOL(fd, info->pos[2]) = look;
  3387. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3388. #endif
  3389. break;
  3390. case 0x8d0:
  3391. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3392. flag = 1;
  3393. case 0x999:
  3394. if (cmd == 0x999)
  3395. WFIFOL(fd, info->pos[1]) = pos;
  3396. else
  3397. WFIFOW(fd, info->pos[1]) = pos;
  3398. WFIFOL(fd, info->pos[2]) = look;
  3399. WFIFOW(fd, info->pos[3]) = flag;
  3400. break;
  3401. }
  3402. WFIFOSET(fd, info->len);
  3403. }
  3404. /// Notifies the client about the result of a request to take off an item.
  3405. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3406. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3407. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3408. /// @ok : //inversed for v2 v5
  3409. /// 0 = failure
  3410. /// 1 = success
  3411. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3412. {
  3413. int fd, header, offs = 0;
  3414. #if PACKETVER >= 20130000
  3415. header = 0x99a;
  3416. ok = ok ? 0 : 1;
  3417. #elif PACKETVER >= 20110824
  3418. header = 0x8d1;
  3419. ok = ok ? 0 : 1;
  3420. #else
  3421. header = 0xac;
  3422. #endif
  3423. nullpo_retv(sd);
  3424. fd=sd->fd;
  3425. WFIFOHEAD(fd, packet_len(header));
  3426. WFIFOW(fd,offs+0) = header;
  3427. WFIFOW(fd,offs+2) = n+2;
  3428. #if PACKETVER >= 20130000
  3429. WFIFOL(fd,offs+4) = pos;
  3430. offs += 2;
  3431. #else
  3432. WFIFOW(fd,offs+4) = pos;
  3433. #endif
  3434. WFIFOB(fd,offs+6) = ok;
  3435. WFIFOSET(fd, packet_len(header));
  3436. }
  3437. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3438. /// 019b <id>.L <effect id>.L
  3439. /// effect id:
  3440. /// 0 = base level up
  3441. /// 1 = job level up
  3442. /// 2 = refine failure
  3443. /// 3 = refine success
  3444. /// 4 = game over
  3445. /// 5 = pharmacy success
  3446. /// 6 = pharmacy failure
  3447. /// 7 = base level up (super novice)
  3448. /// 8 = job level up (super novice)
  3449. /// 9 = base level up (taekwon)
  3450. void clif_misceffect(struct block_list* bl,int type)
  3451. {
  3452. unsigned char buf[32];
  3453. nullpo_retv(bl);
  3454. WBUFW(buf,0) = 0x19b;
  3455. WBUFL(buf,2) = bl->id;
  3456. WBUFL(buf,6) = type;
  3457. clif_send(buf,packet_len(0x19b),bl,AREA);
  3458. }
  3459. /// Notifies clients in the area of a state change.
  3460. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3461. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3462. void clif_changeoption(struct block_list* bl)
  3463. {
  3464. unsigned char buf[32];
  3465. struct status_change *sc;
  3466. struct map_session_data* sd;
  3467. nullpo_retv(bl);
  3468. sc = status_get_sc(bl);
  3469. if (!sc) return; //How can an option change if there's no sc?
  3470. sd = BL_CAST(BL_PC, bl);
  3471. #if PACKETVER >= 7
  3472. WBUFW(buf,0) = 0x229;
  3473. WBUFL(buf,2) = bl->id;
  3474. WBUFW(buf,6) = sc->opt1;
  3475. WBUFW(buf,8) = sc->opt2;
  3476. WBUFL(buf,10) = sc->option;
  3477. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3478. if(disguised(bl)) {
  3479. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3480. WBUFL(buf,2) = -bl->id;
  3481. clif_send(buf,packet_len(0x229),bl,SELF);
  3482. WBUFL(buf,2) = bl->id;
  3483. WBUFL(buf,10) = OPTION_INVISIBLE;
  3484. clif_send(buf,packet_len(0x229),bl,SELF);
  3485. } else
  3486. clif_send(buf,packet_len(0x229),bl,AREA);
  3487. #else
  3488. WBUFW(buf,0) = 0x119;
  3489. WBUFL(buf,2) = bl->id;
  3490. WBUFW(buf,6) = sc->opt1;
  3491. WBUFW(buf,8) = sc->opt2;
  3492. WBUFW(buf,10) = sc->option;
  3493. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3494. if(disguised(bl)) {
  3495. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3496. WBUFL(buf,2) = -bl->id;
  3497. clif_send(buf,packet_len(0x119),bl,SELF);
  3498. WBUFL(buf,2) = bl->id;
  3499. WBUFW(buf,10) = OPTION_INVISIBLE;
  3500. clif_send(buf,packet_len(0x119),bl,SELF);
  3501. } else
  3502. clif_send(buf,packet_len(0x119),bl,AREA);
  3503. #endif
  3504. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3505. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3506. if (sc->data[SC_PROVOKE] && sc->data[SC_PROVOKE]->timer == INVALID_TIMER)
  3507. clif_status_change(bl, StatusIconChangeTable[SC_PROVOKE], 1, -1, 0, 0, 0);
  3508. }
  3509. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3510. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3511. void clif_changeoption2(struct block_list* bl)
  3512. {
  3513. unsigned char buf[20];
  3514. struct status_change *sc;
  3515. sc = status_get_sc(bl);
  3516. if (!sc) return; //How can an option change if there's no sc?
  3517. WBUFW(buf,0) = 0x28a;
  3518. WBUFL(buf,2) = bl->id;
  3519. WBUFL(buf,6) = sc->option;
  3520. WBUFL(buf,10) = clif_setlevel(bl);
  3521. WBUFL(buf,14) = sc->opt3;
  3522. if(disguised(bl)) {
  3523. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3524. WBUFL(buf,2) = -bl->id;
  3525. clif_send(buf,packet_len(0x28a),bl,SELF);
  3526. WBUFL(buf,2) = bl->id;
  3527. WBUFL(buf,6) = OPTION_INVISIBLE;
  3528. clif_send(buf,packet_len(0x28a),bl,SELF);
  3529. } else
  3530. clif_send(buf,packet_len(0x28a),bl,AREA);
  3531. }
  3532. /// Notifies the client about the result of an item use request.
  3533. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3534. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3535. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3536. {
  3537. nullpo_retv(sd);
  3538. if(!ok) {
  3539. int fd=sd->fd;
  3540. WFIFOHEAD(fd,packet_len(0xa8));
  3541. WFIFOW(fd,0)=0xa8;
  3542. WFIFOW(fd,2)=index+2;
  3543. WFIFOW(fd,4)=amount;
  3544. WFIFOB(fd,6)=ok;
  3545. WFIFOSET(fd,packet_len(0xa8));
  3546. }
  3547. else {
  3548. #if PACKETVER < 3
  3549. int fd=sd->fd;
  3550. WFIFOHEAD(fd,packet_len(0xa8));
  3551. WFIFOW(fd,0)=0xa8;
  3552. WFIFOW(fd,2)=index+2;
  3553. WFIFOW(fd,4)=amount;
  3554. WFIFOB(fd,6)=ok;
  3555. WFIFOSET(fd,packet_len(0xa8));
  3556. #else
  3557. unsigned char buf[32];
  3558. WBUFW(buf,0)=0x1c8;
  3559. WBUFW(buf,2)=index+2;
  3560. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3561. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3562. else
  3563. WBUFW(buf,4)=sd->inventory.u.items_inventory[index].nameid;
  3564. WBUFL(buf,6)=sd->bl.id;
  3565. WBUFW(buf,10)=amount;
  3566. WBUFB(buf,12)=ok;
  3567. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3568. #endif
  3569. }
  3570. }
  3571. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3572. /// 00d6 <flag>.B
  3573. /// flag:
  3574. /// 0 = Room has been successfully created (opens chat room)
  3575. /// 1 = Room limit exceeded
  3576. /// 2 = Same room already exists
  3577. void clif_createchat(struct map_session_data* sd, int flag)
  3578. {
  3579. int fd;
  3580. nullpo_retv(sd);
  3581. fd = sd->fd;
  3582. WFIFOHEAD(fd,packet_len(0xd6));
  3583. WFIFOW(fd,0) = 0xd6;
  3584. WFIFOB(fd,2) = flag;
  3585. WFIFOSET(fd,packet_len(0xd6));
  3586. }
  3587. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3588. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3589. /// type:
  3590. /// 0 = private (password protected)
  3591. /// 1 = public
  3592. /// 2 = arena (npc waiting room)
  3593. /// 3 = PK zone (non-clickable)
  3594. void clif_dispchat(struct chat_data* cd, int fd)
  3595. {
  3596. unsigned char buf[128];
  3597. uint8 type;
  3598. if( cd == NULL || cd->owner == NULL )
  3599. return;
  3600. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3601. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3602. : 1;
  3603. WBUFW(buf, 0) = 0xd7;
  3604. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3605. WBUFL(buf, 4) = cd->owner->id;
  3606. WBUFL(buf, 8) = cd->bl.id;
  3607. WBUFW(buf,12) = cd->limit;
  3608. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3609. WBUFB(buf,16) = type;
  3610. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3611. if( fd ) {
  3612. WFIFOHEAD(fd,WBUFW(buf,2));
  3613. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3614. WFIFOSET(fd,WBUFW(buf,2));
  3615. } else {
  3616. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3617. }
  3618. }
  3619. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3620. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3621. /// type:
  3622. /// 0 = private (password protected)
  3623. /// 1 = public
  3624. /// 2 = arena (npc waiting room)
  3625. /// 3 = PK zone (non-clickable)
  3626. void clif_changechatstatus(struct chat_data* cd)
  3627. {
  3628. unsigned char buf[128];
  3629. uint8 type;
  3630. if( cd == NULL || cd->usersd[0] == NULL )
  3631. return;
  3632. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3633. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3634. : 1;
  3635. WBUFW(buf, 0) = 0xdf;
  3636. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3637. WBUFL(buf, 4) = cd->owner->id;
  3638. WBUFL(buf, 8) = cd->bl.id;
  3639. WBUFW(buf,12) = cd->limit;
  3640. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3641. WBUFB(buf,16) = type;
  3642. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3643. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3644. }
  3645. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3646. /// 00d8 <chat id>.L
  3647. void clif_clearchat(struct chat_data *cd,int fd)
  3648. {
  3649. unsigned char buf[32];
  3650. nullpo_retv(cd);
  3651. WBUFW(buf,0) = 0xd8;
  3652. WBUFL(buf,2) = cd->bl.id;
  3653. if( fd ) {
  3654. WFIFOHEAD(fd,packet_len(0xd8));
  3655. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3656. WFIFOSET(fd,packet_len(0xd8));
  3657. } else {
  3658. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3659. }
  3660. }
  3661. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3662. /// 00da <result>.B
  3663. /// result:
  3664. /// 0 = room full
  3665. /// 1 = wrong password
  3666. /// 2 = kicked
  3667. /// 3 = success (no message)
  3668. /// 4 = no enough zeny
  3669. /// 5 = too low level
  3670. /// 6 = too high level
  3671. /// 7 = unsuitable job class
  3672. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3673. {
  3674. int fd;
  3675. nullpo_retv(sd);
  3676. fd = sd->fd;
  3677. WFIFOHEAD(fd,packet_len(0xda));
  3678. WFIFOW(fd,0) = 0xda;
  3679. WFIFOB(fd,2) = flag;
  3680. WFIFOSET(fd,packet_len(0xda));
  3681. }
  3682. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3683. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3684. /// role:
  3685. /// 0 = owner (menu)
  3686. /// 1 = normal
  3687. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3688. {
  3689. int fd;
  3690. int i,t;
  3691. nullpo_retv(sd);
  3692. nullpo_retv(cd);
  3693. fd = sd->fd;
  3694. if (!session_isActive(fd))
  3695. return;
  3696. t = (int)(cd->owner->type == BL_NPC);
  3697. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3698. WFIFOW(fd, 0) = 0xdb;
  3699. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3700. WFIFOL(fd, 4) = cd->bl.id;
  3701. if(cd->owner->type == BL_NPC){
  3702. WFIFOL(fd, 30) = 1;
  3703. WFIFOL(fd, 8) = 0;
  3704. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3705. for (i = 0; i < cd->users; i++) {
  3706. WFIFOL(fd, 8+(i+1)*28) = 1;
  3707. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3708. }
  3709. }else{
  3710. for (i = 0; i < cd->users; i++) {
  3711. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3712. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3713. }
  3714. }
  3715. WFIFOSET(fd, WFIFOW(fd, 2));
  3716. }
  3717. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3718. /// 00dc <users>.W <name>.24B
  3719. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3720. {
  3721. unsigned char buf[29];
  3722. nullpo_retv(sd);
  3723. nullpo_retv(cd);
  3724. WBUFW(buf, 0) = 0xdc;
  3725. WBUFW(buf, 2) = cd->users;
  3726. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3727. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3728. }
  3729. /// Announce the new owner (ZC_ROLE_CHANGE).
  3730. /// 00e1 <role>.L <nick>.24B
  3731. /// role:
  3732. /// 0 = owner (menu)
  3733. /// 1 = normal
  3734. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3735. {
  3736. unsigned char buf[64];
  3737. nullpo_retv(sd);
  3738. nullpo_retv(cd);
  3739. WBUFW(buf, 0) = 0xe1;
  3740. WBUFL(buf, 2) = 1;
  3741. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3742. WBUFW(buf,30) = 0xe1;
  3743. WBUFL(buf,32) = 0;
  3744. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3745. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3746. }
  3747. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3748. /// 00dd <users>.W <nick>.24B <flag>.B
  3749. /// flag:
  3750. /// 0 = left
  3751. /// 1 = kicked
  3752. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3753. {
  3754. unsigned char buf[32];
  3755. nullpo_retv(sd);
  3756. nullpo_retv(cd);
  3757. WBUFW(buf, 0) = 0xdd;
  3758. WBUFW(buf, 2) = cd->users-1;
  3759. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3760. WBUFB(buf,28) = flag;
  3761. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3762. }
  3763. /// Opens a trade request window from char 'name'.
  3764. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3765. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3766. void clif_traderequest(struct map_session_data* sd, const char* name)
  3767. {
  3768. int fd = sd->fd;
  3769. #if PACKETVER < 6
  3770. WFIFOHEAD(fd,packet_len(0xe5));
  3771. WFIFOW(fd,0) = 0xe5;
  3772. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3773. WFIFOSET(fd,packet_len(0xe5));
  3774. #else
  3775. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3776. if( !tsd ) return;
  3777. WFIFOHEAD(fd,packet_len(0x1f4));
  3778. WFIFOW(fd,0) = 0x1f4;
  3779. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3780. WFIFOL(fd,26) = tsd->status.char_id;
  3781. WFIFOW(fd,30) = tsd->status.base_level;
  3782. WFIFOSET(fd,packet_len(0x1f4));
  3783. #endif
  3784. }
  3785. /// Reply to a trade-request.
  3786. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3787. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3788. /// result:
  3789. /// 0 = Char is too far
  3790. /// 1 = Character does not exist
  3791. /// 2 = Trade failed
  3792. /// 3 = Accept
  3793. /// 4 = Cancel
  3794. /// 5 = Busy
  3795. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3796. {
  3797. int fd = sd->fd;
  3798. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3799. if( PACKETVER < 6 || !tsd ) {
  3800. WFIFOHEAD(fd,packet_len(0xe7));
  3801. WFIFOW(fd,0) = 0xe7;
  3802. WFIFOB(fd,2) = type;
  3803. WFIFOSET(fd,packet_len(0xe7));
  3804. } else {
  3805. WFIFOHEAD(fd,packet_len(0x1f5));
  3806. WFIFOW(fd,0) = 0x1f5;
  3807. WFIFOB(fd,2) = type;
  3808. WFIFOL(fd,3) = tsd->status.char_id;
  3809. WFIFOW(fd,7) = tsd->status.base_level;
  3810. WFIFOSET(fd,packet_len(0x1f5));
  3811. }
  3812. }
  3813. /// Notifies the client about an item from other player in current trade.
  3814. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3815. /// 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)
  3816. /// 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)
  3817. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3818. {
  3819. int fd;
  3820. unsigned char *buf;
  3821. #if PACKETVER < 20100223
  3822. const int cmd = 0xe9;
  3823. #elif PACKETVER < 20150225
  3824. const int cmd = 0x80f;
  3825. #else
  3826. const int cmd = 0xa09;
  3827. #endif
  3828. nullpo_retv(sd);
  3829. nullpo_retv(tsd);
  3830. fd = tsd->fd;
  3831. buf = WFIFOP(fd,0);
  3832. WFIFOHEAD(fd,packet_len(cmd));
  3833. WBUFW(buf,0) = cmd;
  3834. if( index == 0 )
  3835. {
  3836. #if PACKETVER < 20100223
  3837. WBUFL(buf,2) = amount; //amount
  3838. WBUFW(buf,6) = 0; // type id
  3839. #else
  3840. WBUFW(buf,2) = 0; // type id
  3841. WBUFB(buf,4) = 0; // item type
  3842. WBUFL(buf,5) = amount; // amount
  3843. buf = WBUFP(buf,1); //Advance 1B
  3844. #endif
  3845. WBUFB(buf,8) = 0; //identify flag
  3846. WBUFB(buf,9) = 0; // attribute
  3847. WBUFB(buf,10)= 0; //refine
  3848. WBUFW(buf,11)= 0; //card (4w)
  3849. WBUFW(buf,13)= 0; //card (4w)
  3850. WBUFW(buf,15)= 0; //card (4w)
  3851. WBUFW(buf,17)= 0; //card (4w)
  3852. #if PACKETVER >= 20150225
  3853. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3854. #endif
  3855. }
  3856. else
  3857. {
  3858. index -= 2; //index fix
  3859. #if PACKETVER < 20100223
  3860. WBUFL(buf,2) = amount; //amount
  3861. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3862. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3863. else
  3864. WBUFW(buf,6) = sd->inventory.u.items_inventory[index].nameid; // type id
  3865. #else
  3866. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3867. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3868. else
  3869. WBUFW(buf,2) = sd->inventory.u.items_inventory[index].nameid; // type id
  3870. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3871. WBUFL(buf,5) = amount; // amount
  3872. buf = WBUFP(buf,1); //Advance 1B
  3873. #endif
  3874. WBUFB(buf,8) = sd->inventory.u.items_inventory[index].identify; //identify flag
  3875. WBUFB(buf,9) = sd->inventory.u.items_inventory[index].attribute; // attribute
  3876. WBUFB(buf,10)= sd->inventory.u.items_inventory[index].refine; //refine
  3877. clif_addcards(WBUFP(buf, 11), &sd->inventory.u.items_inventory[index]);
  3878. #if PACKETVER >= 20150225
  3879. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3880. #endif
  3881. }
  3882. WFIFOSET(fd,packet_len(cmd));
  3883. }
  3884. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3885. /// 00ea <index>.W <result>.B
  3886. /// result:
  3887. /// 0 = success
  3888. /// 1 = overweight
  3889. /// 2 = trade canceled
  3890. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3891. {
  3892. int fd;
  3893. nullpo_retv(sd);
  3894. fd = sd->fd;
  3895. WFIFOHEAD(fd,packet_len(0xea));
  3896. WFIFOW(fd,0) = 0xea;
  3897. WFIFOW(fd,2) = index;
  3898. WFIFOB(fd,4) = fail;
  3899. WFIFOSET(fd,packet_len(0xea));
  3900. }
  3901. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3902. /// 00ec <who>.B
  3903. /// who:
  3904. /// 0 = self
  3905. /// 1 = other player
  3906. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3907. {
  3908. int fd;
  3909. nullpo_retv(sd);
  3910. fd = sd->fd;
  3911. WFIFOHEAD(fd,packet_len(0xec));
  3912. WFIFOW(fd,0) = 0xec;
  3913. WFIFOB(fd,2) = fail;
  3914. WFIFOSET(fd,packet_len(0xec));
  3915. }
  3916. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3917. /// 00ee
  3918. void clif_tradecancelled(struct map_session_data* sd)
  3919. {
  3920. int fd;
  3921. nullpo_retv(sd);
  3922. fd = sd->fd;
  3923. WFIFOHEAD(fd,packet_len(0xee));
  3924. WFIFOW(fd,0) = 0xee;
  3925. WFIFOSET(fd,packet_len(0xee));
  3926. }
  3927. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3928. /// 00f0 <result>.B
  3929. /// result:
  3930. /// 0 = success
  3931. /// 1 = failure
  3932. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3933. {
  3934. int fd;
  3935. nullpo_retv(sd);
  3936. fd = sd->fd;
  3937. WFIFOHEAD(fd,packet_len(0xf0));
  3938. WFIFOW(fd,0) = 0xf0;
  3939. WFIFOB(fd,2) = fail;
  3940. WFIFOSET(fd,packet_len(0xf0));
  3941. }
  3942. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3943. /// 00f1
  3944. /// NOTE: Unknown purpose. Items are not removed until the window is
  3945. /// refreshed (ex. by putting another item in there).
  3946. void clif_tradeundo(struct map_session_data* sd)
  3947. {
  3948. int fd = sd->fd;
  3949. WFIFOHEAD(fd,packet_len(0xf1));
  3950. WFIFOW(fd,0) = 0xf1;
  3951. WFIFOSET(fd,packet_len(0xf1));
  3952. }
  3953. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3954. /// 00f2 <current count>.W <max count>.W
  3955. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3956. {
  3957. int fd;
  3958. nullpo_retv(sd);
  3959. fd=sd->fd;
  3960. WFIFOHEAD(fd,packet_len(0xf2));
  3961. WFIFOW(fd,0) = 0xf2;
  3962. WFIFOW(fd,2) = amount;
  3963. WFIFOW(fd,4) = max_amount;
  3964. WFIFOSET(fd,packet_len(0xf2));
  3965. }
  3966. /// Notifies the client of an item being added to the storage.
  3967. /// 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)
  3968. /// 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)
  3969. /// 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)
  3970. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3971. {
  3972. #if PACKETVER < 5
  3973. const int cmd = 0xf4;
  3974. #elif PACKETVER < 20150225
  3975. const int cmd = 0x1c4;
  3976. #else
  3977. const int cmd = 0xa0a;
  3978. #endif
  3979. int view,fd;
  3980. int offset = 0;
  3981. nullpo_retv(sd);
  3982. nullpo_retv(i);
  3983. fd=sd->fd;
  3984. view = itemdb_viewid(i->nameid);
  3985. WFIFOHEAD(fd,packet_len(cmd));
  3986. WFIFOW(fd, 0) = cmd; // Storage item added
  3987. WFIFOW(fd, 2) = index+1; // index
  3988. WFIFOL(fd, 4) = amount; // amount
  3989. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3990. #if PACKETVER >= 5
  3991. WFIFOB(fd,10) = itemtype(i->nameid); //type
  3992. offset += 1;
  3993. #endif
  3994. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3995. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3996. WFIFOB(fd,12+offset) = i->refine; //refine
  3997. clif_addcards(WFIFOP(fd,13+offset), i);
  3998. #if PACKETVER >= 20150225
  3999. clif_add_random_options(WFIFOP(fd,21+offset), i);
  4000. #endif
  4001. WFIFOSET(fd,packet_len(cmd));
  4002. }
  4003. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4004. /// 00f6 <index>.W <amount>.L
  4005. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4006. {
  4007. int fd;
  4008. nullpo_retv(sd);
  4009. fd=sd->fd;
  4010. WFIFOHEAD(fd,packet_len(0xf6));
  4011. WFIFOW(fd,0)=0xf6; // Storage item removed
  4012. WFIFOW(fd,2)=index+1;
  4013. WFIFOL(fd,4)=amount;
  4014. WFIFOSET(fd,packet_len(0xf6));
  4015. }
  4016. /// Closes storage (ZC_CLOSE_STORE).
  4017. /// 00f8
  4018. void clif_storageclose(struct map_session_data* sd)
  4019. {
  4020. int fd;
  4021. nullpo_retv(sd);
  4022. fd=sd->fd;
  4023. WFIFOHEAD(fd,packet_len(0xf8));
  4024. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4025. WFIFOSET(fd,packet_len(0xf8));
  4026. }
  4027. /*==========================================
  4028. * Server tells 'sd' player client the abouts of 'dstsd' player
  4029. *------------------------------------------*/
  4030. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4031. {
  4032. struct block_list *d_bl;
  4033. int i;
  4034. if( dstsd->chatID ) {
  4035. struct chat_data *cd = NULL;
  4036. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4037. clif_dispchat(cd,sd->fd);
  4038. } else if( dstsd->state.vending )
  4039. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4040. else if( dstsd->state.buyingstore )
  4041. clif_buyingstore_entry_single(sd, dstsd);
  4042. if(dstsd->spiritball > 0)
  4043. clif_spiritball_single(sd->fd, dstsd);
  4044. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4045. clif_spiritcharm_single(sd->fd, dstsd);
  4046. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4047. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4048. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4049. )
  4050. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4051. // display link (sd - dstsd) to sd
  4052. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4053. if( i < MAX_DEVOTION )
  4054. clif_devotion(&sd->bl, sd);
  4055. // display links (dstsd - devotees) to sd
  4056. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4057. if( i < MAX_DEVOTION )
  4058. clif_devotion(&dstsd->bl, sd);
  4059. // display link (dstsd - crusader) to sd
  4060. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4061. clif_devotion(d_bl, sd);
  4062. }
  4063. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  4064. {
  4065. uint8 buf[128];
  4066. struct unit_data *ud;
  4067. struct view_data *vd;
  4068. int len;
  4069. vd = status_get_viewdata(bl);
  4070. if (!vd || vd->class_ == JT_INVISIBLE)
  4071. return;
  4072. /**
  4073. * Hide NPC from maya purple card.
  4074. **/
  4075. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4076. return;
  4077. ud = unit_bl2ud(bl);
  4078. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4079. clif_send(buf,len,&sd->bl,SELF);
  4080. if (vd->cloth_color)
  4081. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4082. if (vd->body_style)
  4083. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4084. switch (bl->type)
  4085. {
  4086. case BL_PC:
  4087. {
  4088. TBL_PC* tsd = (TBL_PC*)bl;
  4089. clif_getareachar_pc(sd, tsd);
  4090. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4091. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4092. else if(tsd->state.size==SZ_MEDIUM)
  4093. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4094. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4095. clif_sendbgemblem_single(sd->fd,tsd);
  4096. if ( tsd->status.robe )
  4097. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4098. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4099. clif_hat_effects(sd,bl,SELF);
  4100. }
  4101. break;
  4102. case BL_MER: // Devotion Effects
  4103. if( ((TBL_MER*)bl)->devotion_flag )
  4104. clif_devotion(bl, sd);
  4105. break;
  4106. case BL_NPC:
  4107. {
  4108. TBL_NPC* nd = (TBL_NPC*)bl;
  4109. if( nd->chat_id )
  4110. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4111. if( nd->size == SZ_BIG )
  4112. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4113. else if( nd->size == SZ_MEDIUM )
  4114. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4115. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4116. clif_progressbar_npc(nd, sd);
  4117. }
  4118. break;
  4119. case BL_MOB:
  4120. {
  4121. TBL_MOB* md = (TBL_MOB*)bl;
  4122. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4123. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4124. else if(md->special_state.size==SZ_MEDIUM)
  4125. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4126. #if PACKETVER >= 20120404
  4127. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4128. int i;
  4129. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4130. if( md->dmglog[i].id == sd->status.char_id )
  4131. clif_monster_hp_bar(md, sd->fd);
  4132. }
  4133. #endif
  4134. }
  4135. break;
  4136. case BL_PET:
  4137. if (vd->head_bottom)
  4138. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4139. break;
  4140. }
  4141. }
  4142. //Modifies the type of damage according to status changes [Skotlex]
  4143. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4144. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4145. {
  4146. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4147. }
  4148. /*==========================================
  4149. * Estimates walk delay based on the damage criteria. [Skotlex]
  4150. *------------------------------------------*/
  4151. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4152. {
  4153. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4154. return 0;
  4155. if (bl->type == BL_PC) {
  4156. if (battle_config.pc_walk_delay_rate != 100)
  4157. delay = delay*battle_config.pc_walk_delay_rate/100;
  4158. } else
  4159. if (battle_config.walk_delay_rate != 100)
  4160. delay = delay*battle_config.walk_delay_rate/100;
  4161. if (div_ > 1) //Multi-hit skills mean higher delays.
  4162. delay += battle_config.multihit_delay*(div_-1);
  4163. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4164. }
  4165. /*========================================== [Playtester]
  4166. * Returns hallucination damage the client displays
  4167. *------------------------------------------*/
  4168. static int clif_hallucination_damage()
  4169. {
  4170. int digit = rnd() % 5 + 1;
  4171. switch (digit)
  4172. {
  4173. case 1:
  4174. return (rnd() % 10);
  4175. case 2:
  4176. return (rnd() % 100);
  4177. case 3:
  4178. return (rnd() % 1000);
  4179. case 4:
  4180. return (rnd() % 10000);
  4181. }
  4182. return (rnd() % 32767);
  4183. }
  4184. /// Sends a 'damage' packet (src performs action on dst)
  4185. /// 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)
  4186. /// 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)
  4187. /// 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)
  4188. /// type:
  4189. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4190. /// 1 = pick up item
  4191. /// 2 = sit down
  4192. /// 3 = stand up
  4193. /// 4 = damage (endure)
  4194. /// 5 = (splash?)
  4195. /// 6 = (skill?)
  4196. /// 7 = (repeat damage?)
  4197. /// 8 = multi-hit damage
  4198. /// 9 = multi-hit damage (endure)
  4199. /// 10 = critical hit
  4200. /// 11 = lucky dodge
  4201. /// 12 = (touch skill?)
  4202. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2, bool spdamage)
  4203. {
  4204. unsigned char buf[34];
  4205. struct status_change *sc;
  4206. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4207. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4208. #if PACKETVER < 20071113
  4209. const int cmd = 0x8a;
  4210. int offset = 0;
  4211. #elif PACKETVER < 20131223
  4212. const int cmd = 0x2e1;
  4213. int offset = 2;
  4214. #else
  4215. const int cmd = 0x8c8;
  4216. int offset = 3;
  4217. #endif
  4218. nullpo_ret(src);
  4219. nullpo_ret(dst);
  4220. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4221. sc = status_get_sc(dst);
  4222. if(sc && sc->count) {
  4223. if(sc->data[SC_HALLUCINATION]) {
  4224. if(damage) damage = clif_hallucination_damage();
  4225. if(damage2) damage2 = clif_hallucination_damage();
  4226. }
  4227. }
  4228. WBUFW(buf,0) = cmd;
  4229. WBUFL(buf,2) = src->id;
  4230. WBUFL(buf,6) = dst->id;
  4231. WBUFL(buf,10) = tick;
  4232. WBUFL(buf,14) = sdelay;
  4233. WBUFL(buf,18) = ddelay;
  4234. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4235. #if PACKETVER < 20071113
  4236. WBUFW(buf,22) = damage ? div : 0;
  4237. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4238. #else
  4239. WBUFL(buf, 22) = damage ? div : 0;
  4240. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4241. #endif
  4242. } else {
  4243. #if PACKETVER < 20071113
  4244. WBUFW(buf,22) = min(damage, INT16_MAX);
  4245. WBUFW(buf,27+offset) = damage2;
  4246. #else
  4247. WBUFL(buf,22) = damage;
  4248. WBUFL(buf,27+offset) = damage2;
  4249. #endif
  4250. }
  4251. #if PACKETVER >= 20131223
  4252. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4253. #endif
  4254. WBUFW(buf,24+offset) = div;
  4255. WBUFB(buf,26+offset) = type;
  4256. if(disguised(dst)) {
  4257. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4258. WBUFL(buf,6) = -dst->id;
  4259. clif_send(buf, packet_len(cmd), dst, SELF);
  4260. } else
  4261. clif_send(buf, packet_len(cmd), dst, AREA);
  4262. if(disguised(src)) {
  4263. WBUFL(buf,2) = -src->id;
  4264. if (disguised(dst))
  4265. WBUFL(buf,6) = dst->id;
  4266. #if PACKETVER < 20071113
  4267. if(damage > 0) WBUFW(buf,22) = -1;
  4268. if(damage2 > 0) WBUFW(buf,27) = -1;
  4269. #else
  4270. if(damage > 0) WBUFL(buf,22) = -1;
  4271. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4272. #endif
  4273. clif_send(buf,packet_len(cmd),src,SELF);
  4274. }
  4275. if(src == dst) {
  4276. unit_setdir(src, unit_getdir(src));
  4277. }
  4278. //Return adjusted can't walk delay for further processing.
  4279. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4280. }
  4281. /*==========================================
  4282. * src picks up dst
  4283. *------------------------------------------*/
  4284. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4285. {
  4286. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4287. unsigned char buf[32];
  4288. nullpo_retv(src);
  4289. nullpo_retv(dst);
  4290. WBUFW(buf, 0) = 0x8a;
  4291. WBUFL(buf, 2) = src->id;
  4292. WBUFL(buf, 6) = dst->id;
  4293. WBUFB(buf,26) = 1;
  4294. clif_send(buf, packet_len(0x8a), src, AREA);
  4295. }
  4296. /*==========================================
  4297. * inform clients in area that `bl` is sitting
  4298. *------------------------------------------*/
  4299. void clif_sitting(struct block_list* bl)
  4300. {
  4301. unsigned char buf[32];
  4302. nullpo_retv(bl);
  4303. WBUFW(buf, 0) = 0x8a;
  4304. WBUFL(buf, 2) = bl->id;
  4305. WBUFB(buf,26) = 2;
  4306. clif_send(buf, packet_len(0x8a), bl, AREA);
  4307. if(disguised(bl)) {
  4308. WBUFL(buf, 2) = - bl->id;
  4309. clif_send(buf, packet_len(0x8a), bl, SELF);
  4310. }
  4311. }
  4312. /*==========================================
  4313. * inform clients in area that `bl` is standing
  4314. *------------------------------------------*/
  4315. void clif_standing(struct block_list* bl)
  4316. {
  4317. unsigned char buf[32];
  4318. nullpo_retv(bl);
  4319. WBUFW(buf, 0) = 0x8a;
  4320. WBUFL(buf, 2) = bl->id;
  4321. WBUFB(buf,26) = 3;
  4322. clif_send(buf, packet_len(0x8a), bl, AREA);
  4323. if(disguised(bl)) {
  4324. WBUFL(buf, 2) = - bl->id;
  4325. clif_send(buf, packet_len(0x8a), bl, SELF);
  4326. }
  4327. }
  4328. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4329. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4330. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4331. {
  4332. unsigned char buf[32];
  4333. WBUFW(buf,0) = 0x192;
  4334. WBUFW(buf,2) = x;
  4335. WBUFW(buf,4) = y;
  4336. WBUFW(buf,6) = type;
  4337. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4338. if( fd )
  4339. {
  4340. WFIFOHEAD(fd,packet_len(0x192));
  4341. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4342. WFIFOSET(fd,packet_len(0x192));
  4343. }
  4344. else
  4345. {
  4346. struct block_list dummy_bl;
  4347. dummy_bl.type = BL_NUL;
  4348. dummy_bl.x = x;
  4349. dummy_bl.y = y;
  4350. dummy_bl.m = m;
  4351. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4352. }
  4353. }
  4354. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4355. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4356. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4357. {
  4358. int view,fd;
  4359. fd=sd->fd;
  4360. WFIFOHEAD(fd,packet_len(0x9d));
  4361. WFIFOW(fd,0)=0x9d;
  4362. WFIFOL(fd,2)=fitem->bl.id;
  4363. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4364. WFIFOW(fd,6)=view;
  4365. else
  4366. WFIFOW(fd,6)=fitem->item.nameid;
  4367. WFIFOB(fd,8)=fitem->item.identify;
  4368. WFIFOW(fd,9)=fitem->bl.x;
  4369. WFIFOW(fd,11)=fitem->bl.y;
  4370. WFIFOW(fd,13)=fitem->item.amount;
  4371. WFIFOB(fd,15)=fitem->subx;
  4372. WFIFOB(fd,16)=fitem->suby;
  4373. WFIFOSET(fd,packet_len(0x9d));
  4374. }
  4375. /// Notifes client about Graffiti
  4376. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4377. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4378. unsigned char buf[128];
  4379. nullpo_retv(bl);
  4380. nullpo_retv(unit);
  4381. WBUFW(buf, 0) = 0x1c9;
  4382. WBUFL(buf, 2) = unit->bl.id;
  4383. WBUFL(buf, 6) = unit->group->src_id;
  4384. WBUFW(buf,10) = unit->bl.x;
  4385. WBUFW(buf,12) = unit->bl.y;
  4386. WBUFB(buf,14) = unit->group->unit_id;
  4387. WBUFB(buf,15) = 1;
  4388. WBUFB(buf,16) = 1;
  4389. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4390. clif_send(buf,packet_len(0x1c9),bl,target);
  4391. }
  4392. /// Notifies the client of a skill unit.
  4393. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4394. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4395. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4396. /// 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)
  4397. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4398. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4399. unsigned char buf[128];
  4400. nullpo_retv(bl);
  4401. nullpo_retv(unit);
  4402. if (bl->type == BL_PC)
  4403. fd = ((TBL_PC*)bl)->fd;
  4404. if (unit->group->state.guildaura)
  4405. return;
  4406. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4407. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4408. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4409. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4410. else
  4411. unit_id = unit->group->unit_id;
  4412. if (!visible)
  4413. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4414. #if PACKETVER >= 3
  4415. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4416. clif_graffiti(bl, unit, target);
  4417. return;
  4418. }
  4419. #endif
  4420. #if PACKETVER <= 20120702
  4421. header = 0x011f;
  4422. //#if PACKETVER < 20110718
  4423. // header = 0x011f;
  4424. //#elif PACKETVER < 20121212
  4425. // header = 0x08c7;
  4426. #elif PACKETVER < 20130731
  4427. header = 0x099f;
  4428. #else
  4429. header = 0x09ca;
  4430. #endif
  4431. len = packet_len(header);
  4432. WBUFW(buf,pos) = header;
  4433. if (header != 0x011f) {
  4434. WBUFW(buf, pos+2) = len;
  4435. pos += 2;
  4436. }
  4437. WBUFL(buf,pos+2) = unit->bl.id;
  4438. WBUFL(buf,pos+6) = unit->group->src_id;
  4439. WBUFW(buf,pos+10) = unit->bl.x;
  4440. WBUFW(buf,pos+12) = unit->bl.y;
  4441. switch (header) {
  4442. case 0x011f:
  4443. WBUFB(buf,pos+14) = unit_id;
  4444. WBUFB(buf,pos+15) = visible;
  4445. break;
  4446. case 0x08c7:
  4447. WBUFB(buf,pos+14) = unit_id;
  4448. WBUFW(buf,pos+15) = unit->range;
  4449. WBUFB(buf,pos+17) = visible;
  4450. break;
  4451. case 0x099f:
  4452. WBUFL(buf,pos+14) = unit_id;
  4453. WBUFW(buf,pos+18) = unit->range;
  4454. WBUFB(buf,pos+20) = visible;
  4455. break;
  4456. case 0x09ca:
  4457. WBUFL(buf,pos+14) = unit_id;
  4458. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4459. WBUFB(buf,pos+19) = visible;
  4460. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4461. break;
  4462. }
  4463. clif_send(buf, len, bl, target);
  4464. if (unit->group->skill_id == WZ_ICEWALL)
  4465. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4466. }
  4467. /*==========================================
  4468. * Server tells client to remove unit of id 'unit->bl.id'
  4469. *------------------------------------------*/
  4470. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4471. {
  4472. nullpo_retv(unit);
  4473. WFIFOHEAD(fd,packet_len(0x120));
  4474. WFIFOW(fd, 0)=0x120;
  4475. WFIFOL(fd, 2)=unit->bl.id;
  4476. WFIFOSET(fd,packet_len(0x120));
  4477. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4478. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4479. }
  4480. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4481. /// 0120 <id>.L
  4482. void clif_skill_delunit(struct skill_unit *unit)
  4483. {
  4484. unsigned char buf[16];
  4485. nullpo_retv(unit);
  4486. WBUFW(buf, 0)=0x120;
  4487. WBUFL(buf, 2)=unit->bl.id;
  4488. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4489. }
  4490. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4491. /// 01ac <id>.L
  4492. /// Only affects units with class [139,153] client-side.
  4493. void clif_skillunit_update(struct block_list* bl)
  4494. {
  4495. unsigned char buf[6];
  4496. nullpo_retv(bl);
  4497. WBUFW(buf,0) = 0x1ac;
  4498. WBUFL(buf,2) = bl->id;
  4499. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4500. }
  4501. /*==========================================
  4502. *
  4503. *------------------------------------------*/
  4504. static int clif_getareachar(struct block_list* bl,va_list ap)
  4505. {
  4506. struct map_session_data *sd;
  4507. nullpo_ret(bl);
  4508. sd=va_arg(ap,struct map_session_data*);
  4509. if (sd == NULL || !sd->fd)
  4510. return 0;
  4511. switch(bl->type){
  4512. case BL_ITEM:
  4513. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4514. break;
  4515. case BL_SKILL:
  4516. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4517. break;
  4518. default:
  4519. if(&sd->bl == bl)
  4520. break;
  4521. clif_getareachar_unit(sd,bl);
  4522. break;
  4523. }
  4524. return 0;
  4525. }
  4526. /*==========================================
  4527. * tbl has gone out of view-size of bl
  4528. *------------------------------------------*/
  4529. int clif_outsight(struct block_list *bl,va_list ap)
  4530. {
  4531. struct block_list *tbl;
  4532. struct view_data *vd;
  4533. TBL_PC *sd, *tsd;
  4534. tbl=va_arg(ap,struct block_list*);
  4535. if(bl == tbl) return 0;
  4536. sd = BL_CAST(BL_PC, bl);
  4537. tsd = BL_CAST(BL_PC, tbl);
  4538. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4539. nullpo_ret(bl);
  4540. switch(bl->type){
  4541. case BL_PC:
  4542. if(sd->vd.class_ != JT_INVISIBLE)
  4543. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4544. if(sd->chatID){
  4545. struct chat_data *cd;
  4546. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4547. if(cd->usersd[0]==sd)
  4548. clif_dispchat(cd,tsd->fd);
  4549. }
  4550. if(sd->state.vending)
  4551. clif_closevendingboard(bl,tsd->fd);
  4552. if(sd->state.buyingstore)
  4553. clif_buyingstore_disappear_entry_single(tsd, sd);
  4554. break;
  4555. case BL_ITEM:
  4556. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4557. break;
  4558. case BL_SKILL:
  4559. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4560. break;
  4561. case BL_NPC:
  4562. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4563. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4564. break;
  4565. default:
  4566. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4567. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4568. break;
  4569. }
  4570. }
  4571. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4572. nullpo_ret(tbl);
  4573. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4574. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4575. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4576. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4577. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4578. }
  4579. return 0;
  4580. }
  4581. /*==========================================
  4582. * tbl has come into view of bl
  4583. *------------------------------------------*/
  4584. int clif_insight(struct block_list *bl,va_list ap)
  4585. {
  4586. struct block_list *tbl;
  4587. TBL_PC *sd, *tsd;
  4588. tbl=va_arg(ap,struct block_list*);
  4589. if (bl == tbl) return 0;
  4590. sd = BL_CAST(BL_PC, bl);
  4591. tsd = BL_CAST(BL_PC, tbl);
  4592. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4593. switch(bl->type){
  4594. case BL_ITEM:
  4595. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4596. break;
  4597. case BL_SKILL:
  4598. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4599. break;
  4600. default:
  4601. clif_getareachar_unit(tsd,bl);
  4602. break;
  4603. }
  4604. }
  4605. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4606. clif_getareachar_unit(sd,tbl);
  4607. }
  4608. return 0;
  4609. }
  4610. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4611. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4612. void clif_skillinfoblock(struct map_session_data *sd)
  4613. {
  4614. int fd;
  4615. int i,len,id;
  4616. nullpo_retv(sd);
  4617. fd = sd->fd;
  4618. if (!fd)
  4619. return;
  4620. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4621. WFIFOW(fd,0) = 0x10f;
  4622. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4623. {
  4624. if( (id = sd->status.skill[i].id) != 0 )
  4625. {
  4626. // workaround for bugreport:5348
  4627. if (len + 37 > 8192)
  4628. break;
  4629. WFIFOW(fd,len) = id;
  4630. WFIFOL(fd,len+2) = skill_get_inf(id);
  4631. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4632. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4633. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4634. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4635. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4636. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4637. else
  4638. WFIFOB(fd,len+36) = 0;
  4639. len += 37;
  4640. }
  4641. }
  4642. WFIFOW(fd,2)=len;
  4643. WFIFOSET(fd,len);
  4644. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4645. for ( ; i < MAX_SKILL; i++)
  4646. {
  4647. if( (id = sd->status.skill[i].id) != 0 )
  4648. {
  4649. clif_addskill(sd, id);
  4650. clif_skillinfo(sd, id, 0);
  4651. }
  4652. }
  4653. }
  4654. /**
  4655. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4656. **/
  4657. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4658. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4659. void clif_addskill(struct map_session_data *sd, int skill_id)
  4660. {
  4661. int fd;
  4662. uint16 idx = 0;
  4663. nullpo_retv(sd);
  4664. fd = sd->fd;
  4665. if (!fd || !(idx = skill_get_index(skill_id)))
  4666. return;
  4667. if( sd->status.skill[idx].id <= 0 )
  4668. return;
  4669. WFIFOHEAD(fd, packet_len(0x111));
  4670. WFIFOW(fd,0) = 0x111;
  4671. WFIFOW(fd,2) = skill_id;
  4672. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4673. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4674. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4675. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4676. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4677. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4678. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4679. else
  4680. WFIFOB(fd,38) = 0;
  4681. WFIFOSET(fd,packet_len(0x111));
  4682. }
  4683. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4684. /// 0441 <skill id>.W
  4685. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4686. {
  4687. #if PACKETVER >= 20081217
  4688. int fd;
  4689. uint16 idx = 0;
  4690. nullpo_retv(sd);
  4691. fd = sd->fd;
  4692. if (!fd || !(idx = skill_get_index(skill_id)))
  4693. return;
  4694. WFIFOHEAD(fd,packet_len(0x441));
  4695. WFIFOW(fd,0) = 0x441;
  4696. WFIFOW(fd,2) = skill_id;
  4697. WFIFOSET(fd,packet_len(0x441));
  4698. #endif
  4699. clif_skillinfoblock(sd);
  4700. }
  4701. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4702. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4703. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4704. int fd;
  4705. nullpo_retv(sd);
  4706. fd = sd->fd;
  4707. WFIFOHEAD(fd, packet_len(0x10e));
  4708. WFIFOW(fd, 0) = 0x10e;
  4709. WFIFOW(fd, 2) = skill_id;
  4710. WFIFOW(fd, 4) = lv;
  4711. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4712. WFIFOW(fd, 8) = range;
  4713. WFIFOB(fd, 10) = upgradable;
  4714. WFIFOSET(fd, packet_len(0x10e));
  4715. }
  4716. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4717. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4718. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4719. {
  4720. const int fd = sd->fd;
  4721. uint16 idx = skill_get_index(skill_id);
  4722. if (!idx)
  4723. return;
  4724. WFIFOHEAD(fd,packet_len(0x7e1));
  4725. WFIFOW(fd,0) = 0x7e1;
  4726. WFIFOW(fd,2) = skill_id;
  4727. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4728. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4729. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4730. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4731. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4732. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4733. else
  4734. WFIFOB(fd,14) = 0;
  4735. WFIFOSET(fd,packet_len(0x7e1));
  4736. }
  4737. /// Notifies clients in area, that an object is about to use a skill.
  4738. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4739. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4740. /// property:
  4741. /// 0 = Yellow cast aura
  4742. /// 1 = Water elemental cast aura
  4743. /// 2 = Earth elemental cast aura
  4744. /// 3 = Fire elemental cast aura
  4745. /// 4 = Wind elemental cast aura
  4746. /// 5 = Poison elemental cast aura
  4747. /// 6 = Holy elemental cast aura
  4748. /// ? = like 0
  4749. /// is disposable:
  4750. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4751. /// 1 = no text
  4752. 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)
  4753. {
  4754. #if PACKETVER < 20091124
  4755. const int cmd = 0x13e;
  4756. #else
  4757. const int cmd = 0x7fb;
  4758. #endif
  4759. unsigned char buf[32];
  4760. WBUFW(buf,0) = cmd;
  4761. WBUFL(buf,2) = src_id;
  4762. WBUFL(buf,6) = dst_id;
  4763. WBUFW(buf,10) = dst_x;
  4764. WBUFW(buf,12) = dst_y;
  4765. WBUFW(buf,14) = skill_id;
  4766. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4767. WBUFL(buf,20) = casttime;
  4768. #if PACKETVER >= 20091124
  4769. WBUFB(buf,24) = 0; // isDisposable
  4770. #endif
  4771. if (disguised(bl)) {
  4772. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4773. WBUFL(buf,2) = -src_id;
  4774. clif_send(buf,packet_len(cmd), bl, SELF);
  4775. } else
  4776. clif_send(buf,packet_len(cmd), bl, AREA);
  4777. }
  4778. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4779. /// 01b9 <id>.L
  4780. void clif_skillcastcancel(struct block_list* bl)
  4781. {
  4782. unsigned char buf[16];
  4783. nullpo_retv(bl);
  4784. WBUFW(buf,0) = 0x1b9;
  4785. WBUFL(buf,2) = bl->id;
  4786. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4787. }
  4788. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4789. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4790. /// num (only used when skill id = NV_BASIC and cause = 0):
  4791. /// 0 = "skill failed" MsgStringTable[159]
  4792. /// 1 = "no emotions" MsgStringTable[160]
  4793. /// 2 = "no sit" MsgStringTable[161]
  4794. /// 3 = "no chat" MsgStringTable[162]
  4795. /// 4 = "no party" MsgStringTable[163]
  4796. /// 5 = "no shout" MsgStringTable[164]
  4797. /// 6 = "no PKing" MsgStringTable[165]
  4798. /// 7 = "no alligning" MsgStringTable[383]
  4799. /// ? = ignored
  4800. /// cause:
  4801. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4802. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4803. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4804. /// "skill failed" MsgStringTable[204] (otherwise)
  4805. /// ... = @see enum useskill_fail_cause
  4806. /// ? = ignored
  4807. ///
  4808. /// if(result!=0) doesn't display any of the previous messages
  4809. /// Note: when this packet is received an unknown flag is always set to 0,
  4810. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4811. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4812. {
  4813. int fd;
  4814. if (!sd) { //Since this is the most common nullpo....
  4815. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4816. return;
  4817. }
  4818. fd=sd->fd;
  4819. if (!fd) return;
  4820. if(battle_config.display_skill_fail&1)
  4821. return; //Disable all skill failed messages
  4822. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4823. return; //Disable delay failed messages
  4824. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4825. return;
  4826. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4827. return;
  4828. WFIFOHEAD(fd,packet_len(0x110));
  4829. WFIFOW(fd,0) = 0x110;
  4830. WFIFOW(fd,2) = skill_id;
  4831. WFIFOL(fd,4) = btype;
  4832. WFIFOB(fd,8) = 0;// success
  4833. WFIFOB(fd,9) = cause;
  4834. WFIFOSET(fd,packet_len(0x110));
  4835. }
  4836. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4837. /// 043d <skill ID>.W <tick>.L
  4838. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4839. {
  4840. #if PACKETVER>=20081112
  4841. int fd;
  4842. nullpo_retv(sd);
  4843. fd=sd->fd;
  4844. WFIFOHEAD(fd,packet_len(0x43d));
  4845. WFIFOW(fd,0) = 0x43d;
  4846. WFIFOW(fd,2) = skill_id;
  4847. WFIFOL(fd,4) = tick;
  4848. WFIFOSET(fd,packet_len(0x43d));
  4849. #endif
  4850. }
  4851. /// Skill attack effect and damage.
  4852. /// 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)
  4853. /// 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)
  4854. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  4855. {
  4856. unsigned char buf[64];
  4857. struct status_change *sc;
  4858. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4859. nullpo_ret(src);
  4860. nullpo_ret(dst);
  4861. type = clif_calc_delay(type,div,damage,ddelay);
  4862. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4863. if(sc->data[SC_HALLUCINATION] && damage)
  4864. damage = clif_hallucination_damage();
  4865. }
  4866. #if PACKETVER < 3
  4867. WBUFW(buf,0)=0x114;
  4868. WBUFW(buf,2)=skill_id;
  4869. WBUFL(buf,4)=src->id;
  4870. WBUFL(buf,8)=dst->id;
  4871. WBUFL(buf,12)=tick;
  4872. WBUFL(buf,16)=sdelay;
  4873. WBUFL(buf,20)=ddelay;
  4874. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4875. WBUFW(buf,24)=damage?div:0;
  4876. } else {
  4877. WBUFW(buf,24)=damage;
  4878. }
  4879. WBUFW(buf,26)=skill_lv;
  4880. WBUFW(buf,28)=div;
  4881. WBUFB(buf,30)=type;
  4882. if (disguised(dst)) {
  4883. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4884. WBUFL(buf,8)=-dst->id;
  4885. clif_send(buf,packet_len(0x114),dst,SELF);
  4886. } else
  4887. clif_send(buf,packet_len(0x114),dst,AREA);
  4888. if(disguised(src)) {
  4889. WBUFL(buf,4)=-src->id;
  4890. if (disguised(dst))
  4891. WBUFL(buf,8)=dst->id;
  4892. if(damage > 0)
  4893. WBUFW(buf,24)=-1;
  4894. clif_send(buf,packet_len(0x114),src,SELF);
  4895. }
  4896. #else
  4897. WBUFW(buf,0)=0x1de;
  4898. WBUFW(buf,2)=skill_id;
  4899. WBUFL(buf,4)=src->id;
  4900. WBUFL(buf,8)=dst->id;
  4901. WBUFL(buf,12)=tick;
  4902. WBUFL(buf,16)=sdelay;
  4903. WBUFL(buf,20)=ddelay;
  4904. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4905. WBUFL(buf,24)=damage?div:0;
  4906. } else {
  4907. WBUFL(buf,24)=damage;
  4908. }
  4909. WBUFW(buf,28)=skill_lv;
  4910. WBUFW(buf,30)=div;
  4911. // For some reason, late 2013 and newer clients have
  4912. // a issue that causes players and monsters to endure
  4913. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4914. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4915. #if PACKETVER < 20131223
  4916. WBUFB(buf,32)=type;
  4917. #else
  4918. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4919. #endif
  4920. if (disguised(dst)) {
  4921. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4922. WBUFL(buf,8)=-dst->id;
  4923. clif_send(buf,packet_len(0x1de),dst,SELF);
  4924. } else
  4925. clif_send(buf,packet_len(0x1de),dst,AREA);
  4926. if(disguised(src)) {
  4927. WBUFL(buf,4)=-src->id;
  4928. if (disguised(dst))
  4929. WBUFL(buf,8)=dst->id;
  4930. if(damage > 0)
  4931. WBUFL(buf,24)=-1;
  4932. clif_send(buf,packet_len(0x1de),src,SELF);
  4933. }
  4934. #endif
  4935. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4936. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4937. }
  4938. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4939. /// 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
  4940. /*
  4941. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  4942. {
  4943. unsigned char buf[64];
  4944. struct status_change *sc;
  4945. nullpo_ret(src);
  4946. nullpo_ret(dst);
  4947. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4948. type = clif_calc_delay(type,div,damage,ddelay);
  4949. sc = status_get_sc(dst);
  4950. if(sc && sc->count) {
  4951. if(sc->data[SC_HALLUCINATION] && damage)
  4952. damage = clif_hallucination_damage();
  4953. }
  4954. WBUFW(buf,0)=0x115;
  4955. WBUFW(buf,2)=skill_id;
  4956. WBUFL(buf,4)=src->id;
  4957. WBUFL(buf,8)=dst->id;
  4958. WBUFL(buf,12)=tick;
  4959. WBUFL(buf,16)=sdelay;
  4960. WBUFL(buf,20)=ddelay;
  4961. WBUFW(buf,24)=dst->x;
  4962. WBUFW(buf,26)=dst->y;
  4963. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4964. WBUFW(buf,28)=damage?div:0;
  4965. } else {
  4966. WBUFW(buf,28)=damage;
  4967. }
  4968. WBUFW(buf,30)=skill_lv;
  4969. WBUFW(buf,32)=div;
  4970. WBUFB(buf,34)=type;
  4971. clif_send(buf,packet_len(0x115),src,AREA);
  4972. if(disguised(src)) {
  4973. WBUFL(buf,4)=-src->id;
  4974. if(damage > 0)
  4975. WBUFW(buf,28)=-1;
  4976. clif_send(buf,packet_len(0x115),src,SELF);
  4977. }
  4978. if (disguised(dst)) {
  4979. WBUFL(buf,8)=-dst->id;
  4980. if (disguised(src))
  4981. WBUFL(buf,4)=src->id;
  4982. else if(damage > 0)
  4983. WBUFW(buf,28)=-1;
  4984. clif_send(buf,packet_len(0x115),dst,SELF);
  4985. }
  4986. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4987. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4988. }
  4989. */
  4990. /// Non-damaging skill effect
  4991. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4992. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4993. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  4994. {
  4995. unsigned char buf[17];
  4996. #if PACKETVER < 20130731
  4997. const int cmd = 0x11a;
  4998. #else
  4999. const int cmd = 0x9cb;
  5000. #endif
  5001. int offset = 0;
  5002. nullpo_ret(dst);
  5003. WBUFW(buf,0) = cmd;
  5004. WBUFW(buf,2) = skill_id;
  5005. #if PACKETVER < 20130731
  5006. WBUFW(buf,4) = min(heal, INT16_MAX);
  5007. #else
  5008. WBUFL(buf,4) = min(heal, INT32_MAX);
  5009. offset += 2;
  5010. #endif
  5011. WBUFL(buf,6+offset) = dst->id;
  5012. WBUFL(buf,10+offset) = src ? src->id : 0;
  5013. WBUFB(buf,14+offset) = fail;
  5014. if (disguised(dst)) {
  5015. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5016. WBUFL(buf,6+offset) = -dst->id;
  5017. clif_send(buf, packet_len(cmd), dst, SELF);
  5018. } else
  5019. clif_send(buf, packet_len(cmd), dst, AREA);
  5020. if(src && disguised(src)) {
  5021. WBUFL(buf,10+offset) = -src->id;
  5022. if (disguised(dst))
  5023. WBUFL(buf,6+offset) = dst->id;
  5024. clif_send(buf, packet_len(cmd), src, SELF);
  5025. }
  5026. return fail;
  5027. }
  5028. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5029. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5030. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  5031. {
  5032. unsigned char buf[32];
  5033. nullpo_retv(src);
  5034. WBUFW(buf,0)=0x117;
  5035. WBUFW(buf,2)=skill_id;
  5036. WBUFL(buf,4)=src->id;
  5037. WBUFW(buf,8)=val;
  5038. WBUFW(buf,10)=x;
  5039. WBUFW(buf,12)=y;
  5040. WBUFL(buf,14)=tick;
  5041. if(disguised(src)) {
  5042. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5043. WBUFL(buf,4)=-src->id;
  5044. clif_send(buf,packet_len(0x117),src,SELF);
  5045. } else
  5046. clif_send(buf,packet_len(0x117),src,AREA);
  5047. }
  5048. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5049. /// 011c <skill id>.W { <map name>.16B }*4
  5050. 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)
  5051. {
  5052. int fd;
  5053. nullpo_retv(sd);
  5054. fd = sd->fd;
  5055. WFIFOHEAD(fd,packet_len(0x11c));
  5056. WFIFOW(fd,0) = 0x11c;
  5057. WFIFOW(fd,2) = skill_id;
  5058. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5059. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5060. else // normal map name
  5061. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5062. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5063. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5064. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5065. WFIFOSET(fd,packet_len(0x11c));
  5066. sd->menuskill_id = skill_id;
  5067. if (skill_id == AL_WARP) {
  5068. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5069. sd->state.workinprogress = WIP_DISABLE_ALL;
  5070. } else
  5071. sd->menuskill_val = skill_lv;
  5072. }
  5073. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5074. /// 011e <type>.B
  5075. /// type:
  5076. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5077. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5078. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5079. ///
  5080. /// @param sd Who receives the message
  5081. /// @param type What message
  5082. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5083. {
  5084. int fd;
  5085. nullpo_retv(sd);
  5086. fd=sd->fd;
  5087. WFIFOHEAD(fd,packet_len(0x11e));
  5088. WFIFOW(fd,0)=0x11e;
  5089. WFIFOB(fd,2)=type;
  5090. WFIFOSET(fd,packet_len(0x11e));
  5091. }
  5092. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5093. /// 0189 <type>.W
  5094. /// type:
  5095. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5096. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5097. ///
  5098. /// @param sd Who receives the message
  5099. /// @param type What message
  5100. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5101. {
  5102. int fd;
  5103. nullpo_retv(sd);
  5104. fd=sd->fd;
  5105. WFIFOHEAD(fd,packet_len(0x189));
  5106. WFIFOW(fd,0)=0x189;
  5107. WFIFOW(fd,2)=type;
  5108. WFIFOSET(fd,packet_len(0x189));
  5109. }
  5110. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5111. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5112. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5113. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5114. {
  5115. struct status_data *status;
  5116. unsigned char buf[64];
  5117. int i;//, fix;
  5118. nullpo_retv(sd);
  5119. nullpo_retv(dst);
  5120. if( dst->type != BL_MOB )
  5121. return;
  5122. status = status_get_status_data(dst);
  5123. WBUFW(buf, 0)=0x18c;
  5124. WBUFW(buf, 2)=status_get_class(dst);
  5125. WBUFW(buf, 4)=status_get_lv(dst);
  5126. WBUFW(buf, 6)=status->size;
  5127. WBUFL(buf, 8)=status->hp;
  5128. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5129. +(battle_config.estimation_type&2?status->def2:0);
  5130. WBUFW(buf,14)=status->race;
  5131. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5132. +(battle_config.estimation_type&2?status->mdef2:0);
  5133. WBUFW(buf,18)= status->def_ele;
  5134. for(i=0;i<9;i++)
  5135. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5136. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5137. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5138. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5139. }
  5140. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5141. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5142. /// material id:
  5143. /// unused by the client
  5144. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5145. {
  5146. int i,c,view,fd;
  5147. nullpo_retv(sd);
  5148. if (sd->menuskill_id == skill_id)
  5149. return; //Avoid resending the menu twice or more times...
  5150. if (skill_id == GC_CREATENEWPOISON)
  5151. skill_id = GC_RESEARCHNEWPOISON;
  5152. fd = sd->fd;
  5153. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5154. WFIFOW(fd, 0) = 0x18d;
  5155. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5156. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5157. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5158. )
  5159. {
  5160. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5161. WFIFOW(fd,c*8+ 4) = view;
  5162. else
  5163. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5164. WFIFOW(fd,c*8+ 6) = 0;
  5165. WFIFOW(fd,c*8+ 8) = 0;
  5166. WFIFOW(fd,c*8+10) = 0;
  5167. c++;
  5168. }
  5169. }
  5170. WFIFOW(fd, 2) = c*8+8;
  5171. WFIFOSET(fd,WFIFOW(fd,2));
  5172. if (c > 0) {
  5173. sd->menuskill_id = skill_id;
  5174. sd->menuskill_val = trigger;
  5175. return;
  5176. }
  5177. }
  5178. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5179. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5180. /// mk type:
  5181. /// 1 = cooking
  5182. /// 2 = arrow
  5183. /// 3 = elemental
  5184. /// 4 = GN_MIX_COOKING
  5185. /// 5 = GN_MAKEBOMB
  5186. /// 6 = GN_S_PHARMACY
  5187. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5188. {
  5189. int fd;
  5190. int i, c;
  5191. int view;
  5192. nullpo_retv(sd);
  5193. fd = sd->fd;
  5194. if(sd->menuskill_id == skill_id)
  5195. return; //Avoid resending the menu twice or more times...
  5196. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5197. WFIFOW(fd,0) = 0x25a;
  5198. WFIFOW(fd,4) = list_type; // list type
  5199. c = 0;
  5200. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5201. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5202. continue;
  5203. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5204. WFIFOW(fd, 6 + 2 * c) = view;
  5205. else
  5206. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5207. c++;
  5208. }
  5209. if( c > 0 || skill_id == AM_PHARMACY) {
  5210. sd->menuskill_id = skill_id;
  5211. sd->menuskill_val = trigger;
  5212. sd->menuskill_val2 = qty; // amount.
  5213. WFIFOW(fd,2) = 6 + 2 * c;
  5214. WFIFOSET(fd,WFIFOW(fd,2));
  5215. } else {
  5216. clif_menuskill_clear(sd);
  5217. #if PACKETVER >= 20090922
  5218. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5219. #else
  5220. WFIFOW(fd,2) = 6 + 2 * c;
  5221. WFIFOSET(fd,WFIFOW(fd,2));
  5222. #endif
  5223. }
  5224. }
  5225. /// Notifies clients of a status change.
  5226. /// 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)]
  5227. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5228. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5229. /// @param bl Sends packet to clients around this object
  5230. /// @param id ID of object that has this effect
  5231. /// @param type Status icon see enum efst_types
  5232. /// @param flag 1:Active, 0:Deactive
  5233. /// @param tick Duration in ms
  5234. /// @param val1
  5235. /// @param val2
  5236. /// @param val3
  5237. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, int tick, int val1, int val2, int val3, enum send_target target_type)
  5238. {
  5239. unsigned char buf[32];
  5240. if (type == EFST_BLANK) //It shows nothing on the client...
  5241. return;
  5242. if (type == EFST_POSTDELAY && tick == 0)
  5243. return;
  5244. nullpo_retv(bl);
  5245. #if PACKETVER >= 20120618
  5246. if (flag && battle_config.display_status_timers)
  5247. WBUFW(buf,0) = 0x983;
  5248. else
  5249. #elif PACKETVER >= 20090121
  5250. if (flag && battle_config.display_status_timers)
  5251. WBUFW(buf,0) = 0x43f;
  5252. else
  5253. #endif
  5254. WBUFW(buf,0) = 0x196;
  5255. WBUFW(buf,2) = type;
  5256. WBUFL(buf,4) = id;
  5257. WBUFB(buf,8) = flag;
  5258. #if PACKETVER >= 20120618
  5259. if (flag && battle_config.display_status_timers) {
  5260. if (tick <= 0)
  5261. tick = 9999; // this is indeed what official servers do
  5262. WBUFL(buf,9) = tick;/* at this stage remain and total are the same value I believe */
  5263. WBUFL(buf,13) = tick;
  5264. WBUFL(buf,17) = val1;
  5265. WBUFL(buf,21) = val2;
  5266. WBUFL(buf,25) = val3;
  5267. }
  5268. #elif PACKETVER >= 20090121
  5269. if (flag && battle_config.display_status_timers) {
  5270. if (tick <= 0)
  5271. tick = 9999; // this is indeed what official servers do
  5272. WBUFL(buf,9) = tick;
  5273. WBUFL(buf,13) = val1;
  5274. WBUFL(buf,17) = val2;
  5275. WBUFL(buf,21) = val3;
  5276. }
  5277. #endif
  5278. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5279. }
  5280. /* Sends status effect to clients around the bl
  5281. * @param bl Object that has the effect
  5282. * @param type Status icon see enum efst_types
  5283. * @param flag 1:Active, 0:Deactive
  5284. * @param tick Duration in ms
  5285. * @param val1
  5286. * @param val2
  5287. * @param val3
  5288. */
  5289. void clif_status_change(struct block_list *bl, int type, int flag, int tick, int val1, int val2, int val3) {
  5290. struct map_session_data *sd = NULL;
  5291. if (type == EFST_BLANK) //It shows nothing on the client...
  5292. return;
  5293. if (type == EFST_POSTDELAY && tick == 0)
  5294. return;
  5295. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5296. return;
  5297. nullpo_retv(bl);
  5298. sd = BL_CAST(BL_PC, bl);
  5299. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5300. return;
  5301. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5302. }
  5303. /**
  5304. * Send any active EFST to those around.
  5305. * @param tbl: Unit to send the packet to
  5306. * @param bl: Objects walking into view
  5307. * @param target: Client send type
  5308. */
  5309. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5310. unsigned char i;
  5311. struct sc_display_entry **sc_display;
  5312. unsigned char sc_display_count;
  5313. bool spheres_sent;
  5314. nullpo_retv(bl);
  5315. switch( bl->type ){
  5316. case BL_PC: {
  5317. struct map_session_data* sd = (struct map_session_data*)bl;
  5318. sc_display = sd->sc_display;
  5319. sc_display_count = sd->sc_display_count;
  5320. spheres_sent = !sd->state.connect_new;
  5321. }
  5322. break;
  5323. case BL_NPC: {
  5324. struct npc_data* nd = (struct npc_data*)bl;
  5325. sc_display = nd->sc_display;
  5326. sc_display_count = nd->sc_display_count;
  5327. spheres_sent = true;
  5328. }
  5329. break;
  5330. default:
  5331. return;
  5332. }
  5333. for (i = 0; i < sc_display_count; i++) {
  5334. enum sc_type type = sc_display[i]->type;
  5335. struct status_change *sc = status_get_sc(bl);
  5336. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5337. int tick = 0;
  5338. if (td)
  5339. tick = DIFF_TICK(td->tick, gettick());
  5340. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5341. #if PACKETVER > 20120418
  5342. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5343. #else
  5344. 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);
  5345. #endif
  5346. }else{
  5347. #if PACKETVER > 20120418
  5348. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5349. #else
  5350. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5351. #endif
  5352. }
  5353. }
  5354. }
  5355. /// Notifies the client when a player enters the screen with an active EFST.
  5356. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5357. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5358. void clif_efst_status_change(struct block_list *bl, int tid, enum send_target target, int type, int tick, int val1, int val2, int val3) {
  5359. #if PACKETVER >= 20111108
  5360. unsigned char buf[32];
  5361. #if PACKETVER >= 20120618
  5362. const int cmd = 0x984;
  5363. #elif PACKETVER >= 20111108
  5364. const int cmd = 0x8ff;
  5365. #endif
  5366. int offset = 0;
  5367. if (type == EFST_BLANK)
  5368. return;
  5369. nullpo_retv(bl);
  5370. if (tick <= 0)
  5371. tick = 9999;
  5372. WBUFW(buf,offset + 0) = cmd;
  5373. WBUFL(buf,offset + 2) = tid;
  5374. WBUFW(buf,offset + 6) = type;
  5375. #if PACKETVER >= 20111108
  5376. WBUFL(buf,offset + 8) = tick; // Set remaining status duration [exneval]
  5377. #if PACKETVER >= 20120618
  5378. WBUFL(buf,offset + 12) = tick;
  5379. offset += 4;
  5380. #endif
  5381. WBUFL(buf,offset + 12) = val1;
  5382. WBUFL(buf,offset + 16) = val2;
  5383. WBUFL(buf,offset + 20) = val3;
  5384. #endif
  5385. clif_send(buf,packet_len(cmd),bl,target);
  5386. #endif
  5387. }
  5388. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5389. /// 008e <packet len>.W <message>.?B
  5390. void clif_displaymessage(const int fd, const char* mes)
  5391. {
  5392. nullpo_retv(mes);
  5393. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5394. if (fd == 0)
  5395. ;
  5396. else {
  5397. char *message, *line;
  5398. message = aStrdup(mes);
  5399. line = strtok(message, "\n");
  5400. #if PACKETVER == 20141022
  5401. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5402. /** so we redirect to ZC_NPC_CHAT **/
  5403. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5404. while(line != NULL) {
  5405. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5406. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5407. if (len > 0) {
  5408. WFIFOHEAD(fd, 13 + len);
  5409. WFIFOW(fd, 0) = 0x2C1;
  5410. WFIFOW(fd, 2) = 13 + len;
  5411. WFIFOL(fd, 4) = 0;
  5412. WFIFOL(fd, 8) = color;
  5413. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5414. WFIFOSET(fd, WFIFOW(fd, 2));
  5415. }
  5416. #else
  5417. while(line != NULL) {
  5418. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5419. int len = strnlen(line, CHAT_SIZE_MAX);
  5420. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5421. WFIFOHEAD(fd, 5 + len);
  5422. WFIFOW(fd,0) = 0x8e;
  5423. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5424. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5425. WFIFOSET(fd, 5 + len);
  5426. }
  5427. #endif
  5428. line = strtok(NULL, "\n");
  5429. }
  5430. aFree(message);
  5431. }
  5432. }
  5433. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5434. /// 009a <packet len>.W <message>.?B
  5435. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5436. {
  5437. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5438. std::unique_ptr<unsigned char> buf(new unsigned char[4+lp+len]);
  5439. WBUFW(buf.get(),0) = 0x9a;
  5440. WBUFW(buf.get(),2) = 4 + lp + len;
  5441. if (type&BC_BLUE)
  5442. 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.
  5443. else if (type&BC_WOE)
  5444. WBUFL(buf.get(),4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5445. memcpy(WBUFP(buf.get(), 4 + lp), mes, len);
  5446. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5447. }
  5448. /*==========================================
  5449. * Displays a message on a 'bl' to all it's nearby clients
  5450. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5451. *------------------------------------------*/
  5452. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5453. size_t len;
  5454. nullpo_retv(bl);
  5455. if(!message)
  5456. return;
  5457. len = strlen(message)+1;
  5458. static_assert(CHAT_SIZE_MAX > 8, "CHAT_SIZE_MAX too small for packet");
  5459. if( len > CHAT_SIZE_MAX ) {
  5460. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  5461. len = CHAT_SIZE_MAX;
  5462. }
  5463. std::unique_ptr<char> buf(new char[8+len]);
  5464. WBUFW(buf.get(),0)=0x8d;
  5465. WBUFW(buf.get(),2)=static_cast<uint16>(len+8);
  5466. WBUFL(buf.get(),4)=bl->id;
  5467. safestrncpy(WBUFCP(buf.get(),8),message,len);
  5468. clif_send((unsigned char *)buf.get(),WBUFW(buf.get(),2),bl,target);
  5469. }
  5470. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5471. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5472. 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)
  5473. {
  5474. std::unique_ptr<unsigned char> buf(new unsigned char[16+len]);
  5475. WBUFW(buf.get(),0) = 0x1c3;
  5476. WBUFW(buf.get(),2) = len + 16;
  5477. WBUFL(buf.get(),4) = fontColor;
  5478. WBUFW(buf.get(),8) = fontType;
  5479. WBUFW(buf.get(),10) = fontSize;
  5480. WBUFW(buf.get(),12) = fontAlign;
  5481. WBUFW(buf.get(),14) = fontY;
  5482. memcpy(WBUFP(buf.get(),16), mes, len);
  5483. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5484. }
  5485. /*
  5486. * Display *msg to all *users in channel
  5487. */
  5488. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5489. DBIterator *iter;
  5490. struct map_session_data *user;
  5491. unsigned short msg_len = 0, len = 0;
  5492. unsigned char buf[CHAT_SIZE_MAX];
  5493. if (!channel || !msg)
  5494. return;
  5495. msg_len = (unsigned short)(strlen(msg) + 1);
  5496. if( msg_len > sizeof(buf)-12 ) {
  5497. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5498. msg_len = sizeof(buf)-12;
  5499. }
  5500. WBUFW(buf,0) = 0x2C1;
  5501. WBUFW(buf,2) = (len = msg_len + 12);
  5502. WBUFL(buf,4) = 0;
  5503. WBUFL(buf,8) = color;
  5504. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5505. iter = db_iterator(channel->users);
  5506. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5507. clif_send(buf, len, &user->bl, SELF);
  5508. }
  5509. dbi_destroy(iter);
  5510. }
  5511. /// Displays heal effect.
  5512. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5513. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5514. /// var id:
  5515. /// 5 = HP (SP_HP)
  5516. /// 7 = SP (SP_SP)
  5517. /// ? = ignored
  5518. void clif_heal(int fd,int type,int val) {
  5519. #if PACKETVER < 20141022
  5520. const int cmd = 0x13d;
  5521. #else
  5522. const int cmd = 0xa27;
  5523. #endif
  5524. WFIFOHEAD(fd, packet_len(cmd));
  5525. WFIFOW(fd,0) = cmd;
  5526. WFIFOW(fd,2) = type;
  5527. #if PACKETVER < 20141022
  5528. WFIFOW(fd,4) = min(val, INT16_MAX);
  5529. #else
  5530. WFIFOL(fd,4) = min(val, INT32_MAX);
  5531. #endif
  5532. WFIFOSET(fd, packet_len(cmd));
  5533. }
  5534. /// Displays resurrection effect (ZC_RESURRECTION).
  5535. /// 0148 <id>.L <type>.W
  5536. /// type:
  5537. /// ignored
  5538. void clif_resurrection(struct block_list *bl,int type)
  5539. {
  5540. unsigned char buf[16];
  5541. nullpo_retv(bl);
  5542. WBUFW(buf,0)=0x148;
  5543. WBUFL(buf,2)=bl->id;
  5544. WBUFW(buf,6)=0;
  5545. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5546. if (disguised(bl))
  5547. clif_spawn(bl);
  5548. }
  5549. /// Sets the map property
  5550. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5551. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5552. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5553. {
  5554. #if PACKETVER >= 20121010
  5555. short cmd = 0x99b;
  5556. unsigned char buf[8];
  5557. #else
  5558. short cmd = 0x199;
  5559. unsigned char buf[4];
  5560. #endif
  5561. WBUFW(buf,0)=cmd;
  5562. WBUFW(buf,2)=property;
  5563. #if PACKETVER >= 20121010
  5564. struct map_data *mapdata = map_getmapdata(bl->m);
  5565. WBUFL(buf,4) = ((mapdata->flag[MF_PVP]?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5566. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5567. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5568. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5569. ((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
  5570. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5571. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5572. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5573. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5574. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5575. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5576. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5577. #endif
  5578. clif_send(buf,packet_len(cmd),bl,t);
  5579. }
  5580. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5581. /// 01d6 <type>.W
  5582. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5583. {
  5584. int fd;
  5585. nullpo_retv(sd);
  5586. fd=sd->fd;
  5587. WFIFOHEAD(fd,packet_len(0x1D6));
  5588. WFIFOW(fd,0)=0x1D6;
  5589. WFIFOW(fd,2)=type;
  5590. WFIFOSET(fd,packet_len(0x1D6));
  5591. }
  5592. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5593. /// 019a <id>.L <ranking>.L <total>.L
  5594. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5595. {
  5596. if(type == 2) {
  5597. int fd = sd->fd;
  5598. WFIFOHEAD(fd,packet_len(0x19a));
  5599. WFIFOW(fd,0) = 0x19a;
  5600. WFIFOL(fd,2) = sd->bl.id;
  5601. WFIFOL(fd,6) = pvprank;
  5602. WFIFOL(fd,10) = pvpnum;
  5603. WFIFOSET(fd,packet_len(0x19a));
  5604. } else {
  5605. unsigned char buf[32];
  5606. WBUFW(buf,0) = 0x19a;
  5607. WBUFL(buf,2) = sd->bl.id;
  5608. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5609. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5610. else
  5611. WBUFL(buf,6) = pvprank;
  5612. WBUFL(buf,10) = pvpnum;
  5613. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5614. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5615. else if(!type)
  5616. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5617. else
  5618. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5619. }
  5620. }
  5621. /*==========================================
  5622. *
  5623. *------------------------------------------*/
  5624. void clif_map_property_mapall(int map_idx, enum map_property property)
  5625. {
  5626. struct block_list bl;
  5627. bl.id = 0;
  5628. bl.type = BL_NUL;
  5629. bl.m = map_idx;
  5630. clif_map_property( &bl, property, ALL_SAMEMAP );
  5631. }
  5632. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5633. /// 0188 <result>.W <index>.W <refine>.W
  5634. /// result:
  5635. /// 0 = success
  5636. /// 1 = failure
  5637. /// 2 = downgrade
  5638. void clif_refine(int fd, int fail, int index, int val)
  5639. {
  5640. WFIFOHEAD(fd,packet_len(0x188));
  5641. WFIFOW(fd,0)=0x188;
  5642. WFIFOW(fd,2)=fail;
  5643. WFIFOW(fd,4)=index+2;
  5644. WFIFOW(fd,6)=val;
  5645. WFIFOSET(fd,packet_len(0x188));
  5646. }
  5647. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5648. /// 0223 <result>.L <nameid>.W
  5649. /// result:
  5650. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5651. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5652. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5653. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5654. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5655. {
  5656. WFIFOHEAD(fd,packet_len(0x223));
  5657. WFIFOW(fd,0)=0x223;
  5658. WFIFOL(fd,2)=result;
  5659. WFIFOW(fd,6)=item_id;
  5660. WFIFOSET(fd,packet_len(0x223));
  5661. }
  5662. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5663. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5664. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5665. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5666. int fd;
  5667. nullpo_retv(sd);
  5668. fd = sd->fd;
  5669. #if PACKETVER < 20091104
  5670. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5671. WFIFOW(fd,0) = 0x97;
  5672. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5673. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5674. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5675. WFIFOSET(fd,WFIFOW(fd,2));
  5676. #else
  5677. struct map_session_data *ssd = map_nick2sd(nick,false);
  5678. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5679. WFIFOW(fd,0) = 0x97;
  5680. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5681. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5682. // If it is not a message from the server or a player from another map-server
  5683. if( ssd ){
  5684. gmlvl = pc_get_group_level(ssd);
  5685. }
  5686. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5687. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5688. WFIFOSET(fd,WFIFOW(fd,2));
  5689. #endif
  5690. }
  5691. /// Inform the player about the result of his whisper action
  5692. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5693. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5694. /// result:
  5695. /// 0 = success to send wisper
  5696. /// 1 = target character is not loged in
  5697. /// 2 = ignored by target
  5698. /// 3 = everyone ignored by target
  5699. void clif_wis_end(int fd, int result)
  5700. {
  5701. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5702. #if PACKETVER < 20131223
  5703. const int cmd = 0x98;
  5704. #else
  5705. const int cmd = 0x9df;
  5706. #endif
  5707. if (!sd)
  5708. return;
  5709. WFIFOHEAD(fd,packet_len(cmd));
  5710. WFIFOW(fd,0) = cmd;
  5711. WFIFOB(fd,2) = (char)result;
  5712. #if PACKETVER >= 20131223
  5713. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5714. #endif
  5715. WFIFOSET(fd,packet_len(cmd));
  5716. }
  5717. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5718. /// 0194 <char id>.L <name>.24B
  5719. /// 0af7 <flag>.W <char id>.L <name>.24B
  5720. void clif_solved_charname(int fd, int charid, const char* name)
  5721. {
  5722. #if PACKETVER >= 20180221
  5723. WFIFOHEAD(fd,packet_len(0xaf7));
  5724. WFIFOW(fd,0) = 0xaf7;
  5725. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5726. WFIFOL(fd,4) = charid;
  5727. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5728. WFIFOSET(fd,packet_len(0x0af7));
  5729. #else
  5730. WFIFOHEAD(fd,packet_len(0x194));
  5731. WFIFOW(fd,0)=0x194;
  5732. WFIFOL(fd,2)=charid;
  5733. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5734. WFIFOSET(fd,packet_len(0x194));
  5735. #endif
  5736. }
  5737. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5738. /// 017b <packet len>.W { <name id>.W }*
  5739. void clif_use_card(struct map_session_data *sd,int idx)
  5740. {
  5741. int i,c,ep;
  5742. int fd=sd->fd;
  5743. nullpo_retv(sd);
  5744. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5745. return;
  5746. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5747. return; //Avoid parsing invalid item indexes (no card/no item)
  5748. ep=sd->inventory_data[idx]->equip;
  5749. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5750. WFIFOW(fd,0)=0x17b;
  5751. for(i=c=0;i<MAX_INVENTORY;i++){
  5752. int j;
  5753. if(sd->inventory_data[i] == NULL)
  5754. continue;
  5755. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5756. continue;
  5757. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5758. continue;
  5759. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5760. continue;
  5761. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5762. continue;
  5763. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5764. continue;
  5765. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5766. if( j == sd->inventory_data[i]->slot ) // No room
  5767. continue;
  5768. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5769. continue;
  5770. WFIFOW(fd,4+c*2)=i+2;
  5771. c++;
  5772. }
  5773. if( !c ) return; // no item is available for card insertion
  5774. WFIFOW(fd,2)=4+c*2;
  5775. WFIFOSET(fd,WFIFOW(fd,2));
  5776. }
  5777. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5778. /// 017d <equip index>.W <card index>.W <result>.B
  5779. /// result:
  5780. /// 0 = success
  5781. /// 1 = failure
  5782. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5783. {
  5784. int fd;
  5785. nullpo_retv(sd);
  5786. fd=sd->fd;
  5787. WFIFOHEAD(fd,packet_len(0x17d));
  5788. WFIFOW(fd,0)=0x17d;
  5789. WFIFOW(fd,2)=idx_equip+2;
  5790. WFIFOW(fd,4)=idx_card+2;
  5791. WFIFOB(fd,6)=flag;
  5792. WFIFOSET(fd,packet_len(0x17d));
  5793. }
  5794. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5795. /// 0177 <packet len>.W { <name id>.W }*
  5796. void clif_item_identify_list(struct map_session_data *sd)
  5797. {
  5798. int i,c;
  5799. int fd;
  5800. nullpo_retv(sd);
  5801. fd=sd->fd;
  5802. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5803. WFIFOW(fd,0)=0x177;
  5804. for(i=c=0;i<MAX_INVENTORY;i++){
  5805. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5806. WFIFOW(fd,c*2+4)=i+2;
  5807. c++;
  5808. }
  5809. }
  5810. if(c > 0) {
  5811. WFIFOW(fd,2)=c*2+4;
  5812. WFIFOSET(fd,WFIFOW(fd,2));
  5813. sd->menuskill_id = MC_IDENTIFY;
  5814. sd->menuskill_val = c;
  5815. sd->state.workinprogress = WIP_DISABLE_ALL;
  5816. }
  5817. }
  5818. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5819. /// 0179 <index>.W <result>.B
  5820. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5821. {
  5822. int fd;
  5823. nullpo_retv(sd);
  5824. fd=sd->fd;
  5825. WFIFOHEAD(fd,packet_len(0x179));
  5826. WFIFOW(fd, 0)=0x179;
  5827. WFIFOW(fd, 2)=idx+2;
  5828. WFIFOB(fd, 4)=flag;
  5829. WFIFOSET(fd,packet_len(0x179));
  5830. }
  5831. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5832. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5833. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5834. {
  5835. int i,c;
  5836. int fd;
  5837. nullpo_retv(sd);
  5838. nullpo_retv(dstsd);
  5839. fd=sd->fd;
  5840. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5841. WFIFOW(fd,0)=0x1fc;
  5842. for(i=c=0;i<MAX_INVENTORY;i++){
  5843. unsigned short nameid;
  5844. if((nameid=dstsd->inventory.u.items_inventory[i].nameid) > 0 && dstsd->inventory.u.items_inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5845. WFIFOW(fd,c*13+4) = i;
  5846. WFIFOW(fd,c*13+6) = nameid;
  5847. WFIFOB(fd,c*13+8) = dstsd->inventory.u.items_inventory[i].refine;
  5848. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->inventory.u.items_inventory[i]);
  5849. c++;
  5850. }
  5851. }
  5852. if(c > 0) {
  5853. WFIFOW(fd,2)=c*13+4;
  5854. WFIFOSET(fd,WFIFOW(fd,2));
  5855. sd->menuskill_id = BS_REPAIRWEAPON;
  5856. sd->menuskill_val = dstsd->bl.id;
  5857. sd->menuskill_val2 = lv;
  5858. }else
  5859. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5860. }
  5861. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5862. /// 01fe <index>.W <result>.B
  5863. /// index:
  5864. /// ignored (inventory index)
  5865. /// result:
  5866. /// 0 = Item repair success.
  5867. /// 1 = Item repair failure.
  5868. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5869. {
  5870. int fd;
  5871. nullpo_retv(sd);
  5872. fd = sd->fd;
  5873. WFIFOHEAD(fd,packet_len(0x1fe));
  5874. WFIFOW(fd, 0)=0x1fe;
  5875. WFIFOW(fd, 2)=idx+2;
  5876. WFIFOB(fd, 4)=flag;
  5877. WFIFOSET(fd,packet_len(0x1fe));
  5878. }
  5879. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5880. /// 02bb <equip location>.W <account id>.L
  5881. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5882. {
  5883. int fd = sd->fd;
  5884. WFIFOHEAD(fd,packet_len(0x2bb));
  5885. WFIFOW(fd,0) = 0x2bb;
  5886. WFIFOW(fd,2) = position;
  5887. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5888. WFIFOSET(fd,packet_len(0x2bb));
  5889. }
  5890. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5891. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5892. void clif_item_refine_list(struct map_session_data *sd)
  5893. {
  5894. int i,c;
  5895. int fd;
  5896. uint16 skill_lv;
  5897. int refine_item[5];
  5898. nullpo_retv(sd);
  5899. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5900. fd=sd->fd;
  5901. refine_item[0] = -1;
  5902. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5903. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5904. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5905. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5906. WFIFOW(fd,0) = 0x221;
  5907. for(i = c = 0; i < MAX_INVENTORY; i++) {
  5908. unsigned char wlv;
  5909. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5910. sd->inventory.u.items_inventory[i].identify && (wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid)) >=1 &&
  5911. refine_item[wlv] != -1 && !(sd->inventory.u.items_inventory[i].equip&EQP_ARMS)){
  5912. WFIFOW(fd,c*13+ 4)=i+2;
  5913. WFIFOW(fd,c*13+ 6) = sd->inventory.u.items_inventory[i].nameid;
  5914. WFIFOB(fd,c*13+ 8) = sd->inventory.u.items_inventory[i].refine;
  5915. clif_addcards(WFIFOP(fd,c*13+9), &sd->inventory.u.items_inventory[i]);
  5916. c++;
  5917. }
  5918. }
  5919. WFIFOW(fd,2)=c*13+4;
  5920. WFIFOSET(fd,WFIFOW(fd,2));
  5921. if (c > 0) {
  5922. sd->menuskill_id = WS_WEAPONREFINE;
  5923. sd->menuskill_val = skill_lv;
  5924. }
  5925. }
  5926. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5927. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5928. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5929. {
  5930. int fd;
  5931. nullpo_retv(sd);
  5932. fd=sd->fd;
  5933. WFIFOHEAD(fd,packet_len(0x147));
  5934. WFIFOW(fd, 0)=0x147;
  5935. WFIFOW(fd, 2)=skill_id;
  5936. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5937. WFIFOW(fd, 6)=0;
  5938. WFIFOW(fd, 8)=skill_lv;
  5939. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5940. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5941. safestrncpy(WFIFOCP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5942. WFIFOB(fd,38)=0;
  5943. WFIFOSET(fd,packet_len(0x147));
  5944. }
  5945. /// Adds an item to character's cart.
  5946. /// 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)
  5947. /// 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)
  5948. /// 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)
  5949. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5950. {
  5951. #if PACKETVER < 5
  5952. const int cmd = 0x124;
  5953. #elif PACKETVER < 20150225
  5954. const int cmd = 0x1c5;
  5955. #else
  5956. const int cmd = 0xa0b;
  5957. #endif
  5958. int view,fd;
  5959. unsigned char *buf;
  5960. int offset = 0;
  5961. nullpo_retv(sd);
  5962. fd=sd->fd;
  5963. if(n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0)
  5964. return;
  5965. WFIFOHEAD(fd,packet_len(cmd));
  5966. buf=WFIFOP(fd,0);
  5967. WBUFW(buf,0)=cmd;
  5968. WBUFW(buf,2)=n+2;
  5969. WBUFL(buf,4)=amount;
  5970. if((view = itemdb_viewid(sd->cart.u.items_cart[n].nameid)) > 0)
  5971. WBUFW(buf,8)=view;
  5972. else
  5973. WBUFW(buf,8)=sd->cart.u.items_cart[n].nameid;
  5974. #if PACKETVER >= 5
  5975. WBUFB(buf,10)=itemdb_type(sd->cart.u.items_cart[n].nameid);
  5976. offset += 1;
  5977. #endif
  5978. WBUFB(buf,10+offset)=sd->cart.u.items_cart[n].identify;
  5979. WBUFB(buf,11+offset)=sd->cart.u.items_cart[n].attribute;
  5980. WBUFB(buf,12+offset)=sd->cart.u.items_cart[n].refine;
  5981. clif_addcards(WBUFP(buf,13+offset), &sd->cart.u.items_cart[n]);
  5982. #if PACKETVER >= 20150225
  5983. clif_add_random_options(WBUFP(buf,21+offset), &sd->cart.u.items_cart[n]);
  5984. #endif
  5985. WFIFOSET(fd,packet_len(cmd));
  5986. }
  5987. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5988. /* Acknowledge an item have been added to cart
  5989. * 012c <result>B
  5990. * result :
  5991. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5992. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5993. */
  5994. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5995. {
  5996. int fd;
  5997. unsigned char *buf;
  5998. nullpo_retv(sd);
  5999. fd = sd->fd;
  6000. buf = WFIFOP(fd,0);
  6001. WBUFW(buf,0) = 0x12c;
  6002. WBUFB(buf,2) = flag;
  6003. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6004. }
  6005. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6006. void clif_bank_open(struct map_session_data *sd){
  6007. int fd;
  6008. nullpo_retv(sd);
  6009. fd = sd->fd;
  6010. WFIFOHEAD(fd,4);
  6011. WFIFOW(fd,0) = 0x09b7;
  6012. WFIFOW(fd,2) = 0;
  6013. WFIFOSET(fd,4);
  6014. }
  6015. /*
  6016. * Request to Open the banking system
  6017. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6018. */
  6019. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6020. //TODO check if preventing trade or stuff like that
  6021. //also mark something in case char ain't available for saving, should we check now ?
  6022. nullpo_retv(sd);
  6023. if( !battle_config.feature_banking ) {
  6024. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6025. return;
  6026. }
  6027. else {
  6028. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6029. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6030. if(sd->status.account_id == aid){
  6031. sd->state.banking = 1;
  6032. //request save ?
  6033. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6034. //on succes open bank ?
  6035. clif_bank_open(sd);
  6036. }
  6037. }
  6038. }
  6039. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6040. void clif_bank_close(struct map_session_data *sd){
  6041. int fd;
  6042. nullpo_retv(sd);
  6043. fd = sd->fd;
  6044. WFIFOHEAD(fd,4);
  6045. WFIFOW(fd,0) = 0x09B9;
  6046. WFIFOW(fd,2) = 0;
  6047. WFIFOSET(fd,4);
  6048. }
  6049. /*
  6050. * Request to close the banking system
  6051. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6052. */
  6053. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6054. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6055. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6056. nullpo_retv(sd);
  6057. if( !battle_config.feature_banking ) {
  6058. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6059. //still allow to go trough to not stuck player if we have disable it while they was in
  6060. }
  6061. if(sd->status.account_id == aid){
  6062. sd->state.banking = 0;
  6063. clif_bank_close(sd);
  6064. }
  6065. }
  6066. /*
  6067. * Display how much we got in bank (I suppose)
  6068. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6069. */
  6070. void clif_Bank_Check(struct map_session_data* sd) {
  6071. unsigned char buf[13];
  6072. struct s_packet_db* info;
  6073. int16 len;
  6074. int cmd = 0;
  6075. nullpo_retv(sd);
  6076. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6077. if(!cmd) cmd = 0x09A6; //default
  6078. info = &packet_db[cmd];
  6079. len = info->len;
  6080. if(!len) return; //version as packet disable
  6081. // sd->state.banking = 1; //mark opening and closing
  6082. WBUFW(buf,0) = cmd;
  6083. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6084. WBUFW(buf,info->pos[1]) = 0; //reason
  6085. clif_send(buf,len,&sd->bl,SELF);
  6086. }
  6087. /*
  6088. * Requesting the data in bank
  6089. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6090. */
  6091. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6092. nullpo_retv(sd);
  6093. if( !battle_config.feature_banking ) {
  6094. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6095. return;
  6096. }
  6097. else {
  6098. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6099. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6100. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6101. clif_Bank_Check(sd);
  6102. }
  6103. }
  6104. /*
  6105. * Acknowledge of deposit some money in bank
  6106. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6107. */
  6108. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6109. unsigned char buf[17];
  6110. struct s_packet_db* info;
  6111. int16 len;
  6112. int cmd =0;
  6113. nullpo_retv(sd);
  6114. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6115. if(!cmd) cmd = 0x09A8;
  6116. info = &packet_db[cmd];
  6117. len = info->len;
  6118. if(!len) return; //version as packet disable
  6119. WBUFW(buf,0) = cmd;
  6120. WBUFW(buf,info->pos[0]) = (short)reason;
  6121. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6122. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6123. clif_send(buf,len,&sd->bl,SELF);
  6124. }
  6125. /*
  6126. * Request saving some money in bank
  6127. * @author : original [Yommy/Hercules]
  6128. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6129. */
  6130. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6131. nullpo_retv(sd);
  6132. if( !battle_config.feature_banking ) {
  6133. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6134. return;
  6135. }
  6136. else {
  6137. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6138. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6139. int money = RFIFOL(fd,info->pos[1]);
  6140. if(sd->status.account_id == aid){
  6141. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6142. clif_bank_deposit(sd,reason);
  6143. }
  6144. }
  6145. }
  6146. /*
  6147. * Acknowledge of withdrawing some money from bank
  6148. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6149. */
  6150. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6151. unsigned char buf[17];
  6152. struct s_packet_db* info;
  6153. int16 len;
  6154. int cmd;
  6155. nullpo_retv(sd);
  6156. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6157. if(!cmd) cmd = 0x09AA;
  6158. info = &packet_db[cmd];
  6159. len = info->len;
  6160. if(!len) return; //version as packet disable
  6161. WBUFW(buf,0) = cmd;
  6162. WBUFW(buf,info->pos[0]) = (short)reason;
  6163. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6164. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6165. clif_send(buf,len,&sd->bl,SELF);
  6166. }
  6167. /*
  6168. * Request Withdrawing some money from bank
  6169. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6170. */
  6171. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6172. nullpo_retv(sd);
  6173. if( !battle_config.feature_banking ) {
  6174. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6175. return;
  6176. }
  6177. else {
  6178. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6179. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6180. int money = RFIFOL(fd,info->pos[1]);
  6181. if(sd->status.account_id == aid){
  6182. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6183. clif_bank_withdraw(sd,reason);
  6184. }
  6185. }
  6186. }
  6187. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6188. /// 0125 <index>.W <amount>.L
  6189. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6190. {
  6191. int fd;
  6192. nullpo_retv(sd);
  6193. fd=sd->fd;
  6194. WFIFOHEAD(fd,packet_len(0x125));
  6195. WFIFOW(fd,0)=0x125;
  6196. WFIFOW(fd,2)=n+2;
  6197. WFIFOL(fd,4)=amount;
  6198. WFIFOSET(fd,packet_len(0x125));
  6199. }
  6200. /// Opens the shop creation menu (ZC_OPENSTORE).
  6201. /// 012d <num>.W
  6202. /// num:
  6203. /// number of allowed item slots
  6204. void clif_openvendingreq(struct map_session_data* sd, int num)
  6205. {
  6206. int fd;
  6207. nullpo_retv(sd);
  6208. fd = sd->fd;
  6209. WFIFOHEAD(fd,packet_len(0x12d));
  6210. WFIFOW(fd,0) = 0x12d;
  6211. WFIFOW(fd,2) = num;
  6212. WFIFOSET(fd,packet_len(0x12d));
  6213. }
  6214. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6215. /// 0131 <owner id>.L <message>.80B
  6216. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6217. {
  6218. unsigned char buf[128];
  6219. nullpo_retv(bl);
  6220. WBUFW(buf,0) = 0x131;
  6221. WBUFL(buf,2) = bl->id;
  6222. safestrncpy(WBUFCP(buf,6), message, 80);
  6223. if( fd ) {
  6224. WFIFOHEAD(fd,packet_len(0x131));
  6225. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6226. WFIFOSET(fd,packet_len(0x131));
  6227. } else {
  6228. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6229. }
  6230. }
  6231. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6232. /// 0132 <owner id>.L
  6233. void clif_closevendingboard(struct block_list* bl, int fd)
  6234. {
  6235. unsigned char buf[16];
  6236. nullpo_retv(bl);
  6237. WBUFW(buf,0) = 0x132;
  6238. WBUFL(buf,2) = bl->id;
  6239. if( fd ) {
  6240. WFIFOHEAD(fd,packet_len(0x132));
  6241. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6242. WFIFOSET(fd,packet_len(0x132));
  6243. } else {
  6244. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6245. }
  6246. }
  6247. /// Sends a list of items in a shop.
  6248. /// 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)
  6249. /// 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)
  6250. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6251. {
  6252. int i,fd;
  6253. int count;
  6254. struct map_session_data* vsd;
  6255. #if PACKETVER < 20100105
  6256. const int cmd = 0x133;
  6257. const int offset = 8;
  6258. #else
  6259. const int cmd = 0x800;
  6260. const int offset = 12;
  6261. #endif
  6262. #if PACKETVER < 20150225
  6263. const int item_length = 22;
  6264. #elif PACKETVER < 20160921
  6265. const int item_length = 47;
  6266. #else
  6267. const int item_length = 53;
  6268. #endif
  6269. nullpo_retv(sd);
  6270. nullpo_retv(vending);
  6271. nullpo_retv(vsd=map_id2sd(id));
  6272. fd = sd->fd;
  6273. count = vsd->vend_num;
  6274. WFIFOHEAD(fd, offset+count*item_length);
  6275. WFIFOW(fd,0) = cmd;
  6276. WFIFOW(fd,2) = offset+count*item_length;
  6277. WFIFOL(fd,4) = id;
  6278. #if PACKETVER >= 20100105
  6279. WFIFOL(fd,8) = vsd->vender_id;
  6280. #endif
  6281. for( i = 0; i < count; i++ )
  6282. {
  6283. int index = vending[i].index;
  6284. struct item_data* data = itemdb_search(vsd->cart.u.items_cart[index].nameid);
  6285. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6286. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6287. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6288. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6289. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->cart.u.items_cart[index].nameid;
  6290. WFIFOB(fd,offset+11+i*item_length) = vsd->cart.u.items_cart[index].identify;
  6291. WFIFOB(fd,offset+12+i*item_length) = vsd->cart.u.items_cart[index].attribute;
  6292. WFIFOB(fd,offset+13+i*item_length) = vsd->cart.u.items_cart[index].refine;
  6293. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->cart.u.items_cart[index]);
  6294. #if PACKETVER >= 20150225
  6295. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->cart.u.items_cart[index]);
  6296. #if PACKETVER >= 20160921
  6297. WFIFOL(fd,offset+47+i*item_length) = pc_equippoint_sub(sd,data);
  6298. WFIFOW(fd,offset+51+i*item_length) = data->look;
  6299. #endif
  6300. #endif
  6301. }
  6302. WFIFOSET(fd,WFIFOW(fd,2));
  6303. }
  6304. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6305. /// 0135 <index>.W <amount>.W <result>.B
  6306. /// result:
  6307. /// 0 = success
  6308. /// 1 = not enough zeny
  6309. /// 2 = overweight
  6310. /// 4 = out of stock
  6311. /// 5 = "cannot use an npc shop while in a trade"
  6312. /// 6 = Because the store information was incorrect the item was not purchased.
  6313. /// 7 = No sales information.
  6314. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6315. {
  6316. int fd;
  6317. nullpo_retv(sd);
  6318. fd = sd->fd;
  6319. WFIFOHEAD(fd,packet_len(0x135));
  6320. WFIFOW(fd,0) = 0x135;
  6321. WFIFOW(fd,2) = index+2;
  6322. WFIFOW(fd,4) = amount;
  6323. WFIFOB(fd,6) = fail;
  6324. WFIFOSET(fd,packet_len(0x135));
  6325. }
  6326. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6327. /// 0a28 <Result>.B
  6328. /// result:
  6329. /// 0 = Successed
  6330. /// 1 = Failed
  6331. void clif_openvending_ack(struct map_session_data* sd, int result)
  6332. {
  6333. int fd;
  6334. nullpo_retv(sd);
  6335. fd = sd->fd;
  6336. WFIFOHEAD(fd, 3);
  6337. WFIFOW(fd,0) = 0xa28;
  6338. WFIFOB(fd,2) = result;
  6339. WFIFOSET(fd, 3);
  6340. }
  6341. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6342. /// 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 }*
  6343. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6344. {
  6345. int i,fd;
  6346. int count;
  6347. #if PACKETVER < 20150225
  6348. const int item_length = 22;
  6349. #else
  6350. const int item_length = 47;
  6351. #endif
  6352. nullpo_retv(sd);
  6353. fd = sd->fd;
  6354. count = sd->vend_num;
  6355. WFIFOHEAD(fd, 8+count*item_length);
  6356. WFIFOW(fd,0) = 0x136;
  6357. WFIFOW(fd,2) = 8+count*item_length;
  6358. WFIFOL(fd,4) = id;
  6359. for( i = 0; i < count; i++ ) {
  6360. int index = vending[i].index;
  6361. struct item_data* data = itemdb_search(sd->cart.u.items_cart[index].nameid);
  6362. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6363. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6364. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6365. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6366. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->cart.u.items_cart[index].nameid;
  6367. WFIFOB(fd,19+i*item_length) = sd->cart.u.items_cart[index].identify;
  6368. WFIFOB(fd,20+i*item_length) = sd->cart.u.items_cart[index].attribute;
  6369. WFIFOB(fd,21+i*item_length) = sd->cart.u.items_cart[index].refine;
  6370. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->cart.u.items_cart[index]);
  6371. #if PACKETVER >= 20150225
  6372. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->cart.u.items_cart[index]);
  6373. #endif
  6374. }
  6375. WFIFOSET(fd,WFIFOW(fd,2));
  6376. #if PACKETVER >= 20141022
  6377. /// 0 = Successed
  6378. /// 1 = Failed
  6379. clif_openvending_ack(sd, 0);
  6380. #endif
  6381. }
  6382. /// Inform merchant that someone has bought an item.
  6383. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6384. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6385. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6386. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6387. const int cmd = 0x137;
  6388. #else
  6389. const int cmd = 0x9e5;
  6390. #endif
  6391. int fd = sd->fd;
  6392. nullpo_retv(sd);
  6393. WFIFOHEAD(fd,packet_len(cmd));
  6394. WFIFOW(fd,0) = cmd;
  6395. WFIFOW(fd,2) = index+2;
  6396. WFIFOW(fd,4) = amount;
  6397. #if PACKETVER >= 20141016
  6398. WFIFOL(fd,6) = char_id; // GID
  6399. WFIFOL(fd,10) = (int)time(NULL); // Date
  6400. WFIFOL(fd,14) = zeny; // zeny
  6401. #endif
  6402. WFIFOSET(fd,packet_len(cmd));
  6403. }
  6404. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6405. /// 00fa <result>.B
  6406. /// result:
  6407. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6408. /// 1 = MsgStringTable[78]="party name already exists"
  6409. /// 2 = MsgStringTable[79]="already in a party"
  6410. /// 3 = cannot organize parties on this map
  6411. /// ? = nothing
  6412. void clif_party_created(struct map_session_data *sd,int result)
  6413. {
  6414. int fd;
  6415. nullpo_retv(sd);
  6416. fd=sd->fd;
  6417. WFIFOHEAD(fd,packet_len(0xfa));
  6418. WFIFOW(fd,0)=0xfa;
  6419. WFIFOB(fd,2)=result;
  6420. WFIFOSET(fd,packet_len(0xfa));
  6421. }
  6422. /// Adds new member to a party.
  6423. /// 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)
  6424. /// 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)
  6425. /// 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)
  6426. /// role:
  6427. /// 0 = leader
  6428. /// 1 = normal
  6429. /// state:
  6430. /// 0 = connected
  6431. /// 1 = disconnected
  6432. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6433. {
  6434. int i;
  6435. #if PACKETVER < 20170502
  6436. unsigned char buf[81];
  6437. int cmd = 0x1e9;
  6438. int offset = 0;
  6439. #else
  6440. unsigned char buf[85];
  6441. int cmd = 0xa43;
  6442. int offset = 4;
  6443. #endif
  6444. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6445. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6446. } else {
  6447. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6448. }
  6449. if (i >= MAX_PARTY) return; //Should never happen...
  6450. sd = p->data[i].sd;
  6451. WBUFW(buf, 0) = cmd;
  6452. WBUFL(buf, 2) = sd->status.account_id;
  6453. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6454. #if PACKETVER >= 20170502
  6455. WBUFW(buf,10) = sd->status.class_;
  6456. WBUFW(buf,12) = sd->status.base_level;
  6457. #endif
  6458. WBUFW(buf,offset+10) = sd->bl.x;
  6459. WBUFW(buf,offset+12) = sd->bl.y;
  6460. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6461. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6462. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6463. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6464. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6465. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6466. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6467. }
  6468. /// Sends party information (ZC_GROUP_LIST).
  6469. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6470. /// role:
  6471. /// 0 = leader
  6472. /// 1 = normal
  6473. /// state:
  6474. /// 0 = connected
  6475. /// 1 = disconnected
  6476. /// 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
  6477. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6478. {
  6479. struct map_session_data* party_sd = NULL;
  6480. int i, c;
  6481. #if PACKETVER < 20170502
  6482. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6483. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6484. int cmd = 0xfb;
  6485. #else
  6486. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6487. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6488. int cmd = 0xa44;
  6489. #endif
  6490. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6491. nullpo_retv(p);
  6492. WBUFW(buf,0) = cmd;
  6493. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6494. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6495. {
  6496. struct party_member* m = &p->party.member[i];
  6497. if(!m->account_id) continue;
  6498. if(party_sd == NULL) party_sd = p->data[i].sd;
  6499. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6500. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6501. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6502. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6503. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6504. #if PACKETVER >= 20170502
  6505. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6506. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6507. #endif
  6508. c++;
  6509. }
  6510. #if PACKETVER < 20170502
  6511. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6512. #else
  6513. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6514. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6515. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6516. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6517. #endif
  6518. if(sd) { // send only to self
  6519. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6520. } else if (party_sd) { // send to whole party
  6521. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6522. }
  6523. }
  6524. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6525. /// 02c9 <flag>.B
  6526. /// flag:
  6527. /// 0 = allow party invites
  6528. /// 1 = auto-deny party invites
  6529. void clif_partyinvitationstate(struct map_session_data* sd)
  6530. {
  6531. int fd;
  6532. nullpo_retv(sd);
  6533. fd = sd->fd;
  6534. WFIFOHEAD(fd, packet_len(0x2c9));
  6535. WFIFOW(fd, 0) = 0x2c9;
  6536. WFIFOB(fd, 2) = 0; // not implemented
  6537. WFIFOSET(fd, packet_len(0x2c9));
  6538. }
  6539. /// Party invitation request.
  6540. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6541. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6542. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6543. {
  6544. #if PACKETVER < 20070821
  6545. const int cmd = 0xfe;
  6546. #else
  6547. const int cmd = 0x2c6;
  6548. #endif
  6549. int fd;
  6550. struct party_data *p;
  6551. nullpo_retv(sd);
  6552. nullpo_retv(tsd);
  6553. fd=tsd->fd;
  6554. if( (p=party_search(sd->status.party_id))==NULL )
  6555. return;
  6556. WFIFOHEAD(fd,packet_len(cmd));
  6557. WFIFOW(fd,0)=cmd;
  6558. WFIFOL(fd,2)=sd->status.party_id;
  6559. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6560. WFIFOSET(fd,packet_len(cmd));
  6561. }
  6562. /// Party invite result.
  6563. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6564. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6565. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6566. {
  6567. int fd;
  6568. nullpo_retv(sd);
  6569. fd=sd->fd;
  6570. #if PACKETVER < 20070904
  6571. if( reply == PARTY_REPLY_OFFLINE ) {
  6572. clif_displaymessage(fd, msg_txt(sd,3));
  6573. return;
  6574. }
  6575. #endif
  6576. #if PACKETVER < 20070821
  6577. WFIFOHEAD(fd,packet_len(0xfd));
  6578. WFIFOW(fd,0) = 0xfd;
  6579. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6580. WFIFOB(fd,26) = reply;
  6581. WFIFOSET(fd,packet_len(0xfd));
  6582. #else
  6583. WFIFOHEAD(fd,packet_len(0x2c5));
  6584. WFIFOW(fd,0) = 0x2c5;
  6585. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6586. WFIFOL(fd,26) = reply;
  6587. WFIFOSET(fd,packet_len(0x2c5));
  6588. #endif
  6589. }
  6590. /// Updates party settings.
  6591. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6592. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6593. /// exp option:
  6594. /// 0 = exp sharing disabled
  6595. /// 1 = exp sharing enabled
  6596. /// 2 = cannot change exp sharing
  6597. ///
  6598. /// flag:
  6599. /// 0 = send to party
  6600. /// 1 = send to sd
  6601. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6602. {
  6603. unsigned char buf[16];
  6604. #if PACKETVER < 20090603
  6605. const int cmd = 0x101;
  6606. #else
  6607. const int cmd = 0x7d8;
  6608. #endif
  6609. nullpo_retv(p);
  6610. if(!sd && flag==0){
  6611. int i;
  6612. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6613. if (i < MAX_PARTY)
  6614. sd = p->data[i].sd;
  6615. }
  6616. if(!sd) return;
  6617. WBUFW(buf,0)=cmd;
  6618. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6619. #if PACKETVER >= 20090603
  6620. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6621. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6622. #endif
  6623. if(flag==0)
  6624. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6625. else
  6626. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6627. }
  6628. /**
  6629. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6630. * @param sd Send the notification for this player
  6631. * @param account_id Account ID of kicked member
  6632. * @param name Name of kicked member
  6633. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6634. * @param target Send target
  6635. **/
  6636. 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) {
  6637. unsigned char buf[2+4+NAME_LENGTH+1];
  6638. if (!sd)
  6639. return;
  6640. WBUFW(buf,0) = 0x0105;
  6641. WBUFL(buf,2) = account_id;
  6642. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6643. WBUFB(buf,6+NAME_LENGTH) = result;
  6644. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6645. }
  6646. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6647. /// 0109 <packet len>.W <account id>.L <message>.?B
  6648. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6649. {
  6650. struct map_session_data *sd;
  6651. int i;
  6652. nullpo_retv(p);
  6653. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6654. if(i < MAX_PARTY){
  6655. unsigned char buf[1024];
  6656. if( len > sizeof(buf)-8 )
  6657. {
  6658. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6659. len = sizeof(buf)-8;
  6660. }
  6661. sd = p->data[i].sd;
  6662. WBUFW(buf,0)=0x109;
  6663. WBUFW(buf,2)=len+8;
  6664. WBUFL(buf,4)=account_id;
  6665. safestrncpy(WBUFCP(buf,8), mes, len);
  6666. clif_send(buf,len+8,&sd->bl,PARTY);
  6667. }
  6668. }
  6669. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6670. /// 0107 <account id>.L <x>.W <y>.W
  6671. void clif_party_xy(struct map_session_data *sd)
  6672. {
  6673. unsigned char buf[16];
  6674. nullpo_retv(sd);
  6675. WBUFW(buf,0)=0x107;
  6676. WBUFL(buf,2)=sd->status.account_id;
  6677. WBUFW(buf,6)=sd->bl.x;
  6678. WBUFW(buf,8)=sd->bl.y;
  6679. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6680. }
  6681. /*==========================================
  6682. * Sends x/y dot to a single fd. [Skotlex]
  6683. *------------------------------------------*/
  6684. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6685. {
  6686. WFIFOHEAD(fd,packet_len(0x107));
  6687. WFIFOW(fd,0)=0x107;
  6688. WFIFOL(fd,2)=sd->status.account_id;
  6689. WFIFOW(fd,6)=sd->bl.x;
  6690. WFIFOW(fd,8)=sd->bl.y;
  6691. WFIFOSET(fd,packet_len(0x107));
  6692. }
  6693. /// Updates HP bar of a party member.
  6694. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6695. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6696. void clif_party_hp(struct map_session_data *sd)
  6697. {
  6698. unsigned char buf[16];
  6699. #if PACKETVER < 20100126
  6700. const int cmd = 0x106;
  6701. #else
  6702. const int cmd = 0x80e;
  6703. #endif
  6704. nullpo_retv(sd);
  6705. WBUFW(buf,0)=cmd;
  6706. WBUFL(buf,2)=sd->status.account_id;
  6707. #if PACKETVER < 20100126
  6708. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6709. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6710. WBUFW(buf,8) = 100;
  6711. } else {
  6712. WBUFW(buf,6) = sd->battle_status.hp;
  6713. WBUFW(buf,8) = sd->battle_status.max_hp;
  6714. }
  6715. #else
  6716. WBUFL(buf,6) = sd->battle_status.hp;
  6717. WBUFL(buf,10) = sd->battle_status.max_hp;
  6718. #endif
  6719. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6720. }
  6721. /// Notifies the party members of a character's death or revival.
  6722. /// 0AB2 <GID>.L <dead>.B
  6723. void clif_party_dead( struct map_session_data *sd ){
  6724. #if PACKETVER >= 20170502
  6725. unsigned char buf[7];
  6726. nullpo_retv(sd);
  6727. WBUFW(buf, 0) = 0xab2;
  6728. WBUFL(buf, 2) = sd->status.account_id;
  6729. WBUFB(buf, 6) = pc_isdead(sd);
  6730. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6731. #endif
  6732. }
  6733. /// Updates the job and level of a party member
  6734. /// 0abd <account id>.L <job>.W <level>.W
  6735. void clif_party_job_and_level(struct map_session_data *sd){
  6736. #if PACKETVER >= 20170502
  6737. unsigned char buf[10];
  6738. nullpo_retv(sd);
  6739. WBUFW(buf, 0) = 0xabd;
  6740. WBUFL(buf, 2) = sd->status.account_id;
  6741. WBUFW(buf, 6) = sd->status.class_;
  6742. WBUFW(buf, 8) = sd->status.base_level;
  6743. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6744. #endif
  6745. }
  6746. /*==========================================
  6747. * Sends HP bar to a single fd. [Skotlex]
  6748. *------------------------------------------*/
  6749. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6750. {
  6751. #if PACKETVER < 20100126
  6752. const int cmd = 0x106;
  6753. #else
  6754. const int cmd = 0x80e;
  6755. #endif
  6756. WFIFOHEAD(fd,packet_len(cmd));
  6757. WFIFOW(fd,0) = cmd;
  6758. WFIFOL(fd,2) = id;
  6759. #if PACKETVER < 20100126
  6760. if( maxhp > INT16_MAX )
  6761. {// To correctly display the %hp bar. [Skotlex]
  6762. WFIFOW(fd,6) = hp/(maxhp/100);
  6763. WFIFOW(fd,8) = 100;
  6764. } else {
  6765. WFIFOW(fd,6) = hp;
  6766. WFIFOW(fd,8) = maxhp;
  6767. }
  6768. #else
  6769. WFIFOL(fd,6) = hp;
  6770. WFIFOL(fd,10) = maxhp;
  6771. #endif
  6772. WFIFOSET(fd, packet_len(cmd));
  6773. }
  6774. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6775. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6776. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6777. {
  6778. int fd;
  6779. nullpo_retv(sd);
  6780. nullpo_retv(bl);
  6781. fd=sd->fd;
  6782. WFIFOHEAD(fd,packet_len(0x139));
  6783. WFIFOW(fd, 0)=0x139;
  6784. WFIFOL(fd, 2)=bl->id;
  6785. WFIFOW(fd, 6)=bl->x;
  6786. WFIFOW(fd, 8)=bl->y;
  6787. WFIFOW(fd,10)=sd->bl.x;
  6788. WFIFOW(fd,12)=sd->bl.y;
  6789. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6790. WFIFOSET(fd,packet_len(0x139));
  6791. }
  6792. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6793. /// 018f <result>.W <name id>.W
  6794. /// result:
  6795. /// 0 = success
  6796. /// 1 = failure
  6797. /// 2 = success (alchemist)
  6798. /// 3 = failure (alchemist)
  6799. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6800. {
  6801. int view,fd;
  6802. nullpo_retv(sd);
  6803. fd = sd->fd;
  6804. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6805. WFIFOHEAD(fd,packet_len(0x18f));
  6806. WFIFOW(fd, 0)=0x18f;
  6807. WFIFOW(fd, 2)=flag;
  6808. if((view = itemdb_viewid(nameid)) > 0)
  6809. WFIFOW(fd, 4)=view;
  6810. else
  6811. WFIFOW(fd, 4)=nameid;
  6812. WFIFOSET(fd,packet_len(0x18f));
  6813. }
  6814. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6815. /// 019e
  6816. void clif_catch_process(struct map_session_data *sd)
  6817. {
  6818. int fd;
  6819. nullpo_retv(sd);
  6820. fd=sd->fd;
  6821. WFIFOHEAD(fd,packet_len(0x19e));
  6822. WFIFOW(fd,0)=0x19e;
  6823. WFIFOSET(fd,packet_len(0x19e));
  6824. }
  6825. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6826. /// 01a0 <result>.B
  6827. /// 0 = failure
  6828. /// 1 = success
  6829. void clif_pet_roulette(struct map_session_data *sd,int data)
  6830. {
  6831. int fd;
  6832. nullpo_retv(sd);
  6833. fd=sd->fd;
  6834. WFIFOHEAD(fd,packet_len(0x1a0));
  6835. WFIFOW(fd,0)=0x1a0;
  6836. WFIFOB(fd,2)=data;
  6837. WFIFOSET(fd,packet_len(0x1a0));
  6838. }
  6839. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6840. /// 01a6 <packet len>.W { <index>.W }*
  6841. void clif_sendegg(struct map_session_data *sd)
  6842. {
  6843. int i,n=0,fd;
  6844. nullpo_retv(sd);
  6845. fd=sd->fd;
  6846. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6847. clif_displaymessage(fd, msg_txt(sd,666));
  6848. return;
  6849. }
  6850. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6851. WFIFOW(fd,0)=0x1a6;
  6852. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6853. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6854. sd->inventory_data[i]->type != IT_PETEGG ||
  6855. sd->inventory.u.items_inventory[i].amount <= 0)
  6856. continue;
  6857. WFIFOW(fd,n*2+4)=i+2;
  6858. n++;
  6859. }
  6860. WFIFOW(fd,2)=4+n*2;
  6861. WFIFOSET(fd,WFIFOW(fd,2));
  6862. sd->menuskill_id = SA_TAMINGMONSTER;
  6863. sd->menuskill_val = -1;
  6864. }
  6865. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6866. /// 01a4 <type>.B <id>.L <data>.L
  6867. /// type:
  6868. /// 0 = pre-init (data = 0)
  6869. /// 1 = intimacy (data = 0~4)
  6870. /// 2 = hunger (data = 0~4)
  6871. /// 3 = accessory
  6872. /// 4 = performance (data = 1~3: normal, 4: special)
  6873. /// 5 = hairstyle
  6874. ///
  6875. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6876. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6877. {
  6878. uint8 buf[16];
  6879. nullpo_retv(pd);
  6880. WBUFW(buf,0) = 0x1a4;
  6881. WBUFB(buf,2) = type;
  6882. WBUFL(buf,3) = pd->bl.id;
  6883. WBUFL(buf,7) = param;
  6884. if (sd)
  6885. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6886. else
  6887. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6888. }
  6889. /// Pet's base data (ZC_PROPERTY_PET).
  6890. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6891. void clif_send_petstatus(struct map_session_data *sd)
  6892. {
  6893. int fd;
  6894. struct s_pet *pet;
  6895. nullpo_retv(sd);
  6896. nullpo_retv(sd->pd);
  6897. fd=sd->fd;
  6898. pet = &sd->pd->pet;
  6899. WFIFOHEAD(fd,packet_len(0x1a2));
  6900. WFIFOW(fd,0)=0x1a2;
  6901. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6902. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6903. WFIFOW(fd,27)=pet->level;
  6904. WFIFOW(fd,29)=pet->hungry;
  6905. WFIFOW(fd,31)=pet->intimate;
  6906. WFIFOW(fd,33)=pet->equip;
  6907. #if PACKETVER >= 20081126
  6908. WFIFOW(fd,35)=pet->class_;
  6909. #endif
  6910. WFIFOSET(fd,packet_len(0x1a2));
  6911. }
  6912. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6913. /// 01aa <id>.L <data>.L
  6914. /// data:
  6915. /// @see CZ_PET_ACT.
  6916. void clif_pet_emotion(struct pet_data *pd,int param)
  6917. {
  6918. unsigned char buf[16];
  6919. s_pet_db *pet_db_ptr;
  6920. nullpo_retv(pd);
  6921. pet_db_ptr = pd->get_pet_db();
  6922. memset(buf,0,packet_len(0x1aa));
  6923. WBUFW(buf,0)=0x1aa;
  6924. WBUFL(buf,2)=pd->bl.id;
  6925. if(param >= 100 && pet_db_ptr->talk_convert_class) {
  6926. if(pet_db_ptr->talk_convert_class < 0)
  6927. return;
  6928. else if(pet_db_ptr->talk_convert_class > 0) {
  6929. // replace mob_id component of talk/act data
  6930. param -= (pd->pet.class_ - 100)*100;
  6931. param += (pet_db_ptr->talk_convert_class - 100)*100;
  6932. }
  6933. }
  6934. WBUFL(buf,6)=param;
  6935. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6936. }
  6937. /// Result of request to feed a pet (ZC_FEED_PET).
  6938. /// 01a3 <result>.B <name id>.W
  6939. /// result:
  6940. /// 0 = failure
  6941. /// 1 = success
  6942. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6943. {
  6944. int fd;
  6945. nullpo_retv(sd);
  6946. fd=sd->fd;
  6947. WFIFOHEAD(fd,packet_len(0x1a3));
  6948. WFIFOW(fd,0)=0x1a3;
  6949. WFIFOB(fd,2)=fail;
  6950. WFIFOW(fd,3)=foodid;
  6951. WFIFOSET(fd,packet_len(0x1a3));
  6952. }
  6953. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6954. /// 01cd { <skill id>.L }*7
  6955. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6956. {
  6957. int fd;
  6958. nullpo_retv(sd);
  6959. fd=sd->fd;
  6960. WFIFOHEAD(fd,packet_len(0x1cd));
  6961. WFIFOW(fd, 0)=0x1cd;
  6962. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6963. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6964. else
  6965. WFIFOL(fd,2)= 0x00000000;
  6966. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6967. WFIFOL(fd,6)= MG_COLDBOLT;
  6968. else
  6969. WFIFOL(fd,6)= 0x00000000;
  6970. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6971. WFIFOL(fd,10)= MG_FIREBOLT;
  6972. else
  6973. WFIFOL(fd,10)= 0x00000000;
  6974. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6975. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6976. else
  6977. WFIFOL(fd,14)= 0x00000000;
  6978. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6979. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6980. else
  6981. WFIFOL(fd,18)= 0x00000000;
  6982. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6983. WFIFOL(fd,22)= MG_FIREBALL;
  6984. else
  6985. WFIFOL(fd,22)= 0x00000000;
  6986. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6987. WFIFOL(fd,26)= MG_FROSTDIVER;
  6988. else
  6989. WFIFOL(fd,26)= 0x00000000;
  6990. WFIFOSET(fd,packet_len(0x1cd));
  6991. sd->menuskill_id = SA_AUTOSPELL;
  6992. sd->menuskill_val = skill_lv;
  6993. }
  6994. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6995. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6996. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6997. {
  6998. unsigned char buf[56];
  6999. nullpo_retv(src);
  7000. memset(buf,0,packet_len(0x1cf));
  7001. WBUFW(buf,0) = 0x1cf;
  7002. WBUFL(buf,2) = src->id;
  7003. if( src->type == BL_MER )
  7004. {
  7005. struct mercenary_data *md = BL_CAST(BL_MER,src);
  7006. if( md && md->master && md->devotion_flag )
  7007. WBUFL(buf,6) = md->master->bl.id;
  7008. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7009. }
  7010. else
  7011. {
  7012. int i;
  7013. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7014. if( sd == NULL )
  7015. return;
  7016. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7017. WBUFL(buf,6+4*i) = sd->devotion[i];
  7018. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7019. }
  7020. if( tsd )
  7021. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7022. else
  7023. clif_send(buf, packet_len(0x1cf), src, AREA);
  7024. }
  7025. /*==========================================
  7026. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  7027. * Notifies clients in an area of an object's spirits.
  7028. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7029. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7030. *------------------------------------------*/
  7031. void clif_spiritball(struct block_list *bl) {
  7032. unsigned char buf[16];
  7033. TBL_PC *sd = BL_CAST(BL_PC,bl);
  7034. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  7035. nullpo_retv(bl);
  7036. WBUFW(buf, 0) = 0x1d0;
  7037. WBUFL(buf, 2) = bl->id;
  7038. WBUFW(buf, 6) = 0; //init to 0
  7039. switch(bl->type){
  7040. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7041. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7042. }
  7043. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7044. }
  7045. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7046. /// 01d2 <account id>.L <delay>.L
  7047. void clif_combo_delay(struct block_list *bl,int wait)
  7048. {
  7049. unsigned char buf[32];
  7050. nullpo_retv(bl);
  7051. WBUFW(buf,0)=0x1d2;
  7052. WBUFL(buf,2)=bl->id;
  7053. WBUFL(buf,6)=wait;
  7054. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7055. }
  7056. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7057. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7058. /// flag:
  7059. /// 0 = inactive
  7060. /// 1 = active
  7061. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7062. {
  7063. unsigned char buf[32];
  7064. nullpo_retv(src);
  7065. WBUFW(buf,0)=0x1d1;
  7066. WBUFL(buf,2)=src->id;
  7067. WBUFL(buf,6)=dst_id;
  7068. WBUFL(buf,10)=active;
  7069. clif_send(buf,packet_len(0x1d1),src,AREA);
  7070. }
  7071. /// MVP effect (ZC_MVP).
  7072. /// 010c <account id>.L
  7073. void clif_mvp_effect(struct map_session_data *sd)
  7074. {
  7075. unsigned char buf[16];
  7076. nullpo_retv(sd);
  7077. WBUFW(buf,0)=0x10c;
  7078. WBUFL(buf,2)=sd->bl.id;
  7079. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7080. }
  7081. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7082. /// 010a <name id>.W
  7083. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  7084. {
  7085. int view,fd;
  7086. nullpo_retv(sd);
  7087. fd=sd->fd;
  7088. WFIFOHEAD(fd,packet_len(0x10a));
  7089. WFIFOW(fd,0)=0x10a;
  7090. if((view = itemdb_viewid(nameid)) > 0)
  7091. WFIFOW(fd,2)=view;
  7092. else
  7093. WFIFOW(fd,2)=nameid;
  7094. WFIFOSET(fd,packet_len(0x10a));
  7095. }
  7096. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7097. /// 010b <exp>.L
  7098. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7099. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7100. if (battle_config.mvp_exp_reward_message) {
  7101. char e_msg[CHAT_SIZE_MAX];
  7102. sprintf(e_msg, msg_txt(sd, 717), exp);
  7103. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7104. }
  7105. #else
  7106. int fd;
  7107. nullpo_retv(sd);
  7108. fd = sd->fd;
  7109. WFIFOHEAD(fd, packet_len(0x10b));
  7110. WFIFOW(fd,0) = 0x10b;
  7111. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7112. WFIFOSET(fd, packet_len(0x10b));
  7113. #endif
  7114. }
  7115. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7116. /// 010d
  7117. ///
  7118. /// "You are the MVP, but cannot obtain the reward because
  7119. /// you are overweight."
  7120. void clif_mvp_noitem(struct map_session_data* sd)
  7121. {
  7122. int fd = sd->fd;
  7123. WFIFOHEAD(fd,packet_len(0x10d));
  7124. WFIFOW(fd,0) = 0x10d;
  7125. WFIFOSET(fd,packet_len(0x10d));
  7126. }
  7127. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7128. /// 0167 <result>.B
  7129. /// result:
  7130. /// 0 = "Guild has been created."
  7131. /// 1 = "You are already in a Guild."
  7132. /// 2 = "That Guild Name already exists."
  7133. /// 3 = "You need the neccessary item to create a Guild."
  7134. void clif_guild_created(struct map_session_data *sd,int flag)
  7135. {
  7136. int fd;
  7137. nullpo_retv(sd);
  7138. fd=sd->fd;
  7139. WFIFOHEAD(fd,packet_len(0x167));
  7140. WFIFOW(fd,0)=0x167;
  7141. WFIFOB(fd,2)=flag;
  7142. WFIFOSET(fd,packet_len(0x167));
  7143. }
  7144. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7145. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7146. /// mode:
  7147. /// &0x01 = allow invite
  7148. /// &0x10 = allow expel
  7149. void clif_guild_belonginfo(struct map_session_data *sd)
  7150. {
  7151. int ps,fd;
  7152. struct guild* g;
  7153. nullpo_retv(sd);
  7154. nullpo_retv(g = sd->guild);
  7155. fd=sd->fd;
  7156. ps=guild_getposition(sd);
  7157. WFIFOHEAD(fd,packet_len(0x16c));
  7158. WFIFOW(fd,0)=0x16c;
  7159. WFIFOL(fd,2)=g->guild_id;
  7160. WFIFOL(fd,6)=g->emblem_id;
  7161. WFIFOL(fd,10)=g->position[ps].mode;
  7162. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7163. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7164. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7165. WFIFOSET(fd,packet_len(0x16c));
  7166. }
  7167. /// Guild member login notice.
  7168. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7169. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7170. /// status:
  7171. /// 0 = offline
  7172. /// 1 = online
  7173. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7174. {
  7175. unsigned char buf[64];
  7176. struct map_session_data* sd;
  7177. nullpo_retv(g);
  7178. WBUFW(buf, 0)=0x1f2;
  7179. WBUFL(buf, 2)=g->member[idx].account_id;
  7180. WBUFL(buf, 6)=g->member[idx].char_id;
  7181. WBUFL(buf,10)=flag;
  7182. if( ( sd = g->member[idx].sd ) != NULL )
  7183. {
  7184. WBUFW(buf,14) = sd->status.sex;
  7185. WBUFW(buf,16) = sd->status.hair;
  7186. WBUFW(buf,18) = sd->status.hair_color;
  7187. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7188. }
  7189. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7190. {
  7191. WBUFW(buf,14) = 0;
  7192. WBUFW(buf,16) = 0;
  7193. WBUFW(buf,18) = 0;
  7194. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7195. }
  7196. }
  7197. // Function `clif_guild_memberlogin_notice` sends info about
  7198. // logins and logouts of a guild member to the rest members.
  7199. // But at the 1st time (after a player login or map changing)
  7200. // the client won't show the message.
  7201. // So I suggest use this function for sending "first-time-info"
  7202. // to some player on entering the game or changing location.
  7203. // At next time the client would always show the message.
  7204. // The function sends all the statuses in the single packet
  7205. // to economize traffic. [LuzZza]
  7206. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7207. {
  7208. struct guild *g;
  7209. unsigned char buf[14*128];
  7210. int i, count=0, p_len;
  7211. nullpo_retv(sd);
  7212. p_len = packet_len(0x16d);
  7213. if(!(g = sd->guild))
  7214. return;
  7215. for(i=0; i<g->max_member; i++) {
  7216. if(g->member[i].account_id > 0 &&
  7217. g->member[i].account_id != sd->status.account_id) {
  7218. WBUFW(buf,count*p_len) = 0x16d;
  7219. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7220. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7221. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7222. count++;
  7223. }
  7224. }
  7225. clif_send(buf, p_len*count, &sd->bl, SELF);
  7226. }
  7227. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7228. /// 014e <menu flag>.L
  7229. /// menu flag:
  7230. /// 0x00 = Basic Info (always on)
  7231. /// &0x01 = Member manager
  7232. /// &0x02 = Positions
  7233. /// &0x04 = Skills
  7234. /// &0x10 = Expulsion list
  7235. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7236. /// &0x80 = Notice
  7237. void clif_guild_masterormember(struct map_session_data *sd)
  7238. {
  7239. int fd;
  7240. nullpo_retv(sd);
  7241. fd=sd->fd;
  7242. WFIFOHEAD(fd,packet_len(0x14e));
  7243. WFIFOW(fd,0) = 0x14e;
  7244. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7245. WFIFOSET(fd,packet_len(0x14e));
  7246. }
  7247. /// Guild basic information (Territories [Valaris])
  7248. /// 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)
  7249. /// 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)
  7250. /// 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)
  7251. void clif_guild_basicinfo(struct map_session_data *sd) {
  7252. int fd;
  7253. struct guild *g;
  7254. #if PACKETVER < 20160622
  7255. int cmd = 0x1b6;
  7256. int offset = NAME_LENGTH;
  7257. #else
  7258. int cmd = 0xa84;
  7259. int offset = 0;
  7260. #endif
  7261. nullpo_retv(sd);
  7262. fd = sd->fd;
  7263. if( (g = sd->guild) == NULL )
  7264. return;
  7265. WFIFOHEAD(fd,packet_len(cmd));
  7266. WFIFOW(fd, 0)=cmd;
  7267. WFIFOL(fd, 2)=g->guild_id;
  7268. WFIFOL(fd, 6)=g->guild_lv;
  7269. WFIFOL(fd,10)=g->connect_member;
  7270. WFIFOL(fd,14)=g->max_member;
  7271. WFIFOL(fd,18)=g->average_lv;
  7272. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7273. WFIFOL(fd,26)=g->next_exp;
  7274. WFIFOL(fd,30)=0; // Tax Points
  7275. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7276. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7277. WFIFOL(fd,42)=g->emblem_id;
  7278. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7279. #if PACKETVER < 20160622
  7280. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7281. #endif
  7282. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7283. WFIFOL(fd,70+offset+16) = 0; // zeny
  7284. #if PACKETVER >= 20160622
  7285. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7286. #endif
  7287. WFIFOSET(fd,packet_len(cmd));
  7288. }
  7289. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7290. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7291. void clif_guild_allianceinfo(struct map_session_data *sd)
  7292. {
  7293. int fd,i,c;
  7294. struct guild *g;
  7295. nullpo_retv(sd);
  7296. if( (g = sd->guild) == NULL )
  7297. return;
  7298. fd = sd->fd;
  7299. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7300. WFIFOW(fd, 0)=0x14c;
  7301. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7302. struct guild_alliance *a=&g->alliance[i];
  7303. if(a->guild_id>0){
  7304. WFIFOL(fd,c*32+4)=a->opposition;
  7305. WFIFOL(fd,c*32+8)=a->guild_id;
  7306. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7307. c++;
  7308. }
  7309. }
  7310. WFIFOW(fd, 2)=c*32+4;
  7311. WFIFOSET(fd,WFIFOW(fd,2));
  7312. }
  7313. /// Guild member manager information
  7314. /// 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)
  7315. /// state:
  7316. /// 0 = offline
  7317. /// 1 = online
  7318. /// memo:
  7319. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7320. /// 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)
  7321. void clif_guild_memberlist(struct map_session_data *sd)
  7322. {
  7323. int fd;
  7324. int i,c;
  7325. struct guild *g;
  7326. #if PACKETVER < 20161026
  7327. int cmd = 0x154;
  7328. int size = 104;
  7329. #else
  7330. int cmd = 0xaa5;
  7331. int size = 34;
  7332. #endif
  7333. nullpo_retv(sd);
  7334. if( (fd = sd->fd) == 0 )
  7335. return;
  7336. if( (g = sd->guild) == NULL )
  7337. return;
  7338. WFIFOHEAD(fd, g->max_member * size + 4);
  7339. WFIFOW(fd, 0)=cmd;
  7340. for(i=0,c=0;i<g->max_member;i++){
  7341. struct guild_member *m=&g->member[i];
  7342. if(m->account_id==0)
  7343. continue;
  7344. WFIFOL(fd,c*size+ 4)=m->account_id;
  7345. WFIFOL(fd,c*size+ 8)=m->char_id;
  7346. WFIFOW(fd,c*size+12)=m->hair;
  7347. WFIFOW(fd,c*size+14)=m->hair_color;
  7348. WFIFOW(fd,c*size+16)=m->gender;
  7349. WFIFOW(fd,c*size+18)=m->class_;
  7350. WFIFOW(fd,c*size+20)=m->lv;
  7351. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7352. WFIFOL(fd,c*size+26)=m->online;
  7353. WFIFOL(fd,c*size+30)=m->position;
  7354. #if PACKETVER < 20161026
  7355. 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.
  7356. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7357. #else
  7358. WFIFOL(fd,c*size+34)=m->last_login;
  7359. #endif
  7360. c++;
  7361. }
  7362. WFIFOW(fd, 2)=c*size+4;
  7363. WFIFOSET(fd,WFIFOW(fd,2));
  7364. }
  7365. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7366. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7367. void clif_guild_positionnamelist(struct map_session_data *sd)
  7368. {
  7369. int i,fd;
  7370. struct guild *g;
  7371. nullpo_retv(sd);
  7372. if( (g = sd->guild) == NULL )
  7373. return;
  7374. fd = sd->fd;
  7375. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7376. WFIFOW(fd, 0)=0x166;
  7377. for(i=0;i<MAX_GUILDPOSITION;i++){
  7378. WFIFOL(fd,i*28+4)=i;
  7379. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7380. }
  7381. WFIFOW(fd,2)=i*28+4;
  7382. WFIFOSET(fd,WFIFOW(fd,2));
  7383. }
  7384. /// Guild position information (ZC_POSITION_INFO).
  7385. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7386. /// mode:
  7387. /// &0x01 = allow invite
  7388. /// &0x10 = allow expel
  7389. /// ranking:
  7390. /// TODO
  7391. void clif_guild_positioninfolist(struct map_session_data *sd)
  7392. {
  7393. int i,fd;
  7394. struct guild *g;
  7395. nullpo_retv(sd);
  7396. if( (g = sd->guild) == NULL )
  7397. return;
  7398. fd = sd->fd;
  7399. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7400. WFIFOW(fd, 0)=0x160;
  7401. for(i=0;i<MAX_GUILDPOSITION;i++){
  7402. struct guild_position *p=&g->position[i];
  7403. WFIFOL(fd,i*16+ 4)=i;
  7404. WFIFOL(fd,i*16+ 8)=p->mode;
  7405. WFIFOL(fd,i*16+12)=i;
  7406. WFIFOL(fd,i*16+16)=p->exp_mode;
  7407. }
  7408. WFIFOW(fd, 2)=i*16+4;
  7409. WFIFOSET(fd,WFIFOW(fd,2));
  7410. }
  7411. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7412. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7413. /// mode:
  7414. /// &0x01 = allow invite
  7415. /// &0x10 = allow expel
  7416. /// ranking:
  7417. /// TODO
  7418. void clif_guild_positionchanged(struct guild *g,int idx)
  7419. {
  7420. // FIXME: This packet is intended to update the clients after a
  7421. // commit of position info changes, not sending one packet per
  7422. // position.
  7423. struct map_session_data *sd;
  7424. unsigned char buf[128];
  7425. nullpo_retv(g);
  7426. WBUFW(buf, 0)=0x174;
  7427. WBUFW(buf, 2)=44; // packet len
  7428. // GUILD_REG_POSITION_INFO{
  7429. WBUFL(buf, 4)=idx;
  7430. WBUFL(buf, 8)=g->position[idx].mode;
  7431. WBUFL(buf,12)=idx;
  7432. WBUFL(buf,16)=g->position[idx].exp_mode;
  7433. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7434. // }*
  7435. if( (sd=guild_getavailablesd(g))!=NULL )
  7436. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7437. }
  7438. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7439. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7440. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7441. {
  7442. // FIXME: This packet is intended to update the clients after a
  7443. // commit of member position assignment changes, not sending one
  7444. // packet per position.
  7445. struct map_session_data *sd;
  7446. unsigned char buf[64];
  7447. nullpo_retv(g);
  7448. WBUFW(buf, 0)=0x156;
  7449. WBUFW(buf, 2)=16; // packet len
  7450. // MEMBER_POSITION_INFO{
  7451. WBUFL(buf, 4)=g->member[idx].account_id;
  7452. WBUFL(buf, 8)=g->member[idx].char_id;
  7453. WBUFL(buf,12)=g->member[idx].position;
  7454. // }*
  7455. if( (sd=guild_getavailablesd(g))!=NULL )
  7456. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7457. }
  7458. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7459. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7460. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7461. {
  7462. int fd;
  7463. nullpo_retv(sd);
  7464. nullpo_retv(g);
  7465. fd = sd->fd;
  7466. if( g->emblem_len <= 0 )
  7467. return;
  7468. WFIFOHEAD(fd,g->emblem_len+12);
  7469. WFIFOW(fd,0)=0x152;
  7470. WFIFOW(fd,2)=g->emblem_len+12;
  7471. WFIFOL(fd,4)=g->guild_id;
  7472. WFIFOL(fd,8)=g->emblem_id;
  7473. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7474. WFIFOSET(fd,WFIFOW(fd,2));
  7475. }
  7476. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7477. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7478. void clif_guild_emblem_area(struct block_list* bl)
  7479. {
  7480. uint8 buf[12];
  7481. nullpo_retv(bl);
  7482. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7483. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7484. WBUFW(buf,0) = 0x1b4;
  7485. WBUFL(buf,2) = bl->id;
  7486. WBUFL(buf,6) = status_get_guild_id(bl);
  7487. WBUFW(buf,10) = status_get_emblem_id(bl);
  7488. clif_send(buf, 12, bl, AREA_WOS);
  7489. }
  7490. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7491. /// 0162 <packet len>.W <skill points>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B }*
  7492. void clif_guild_skillinfo(struct map_session_data* sd)
  7493. {
  7494. int fd;
  7495. struct guild* g;
  7496. int i,c;
  7497. nullpo_retv(sd);
  7498. if( (g = sd->guild) == NULL )
  7499. return;
  7500. fd = sd->fd;
  7501. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7502. WFIFOW(fd,0) = 0x0162;
  7503. WFIFOW(fd,4) = g->skill_point;
  7504. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7505. {
  7506. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7507. {
  7508. int id = g->skill[i].id;
  7509. int p = 6 + c*37;
  7510. WFIFOW(fd,p+0) = id;
  7511. WFIFOL(fd,p+2) = skill_get_inf(id);
  7512. WFIFOW(fd,p+6) = g->skill[i].lv;
  7513. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7514. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7515. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7516. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7517. c++;
  7518. }
  7519. }
  7520. WFIFOW(fd,2) = 6 + c*37;
  7521. WFIFOSET(fd,WFIFOW(fd,2));
  7522. }
  7523. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7524. /// 016f <subject>.60B <notice>.120B
  7525. void clif_guild_notice(struct map_session_data* sd)
  7526. {
  7527. int fd;
  7528. struct guild* g;
  7529. nullpo_retv(sd);
  7530. nullpo_retv(g = sd->guild);
  7531. fd = sd->fd;
  7532. if ( !session_isActive(fd) )
  7533. return;
  7534. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7535. return;
  7536. WFIFOHEAD(fd,packet_len(0x16f));
  7537. WFIFOW(fd,0) = 0x16f;
  7538. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7539. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7540. WFIFOSET(fd,packet_len(0x16f));
  7541. }
  7542. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7543. /// 016a <guild id>.L <guild name>.24B
  7544. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7545. {
  7546. int fd;
  7547. nullpo_retv(sd);
  7548. nullpo_retv(g);
  7549. fd=sd->fd;
  7550. WFIFOHEAD(fd,packet_len(0x16a));
  7551. WFIFOW(fd,0)=0x16a;
  7552. WFIFOL(fd,2)=g->guild_id;
  7553. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7554. WFIFOSET(fd,packet_len(0x16a));
  7555. }
  7556. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7557. /// 0169 <answer>.B
  7558. /// answer:
  7559. /// 0 = Already in guild.
  7560. /// 1 = Offer rejected.
  7561. /// 2 = Offer accepted.
  7562. /// 3 = Guild full.
  7563. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7564. {
  7565. int fd;
  7566. nullpo_retv(sd);
  7567. fd=sd->fd;
  7568. WFIFOHEAD(fd,packet_len(0x169));
  7569. WFIFOW(fd,0)=0x169;
  7570. WFIFOB(fd,2)=flag;
  7571. WFIFOSET(fd,packet_len(0x169));
  7572. }
  7573. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7574. /// 015a <char name>.24B <reason>.40B
  7575. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7576. {
  7577. unsigned char buf[128];
  7578. nullpo_retv(sd);
  7579. WBUFW(buf, 0)=0x15a;
  7580. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7581. memcpy(WBUFP(buf,26),mes,40);
  7582. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7583. }
  7584. /// Notifies clients of a guild of an expelled member.
  7585. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7586. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7587. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7588. {
  7589. unsigned char buf[128];
  7590. #if PACKETVER < 20100803
  7591. const unsigned short cmd = 0x15c;
  7592. #else
  7593. const unsigned short cmd = 0x839;
  7594. #endif
  7595. nullpo_retv(sd);
  7596. WBUFW(buf,0) = cmd;
  7597. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7598. safestrncpy(WBUFCP(buf,26), mes, 40);
  7599. #if PACKETVER < 20100803
  7600. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7601. #endif
  7602. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7603. }
  7604. /// Guild expulsion list (ZC_BAN_LIST).
  7605. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7606. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7607. void clif_guild_expulsionlist(struct map_session_data* sd)
  7608. {
  7609. #if PACKETVER < 20100803
  7610. const int offset = NAME_LENGTH*2+40;
  7611. #else
  7612. const int offset = NAME_LENGTH+40;
  7613. #endif
  7614. int fd, i, c = 0;
  7615. struct guild* g;
  7616. nullpo_retv(sd);
  7617. if( (g = sd->guild) == NULL )
  7618. return;
  7619. fd = sd->fd;
  7620. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7621. WFIFOW(fd,0) = 0x163;
  7622. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7623. {
  7624. struct guild_expulsion* e = &g->expulsion[i];
  7625. if( e->account_id > 0 )
  7626. {
  7627. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7628. #if PACKETVER < 20100803
  7629. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7630. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7631. #else
  7632. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7633. #endif
  7634. c++;
  7635. }
  7636. }
  7637. WFIFOW(fd,2) = 4 + c*offset;
  7638. WFIFOSET(fd,WFIFOW(fd,2));
  7639. }
  7640. /// Guild chat message (ZC_GUILD_CHAT).
  7641. /// 017f <packet len>.W <message>.?B
  7642. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7643. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7644. struct map_session_data *sd;
  7645. uint8 buf[256];
  7646. if( len == 0 )
  7647. {
  7648. return;
  7649. }
  7650. else if( len > sizeof(buf)-5 )
  7651. {
  7652. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7653. len = sizeof(buf)-5;
  7654. }
  7655. WBUFW(buf, 0) = 0x17f;
  7656. WBUFW(buf, 2) = len + 5;
  7657. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7658. if ((sd = guild_getavailablesd(g)) != NULL)
  7659. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7660. }
  7661. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7662. /// 0171 <inviter account id>.L <guild name>.24B
  7663. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7664. {
  7665. int fd;
  7666. nullpo_retv(sd);
  7667. fd=sd->fd;
  7668. WFIFOHEAD(fd,packet_len(0x171));
  7669. WFIFOW(fd,0)=0x171;
  7670. WFIFOL(fd,2)=account_id;
  7671. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7672. WFIFOSET(fd,packet_len(0x171));
  7673. }
  7674. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7675. /// 0173 <answer>.B
  7676. /// answer:
  7677. /// 0 = Already allied.
  7678. /// 1 = You rejected the offer.
  7679. /// 2 = You accepted the offer.
  7680. /// 3 = They have too any alliances.
  7681. /// 4 = You have too many alliances.
  7682. /// 5 = Alliances are disabled.
  7683. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7684. {
  7685. int fd;
  7686. nullpo_retv(sd);
  7687. fd=sd->fd;
  7688. WFIFOHEAD(fd,packet_len(0x173));
  7689. WFIFOW(fd,0)=0x173;
  7690. WFIFOL(fd,2)=flag;
  7691. WFIFOSET(fd,packet_len(0x173));
  7692. }
  7693. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7694. /// 0184 <other guild id>.L <relation>.L
  7695. /// relation:
  7696. /// 0 = Ally
  7697. /// 1 = Enemy
  7698. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7699. {
  7700. int fd;
  7701. nullpo_retv(sd);
  7702. fd = sd->fd;
  7703. if (fd <= 0)
  7704. return;
  7705. WFIFOHEAD(fd,packet_len(0x184));
  7706. WFIFOW(fd,0)=0x184;
  7707. WFIFOL(fd,2)=guild_id;
  7708. WFIFOL(fd,6)=flag;
  7709. WFIFOSET(fd,packet_len(0x184));
  7710. }
  7711. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7712. /// 0181 <result>.B
  7713. /// result:
  7714. /// 0 = Antagonist has been set.
  7715. /// 1 = Guild has too many Antagonists.
  7716. /// 2 = Already set as an Antagonist.
  7717. /// 3 = Antagonists are disabled.
  7718. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7719. {
  7720. int fd;
  7721. nullpo_retv(sd);
  7722. fd=sd->fd;
  7723. WFIFOHEAD(fd,packet_len(0x181));
  7724. WFIFOW(fd,0)=0x181;
  7725. WFIFOB(fd,2)=flag;
  7726. WFIFOSET(fd,packet_len(0x181));
  7727. }
  7728. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7729. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7730. /*
  7731. void clif_guild_allianceadded(struct guild *g,int idx)
  7732. {
  7733. unsigned char buf[64];
  7734. WBUFW(buf,0)=0x185;
  7735. WBUFL(buf,2)=g->alliance[idx].opposition;
  7736. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7737. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7738. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7739. }
  7740. */
  7741. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7742. /// 015e <reason>.L
  7743. /// 0 = success
  7744. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7745. /// 2 = there are still members in the guild
  7746. void clif_guild_broken(struct map_session_data *sd,int flag)
  7747. {
  7748. int fd;
  7749. nullpo_retv(sd);
  7750. fd=sd->fd;
  7751. WFIFOHEAD(fd,packet_len(0x15e));
  7752. WFIFOW(fd,0)=0x15e;
  7753. WFIFOL(fd,2)=flag;
  7754. WFIFOSET(fd,packet_len(0x15e));
  7755. }
  7756. /// Displays emotion on an object (ZC_EMOTION).
  7757. /// 00c0 <id>.L <type>.B
  7758. /// type:
  7759. /// enum emotion_type
  7760. void clif_emotion(struct block_list *bl,int type)
  7761. {
  7762. unsigned char buf[8];
  7763. nullpo_retv(bl);
  7764. WBUFW(buf,0)=0xc0;
  7765. WBUFL(buf,2)=bl->id;
  7766. WBUFB(buf,6)=type;
  7767. clif_send(buf,packet_len(0xc0),bl,AREA);
  7768. }
  7769. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7770. /// 0191 <id>.L <contents>.80B
  7771. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7772. {
  7773. unsigned char buf[MESSAGE_SIZE+6];
  7774. nullpo_retv(bl);
  7775. WBUFW(buf,0) = 0x191;
  7776. WBUFL(buf,2) = bl->id;
  7777. safestrncpy(WBUFCP(buf,6),talkie,MESSAGE_SIZE);
  7778. clif_send(buf,packet_len(0x191),bl,AREA);
  7779. }
  7780. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7781. /// 01ea <id>.L
  7782. void clif_wedding_effect(struct block_list *bl)
  7783. {
  7784. unsigned char buf[6];
  7785. nullpo_retv(bl);
  7786. WBUFW(buf,0) = 0x1ea;
  7787. WBUFL(buf,2) = bl->id;
  7788. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7789. }
  7790. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7791. /// 01e6 <partner name>.24B
  7792. void clif_callpartner(struct map_session_data *sd)
  7793. {
  7794. unsigned char buf[26];
  7795. nullpo_retv(sd);
  7796. WBUFW(buf,0) = 0x1e6;
  7797. if( sd->status.partner_id ) {
  7798. const char *p = map_charid2nick(sd->status.partner_id);
  7799. struct map_session_data *p_sd = pc_get_partner(sd);
  7800. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7801. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7802. else
  7803. WBUFB(buf,2) = 0;
  7804. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7805. WBUFB(buf,2) = 0;
  7806. }
  7807. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7808. }
  7809. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7810. /// 01e4
  7811. /// This packet while still implemented by the client is no longer being officially used.
  7812. /*
  7813. void clif_marriage_process(struct map_session_data *sd)
  7814. {
  7815. int fd;
  7816. nullpo_retv(sd);
  7817. fd=sd->fd;
  7818. WFIFOHEAD(fd,packet_len(0x1e4));
  7819. WFIFOW(fd,0)=0x1e4;
  7820. WFIFOSET(fd,packet_len(0x1e4));
  7821. }
  7822. */
  7823. /// Notice of divorce (ZC_DIVORCE).
  7824. /// 0205 <partner name>.24B
  7825. void clif_divorced(struct map_session_data* sd, const char* name)
  7826. {
  7827. int fd;
  7828. nullpo_retv(sd);
  7829. fd=sd->fd;
  7830. WFIFOHEAD(fd,packet_len(0x205));
  7831. WFIFOW(fd,0)=0x205;
  7832. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7833. WFIFOSET(fd, packet_len(0x205));
  7834. }
  7835. /// Marriage proposal (ZC_REQ_COUPLE).
  7836. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7837. /// This packet while still implemented by the client is no longer being officially used.
  7838. /*
  7839. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7840. {
  7841. nullpo_retv(sd);
  7842. WFIFOHEAD(fd,packet_len(0x1e2));
  7843. WFIFOW(fd,0) = 0x1e2;
  7844. WFIFOL(fd,2) = ssd->status.account_id;
  7845. WFIFOL(fd,6) = ssd->status.char_id;
  7846. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7847. WFIFOSET(fd, packet_len(0x1e2));
  7848. }
  7849. */
  7850. /*==========================================
  7851. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7852. *------------------------------------------*/
  7853. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7854. {
  7855. unsigned char buf[256];
  7856. if( len == 0 ) {
  7857. return;
  7858. } else if( len > sizeof(buf)-5 ) {
  7859. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7860. len = sizeof(buf)-5;
  7861. }
  7862. WBUFW(buf, 0) = 0x17f;
  7863. WBUFW(buf, 2) = len + 5;
  7864. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7865. clif_send(buf, WBUFW(buf,2), src, target);
  7866. }
  7867. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7868. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7869. /// 00cd <result>.B
  7870. /// result:
  7871. /// 0 = failure
  7872. /// 1 = success
  7873. void clif_GM_kickack(struct map_session_data *sd, int id)
  7874. {
  7875. int fd;
  7876. nullpo_retv(sd);
  7877. fd = sd->fd;
  7878. WFIFOHEAD(fd,packet_len(0xcd));
  7879. WFIFOW(fd,0) = 0xcd;
  7880. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7881. WFIFOSET(fd, packet_len(0xcd));
  7882. }
  7883. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7884. {
  7885. int fd;
  7886. nullpo_retv(tsd);
  7887. fd = tsd->fd;
  7888. if (sd == NULL)
  7889. tsd->state.keepshop = true;
  7890. if (fd > 0)
  7891. clif_authfail_fd(fd, 15);
  7892. else
  7893. map_quit(tsd);
  7894. if (sd)
  7895. clif_GM_kickack(sd, tsd->status.account_id);
  7896. }
  7897. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7898. /// 014a <result>.L
  7899. /// result:
  7900. /// 0 = "A manner point has been successfully aligned."
  7901. /// 1 = MP_FAILURE_EXHAUST
  7902. /// 2 = MP_FAILURE_ALREADY_GIVING
  7903. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7904. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7905. /// 5 = "You got a good point from %s."
  7906. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7907. {
  7908. int fd;
  7909. nullpo_retv(sd);
  7910. fd = sd->fd;
  7911. WFIFOHEAD(fd,packet_len(0x14a));
  7912. WFIFOW(fd,0) = 0x14a;
  7913. WFIFOL(fd,2) = type;
  7914. WFIFOSET(fd, packet_len(0x14a));
  7915. }
  7916. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7917. /// 014b <type>.B <GM name>.24B
  7918. /// type:
  7919. /// 0 = positive (unmute)
  7920. /// 1 = negative (mute)
  7921. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7922. {
  7923. int fd;
  7924. nullpo_retv(sd);
  7925. nullpo_retv(tsd);
  7926. fd = tsd->fd;
  7927. WFIFOHEAD(fd,packet_len(0x14b));
  7928. WFIFOW(fd,0) = 0x14b;
  7929. WFIFOB(fd,2) = type;
  7930. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7931. WFIFOSET(fd, packet_len(0x14b));
  7932. }
  7933. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7934. /// 00d1 <type>.B <result>.B
  7935. /// type:
  7936. /// 0 = /ex (deny)
  7937. /// 1 = /in (allow)
  7938. /// result:
  7939. /// 0 = success
  7940. /// 1 = failure
  7941. /// 2 = too many blocks
  7942. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7943. {
  7944. int fd;
  7945. nullpo_retv(sd);
  7946. fd=sd->fd;
  7947. WFIFOHEAD(fd,packet_len(0xd1));
  7948. WFIFOW(fd,0)=0xd1;
  7949. WFIFOB(fd,2)=type;
  7950. WFIFOB(fd,3)=flag;
  7951. WFIFOSET(fd,packet_len(0xd1));
  7952. }
  7953. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7954. /// 00d2 <type>.B <result>.B
  7955. /// type:
  7956. /// 0 = /exall (deny)
  7957. /// 1 = /inall (allow)
  7958. /// result:
  7959. /// 0 = success
  7960. /// 1 = failure
  7961. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7962. {
  7963. int fd;
  7964. nullpo_retv(sd);
  7965. fd=sd->fd;
  7966. WFIFOHEAD(fd,packet_len(0xd2));
  7967. WFIFOW(fd,0)=0xd2;
  7968. WFIFOB(fd,2)=type;
  7969. WFIFOB(fd,3)=flag;
  7970. WFIFOSET(fd,packet_len(0xd2));
  7971. }
  7972. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7973. /// 07fe <bgm>.24B
  7974. void clif_playBGM(struct map_session_data* sd, const char* name)
  7975. {
  7976. int fd;
  7977. nullpo_retv(sd);
  7978. fd = sd->fd;
  7979. WFIFOHEAD(fd,packet_len(0x7fe));
  7980. WFIFOW(fd,0) = 0x7fe;
  7981. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7982. WFIFOSET(fd,packet_len(0x7fe));
  7983. }
  7984. /// Plays/stops a wave sound (ZC_SOUND).
  7985. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7986. /// file name:
  7987. /// relative to data\wav
  7988. /// act:
  7989. /// 0 = play (once)
  7990. /// 1 = play (repeat, does not work)
  7991. /// 2 = stops all sound instances of file name (does not work)
  7992. /// term:
  7993. /// unknown purpose, only relevant to act = 1
  7994. /// npc id:
  7995. /// The accustic direction of the sound is determined by the
  7996. /// relative position of the NPC to the player (3D sound).
  7997. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7998. {
  7999. int fd;
  8000. nullpo_retv(sd);
  8001. nullpo_retv(bl);
  8002. fd = sd->fd;
  8003. WFIFOHEAD(fd,packet_len(0x1d3));
  8004. WFIFOW(fd,0) = 0x1d3;
  8005. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8006. WFIFOB(fd,26) = type;
  8007. WFIFOL(fd,27) = 0;
  8008. WFIFOL(fd,31) = bl->id;
  8009. WFIFOSET(fd,packet_len(0x1d3));
  8010. }
  8011. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8012. {
  8013. unsigned char buf[40];
  8014. nullpo_retv(bl);
  8015. WBUFW(buf,0) = 0x1d3;
  8016. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8017. WBUFB(buf,26) = type;
  8018. WBUFL(buf,27) = 0;
  8019. WBUFL(buf,31) = bl->id;
  8020. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8021. }
  8022. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8023. /// 01f3 <id>.L <effect id>.L
  8024. /// effect id:
  8025. /// @see doc/effect_list.txt
  8026. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8027. {
  8028. unsigned char buf[24];
  8029. nullpo_retv(bl);
  8030. memset(buf, 0, packet_len(0x1f3));
  8031. WBUFW(buf,0) = 0x1f3;
  8032. WBUFL(buf,2) = bl->id;
  8033. WBUFL(buf,6) = type;
  8034. clif_send(buf, packet_len(0x1f3), bl, target);
  8035. if (disguised(bl)) {
  8036. WBUFL(buf,2) = -bl->id;
  8037. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8038. }
  8039. }
  8040. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8041. {
  8042. WFIFOHEAD(fd,10);
  8043. WFIFOW(fd,0) = 0x1f3;
  8044. WFIFOL(fd,2) = bl->id;
  8045. WFIFOL(fd,6) = type;
  8046. WFIFOSET(fd,10);
  8047. }
  8048. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8049. /// 0284 <id>.L <effect id>.L <num data>.L
  8050. /// effect id:
  8051. /// @see doc/effect_list.txt
  8052. /// num data:
  8053. /// effect-dependent value
  8054. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8055. {
  8056. uint8 buf[14];
  8057. WBUFW(buf,0) = 0x284;
  8058. WBUFL(buf,2) = bl->id;
  8059. WBUFL(buf,6) = effect_id;
  8060. WBUFL(buf,10) = num;
  8061. clif_send(buf, packet_len(0x284), bl, target);
  8062. if( disguised(bl) )
  8063. {
  8064. WBUFL(buf,2) = -bl->id;
  8065. clif_send(buf, packet_len(0x284), bl, SELF);
  8066. }
  8067. }
  8068. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8069. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8070. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, struct map_session_data *sd) {
  8071. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8072. uint8 buf[CHAT_SIZE_MAX];
  8073. nullpo_retv(bl);
  8074. if (msg_len > sizeof(buf) - 12) {
  8075. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8076. msg_len = sizeof(buf) - 12;
  8077. }
  8078. if (rgb2bgr)
  8079. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8080. WBUFW(buf,0) = 0x2C1;
  8081. WBUFW(buf,2) = msg_len + 12;
  8082. WBUFL(buf,4) = bl->id;
  8083. WBUFL(buf,8) = color;
  8084. memcpy(WBUFCP(buf,12), msg, msg_len);
  8085. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8086. }
  8087. /**
  8088. * Notifies the client that the storage window is still open
  8089. *
  8090. * Should only be used in cases where the client closed the
  8091. * storage window without server's consent
  8092. */
  8093. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8094. // Notify the client that the storage is open
  8095. if( sd->state.storage_flag == 1 ) {
  8096. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8097. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8098. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8099. }
  8100. // Notify the client that the gstorage is open otherwise it will
  8101. // remain locked forever and nobody will be able to access it
  8102. if( sd->state.storage_flag == 2 ) {
  8103. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8104. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8105. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8106. else {
  8107. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8108. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8109. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8110. }
  8111. }
  8112. }
  8113. // refresh the client's screen, getting rid of any effects
  8114. void clif_refresh(struct map_session_data *sd)
  8115. {
  8116. nullpo_retv(sd);
  8117. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8118. clif_inventorylist(sd);
  8119. if(pc_iscarton(sd)) {
  8120. clif_cartlist(sd);
  8121. clif_updatestatus(sd,SP_CARTINFO);
  8122. }
  8123. clif_updatestatus(sd,SP_WEIGHT);
  8124. clif_updatestatus(sd,SP_MAXWEIGHT);
  8125. clif_updatestatus(sd,SP_STR);
  8126. clif_updatestatus(sd,SP_AGI);
  8127. clif_updatestatus(sd,SP_VIT);
  8128. clif_updatestatus(sd,SP_INT);
  8129. clif_updatestatus(sd,SP_DEX);
  8130. clif_updatestatus(sd,SP_LUK);
  8131. if (sd->spiritball)
  8132. clif_spiritball_single(sd->fd, sd);
  8133. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8134. clif_spiritcharm_single(sd->fd, sd);
  8135. if (sd->vd.cloth_color)
  8136. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8137. if (sd->vd.body_style)
  8138. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8139. if(hom_is_active(sd->hd))
  8140. clif_send_homdata(sd,SP_ACK,0);
  8141. if( sd->md ) {
  8142. clif_mercenary_info(sd);
  8143. clif_mercenary_skillblock(sd);
  8144. }
  8145. if( sd->ed )
  8146. clif_elemental_info(sd);
  8147. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8148. clif_weather_check(sd);
  8149. if( sd->chatID )
  8150. chat_leavechat(sd,0);
  8151. if( sd->state.vending )
  8152. clif_openvending(sd, sd->bl.id, sd->vending);
  8153. if( pc_issit(sd) )
  8154. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8155. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8156. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8157. else
  8158. clif_changed_dir(&sd->bl, SELF);
  8159. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8160. //Issue #2143
  8161. //Cancel Trading State
  8162. if (sd->state.trading)
  8163. trade_tradecancel(sd);
  8164. //Cancel Buying/Selling State
  8165. if (sd->state.buyingstore)
  8166. buyingstore_close(sd);
  8167. mail_clear(sd);
  8168. if( disguised(&sd->bl) ) {/* refresh-da */
  8169. short disguise = sd->disguise;
  8170. pc_disguise(sd, 0);
  8171. pc_disguise(sd, disguise);
  8172. }
  8173. clif_refresh_storagewindow(sd);
  8174. }
  8175. /// Updates the object's (bl) name on client.
  8176. /// Used to update when a char leaves a party/guild. [Skotlex]
  8177. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8178. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8179. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8180. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8181. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8182. unsigned char buf[106];
  8183. int cmd = 0x95;
  8184. nullpo_retv(src);
  8185. nullpo_retv(bl);
  8186. WBUFW(buf,0) = cmd;
  8187. WBUFL(buf,2) = bl->id;
  8188. switch( bl->type )
  8189. {
  8190. case BL_PC:
  8191. {
  8192. struct map_session_data *sd = (struct map_session_data *)bl;
  8193. struct party_data *p = NULL;
  8194. #if PACKETVER >= 20150513
  8195. WBUFW(buf, 0) = cmd = 0xa30;
  8196. #else
  8197. WBUFW(buf, 0) = cmd = 0x195;
  8198. #endif
  8199. //Requesting your own "shadow" name. [Skotlex]
  8200. if( src == bl && target == SELF && sd->disguise ){
  8201. WBUFL(buf,2) = -bl->id;
  8202. }
  8203. if( sd->fakename[0] ) {
  8204. safestrncpy(WBUFCP(buf,6), sd->fakename, NAME_LENGTH);
  8205. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  8206. #if PACKETVER >= 20150513
  8207. WBUFL(buf,102) = 0; // Title ID
  8208. #endif
  8209. break;
  8210. }
  8211. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  8212. if( sd->status.party_id ){
  8213. p = party_search(sd->status.party_id);
  8214. }
  8215. // do not display party unless the player is also in a guild
  8216. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8217. safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH);
  8218. }else{
  8219. WBUFB(buf,30) = 0;
  8220. }
  8221. if( sd->guild ){
  8222. int position;
  8223. // Will get the position of the guild the player is in
  8224. position = guild_getposition(sd);
  8225. safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH);
  8226. safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH);
  8227. }else if( sd->clan ){
  8228. WBUFB(buf,54) = 0;
  8229. safestrncpy(WBUFCP(buf,78), sd->clan->name,NAME_LENGTH);
  8230. }else{ //Assume no guild and no clan
  8231. WBUFB(buf,54) = 0;
  8232. WBUFB(buf,78) = 0;
  8233. }
  8234. #if PACKETVER >= 20150513
  8235. WBUFL(buf,102) = sd->status.title_id; // Title ID
  8236. #endif
  8237. }
  8238. break;
  8239. //[blackhole89]
  8240. case BL_HOM:
  8241. safestrncpy(WBUFCP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8242. break;
  8243. case BL_MER:
  8244. safestrncpy(WBUFCP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8245. break;
  8246. case BL_PET:
  8247. safestrncpy(WBUFCP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8248. break;
  8249. case BL_NPC:
  8250. safestrncpy(WBUFCP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8251. break;
  8252. case BL_MOB:
  8253. {
  8254. struct mob_data *md = (struct mob_data *)bl;
  8255. nullpo_retv(md);
  8256. safestrncpy(WBUFCP(buf,6), md->name, NAME_LENGTH);
  8257. if( md->guardian_data && md->guardian_data->guild_id )
  8258. {
  8259. #if PACKETVER >= 20150513
  8260. WBUFW(buf, 0) = cmd = 0xa30;
  8261. #else
  8262. WBUFW(buf, 0) = cmd = 0x195;
  8263. #endif
  8264. WBUFB(buf,30) = 0;
  8265. safestrncpy(WBUFCP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8266. safestrncpy(WBUFCP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8267. }
  8268. else if( battle_config.show_mob_info )
  8269. {
  8270. char mobhp[50], *str_p = mobhp;
  8271. #if PACKETVER >= 20150513
  8272. WBUFW(buf, 0) = cmd = 0xa30;
  8273. #else
  8274. WBUFW(buf, 0) = cmd = 0x195;
  8275. #endif
  8276. if( battle_config.show_mob_info&4 )
  8277. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8278. if( battle_config.show_mob_info&1 )
  8279. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8280. if( battle_config.show_mob_info&2 )
  8281. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8282. //Even thought mobhp ain't a name, we send it as one so the client
  8283. //can parse it. [Skotlex]
  8284. if( str_p != mobhp )
  8285. {
  8286. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8287. safestrncpy(WBUFCP(buf,30), mobhp, NAME_LENGTH);
  8288. WBUFB(buf,54) = 0;
  8289. WBUFB(buf,78) = 0;
  8290. }
  8291. }
  8292. #if PACKETVER >= 20150513
  8293. WBUFL(buf, 102) = 0; // Title ID
  8294. #endif
  8295. }
  8296. break;
  8297. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8298. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8299. // break;
  8300. return;
  8301. case BL_ELEM:
  8302. safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8303. break;
  8304. default:
  8305. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8306. return;
  8307. }
  8308. clif_send(buf, packet_len(cmd), src, target);
  8309. }
  8310. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8311. /// 01ff <id>.L <x>.W <y>.W
  8312. ///
  8313. /// Visually moves(instant) a character to x,y. The char moves even
  8314. /// when the target cell isn't walkable. If the char is sitting it
  8315. /// stays that way.
  8316. void clif_slide(struct block_list *bl, int x, int y)
  8317. {
  8318. unsigned char buf[10];
  8319. nullpo_retv(bl);
  8320. WBUFW(buf, 0) = 0x01ff;
  8321. WBUFL(buf, 2) = bl->id;
  8322. WBUFW(buf, 6) = x;
  8323. WBUFW(buf, 8) = y;
  8324. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8325. if( disguised(bl) )
  8326. {
  8327. WBUFL(buf,2) = -bl->id;
  8328. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8329. }
  8330. }
  8331. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8332. /// 008d <packet len>.W <id>.L <message>.?B
  8333. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8334. {
  8335. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8336. int len_mes = strlen(mes)+1; //Account for \0
  8337. if (len_mes > sizeof(buf)-8) {
  8338. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8339. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8340. }
  8341. // send message to others
  8342. if (flag == AREA) {
  8343. WBUFW(buf,0) = 0x8d;
  8344. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8345. WBUFL(buf,4) = bl->id;
  8346. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8347. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8348. }
  8349. // send back message to the speaker
  8350. if( bl->type == BL_PC ) {
  8351. WBUFW(buf,0) = 0x8e;
  8352. WBUFW(buf, 2) = len_mes + 4;
  8353. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8354. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8355. }
  8356. }
  8357. /*==========================
  8358. * Minimap fix [Kevin]
  8359. * Remove dot from minimap
  8360. *--------------------------*/
  8361. void clif_party_xy_remove(struct map_session_data *sd)
  8362. {
  8363. unsigned char buf[16];
  8364. nullpo_retv(sd);
  8365. WBUFW(buf,0)=0x107;
  8366. WBUFL(buf,2)=sd->status.account_id;
  8367. WBUFW(buf,6)=-1;
  8368. WBUFW(buf,8)=-1;
  8369. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8370. }
  8371. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8372. /// 0215 <msg id>.L
  8373. /// msg id:
  8374. /// 0x15 = End all negative status (PA_GOSPEL)
  8375. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8376. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8377. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8378. /// 0x19 = All stats +20 (PA_GOSPEL)
  8379. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8380. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8381. /// 0x1e = DEF +25% (PA_GOSPEL)
  8382. /// 0x1f = ATK +100% (PA_GOSPEL)
  8383. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8384. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8385. /// ? = nothing
  8386. void clif_gospel_info(struct map_session_data *sd, int type)
  8387. {
  8388. int fd=sd->fd;
  8389. WFIFOHEAD(fd,packet_len(0x215));
  8390. WFIFOW(fd,0)=0x215;
  8391. WFIFOL(fd,2)=type;
  8392. WFIFOSET(fd, packet_len(0x215));
  8393. }
  8394. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8395. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8396. /// result:
  8397. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8398. /// star:
  8399. /// 0 = Place of the Sun
  8400. /// 1 = Place of the Moon
  8401. /// 2 = Place of the Stars
  8402. /// 1 = Star Gladiator %s's %s: <mapname>
  8403. /// star:
  8404. /// 0 = Place of the Sun
  8405. /// 1 = Place of the Moon
  8406. /// 2 = Place of the Stars
  8407. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8408. /// star:
  8409. /// 0 = Target of the Sun
  8410. /// 1 = Target of the Moon
  8411. /// 2 = Target of the Stars
  8412. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8413. /// star:
  8414. /// 0 = Monster of the Sun
  8415. /// 1 = Monster of the Moon
  8416. /// 2 = Monster of the Stars
  8417. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8418. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8419. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8420. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8421. /// 40 = Target HP : <monster_id used as HP>
  8422. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8423. {
  8424. int fd = sd->fd;
  8425. WFIFOHEAD(fd,packet_len(0x20e));
  8426. WFIFOW(fd,0) = 0x20e;
  8427. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8428. WFIFOL(fd,26) = monster_id;
  8429. WFIFOB(fd,30) = star;
  8430. WFIFOB(fd,31) = result;
  8431. WFIFOSET(fd,packet_len(0x20e));
  8432. }
  8433. /*==========================================
  8434. * Info about Star Glaldiator save map [Komurka]
  8435. * type: 1: Information, 0: Map registered
  8436. *------------------------------------------*/
  8437. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8438. {
  8439. char mapname[MAP_NAME_LENGTH_EXT];
  8440. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8441. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8442. }
  8443. /*==========================================
  8444. * Info about Star Glaldiator hate mob [Komurka]
  8445. * type: 1: Register mob, 0: Information.
  8446. *------------------------------------------*/
  8447. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8448. {
  8449. if( pcdb_checkid(class_) ) {
  8450. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8451. } else if( mobdb_checkid(class_) ) {
  8452. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8453. } else {
  8454. 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);
  8455. }
  8456. }
  8457. /*==========================================
  8458. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8459. *------------------------------------------*/
  8460. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8461. {
  8462. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8463. }
  8464. /*==========================================
  8465. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8466. *------------------------------------------*/
  8467. void clif_feel_hate_reset(struct map_session_data *sd)
  8468. {
  8469. clif_starskill(sd, "", 0, 0, 30);
  8470. }
  8471. /// Send out reply to configuration change
  8472. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8473. /// type: see enum e_config_type
  8474. /// value:
  8475. /// false = disabled
  8476. /// true = enabled
  8477. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8478. int fd;
  8479. nullpo_retv(sd);
  8480. fd = sd->fd;
  8481. WFIFOHEAD(fd, packet_len(0x2d9));
  8482. WFIFOW(fd, 0) = 0x2d9;
  8483. WFIFOL(fd, 2) = type;
  8484. WFIFOL(fd, 6) = enabled;
  8485. WFIFOSET(fd, packet_len(0x2d9));
  8486. }
  8487. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8488. /// 02da <open equip window>.B
  8489. /// open equip window:
  8490. /// 0 = disabled
  8491. /// 1 = enabled
  8492. void clif_equipcheckbox(struct map_session_data* sd)
  8493. {
  8494. int fd;
  8495. nullpo_retv(sd);
  8496. fd = sd->fd;
  8497. WFIFOHEAD(fd, packet_len(0x2da));
  8498. WFIFOW(fd, 0) = 0x2da;
  8499. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8500. WFIFOSET(fd, packet_len(0x2da));
  8501. }
  8502. /// Sends info about a player's equipped items.
  8503. /// 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)
  8504. /// 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)
  8505. /// 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)
  8506. /// 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)
  8507. /// 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)
  8508. /// 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)
  8509. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8510. {
  8511. uint8* buf;
  8512. int i, n, fd, offset = 0;
  8513. #if PACKETVER < 20100629
  8514. const int s = 26;
  8515. #elif PACKETVER < 20120925
  8516. const int s = 28;
  8517. #elif PACKETVER < 20150225
  8518. const int s = 31;
  8519. #else
  8520. const int s = 57;
  8521. #endif
  8522. nullpo_retv(sd);
  8523. nullpo_retv(tsd);
  8524. fd = sd->fd;
  8525. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8526. buf = WFIFOP(fd,0);
  8527. #if PACKETVER < 20101124
  8528. WBUFW(buf, 0) = 0x2d7;
  8529. #elif PACKETVER < 20120925
  8530. WBUFW(buf, 0) = 0x859;
  8531. #elif PACKETVER < 20150225
  8532. WBUFW(buf, 0) = 0x997;
  8533. #else
  8534. WBUFW(buf, 0) = 0xa2d;
  8535. #endif
  8536. safestrncpy(WBUFCP(buf, 4), tsd->status.name, NAME_LENGTH);
  8537. WBUFW(buf,28) = tsd->status.class_;
  8538. WBUFW(buf,30) = tsd->vd.hair_style;
  8539. WBUFW(buf,32) = tsd->vd.head_bottom;
  8540. WBUFW(buf,34) = tsd->vd.head_mid;
  8541. WBUFW(buf,36) = tsd->vd.head_top;
  8542. #if PACKETVER >= 20110111
  8543. WBUFW(buf,38) = tsd->vd.robe;
  8544. offset+= 2;
  8545. buf = WBUFP(buf,2);
  8546. #endif
  8547. WBUFW(buf,38) = tsd->vd.hair_color;
  8548. WBUFW(buf,40) = tsd->vd.cloth_color;
  8549. WBUFB(buf,42) = tsd->vd.sex;
  8550. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8551. {
  8552. if (tsd->inventory.u.items_inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8553. continue;
  8554. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8555. continue;
  8556. // Add item info : refine, identify flag, element, etc.
  8557. 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));
  8558. n++;
  8559. }
  8560. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8561. WFIFOSET(fd, WFIFOW(fd, 2));
  8562. }
  8563. /// Display msgstringtable.txt string (ZC_MSG).
  8564. /// 0291 <message>.W
  8565. void clif_msg(struct map_session_data* sd, unsigned short id)
  8566. {
  8567. int fd;
  8568. nullpo_retv(sd);
  8569. fd = sd->fd;
  8570. WFIFOHEAD(fd, packet_len(0x291));
  8571. WFIFOW(fd, 0) = 0x291;
  8572. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8573. WFIFOSET(fd, packet_len(0x291));
  8574. }
  8575. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8576. /// 0x7e2 <message>.W <value>.L
  8577. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8578. {
  8579. int fd = sd->fd;
  8580. WFIFOHEAD(fd, packet_len(0x7e2));
  8581. WFIFOW(fd,0) = 0x7e2;
  8582. WFIFOW(fd,2) = id;
  8583. WFIFOL(fd,4) = value;
  8584. WFIFOSET(fd, packet_len(0x7e2));
  8585. }
  8586. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8587. /// 07e6 <skill id>.W <msg id>.L
  8588. ///
  8589. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8590. /// "[SkillName] Message"
  8591. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8592. {
  8593. int fd = sd->fd;
  8594. WFIFOHEAD(fd, packet_len(0x7e6));
  8595. WFIFOW(fd,0) = 0x7e6;
  8596. WFIFOW(fd,2) = skill_id;
  8597. WFIFOL(fd,4) = msg_id;
  8598. WFIFOSET(fd, packet_len(0x7e6));
  8599. }
  8600. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8601. /// 09cd <msg id>.W <color>.L
  8602. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8603. nullpo_retv(sd);
  8604. int fd = sd->fd;
  8605. WFIFOHEAD(fd, packet_len(0x9cd));
  8606. WFIFOW(fd, 0) = 0x9cd;
  8607. WFIFOW(fd, 2) = msg_id;
  8608. WFIFOL(fd, 4) = color;
  8609. WFIFOSET(fd, packet_len(0x9cd));
  8610. }
  8611. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8612. /// Returns true if the packet was parsed successfully.
  8613. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8614. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8615. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8616. const char* seperator = " : ";
  8617. int fd;
  8618. struct s_packet_db* info;
  8619. uint16 packetLength, inputLength;
  8620. const char *input, *name, *message;
  8621. size_t nameLength, messageLength;
  8622. fd = sd->fd;
  8623. info = &packet_db[RFIFOW(fd,0)];
  8624. packetLength = RFIFOW(fd,info->pos[0]);
  8625. input = RFIFOCP(fd,info->pos[1]);
  8626. // basic structure check for the 4-byte header
  8627. if( packetLength < 4 ){
  8628. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8629. return false;
  8630. }else{
  8631. inputLength = packetLength - 4;
  8632. }
  8633. // process <name> part of the packet
  8634. if( whisperFormat ) {
  8635. // name has fixed width
  8636. if( inputLength < NAME_LENGTH + 1 ) {
  8637. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8638. return false;
  8639. }
  8640. name = input;
  8641. // validate name
  8642. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8643. // only restriction is that the name must be zero-terminated
  8644. if( name[nameLength] != '\0' ) {
  8645. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8646. return false;
  8647. }
  8648. message = input + NAME_LENGTH;
  8649. messageLength = inputLength - NAME_LENGTH;
  8650. }else{
  8651. // name and message are separated by ' : '
  8652. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8653. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8654. // check if there's enough data provided
  8655. if( inputLength < nameLength + seperatorLength + 1 ){
  8656. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8657. return false;
  8658. }
  8659. name = input;
  8660. // validate name
  8661. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8662. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8663. {
  8664. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8665. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8666. set_eof(sd->fd); // Just kick them out to correct it.
  8667. return false;
  8668. }
  8669. message = input + nameLength + seperatorLength;
  8670. messageLength = inputLength - nameLength - seperatorLength;
  8671. }
  8672. #if PACKETVER < 20151001
  8673. // the declared length must match real length
  8674. if( messageLength != strnlen(message, messageLength)+1 ) {
  8675. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8676. return false;
  8677. }
  8678. // verify <message> part of the packet
  8679. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8680. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8681. return false;
  8682. }
  8683. #else
  8684. // No zero termination anymore
  8685. messageLength += 1;
  8686. #endif
  8687. // messages mustn't be too long
  8688. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8689. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8690. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8691. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8692. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8693. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8694. return false;
  8695. }
  8696. // If it is not a whisper message, set the name to the fakename of the player
  8697. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8698. strcpy( out_name, sd->fakename );
  8699. }else{
  8700. safestrncpy( out_name, name, nameLength + 1 );
  8701. }
  8702. safestrncpy( out_message, message, messageLength );
  8703. if( whisperFormat ){
  8704. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8705. out_full_message[nameLength] = '\0';
  8706. }else{
  8707. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8708. }
  8709. if( is_atcommand( fd, sd, out_message, 1 ) )
  8710. return false;
  8711. if (sd->sc.cant.chat)
  8712. return false; //no "chatting" while muted.
  8713. if( battle_config.min_chat_delay ) { //[Skotlex]
  8714. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8715. return false;
  8716. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8717. }
  8718. if (battle_config.idletime_option&IDLE_CHAT)
  8719. sd->idletime = last_tick;
  8720. return true;
  8721. }
  8722. /**
  8723. * Displays a message if the player enters a PK Zone (during pk_mode)
  8724. * @param sd: Player data
  8725. */
  8726. inline void clif_pk_mode_message(struct map_session_data * sd)
  8727. {
  8728. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8729. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8730. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8731. char output[CHAT_SIZE_MAX];
  8732. // 1504: You've entered a PK Zone (safe until level %d).
  8733. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8734. battle_config.pk_min_level);
  8735. clif_showscript(&sd->bl, output, SELF);
  8736. } else {
  8737. // 1503: You've entered a PK Zone.
  8738. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8739. }
  8740. }
  8741. return;
  8742. }
  8743. // ---------------------
  8744. // clif_parse_wanttoconnect
  8745. // ---------------------
  8746. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8747. // error codes:
  8748. // 0 - Success
  8749. // 1 - Unknown packet_ver
  8750. // 2 - Invalid account_id
  8751. // 3 - Invalid char_id
  8752. // 4 - Invalid login_id1 (reserved)
  8753. // 5 - Invalid client_tick (reserved)
  8754. // 6 - Invalid sex
  8755. // Only the first 'invalid' error that appears is used.
  8756. static int clif_parse_WantToConnection_sub(int fd)
  8757. {
  8758. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8759. unsigned short cmd;
  8760. //By default, start searching on the default one.
  8761. cmd = RFIFOW(fd, 0);
  8762. packet_len = RFIFOREST(fd);
  8763. // FIXME: If the packet is not received at once, this will FAIL.
  8764. // Figure out, when it happens, that only part of the packet is
  8765. // received, or fix the function to be able to deal with that
  8766. // case.
  8767. if( packet_len != packet_db[cmd].len )
  8768. return 1; /* wrong length */
  8769. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8770. return 2; /* invalid account_id */
  8771. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8772. return 3; /* invalid char_id */
  8773. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8774. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8775. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8776. return 6; /* invalid sex */
  8777. else
  8778. return 0;
  8779. }
  8780. /// Request to connect to map-server.
  8781. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8782. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8783. /// There are various variants of this packet, some of them have padding between fields.
  8784. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8785. {
  8786. struct block_list* bl;
  8787. struct auth_node* node;
  8788. int cmd, account_id, char_id, login_id1, sex, err;
  8789. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8790. if (sd) {
  8791. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8792. return;
  8793. }
  8794. cmd = RFIFOW(fd, 0);
  8795. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8796. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8797. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8798. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8799. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8800. err = clif_parse_WantToConnection_sub(fd);
  8801. if( err ){ // connection rejected
  8802. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8803. err == 1 ? "." :
  8804. err == 2 ? ", possibly for having an invalid account_id." :
  8805. err == 3 ? ", possibly for having an invalid char_id." :
  8806. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8807. err == 4 ? ", possibly for having an invalid login_id1." :
  8808. err == 5 ? ", possibly for having an invalid client_tick." :
  8809. */
  8810. err == 6 ? ", possibly for having an invalid sex." :
  8811. ". ERROR invalid error code"));
  8812. WFIFOHEAD(fd,packet_len(0x6a));
  8813. WFIFOW(fd,0) = 0x6a;
  8814. WFIFOB(fd,2) = err;
  8815. WFIFOSET(fd,packet_len(0x6a));
  8816. #ifdef DUMP_INVALID_PACKET
  8817. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8818. #endif
  8819. RFIFOSKIP(fd, RFIFOREST(fd));
  8820. set_eof(fd);
  8821. return;
  8822. }
  8823. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8824. clif_authfail_fd(fd,1);// server closed
  8825. return;
  8826. }
  8827. //Check for double login.
  8828. bl = map_id2bl(account_id);
  8829. if(bl && bl->type != BL_PC) {
  8830. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8831. WFIFOHEAD(fd,packet_len(0x6a));
  8832. WFIFOW(fd,0) = 0x6a;
  8833. WFIFOB(fd,2) = 3; // Rejected by server
  8834. WFIFOSET(fd,packet_len(0x6a));
  8835. set_eof(fd);
  8836. return;
  8837. }
  8838. if (bl ||
  8839. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8840. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8841. {
  8842. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8843. return;
  8844. }
  8845. CREATE(sd, TBL_PC, 1);
  8846. sd->fd = fd;
  8847. #ifdef PACKET_OBFUSCATION
  8848. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8849. #endif
  8850. session[fd]->session_data = sd;
  8851. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8852. #if PACKETVER < 20070521
  8853. WFIFOHEAD(fd,4);
  8854. WFIFOL(fd,0) = sd->bl.id;
  8855. WFIFOSET(fd,4);
  8856. #else
  8857. WFIFOHEAD(fd,packet_len(0x283));
  8858. WFIFOW(fd,0) = 0x283;
  8859. WFIFOL(fd,2) = sd->bl.id;
  8860. WFIFOSET(fd,packet_len(0x283));
  8861. #endif
  8862. chrif_authreq(sd,false);
  8863. }
  8864. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8865. /// 007d
  8866. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8867. {
  8868. bool guild_notice = false;
  8869. if(sd->bl.prev != NULL)
  8870. return;
  8871. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8872. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8873. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8874. sd->state.connect_new = 0;
  8875. return;
  8876. }
  8877. if (sd->state.rewarp) { //Rewarp player.
  8878. sd->state.rewarp = 0;
  8879. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8880. return;
  8881. }
  8882. sd->state.warping = 0;
  8883. // look
  8884. #if PACKETVER < 4
  8885. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8886. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8887. #else
  8888. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8889. #endif
  8890. pc_set_costume_view(sd);
  8891. if(sd->vd.cloth_color)
  8892. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8893. if(sd->vd.body_style)
  8894. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8895. // item
  8896. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8897. pc_checkitem(sd);
  8898. // cart
  8899. if(pc_iscarton(sd)) {
  8900. clif_cartlist(sd);
  8901. clif_updatestatus(sd,SP_CARTINFO);
  8902. }
  8903. // weight
  8904. clif_updatestatus(sd,SP_WEIGHT);
  8905. clif_updatestatus(sd,SP_MAXWEIGHT);
  8906. // guild
  8907. // (needs to go before clif_spawn() to show guild emblems correctly)
  8908. if(sd->status.guild_id)
  8909. guild_send_memberinfoshort(sd,1);
  8910. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8911. if(battle_config.pc_invincible_time > 0) {
  8912. if(mapdata_flag_gvg(mapdata))
  8913. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8914. else
  8915. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8916. }
  8917. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8918. map_spawnmobs(sd->bl.m);
  8919. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8920. mapdata->users_pvp++;
  8921. }
  8922. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8923. // reset the callshop flag if the player changes map
  8924. sd->state.callshop = 0;
  8925. if(map_addblock(&sd->bl))
  8926. return;
  8927. clif_spawn(&sd->bl);
  8928. // Party
  8929. // (needs to go after clif_spawn() to show hp bars correctly)
  8930. if(sd->status.party_id) {
  8931. party_send_movemap(sd);
  8932. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8933. }
  8934. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8935. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  8936. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8937. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  8938. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8939. sd->pvp_rank = 0;
  8940. sd->pvp_lastusers = 0;
  8941. sd->pvp_point = 5;
  8942. sd->pvp_won = 0;
  8943. sd->pvp_lost = 0;
  8944. }
  8945. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8946. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8947. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8948. else if (mapdata->flag[MF_GVG_DUNGEON])
  8949. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8950. else if( mapdata_flag_gvg(mapdata) )
  8951. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8952. else
  8953. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8954. // info about nearby objects
  8955. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8956. 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);
  8957. // pet
  8958. if( sd->pd ) {
  8959. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8960. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8961. pet_menu(sd, 3); //Option 3 is return to egg.
  8962. } else {
  8963. if(map_addblock(&sd->pd->bl))
  8964. return;
  8965. clif_spawn(&sd->pd->bl);
  8966. clif_send_petdata(sd,sd->pd,0,0);
  8967. clif_send_petstatus(sd);
  8968. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8969. }
  8970. }
  8971. //homunculus [blackhole89]
  8972. if( hom_is_active(sd->hd) ) {
  8973. if(map_addblock(&sd->hd->bl))
  8974. return;
  8975. clif_spawn(&sd->hd->bl);
  8976. clif_send_homdata(sd,SP_ACK,0);
  8977. clif_hominfo(sd,sd->hd,1);
  8978. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8979. clif_homskillinfoblock(sd);
  8980. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8981. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8982. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8983. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8984. }
  8985. if( sd->md ) {
  8986. if(map_addblock(&sd->md->bl))
  8987. return;
  8988. clif_spawn(&sd->md->bl);
  8989. clif_mercenary_info(sd);
  8990. clif_mercenary_skillblock(sd);
  8991. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8992. }
  8993. if( sd->ed ) {
  8994. if (map_addblock(&sd->ed->bl))
  8995. return;
  8996. clif_spawn(&sd->ed->bl);
  8997. clif_elemental_info(sd);
  8998. clif_elemental_updatestatus(sd,SP_HP);
  8999. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9000. clif_elemental_updatestatus(sd,SP_SP);
  9001. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9002. }
  9003. if(sd->state.connect_new) {
  9004. int lv;
  9005. guild_notice = true;
  9006. clif_skillinfoblock(sd);
  9007. clif_hotkeys_send(sd);
  9008. clif_updatestatus(sd,SP_BASEEXP);
  9009. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9010. clif_updatestatus(sd,SP_JOBEXP);
  9011. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9012. clif_updatestatus(sd,SP_SKILLPOINT);
  9013. clif_initialstatus(sd);
  9014. if (sd->sc.option&OPTION_FALCON)
  9015. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9016. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  9017. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9018. else if (sd->sc.option&OPTION_WUGRIDER)
  9019. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9020. else if (sd->sc.data[SC_ALL_RIDING])
  9021. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9022. if(sd->status.manner < 0)
  9023. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9024. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9025. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9026. if(sd->bl.m == sd->feel_map[0].m
  9027. || sd->bl.m == sd->feel_map[1].m
  9028. || sd->bl.m == sd->feel_map[2].m)
  9029. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9030. }
  9031. if(sd->pd && sd->pd->pet.intimate > 900)
  9032. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9033. if(hom_is_active(sd->hd))
  9034. hom_init_timers(sd->hd);
  9035. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9036. sd->state.night = 1;
  9037. clif_status_load(&sd->bl, EFST_SKE, 1);
  9038. }
  9039. // Notify everyone that this char logged in [Skotlex].
  9040. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9041. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9042. //Login Event
  9043. npc_script_event(sd, NPCE_LOGIN);
  9044. }
  9045. } else {
  9046. //For some reason the client "loses" these on warp/map-change.
  9047. clif_updatestatus(sd,SP_STR);
  9048. clif_updatestatus(sd,SP_AGI);
  9049. clif_updatestatus(sd,SP_VIT);
  9050. clif_updatestatus(sd,SP_INT);
  9051. clif_updatestatus(sd,SP_DEX);
  9052. clif_updatestatus(sd,SP_LUK);
  9053. // abort currently running script
  9054. sd->state.using_fake_npc = 0;
  9055. sd->state.menu_or_input = 0;
  9056. sd->npc_menu = 0;
  9057. if(sd->npc_id)
  9058. npc_event_dequeue(sd);
  9059. }
  9060. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9061. #if PACKETVER >= 20070918
  9062. clif_partyinvitationstate(sd);
  9063. clif_equipcheckbox(sd);
  9064. #endif
  9065. #if PACKETVER >= 20170920
  9066. if( battle_config.homunculus_autofeed_always ){
  9067. // Always send ON or OFF
  9068. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9069. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9070. }else{
  9071. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9072. }
  9073. }else{
  9074. // Only send when enabled
  9075. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9076. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9077. }
  9078. }
  9079. #endif
  9080. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9081. clif_guild_notice(sd); // Displays after VIP
  9082. guild_notice = false; // Do not display it twice
  9083. }
  9084. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9085. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9086. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9087. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9088. }
  9089. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9090. { //Display night.
  9091. if( !sd->state.night )
  9092. {
  9093. sd->state.night = 1;
  9094. clif_status_load(&sd->bl, EFST_SKE, 1);
  9095. }
  9096. }
  9097. else if( sd->state.night )
  9098. { //Clear night display.
  9099. sd->state.night = 0;
  9100. clif_status_load(&sd->bl, EFST_SKE, 0);
  9101. }
  9102. if( mapdata->flag[MF_BATTLEGROUND] )
  9103. {
  9104. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9105. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9106. clif_bg_updatescore_single(sd);
  9107. }
  9108. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9109. {
  9110. char output[128];
  9111. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9112. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9113. }
  9114. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9115. mapdata->hpmeter_visible++;
  9116. sd->state.hpmeter_visible = 1;
  9117. }
  9118. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9119. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9120. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9121. #ifdef VIP_ENABLE
  9122. if (!sd->state.connect_new &&
  9123. !sd->vip.disableshowrate &&
  9124. sd->state.pmap != sd->bl.m &&
  9125. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9126. )
  9127. {
  9128. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9129. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9130. }
  9131. #endif
  9132. // Instances do not need their own channels
  9133. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9134. channel_mjoin(sd); //join new map
  9135. clif_pk_mode_message(sd);
  9136. }
  9137. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9138. clif_guild_notice(sd); // Displays at end
  9139. }
  9140. mail_clear(sd);
  9141. /* Guild Aura Init */
  9142. if( sd->guild && sd->state.gmaster_flag ) {
  9143. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9144. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9145. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9146. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9147. }
  9148. if( sd->state.vending ) { /* show we have a vending */
  9149. clif_openvending(sd,sd->bl.id,sd->vending);
  9150. clif_showvendingboard(&sd->bl,sd->message,0);
  9151. }
  9152. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9153. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9154. npc_script_event(sd, NPCE_LOADMAP);
  9155. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  9156. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9157. if (sd->sc.opt2) //Client loses these on warp.
  9158. clif_changeoption(&sd->bl);
  9159. 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)) {
  9160. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9161. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9162. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9163. }
  9164. clif_weather_check(sd);
  9165. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9166. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9167. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9168. else
  9169. sd->areanpc_id = 0;
  9170. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9171. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9172. pc_setdead(sd);
  9173. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9174. if(pc_isdead(sd))
  9175. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9176. else {
  9177. skill_usave_trigger(sd);
  9178. if (battle_config.spawn_direction)
  9179. clif_changed_dir(&sd->bl, SELF);
  9180. }
  9181. // Trigger skill effects if you appear standing on them
  9182. if(!battle_config.pc_invincible_time)
  9183. skill_unit_move(&sd->bl,gettick(),1);
  9184. pc_show_questinfo_reinit(sd);
  9185. pc_show_questinfo(sd);
  9186. #if PACKETVER >= 20150513
  9187. if( sd->mail.inbox.unread ){
  9188. clif_Mail_new(sd, 0, NULL, NULL);
  9189. }
  9190. #endif
  9191. sd->state.connect_new = 0;
  9192. sd->state.changemap = false;
  9193. }
  9194. /// Server's tick (ZC_NOTIFY_TIME).
  9195. /// 007f <time>.L
  9196. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  9197. {
  9198. int fd = sd->fd;
  9199. WFIFOHEAD(fd,packet_len(0x7f));
  9200. WFIFOW(fd,0) = 0x7f;
  9201. WFIFOL(fd,2) = time;
  9202. WFIFOSET(fd,packet_len(0x7f));
  9203. }
  9204. /// Request for server's tick.
  9205. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9206. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9207. /// There are various variants of this packet, some of them have padding between fields.
  9208. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9209. {
  9210. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9211. clif_notify_time(sd, gettick());
  9212. }
  9213. /// Sends hotkey bar.
  9214. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9215. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9216. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9217. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9218. void clif_hotkeys_send(struct map_session_data *sd) {
  9219. #ifdef HOTKEY_SAVING
  9220. const int fd = sd->fd;
  9221. int i;
  9222. int offset = 2;
  9223. #if PACKETVER < 20090603
  9224. const int cmd = 0x2b9;
  9225. #elif PACKETVER < 20141022
  9226. const int cmd = 0x7d9;
  9227. #else
  9228. char Rotate = sd->status.hotkey_rowshift;
  9229. const int cmd = 0xa00;
  9230. offset = 3;
  9231. #endif
  9232. if (!fd) return;
  9233. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9234. WFIFOW(fd, 0) = cmd;
  9235. #if PACKETVER >= 20141022
  9236. WFIFOB(fd, 2) = Rotate;
  9237. #endif
  9238. for(i = 0; i < MAX_HOTKEYS; i++) {
  9239. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9240. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9241. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9242. }
  9243. WFIFOSET(fd, packet_len(cmd));
  9244. #endif
  9245. }
  9246. /// Request to update a position on the hotkey row bar
  9247. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9248. int cmd = RFIFOW(fd, 0);
  9249. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  9250. }
  9251. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9252. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9253. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9254. #ifdef HOTKEY_SAVING
  9255. unsigned short idx;
  9256. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9257. idx = RFIFOW(fd, info->pos[0]);
  9258. if (idx >= MAX_HOTKEYS) return;
  9259. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9260. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9261. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9262. #endif
  9263. }
  9264. /// Displays cast-like progress bar (ZC_PROGRESS).
  9265. /// 02f0 <color>.L <time>.L
  9266. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9267. {
  9268. int fd = sd->fd;
  9269. WFIFOHEAD(fd,packet_len(0x2f0));
  9270. WFIFOW(fd,0) = 0x2f0;
  9271. WFIFOL(fd,2) = color;
  9272. WFIFOL(fd,6) = second;
  9273. WFIFOSET(fd,packet_len(0x2f0));
  9274. }
  9275. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9276. /// 02f2
  9277. void clif_progressbar_abort(struct map_session_data * sd)
  9278. {
  9279. int fd = sd->fd;
  9280. WFIFOHEAD(fd,packet_len(0x2f2));
  9281. WFIFOW(fd,0) = 0x2f2;
  9282. WFIFOSET(fd,packet_len(0x2f2));
  9283. }
  9284. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9285. /// 02f1
  9286. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9287. {
  9288. int npc_id = sd->progressbar.npc_id;
  9289. if( gettick() < sd->progressbar.timeout && sd->st )
  9290. sd->st->state = END;
  9291. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9292. sd->state.workinprogress = WIP_DISABLE_NONE;
  9293. npc_scriptcont(sd, npc_id, false);
  9294. }
  9295. /// Displays cast-like progress bar on a NPC
  9296. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9297. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9298. #if PACKETVER >= 20130821
  9299. unsigned char buf[14];
  9300. if( nd->progressbar.timeout > 0 ){
  9301. WBUFW(buf,0) = 0x9d1;
  9302. WBUFL(buf,2) = nd->bl.id;
  9303. WBUFL(buf,6) = nd->progressbar.color;
  9304. WBUFL(buf,10) = ( nd->progressbar.timeout - gettick() ) / 1000;
  9305. if( sd ){
  9306. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9307. }else{
  9308. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9309. }
  9310. }
  9311. #endif
  9312. }
  9313. /// Request to walk to a certain position on the current map.
  9314. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9315. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9316. /// There are various variants of this packet, some of them have padding between fields.
  9317. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9318. {
  9319. short x, y;
  9320. if (pc_isdead(sd)) {
  9321. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9322. return;
  9323. }
  9324. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9325. ; //You CAN walk on this OPT1 value.
  9326. else if (sd->progressbar.npc_id) {
  9327. clif_progressbar_abort(sd);
  9328. return; // First walk attempt cancels the progress bar
  9329. } else if (pc_cant_act(sd))
  9330. return;
  9331. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9332. return;
  9333. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9334. //A move command one cell west is only valid if the target cell is free
  9335. if(battle_config.official_cell_stack_limit > 0
  9336. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9337. return;
  9338. // Cloaking wall check is actually updated when you click to process next movement
  9339. // not when you move each cell. This is official behaviour.
  9340. if (sd->sc.data[SC_CLOAKING])
  9341. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9342. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9343. pc_delinvincibletimer(sd);
  9344. //Set last idle time... [Skotlex]
  9345. if (battle_config.idletime_option&IDLE_WALK)
  9346. sd->idletime = last_tick;
  9347. unit_walktoxy(&sd->bl, x, y, 4);
  9348. }
  9349. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9350. /// 018b <result>.W
  9351. /// result:
  9352. /// 0 = disconnect (quit)
  9353. /// 1 = cannot disconnect (wait 10 seconds)
  9354. /// ? = ignored
  9355. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9356. {
  9357. int fd = sd->fd;
  9358. WFIFOHEAD(fd,packet_len(0x18b));
  9359. WFIFOW(fd,0) = 0x18b;
  9360. WFIFOW(fd,2) = result;
  9361. WFIFOSET(fd,packet_len(0x18b));
  9362. }
  9363. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9364. /// 018a <type>.W
  9365. /// type:
  9366. /// 0 = quit
  9367. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9368. {
  9369. /* Rovert's prevent logout option fixed [Valaris] */
  9370. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9371. 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] &&
  9372. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9373. {
  9374. set_eof(fd);
  9375. pc_damage_log_clear(sd,0);
  9376. clif_disconnect_ack(sd, 0);
  9377. } else {
  9378. clif_disconnect_ack(sd, 1);
  9379. }
  9380. }
  9381. /// Requesting unit's name.
  9382. /// 0094 <id>.L (CZ_REQNAME)
  9383. /// 0368 <id>.L (CZ_REQNAME2)
  9384. /// There are various variants of this packet, some of them have padding between fields.
  9385. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9386. {
  9387. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9388. struct block_list* bl;
  9389. //struct status_change *sc;
  9390. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9391. id = sd->bl.id;
  9392. bl = map_id2bl(id);
  9393. if( bl == NULL )
  9394. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9395. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9396. return; // Block namerequests past view range
  9397. // 'see people in GM hide' cheat detection
  9398. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9399. sc = status_get_sc(bl);
  9400. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9401. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9402. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9403. ) {
  9404. char gm_msg[256];
  9405. 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);
  9406. ShowWarning(gm_msg);
  9407. // information is sent to all online GMs
  9408. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9409. return;
  9410. }
  9411. */
  9412. clif_name(&sd->bl,bl,SELF);
  9413. }
  9414. /// Validates and processes global messages
  9415. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9416. /// There are various variants of this packet.
  9417. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9418. {
  9419. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9420. size_t length;
  9421. // validate packet and retrieve name and message
  9422. if( !clif_process_message(sd, false, name, message, output ) )
  9423. return;
  9424. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9425. channel_send(sd->gcbind,sd,message);
  9426. return;
  9427. }
  9428. // send message to others (using the send buffer for temp. storage)
  9429. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9430. length = strlen(output) + 1;
  9431. // send back message to the speaker
  9432. WFIFOHEAD(fd,4+length);
  9433. WFIFOW(fd,0) = 0x8e;
  9434. WFIFOW(fd,2) = (uint16)(4+length);
  9435. safestrncpy(WFIFOCP(fd,4), output, length );
  9436. WFIFOSET(fd, WFIFOW(fd,2));
  9437. #ifdef PCRE_SUPPORT
  9438. // trigger listening npcs
  9439. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9440. #endif
  9441. // Chat logging type 'O' / Global Chat
  9442. 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);
  9443. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9444. }
  9445. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9446. /// Request to warp to a map on given coordinates.
  9447. /// 0140 <map name>.16B <x>.W <y>.W
  9448. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9449. {
  9450. char command[MAP_NAME_LENGTH_EXT+25];
  9451. char* map_name;
  9452. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9453. map_name = RFIFOCP(fd,info->pos[0]);
  9454. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9455. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9456. RFIFOW(fd,info->pos[1]), //x
  9457. RFIFOW(fd,info->pos[2])); //y
  9458. is_atcommand(fd, sd, command, 1);
  9459. }
  9460. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9461. /// 009c <id>.L <head dir>.W <dir>.B
  9462. /// head dir:
  9463. /// 0 = straight
  9464. /// 1 = turned CW
  9465. /// 2 = turned CCW
  9466. /// dir:
  9467. /// 0 = north
  9468. /// 1 = northwest
  9469. /// 2 = west
  9470. /// 3 = southwest
  9471. /// 4 = south
  9472. /// 5 = southeast
  9473. /// 6 = east
  9474. /// 7 = northeast
  9475. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9476. {
  9477. unsigned char buf[64];
  9478. WBUFW(buf,0) = 0x9c;
  9479. WBUFL(buf,2) = bl->id;
  9480. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9481. WBUFB(buf,8) = unit_getdir(bl);
  9482. clif_send(buf, packet_len(0x9c), bl, target);
  9483. if (disguised(bl)) {
  9484. WBUFL(buf,2) = -bl->id;
  9485. WBUFW(buf,6) = 0;
  9486. clif_send(buf, packet_len(0x9c), bl, SELF);
  9487. }
  9488. }
  9489. /// Request to change own body and head direction.
  9490. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9491. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9492. /// There are various variants of this packet, some of them have padding between fields.
  9493. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9494. {
  9495. unsigned char headdir, dir;
  9496. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9497. headdir = RFIFOB(fd,info->pos[0]);
  9498. dir = RFIFOB(fd,info->pos[1]);
  9499. pc_setdir(sd, dir, headdir);
  9500. clif_changed_dir(&sd->bl, AREA_WOS);
  9501. }
  9502. /// Request to show an emotion (CZ_REQ_EMOTION).
  9503. /// 00bf <type>.B
  9504. /// type:
  9505. /// @see enum emotion_type
  9506. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9507. {
  9508. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9509. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9510. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9511. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9512. return;
  9513. }
  9514. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9515. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9516. sd->emotionlasttime = time(NULL);
  9517. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9518. return;
  9519. }
  9520. sd->emotionlasttime = time(NULL);
  9521. if (battle_config.idletime_option&IDLE_EMOTION)
  9522. sd->idletime = last_tick;
  9523. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9524. emoticon = rnd()%6+ET_DICE1;
  9525. }
  9526. clif_emotion(&sd->bl, emoticon);
  9527. } else
  9528. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9529. }
  9530. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9531. /// 00c2 <count>.L
  9532. void clif_user_count(struct map_session_data* sd, int count)
  9533. {
  9534. int fd = sd->fd;
  9535. WFIFOHEAD(fd,packet_len(0xc2));
  9536. WFIFOW(fd,0) = 0xc2;
  9537. WFIFOL(fd,2) = count;
  9538. WFIFOSET(fd,packet_len(0xc2));
  9539. }
  9540. /// /w /who (CZ_REQ_USER_COUNT).
  9541. /// Request to display amount of currently connected players.
  9542. /// 00c1
  9543. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9544. {
  9545. clif_user_count(sd, map_getusers());
  9546. }
  9547. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9548. {
  9549. if (pc_isdead(sd)) {
  9550. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9551. return;
  9552. }
  9553. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9554. // (not all are included in pc_can_attack)
  9555. if (sd->sc.count &&
  9556. (sd->sc.data[SC_TRICKDEAD] ||
  9557. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9558. sd->sc.data[SC_BLADESTOP] ||
  9559. sd->sc.data[SC__MANHOLE] ||
  9560. sd->sc.data[SC_SUHIDE] ))
  9561. return;
  9562. if(action_type != 0x00 && action_type != 0x07)
  9563. pc_stop_walking(sd, 1);
  9564. pc_stop_attack(sd);
  9565. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9566. target_id = sd->bl.id;
  9567. switch(action_type)
  9568. {
  9569. case 0x00: // once attack
  9570. case 0x07: // continuous attack
  9571. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9572. return;
  9573. if( sd->sc.option&OPTION_COSTUME )
  9574. return;
  9575. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9576. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9577. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9578. return;
  9579. }
  9580. }
  9581. pc_delinvincibletimer(sd);
  9582. if (battle_config.idletime_option&IDLE_ATTACK)
  9583. sd->idletime = last_tick;
  9584. unit_attack(&sd->bl, target_id, action_type != 0);
  9585. break;
  9586. case 0x02: // sitdown
  9587. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9588. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9589. break;
  9590. }
  9591. if(pc_issit(sd)) {
  9592. //Bugged client? Just refresh them.
  9593. clif_sitting(&sd->bl);
  9594. return;
  9595. }
  9596. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9597. break;
  9598. if (sd->sc.count && (
  9599. sd->sc.data[SC_DANCING] ||
  9600. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9601. )) //No sitting during these states either.
  9602. break;
  9603. if (battle_config.idletime_option&IDLE_SIT)
  9604. sd->idletime = last_tick;
  9605. pc_setsit(sd);
  9606. skill_sit(sd, 1);
  9607. clif_sitting(&sd->bl);
  9608. break;
  9609. case 0x03: // standup
  9610. if (!pc_issit(sd)) {
  9611. //Bugged client? Just refresh them.
  9612. clif_standing(&sd->bl);
  9613. return;
  9614. }
  9615. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9616. break;
  9617. if (pc_setstand(sd, false)) {
  9618. if (battle_config.idletime_option&IDLE_SIT)
  9619. sd->idletime = last_tick;
  9620. skill_sit(sd, 0);
  9621. clif_standing(&sd->bl);
  9622. }
  9623. break;
  9624. }
  9625. }
  9626. /// Request for an action.
  9627. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9628. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9629. /// action:
  9630. /// 0 = attack
  9631. /// 1 = pick up item
  9632. /// 2 = sit down
  9633. /// 3 = stand up
  9634. /// 7 = continous attack
  9635. /// 12 = (touch skill?)
  9636. /// There are various variants of this packet, some of them have padding between fields.
  9637. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9638. {
  9639. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9640. clif_parse_ActionRequest_sub(sd,
  9641. RFIFOB(fd,info->pos[1]),
  9642. RFIFOL(fd,info->pos[0]),
  9643. gettick()
  9644. );
  9645. }
  9646. /// Response to the death/system menu (CZ_RESTART).
  9647. /// 00b2 <type>.B
  9648. /// type:
  9649. /// 0 = restart (respawn)
  9650. /// 1 = char-select (disconnect)
  9651. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9652. {
  9653. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9654. case 0x00:
  9655. pc_respawn(sd,CLR_OUTSIGHT);
  9656. break;
  9657. case 0x01:
  9658. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9659. 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] &&
  9660. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9661. { //Send to char-server for character selection.
  9662. pc_damage_log_clear(sd,0);
  9663. chrif_charselectreq(sd, session[fd]->client_addr);
  9664. } else {
  9665. clif_disconnect_ack(sd, 1);
  9666. }
  9667. break;
  9668. }
  9669. }
  9670. /// Validates and processes whispered messages (CZ_WHISPER).
  9671. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9672. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9673. {
  9674. struct map_session_data* dstsd;
  9675. int i;
  9676. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9677. // validate packet and retrieve name and message
  9678. if( !clif_process_message( sd, true, target, message, output ) )
  9679. return;
  9680. // Chat logging type 'W' / Whisper
  9681. 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);
  9682. //-------------------------------------------------------//
  9683. // Lordalfa - Paperboy - To whisper NPC commands //
  9684. //-------------------------------------------------------//
  9685. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9686. {
  9687. char* str = target+4; //Skip the NPC: string part.
  9688. struct npc_data* npc;
  9689. if ((npc = npc_name2id(str))) {
  9690. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9691. char *split;
  9692. char event[EVENT_NAME_LENGTH];
  9693. str = message;
  9694. // skip codepage indicator, if detected
  9695. if( str[0] == '|' && strlen(str) >= 4 )
  9696. str += 3;
  9697. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9698. split = strchr(str,'#');
  9699. if( split == NULL ) { // use the remaining string
  9700. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9701. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9702. split_data[i][0] = '\0';
  9703. break;
  9704. }
  9705. *split = '\0';
  9706. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9707. str = split+1;
  9708. }
  9709. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9710. char variablename[CHAT_SIZE_MAX];
  9711. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9712. set_var(sd,variablename,(char *) split_data[i]);
  9713. }
  9714. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9715. npc_event(sd,event,0); // Calls the NPC label
  9716. return;
  9717. }
  9718. } else if( target[0] == '#' ) {
  9719. struct Channel *channel = NULL;
  9720. char* chname = target;
  9721. channel = channel_name2channel(chname,sd,3);
  9722. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9723. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9724. channel_send(channel,sd,message);
  9725. }
  9726. else if( channel->pass[0] == '\0') { //no pass needed
  9727. if (channel_join(channel,sd)==0)
  9728. channel_send(channel,sd,message); //join success
  9729. }
  9730. else {
  9731. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9732. }
  9733. return;
  9734. }
  9735. }
  9736. // searching destination character
  9737. dstsd = map_nick2sd(target,false);
  9738. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9739. // player is not on this map-server
  9740. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9741. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9742. // and if we ask for 'Test', we must not contact 'test' player
  9743. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9744. intif_wis_message(sd, target, message, strlen(message) + 1);
  9745. return;
  9746. }
  9747. // if player ignores everyone
  9748. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9749. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9750. clif_wis_end(fd, 1); // 1: target character is not logged in
  9751. else
  9752. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9753. return;
  9754. }
  9755. // if player is autotrading
  9756. if (dstsd->state.autotrade == 1){
  9757. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9758. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9759. return;
  9760. }
  9761. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9762. // if player ignores the source character
  9763. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9764. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9765. clif_wis_end(fd, 2); // 2: ignored by target
  9766. return;
  9767. }
  9768. }
  9769. // notify sender of success
  9770. clif_wis_end(fd, 0); // 0: success to send wisper
  9771. // Normal message
  9772. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9773. }
  9774. /// /b /nb (CZ_BROADCAST).
  9775. /// Request to broadcast a message on whole server.
  9776. /// 0099 <packet len>.W <text>.?B 00
  9777. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9778. char command[CHAT_SIZE_MAX+11];
  9779. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9780. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9781. char* msg = RFIFOCP(fd,info->pos[1]);
  9782. // as the length varies depending on the command used, just block unreasonably long strings
  9783. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9784. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9785. is_atcommand(fd, sd, command, 1);
  9786. }
  9787. /// Request to pick up an item.
  9788. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9789. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9790. /// There are various variants of this packet, some of them have padding between fields.
  9791. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9792. {
  9793. struct flooritem_data *fitem;
  9794. int map_object_id;
  9795. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9796. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9797. do {
  9798. if (pc_isdead(sd)) {
  9799. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9800. break;
  9801. }
  9802. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9803. break;
  9804. if (pc_cant_act(sd))
  9805. break;
  9806. if (!pc_takeitem(sd, fitem))
  9807. break;
  9808. return;
  9809. } while (0);
  9810. // Client REQUIRES a fail packet or you can no longer pick items.
  9811. clif_additem(sd,0,0,6);
  9812. }
  9813. /// Request to drop an item.
  9814. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9815. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9816. /// There are various variants of this packet, some of them have padding between fields.
  9817. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9818. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9819. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9820. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9821. for(;;) {
  9822. if (pc_isdead(sd))
  9823. break;
  9824. if (pc_cant_act2(sd) || sd->npc_id)
  9825. break;
  9826. if (sd->sc.count && (
  9827. sd->sc.data[SC_AUTOCOUNTER] ||
  9828. sd->sc.data[SC_BLADESTOP] ||
  9829. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9830. ))
  9831. break;
  9832. if (!pc_dropitem(sd, item_index, item_amount))
  9833. break;
  9834. if (battle_config.idletime_option&IDLE_DROPITEM)
  9835. sd->idletime = last_tick;
  9836. return;
  9837. }
  9838. //Because the client does not like being ignored.
  9839. clif_dropitem(sd, item_index,0);
  9840. }
  9841. /// Request to use an item.
  9842. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9843. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9844. /// There are various variants of this packet, some of them have padding between fields.
  9845. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9846. {
  9847. int n;
  9848. if (pc_isdead(sd)) {
  9849. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9850. return;
  9851. }
  9852. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9853. return;
  9854. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9855. if (battle_config.idletime_option&IDLE_USEITEM)
  9856. sd->idletime = last_tick;
  9857. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9858. if(n <0 || n >= MAX_INVENTORY)
  9859. return;
  9860. if (!pc_useitem(sd,n))
  9861. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9862. }
  9863. /// Request to equip an item
  9864. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9865. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9866. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9867. {
  9868. int index;
  9869. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9870. if(pc_isdead(sd)) {
  9871. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9872. return;
  9873. }
  9874. index = RFIFOW(fd,info->pos[0])-2;
  9875. if (index < 0 || index >= MAX_INVENTORY)
  9876. return; //Out of bounds check.
  9877. if(sd->npc_id && !sd->npc_item_flag) {
  9878. return;
  9879. } else if (sd->state.storage_flag || sd->sc.opt1)
  9880. ; //You can equip/unequip stuff while storage is open/under status changes
  9881. else if (pc_cant_act2(sd))
  9882. return;
  9883. if(!sd->inventory.u.items_inventory[index].identify) {
  9884. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9885. return;
  9886. }
  9887. if(!sd->inventory_data[index])
  9888. return;
  9889. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9890. pet_equipitem(sd,index);
  9891. return;
  9892. }
  9893. if (battle_config.idletime_option&IDLE_USEITEM)
  9894. sd->idletime = last_tick;
  9895. //Client doesn't send the position for ammo.
  9896. if(sd->inventory_data[index]->type == IT_AMMO)
  9897. pc_equipitem(sd,index,EQP_AMMO);
  9898. else {
  9899. int req_pos;
  9900. #if PACKETVER >= 20120925
  9901. req_pos = RFIFOL(fd,info->pos[1]);
  9902. #else
  9903. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9904. #endif
  9905. pc_equipitem(sd,index,req_pos);
  9906. }
  9907. }
  9908. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9909. /// 00ab <index>.W
  9910. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9911. {
  9912. int index;
  9913. if(pc_isdead(sd)) {
  9914. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9915. return;
  9916. }
  9917. if (sd->npc_id && !sd->npc_item_flag) {
  9918. return;
  9919. } else if (sd->state.storage_flag || sd->sc.opt1)
  9920. ; //You can equip/unequip stuff while storage is open/under status changes
  9921. else if (pc_cant_act2(sd))
  9922. return;
  9923. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9924. if (battle_config.idletime_option&IDLE_USEITEM)
  9925. sd->idletime = last_tick;
  9926. pc_unequipitem(sd,index,1);
  9927. }
  9928. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9929. /// 0090 <id>.L <type>.B
  9930. /// type:
  9931. /// 1 = click
  9932. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9933. {
  9934. struct block_list *bl;
  9935. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9936. if(pc_isdead(sd)) {
  9937. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9938. return;
  9939. }
  9940. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  9941. #ifdef RENEWAL
  9942. clif_msg( sd, WORK_IN_PROGRESS );
  9943. #endif
  9944. return;
  9945. }
  9946. if( sd->state.mail_writing )
  9947. return;
  9948. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9949. //type = RFIFOB(fd,info->pos[1]);
  9950. if (!bl) return;
  9951. switch (bl->type) {
  9952. case BL_MOB:
  9953. case BL_PC:
  9954. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9955. break;
  9956. case BL_NPC:
  9957. #ifdef RENEWAL
  9958. 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
  9959. clif_msg(sd, WORK_IN_PROGRESS);
  9960. break;
  9961. }
  9962. #endif
  9963. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  9964. struct npc_data* nd = (struct npc_data*)bl;
  9965. // Progressbar is running
  9966. if( nd->progressbar.timeout > 0 ){
  9967. return;
  9968. }
  9969. npc_click(sd,nd);
  9970. }
  9971. break;
  9972. }
  9973. }
  9974. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9975. /// 00c5 <id>.L <type>.B
  9976. /// type:
  9977. /// 0 = buy
  9978. /// 1 = sell
  9979. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9980. {
  9981. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9982. if (sd->state.trading)
  9983. return;
  9984. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9985. }
  9986. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9987. /// 00ca <result>.B
  9988. /// result:
  9989. /// 0 = "The deal has successfully completed."
  9990. /// 1 = "You do not have enough zeny."
  9991. /// 2 = "You are over your Weight Limit."
  9992. /// 3 = "Out of the maximum capacity, you have too many items."
  9993. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9994. {
  9995. int fd = sd->fd;
  9996. WFIFOHEAD(fd,packet_len(0xca));
  9997. WFIFOW(fd,0) = 0xca;
  9998. WFIFOB(fd,2) = result;
  9999. WFIFOSET(fd,packet_len(0xca));
  10000. }
  10001. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10002. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10003. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  10004. {
  10005. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10006. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  10007. int result;
  10008. if( sd->state.trading || !sd->npc_shopid )
  10009. result = 1;
  10010. else
  10011. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  10012. sd->npc_shopid = 0; //Clear shop data.
  10013. clif_npc_buy_result(sd, result);
  10014. }
  10015. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10016. /// 00cb <result>.B
  10017. /// result:
  10018. /// 0 = "The deal has successfully completed."
  10019. /// 1 = "The deal has failed."
  10020. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10021. {
  10022. int fd = sd->fd;
  10023. WFIFOHEAD(fd,packet_len(0xcb));
  10024. WFIFOW(fd,0) = 0xcb;
  10025. WFIFOB(fd,2) = result;
  10026. WFIFOSET(fd,packet_len(0xcb));
  10027. }
  10028. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10029. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10030. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10031. {
  10032. int fail=0,n;
  10033. unsigned short *item_list;
  10034. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10035. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10036. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10037. if (sd->state.trading || !sd->npc_shopid)
  10038. fail = 1;
  10039. else
  10040. fail = npc_selllist(sd,n,item_list);
  10041. sd->npc_shopid = 0; //Clear shop data.
  10042. clif_npc_sell_result(sd, fail);
  10043. }
  10044. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10045. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10046. /// type:
  10047. /// 0 = private
  10048. /// 1 = public
  10049. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10050. {
  10051. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10052. int len = RFIFOW(fd,info->pos[0])-15;
  10053. int limit = RFIFOW(fd,info->pos[1]);
  10054. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10055. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10056. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10057. char s_password[CHATROOM_PASS_SIZE];
  10058. char s_title[CHATROOM_TITLE_SIZE];
  10059. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10060. return;
  10061. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10062. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10063. return;
  10064. }
  10065. if( npc_isnear(&sd->bl) ) {
  10066. // uncomment to send msg_txt.
  10067. //char output[150];
  10068. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10069. //clif_displaymessage(sd->fd, output);
  10070. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10071. return;
  10072. }
  10073. if( len <= 0 )
  10074. return; // invalid input
  10075. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10076. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10077. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10078. }
  10079. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10080. /// 00d9 <chat ID>.L <passwd>.8B
  10081. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10082. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10083. int chatid = RFIFOL(fd,info->pos[0]);
  10084. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10085. chat_joinchat(sd,chatid,password);
  10086. }
  10087. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10088. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10089. /// type:
  10090. /// 0 = private
  10091. /// 1 = public
  10092. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10093. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10094. int len = RFIFOW(fd,info->pos[0])-15;
  10095. int limit = RFIFOW(fd,info->pos[1]);
  10096. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10097. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10098. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10099. char s_password[CHATROOM_PASS_SIZE];
  10100. char s_title[CHATROOM_TITLE_SIZE];
  10101. if( len <= 0 )
  10102. return; // invalid input
  10103. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10104. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10105. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10106. }
  10107. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10108. /// 00e0 <role>.L <nick>.24B
  10109. /// role:
  10110. /// 0 = owner
  10111. /// 1 = normal
  10112. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10113. {
  10114. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10115. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10116. }
  10117. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10118. /// 00e2 <name>.24B
  10119. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10120. {
  10121. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10122. }
  10123. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10124. /// 00e3
  10125. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10126. {
  10127. chat_leavechat(sd,0);
  10128. }
  10129. //Handles notifying asker and rejecter of what has just ocurred.
  10130. //Type is used to determine the correct msg_txt to use:
  10131. //0:
  10132. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10133. {
  10134. const char* msg;
  10135. char output[256];
  10136. // Your request has been rejected by autoreject option.
  10137. msg = msg_txt(sd,392);
  10138. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10139. //Notice that a request was rejected.
  10140. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10141. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10142. }
  10143. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10144. /// 00e4 <account id>.L
  10145. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10146. {
  10147. struct map_session_data *t_sd;
  10148. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10149. if(!sd->chatID && pc_cant_act(sd))
  10150. return; //You can trade while in a chatroom.
  10151. if(t_sd){
  10152. // @noask [LuzZza]
  10153. if(t_sd->state.noask) {
  10154. clif_noask_sub(sd, t_sd, 0);
  10155. return;
  10156. }
  10157. if (t_sd->state.mail_writing) {
  10158. int old = sd->trade_partner;
  10159. // Fake trading
  10160. sd->trade_partner = t_sd->status.account_id;
  10161. clif_tradestart(sd, 5);
  10162. // Restore old state
  10163. sd->trade_partner = old;
  10164. return;
  10165. }
  10166. }
  10167. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10168. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10169. return;
  10170. }
  10171. trade_traderequest(sd,t_sd);
  10172. }
  10173. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10174. /// 00e6 <result>.B
  10175. /// result:
  10176. /// 3 = accepted
  10177. /// 4 = rejected
  10178. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10179. {
  10180. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10181. }
  10182. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10183. /// 00e8 <index>.W <amount>.L
  10184. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10185. {
  10186. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10187. short index = RFIFOW(fd,info->pos[0]);
  10188. int amount = RFIFOL(fd,info->pos[1]);
  10189. if( index == 0 )
  10190. trade_tradeaddzeny(sd, amount);
  10191. else
  10192. trade_tradeadditem(sd, index, (short)amount);
  10193. }
  10194. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10195. /// 00eb
  10196. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10197. {
  10198. trade_tradeok(sd);
  10199. }
  10200. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10201. /// 00ed
  10202. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10203. {
  10204. trade_tradecancel(sd);
  10205. }
  10206. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10207. /// 00ef
  10208. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10209. {
  10210. trade_tradecommit(sd);
  10211. }
  10212. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10213. /// 0118
  10214. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10215. {
  10216. pc_stop_attack(sd);
  10217. if (sd) sd->ud.state.attack_continue = 0;
  10218. }
  10219. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10220. /// 0126 <index>.W <amount>.L
  10221. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10222. {
  10223. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10224. if (pc_istrading(sd))
  10225. return;
  10226. if (!pc_iscarton(sd))
  10227. return;
  10228. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10229. }
  10230. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10231. /// 0127 <index>.W <amount>.L
  10232. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10233. {
  10234. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10235. if (!pc_iscarton(sd))
  10236. return;
  10237. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10238. }
  10239. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10240. /// 012a
  10241. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10242. {
  10243. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10244. #ifdef NEW_CARTS
  10245. && sd->sc.data[SC_PUSH_CART] )
  10246. pc_setcart(sd,0);
  10247. #else
  10248. )
  10249. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10250. #endif
  10251. else // priority to remove this option before we can clear cart
  10252. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10253. }
  10254. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10255. /// 097f <Length>.W <identity>.L <type>.B
  10256. void clif_SelectCart(struct map_session_data *sd) {
  10257. #if PACKETVER >= 20150826
  10258. int i = 0, carts = 3;
  10259. int fd = sd->fd;
  10260. WFIFOHEAD(fd,8 + carts);
  10261. WFIFOW(fd,0) = 0x97f;
  10262. WFIFOW(fd,2) = 8 + carts;
  10263. WFIFOL(fd,4) = sd->status.account_id;
  10264. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10265. for( i = 0; i < carts; i++ ) {
  10266. WFIFOB(fd,8 + i) = 10 + i;
  10267. }
  10268. WFIFOSET(fd,8 + carts);
  10269. #endif
  10270. }
  10271. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10272. /// 0980 <identity>.L <type>.B
  10273. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10274. #if PACKETVER >= 20150826
  10275. int type;
  10276. // Check identity
  10277. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10278. return;
  10279. type = (int)RFIFOB(fd,6);
  10280. // Check type
  10281. if( type < 10 || type > MAX_CARTS )
  10282. return;
  10283. pc_setcart(sd, type);
  10284. #endif
  10285. }
  10286. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10287. /// 01af <num>.W
  10288. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10289. {// TODO: State tracking?
  10290. int type;
  10291. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10292. return;
  10293. #ifdef RENEWAL
  10294. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10295. clif_msg(sd, WORK_IN_PROGRESS);
  10296. return;
  10297. }
  10298. #endif
  10299. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10300. if(
  10301. #ifdef NEW_CARTS
  10302. (type == 9 && sd->status.base_level > 130) ||
  10303. (type == 8 && sd->status.base_level > 120) ||
  10304. (type == 7 && sd->status.base_level > 110) ||
  10305. (type == 6 && sd->status.base_level > 100) ||
  10306. #endif
  10307. (type == 5 && sd->status.base_level > 90) ||
  10308. (type == 4 && sd->status.base_level > 80) ||
  10309. (type == 3 && sd->status.base_level > 65) ||
  10310. (type == 2 && sd->status.base_level > 40) ||
  10311. (type == 1))
  10312. pc_setcart(sd, type);
  10313. }
  10314. /// Request to increase status (CZ_STATUS_CHANGE).
  10315. /// 00bb <status id>.W <amount>.B
  10316. /// status id:
  10317. /// SP_STR ~ SP_LUK
  10318. /// amount:
  10319. /// Old clients always send 1 for this, even when using /str+ and the like.
  10320. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10321. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10322. {
  10323. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10324. if( increase_amount < 0 ) {
  10325. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10326. fd, increase_amount);
  10327. }
  10328. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10329. }
  10330. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10331. /// 0112 <skill id>.W
  10332. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10333. {
  10334. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10335. }
  10336. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10337. {
  10338. int lv;
  10339. if( !hd )
  10340. return;
  10341. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10342. clif_emotion(&hd->bl, ET_THINK);
  10343. return;
  10344. }
  10345. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10346. target_id = hd->bl.id;
  10347. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10348. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10349. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10350. clif_emotion(&hd->bl, ET_THINK);
  10351. if (hd->master)
  10352. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10353. return;
  10354. }
  10355. lv = hom_checkskill(hd, skill_id);
  10356. if( skill_lv > lv )
  10357. skill_lv = lv;
  10358. if( skill_lv )
  10359. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10360. }
  10361. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10362. {
  10363. int lv;
  10364. if( !hd )
  10365. return;
  10366. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10367. clif_emotion(&hd->bl, ET_THINK);
  10368. return;
  10369. }
  10370. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10371. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10372. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10373. clif_emotion(&hd->bl, ET_THINK);
  10374. if (hd->master)
  10375. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10376. return;
  10377. }
  10378. if( hd->sc.data[SC_BASILICA] )
  10379. return;
  10380. lv = hom_checkskill(hd, skill_id);
  10381. if( skill_lv > lv )
  10382. skill_lv = lv;
  10383. if( skill_lv )
  10384. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10385. }
  10386. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10387. {
  10388. int lv;
  10389. if( !md )
  10390. return;
  10391. if( skill_isNotOk_mercenary(skill_id, md) )
  10392. return;
  10393. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10394. target_id = md->bl.id;
  10395. if( md->ud.skilltimer != INVALID_TIMER )
  10396. {
  10397. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10398. }
  10399. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10400. return;
  10401. lv = mercenary_checkskill(md, skill_id);
  10402. if( skill_lv > lv )
  10403. skill_lv = lv;
  10404. if( skill_lv )
  10405. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10406. }
  10407. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10408. {
  10409. int lv;
  10410. if( !md )
  10411. return;
  10412. if( skill_isNotOk_mercenary(skill_id, md) )
  10413. return;
  10414. if( md->ud.skilltimer != INVALID_TIMER )
  10415. return;
  10416. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10417. {
  10418. if (md->master)
  10419. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10420. return;
  10421. }
  10422. if( md->sc.data[SC_BASILICA] )
  10423. return;
  10424. lv = mercenary_checkskill(md, skill_id);
  10425. if( skill_lv > lv )
  10426. skill_lv = lv;
  10427. if( skill_lv )
  10428. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10429. }
  10430. /// Request to use a targeted skill.
  10431. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10432. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10433. /// There are various variants of this packet, some of them have padding between fields.
  10434. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10435. {
  10436. uint16 skill_id, skill_lv;
  10437. int inf,target_id;
  10438. unsigned int tick = gettick();
  10439. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10440. skill_lv = RFIFOW(fd,info->pos[0]);
  10441. skill_id = RFIFOW(fd,info->pos[1]);
  10442. target_id = RFIFOL(fd,info->pos[2]);
  10443. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10444. inf = skill_get_inf(skill_id);
  10445. if (inf&INF_GROUND_SKILL || !inf)
  10446. return; //Using a ground/passive skill on a target? WRONG.
  10447. if( SKILL_CHK_HOMUN(skill_id) ) {
  10448. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10449. return;
  10450. }
  10451. if( SKILL_CHK_MERC(skill_id) ) {
  10452. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10453. return;
  10454. }
  10455. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10456. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10457. sd->idletime = last_tick;
  10458. if( sd->npc_id ){
  10459. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10460. #ifdef RENEWAL
  10461. clif_msg( sd, WORK_IN_PROGRESS );
  10462. #endif
  10463. return;
  10464. }
  10465. }
  10466. if ((pc_cant_act2(sd) || sd->chatID) &&
  10467. skill_id != RK_REFRESH &&
  10468. !(skill_id == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10469. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10470. return;
  10471. if( pc_issit(sd) )
  10472. return;
  10473. if( skill_isNotOk(skill_id, sd) )
  10474. return;
  10475. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10476. target_id = sd->bl.id; // never trust the client
  10477. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10478. target_id = sd->bl.id;
  10479. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10480. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10481. return;
  10482. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10483. if( sd->skillitem != skill_id ) {
  10484. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10485. return;
  10486. }
  10487. }
  10488. if( sd->sc.option&OPTION_COSTUME )
  10489. return;
  10490. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10491. return; // On basilica only caster can use Basilica again to stop it.
  10492. if( sd->menuskill_id ) {
  10493. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10494. clif_menuskill_clear(sd); //Cancel pet capture.
  10495. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10496. return; //Can't use skills while a menu is open.
  10497. }
  10498. if( sd->skillitem == skill_id ) {
  10499. if( skill_lv != sd->skillitemlv )
  10500. skill_lv = sd->skillitemlv;
  10501. if( !(inf&INF_SELF_SKILL) )
  10502. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10503. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10504. return;
  10505. }
  10506. sd->skillitem = sd->skillitemlv = 0;
  10507. if( SKILL_CHK_GUILD(skill_id) ) {
  10508. if( sd->state.gmaster_flag )
  10509. skill_lv = guild_checkskill(sd->guild, skill_id);
  10510. else
  10511. skill_lv = 0;
  10512. } else {
  10513. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10514. }
  10515. pc_delinvincibletimer(sd);
  10516. if( skill_lv )
  10517. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10518. }
  10519. /*==========================================
  10520. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10521. *------------------------------------------*/
  10522. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10523. {
  10524. unsigned int tick = gettick();
  10525. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10526. return; //Using a target skill on the ground? WRONG.
  10527. if( SKILL_CHK_HOMUN(skill_id) ) {
  10528. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10529. return;
  10530. }
  10531. if( SKILL_CHK_MERC(skill_id) ) {
  10532. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10533. return;
  10534. }
  10535. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10536. #ifdef RENEWAL
  10537. clif_msg( sd, WORK_IN_PROGRESS );
  10538. #endif
  10539. return;
  10540. }
  10541. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10542. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10543. sd->idletime = last_tick;
  10544. if( skill_isNotOk(skill_id, sd) )
  10545. return;
  10546. if( skillmoreinfo != -1 ) {
  10547. if( pc_issit(sd) ) {
  10548. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10549. return;
  10550. }
  10551. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10552. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10553. }
  10554. if( sd->ud.skilltimer != INVALID_TIMER )
  10555. return;
  10556. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10557. if( sd->skillitem != skill_id ) {
  10558. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10559. return;
  10560. }
  10561. }
  10562. if( sd->sc.option&OPTION_COSTUME )
  10563. return;
  10564. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10565. return; // On basilica only caster can use Basilica again to stop it.
  10566. if( sd->menuskill_id ) {
  10567. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10568. clif_menuskill_clear(sd); //Cancel pet capture.
  10569. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10570. return; //Can't use skills while a menu is open.
  10571. }
  10572. pc_delinvincibletimer(sd);
  10573. if( sd->skillitem == skill_id ) {
  10574. if( skill_lv != sd->skillitemlv )
  10575. skill_lv = sd->skillitemlv;
  10576. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10577. } else {
  10578. int lv;
  10579. sd->skillitem = sd->skillitemlv = 0;
  10580. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10581. if( skill_lv > lv )
  10582. skill_lv = lv;
  10583. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10584. }
  10585. }
  10586. }
  10587. /// Request to use a ground skill.
  10588. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10589. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10590. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10591. /// There are various variants of this packet, some of them have padding between fields.
  10592. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10593. {
  10594. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10595. if (pc_cant_act(sd))
  10596. return;
  10597. if (pc_issit(sd))
  10598. return;
  10599. clif_parse_UseSkillToPosSub(fd, sd,
  10600. RFIFOW(fd,info->pos[0]), //skill lv
  10601. RFIFOW(fd,info->pos[1]), //skill num
  10602. RFIFOW(fd,info->pos[2]), //pos x
  10603. RFIFOW(fd,info->pos[3]), //pos y
  10604. // TODO: find out what this is intended to do
  10605. //RFIFOB(fd, info->pos[4])
  10606. -1 //Skill more info.
  10607. );
  10608. }
  10609. /// Request to use a ground skill with text.
  10610. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10611. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10612. /// There are various variants of this packet, some of them have padding between fields.
  10613. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10614. {
  10615. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10616. if (pc_cant_act(sd))
  10617. return;
  10618. if (pc_issit(sd))
  10619. return;
  10620. clif_parse_UseSkillToPosSub(fd, sd,
  10621. RFIFOW(fd,info->pos[0]), //Skill lv
  10622. RFIFOW(fd,info->pos[1]), //Skill num
  10623. RFIFOW(fd,info->pos[2]), //pos x
  10624. RFIFOW(fd,info->pos[3]), //pos y
  10625. info->pos[4] //skill more info
  10626. );
  10627. }
  10628. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10629. /// 011b <skill id>.W <map name>.16B
  10630. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10631. {
  10632. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10633. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10634. char map_name[MAP_NAME_LENGTH];
  10635. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10636. sd->state.workinprogress = WIP_DISABLE_NONE;
  10637. if(skill_id != sd->menuskill_id)
  10638. return;
  10639. //It is possible to use teleport with the storage window open bugreport:8027
  10640. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10641. clif_menuskill_clear(sd);
  10642. return;
  10643. }
  10644. pc_delinvincibletimer(sd);
  10645. skill_castend_map(sd,skill_id,map_name);
  10646. }
  10647. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10648. /// 011d
  10649. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10650. {
  10651. if (!pc_isdead(sd))
  10652. pc_memo(sd,-1);
  10653. }
  10654. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10655. /// 018e <name id>.W { <material id>.W }*3
  10656. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10657. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10658. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10659. int slot1 = RFIFOW(fd,info->pos[1]);
  10660. int slot2 = RFIFOW(fd,info->pos[2]);
  10661. int slot3 = RFIFOW(fd,info->pos[3]);
  10662. short produce_idx = -1;
  10663. switch( sd->menuskill_id ) {
  10664. case -1:
  10665. case AM_PHARMACY:
  10666. case RK_RUNEMASTERY:
  10667. case GC_RESEARCHNEWPOISON:
  10668. break;
  10669. default:
  10670. return;
  10671. }
  10672. if (pc_istrading(sd)) {
  10673. //Make it fail to avoid shop exploits where you sell something different than you see.
  10674. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10675. clif_menuskill_clear(sd);
  10676. return;
  10677. }
  10678. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10679. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10680. clif_menuskill_clear(sd);
  10681. }
  10682. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10683. /// 025b <mk type>.W <name id>.W
  10684. /// mk type:
  10685. /// 1 = cooking
  10686. /// 2 = arrow
  10687. /// 3 = elemental
  10688. /// 4 = GN_MIX_COOKING
  10689. /// 5 = GN_MAKEBOMB
  10690. /// 6 = GN_S_PHARMACY
  10691. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10692. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10693. int type = RFIFOW(fd,info->pos[0]);
  10694. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10695. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10696. short food_idx = -1;
  10697. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10698. return;
  10699. if (pc_istrading(sd)) {
  10700. //Make it fail to avoid shop exploits where you sell something different than you see.
  10701. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10702. clif_menuskill_clear(sd);
  10703. return;
  10704. }
  10705. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10706. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10707. clif_menuskill_clear(sd);
  10708. }
  10709. /// Answer to repair weapon item selection dialog
  10710. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10711. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10712. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10713. {
  10714. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10715. return;
  10716. if (pc_istrading(sd)) {
  10717. //Make it fail to avoid shop exploits where you sell something different than you see.
  10718. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10719. clif_menuskill_clear(sd);
  10720. return;
  10721. }
  10722. skill_repairweapon(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10723. //nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10724. //refine = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  10725. //for(i = 0; i<MAX_SLOTS; i++)
  10726. // card[i] = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3+i]);
  10727. clif_menuskill_clear(sd);
  10728. }
  10729. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10730. /// 0222 <index>.L
  10731. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10732. {
  10733. int idx;
  10734. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10735. return;
  10736. if (pc_istrading(sd)) {
  10737. //Make it fail to avoid shop exploits where you sell something different than you see.
  10738. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10739. clif_menuskill_clear(sd);
  10740. return;
  10741. }
  10742. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10743. skill_weaponrefine(sd, idx-2);
  10744. clif_menuskill_clear(sd);
  10745. }
  10746. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10747. /// 00b8 <npc id>.L <choice>.B
  10748. /// choice:
  10749. /// 1~254 = menu item
  10750. /// 255 = cancel
  10751. /// NOTE: If there were more than 254 items in the list, choice
  10752. /// overflows to choice%256.
  10753. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10754. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10755. int npc_id = RFIFOL(fd,info->pos[0]);
  10756. uint8 select = RFIFOB(fd,info->pos[1]);
  10757. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10758. #ifdef SECURE_NPCTIMEOUT
  10759. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10760. #endif
  10761. TBL_NPC* nd = map_id2nd(npc_id);
  10762. 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);
  10763. clif_GM_kick(NULL,sd);
  10764. #ifdef SECURE_NPCTIMEOUT
  10765. }
  10766. #endif
  10767. return;
  10768. }
  10769. sd->npc_menu = select;
  10770. npc_scriptcont(sd,npc_id, false);
  10771. }
  10772. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10773. /// 00b9 <npc id>.L
  10774. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10775. {
  10776. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10777. }
  10778. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10779. /// 0143 <npc id>.L <value>.L
  10780. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10781. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10782. int npcid = RFIFOL(fd,info->pos[0]);
  10783. int amount = (int)RFIFOL(fd,info->pos[1]);
  10784. sd->npc_amount = amount;
  10785. npc_scriptcont(sd, npcid, false);
  10786. }
  10787. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10788. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10789. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10790. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10791. int message_len = RFIFOW(fd,info->pos[0])-8;
  10792. int npcid = RFIFOL(fd,info->pos[1]);
  10793. const char* message = RFIFOCP(fd,info->pos[2]);
  10794. if( message_len <= 0 )
  10795. return; // invalid input
  10796. #if PACKETVER >= 20151001
  10797. message_len++;
  10798. #endif
  10799. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10800. npc_scriptcont(sd, npcid, false);
  10801. }
  10802. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10803. /// 0146 <npc id>.L
  10804. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10805. {
  10806. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10807. return;
  10808. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10809. }
  10810. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10811. /// 0178 <index>.W
  10812. /// index:
  10813. /// -1 = cancel
  10814. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10815. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10816. if (sd->menuskill_id != MC_IDENTIFY)
  10817. return;
  10818. // Ignore the request
  10819. // - Invalid item index
  10820. // - Invalid item ID or item doesn't exist
  10821. // - Item is already identified
  10822. if (idx < 0 || idx >= MAX_INVENTORY ||
  10823. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10824. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10825. sd->state.workinprogress = WIP_DISABLE_NONE;
  10826. clif_menuskill_clear(sd);
  10827. return;
  10828. }
  10829. skill_identify(sd, idx);
  10830. clif_menuskill_clear(sd);
  10831. }
  10832. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10833. /// 01ae <name id>.W
  10834. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10835. unsigned short nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10836. if (pc_istrading(sd)) {
  10837. //Make it fail to avoid shop exploits where you sell something different than you see.
  10838. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10839. clif_menuskill_clear(sd);
  10840. return;
  10841. }
  10842. switch (sd->menuskill_id) {
  10843. case AC_MAKINGARROW:
  10844. skill_arrow_create(sd,nameid);
  10845. break;
  10846. case SA_CREATECON:
  10847. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10848. break;
  10849. case WL_READING_SB:
  10850. skill_spellbook(sd,nameid);
  10851. break;
  10852. case GC_POISONINGWEAPON:
  10853. skill_poisoningweapon(sd,nameid);
  10854. break;
  10855. case NC_MAGICDECOY:
  10856. skill_magicdecoy(sd,nameid);
  10857. break;
  10858. }
  10859. clif_menuskill_clear(sd);
  10860. }
  10861. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10862. /// 01ce <skill id>.L
  10863. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10864. {
  10865. if (sd->menuskill_id != SA_AUTOSPELL)
  10866. return;
  10867. sd->state.workinprogress = WIP_DISABLE_NONE;
  10868. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10869. clif_menuskill_clear(sd);
  10870. }
  10871. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10872. /// 017a <card index>.W
  10873. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10874. {
  10875. if (sd->state.trading != 0)
  10876. return;
  10877. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10878. }
  10879. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10880. /// 017c <card index>.W <equip index>.W
  10881. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10882. {
  10883. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10884. if (sd->state.trading != 0)
  10885. return;
  10886. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10887. }
  10888. /// Request of character's name by char ID.
  10889. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10890. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10891. /// There are various variants of this packet, some of them have padding between fields.
  10892. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10893. {
  10894. int charid;
  10895. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10896. map_reqnickdb(sd, charid);
  10897. }
  10898. /// /resetskill /resetstate (CZ_RESET).
  10899. /// Request to reset stats or skills.
  10900. /// 0197 <type>.W
  10901. /// type:
  10902. /// 0 = state
  10903. /// 1 = skill
  10904. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10905. char cmd[15];
  10906. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10907. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10908. else
  10909. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10910. is_atcommand(fd, sd, cmd, 1);
  10911. }
  10912. /// /lb /nlb (CZ_LOCALBROADCAST).
  10913. /// Request to broadcast a message on current map.
  10914. /// 019c <packet len>.W <text>.?B
  10915. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10916. {
  10917. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10918. char command[CHAT_SIZE_MAX+16];
  10919. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10920. char* msg = RFIFOCP(fd,info->pos[1]);
  10921. // as the length varies depending on the command used, just block unreasonably long strings
  10922. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10923. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10924. is_atcommand(fd, sd, command, 1);
  10925. }
  10926. /// Request to move an item from inventory to storage.
  10927. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10928. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10929. /// There are various variants of this packet, some of them have padding between fields.
  10930. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10931. {
  10932. int item_index, item_amount;
  10933. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10934. if (pc_istrading(sd))
  10935. return;
  10936. item_index = RFIFOW(fd,info->pos[0])-2;
  10937. item_amount = RFIFOL(fd,info->pos[1]);
  10938. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10939. return;
  10940. if (sd->state.storage_flag == 1)
  10941. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  10942. else
  10943. if (sd->state.storage_flag == 2)
  10944. storage_guild_storageadd(sd, item_index, item_amount);
  10945. else if (sd->state.storage_flag == 3)
  10946. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  10947. }
  10948. /// Request to move an item from storage to inventory.
  10949. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10950. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10951. /// There are various variants of this packet, some of them have padding between fields.
  10952. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10953. {
  10954. int item_index, item_amount;
  10955. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10956. item_index = RFIFOW(fd,info->pos[0])-1;
  10957. item_amount = RFIFOL(fd,info->pos[1]);
  10958. if (sd->state.storage_flag == 1)
  10959. storage_storageget(sd, &sd->storage, item_index, item_amount);
  10960. else if(sd->state.storage_flag == 2)
  10961. storage_guild_storageget(sd, item_index, item_amount);
  10962. else if(sd->state.storage_flag == 3)
  10963. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  10964. }
  10965. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10966. /// 0129 <index>.W <amount>.L
  10967. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10968. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10969. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10970. int amount = RFIFOL(fd,info->pos[1]);
  10971. if( sd->state.vending )
  10972. return;
  10973. if (!pc_iscarton(sd))
  10974. return;
  10975. if (sd->state.storage_flag == 1)
  10976. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  10977. else if (sd->state.storage_flag == 2)
  10978. storage_guild_storageaddfromcart(sd, idx, amount);
  10979. else if (sd->state.storage_flag == 3)
  10980. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  10981. }
  10982. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10983. /// 0128 <index>.W <amount>.L
  10984. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10985. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10986. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10987. int amount = RFIFOL(fd,info->pos[1]);
  10988. if( sd->state.vending )
  10989. return;
  10990. if (!pc_iscarton(sd))
  10991. return;
  10992. if (sd->state.storage_flag == 1)
  10993. storage_storagegettocart(sd, &sd->storage, idx, amount);
  10994. else
  10995. if (sd->state.storage_flag == 2)
  10996. storage_guild_storagegettocart(sd, idx, amount);
  10997. else if (sd->state.storage_flag == 3)
  10998. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  10999. }
  11000. /// Request to close storage (CZ_CLOSE_STORE).
  11001. /// 00f7
  11002. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11003. {
  11004. if( sd->state.storage_flag == 1 )
  11005. storage_storageclose(sd);
  11006. else
  11007. if( sd->state.storage_flag == 2 )
  11008. storage_guild_storageclose(sd);
  11009. else if( sd->state.storage_flag == 3 )
  11010. storage_premiumStorage_close(sd);
  11011. }
  11012. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11013. /// 023a <info>.W
  11014. /// info:
  11015. /// 0 = password has not been set yet
  11016. /// 1 = storage is password-protected
  11017. /// 8 = too many wrong passwords
  11018. /// ? = ignored
  11019. /// NOTE: This packet is only available on certain non-kRO clients.
  11020. void clif_storagepassword(struct map_session_data* sd, short info)
  11021. {
  11022. int fd = sd->fd;
  11023. WFIFOHEAD(fd,packet_len(0x23a));
  11024. WFIFOW(fd,0) = 0x23a;
  11025. WFIFOW(fd,2) = info;
  11026. WFIFOSET(fd,packet_len(0x23a));
  11027. }
  11028. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11029. /// 023b <type>.W <password>.16B <new password>.16B
  11030. /// type:
  11031. /// 2 = change password
  11032. /// 3 = check password
  11033. /// NOTE: This packet is only available on certain non-kRO clients.
  11034. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11035. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11036. // int type = RFIFOW(fd,info->pos[0]);
  11037. // char* password = RFIFOP(fd,info->pos[1]);
  11038. // char* new_password = RFIFOP(fd,info->pos[2]);
  11039. // storage_changepass(sd,password,new_password);
  11040. }
  11041. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11042. /// 023c <result>.W <error count>.W
  11043. /// result:
  11044. /// 4 = password change success
  11045. /// 5 = password change failure
  11046. /// 6 = password check success
  11047. /// 7 = password check failure
  11048. /// 8 = too many wrong passwords
  11049. /// ? = ignored
  11050. /// NOTE: This packet is only available on certain non-kRO clients.
  11051. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11052. {
  11053. int fd = sd->fd;
  11054. WFIFOHEAD(fd,packet_len(0x23c));
  11055. WFIFOW(fd,0) = 0x23c;
  11056. WFIFOW(fd,2) = result;
  11057. WFIFOW(fd,4) = error_count;
  11058. WFIFOSET(fd,packet_len(0x23c));
  11059. }
  11060. /// Party creation request
  11061. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11062. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11063. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11064. name[NAME_LENGTH-1] = '\0';
  11065. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11066. clif_displaymessage(fd, msg_txt(sd,227));
  11067. return;
  11068. }
  11069. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11070. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11071. return;
  11072. }
  11073. party_create(sd,name,0,0);
  11074. }
  11075. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11076. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11077. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11078. char* name = RFIFOCP(fd,info->pos[0]);
  11079. int item1 = RFIFOB(fd,info->pos[1]);
  11080. int item2 = RFIFOB(fd,info->pos[2]);
  11081. name[NAME_LENGTH-1] = '\0';
  11082. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11083. clif_displaymessage(fd, msg_txt(sd,227));
  11084. return;
  11085. }
  11086. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11087. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11088. return;
  11089. }
  11090. party_create(sd,name,item1,item2);
  11091. }
  11092. /// Party invitation request
  11093. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11094. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11095. {
  11096. struct map_session_data *t_sd;
  11097. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11098. clif_displaymessage(fd, msg_txt(sd,227));
  11099. return;
  11100. }
  11101. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11102. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11103. clif_noask_sub(sd, t_sd, 1);
  11104. return;
  11105. }
  11106. party_invite(sd, t_sd);
  11107. }
  11108. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11109. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11110. struct map_session_data *t_sd;
  11111. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11112. name[NAME_LENGTH-1] = '\0';
  11113. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11114. clif_displaymessage(fd, msg_txt(sd,227));
  11115. return;
  11116. }
  11117. t_sd = map_nick2sd(name,false);
  11118. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11119. clif_noask_sub(sd, t_sd, 1);
  11120. return;
  11121. }
  11122. party_invite(sd, t_sd);
  11123. }
  11124. /// Party invitation reply
  11125. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11126. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11127. /// flag:
  11128. /// 0 = reject
  11129. /// 1 = accept
  11130. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11131. {
  11132. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11133. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11134. RFIFOL(fd,info->pos[1]));
  11135. }
  11136. //(CZ_PARTY_JOIN_REQ_ACK)
  11137. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11138. {
  11139. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11140. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11141. RFIFOB(fd,info->pos[1]));
  11142. }
  11143. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11144. /// 0100
  11145. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11146. {
  11147. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11148. clif_displaymessage(fd, msg_txt(sd,227));
  11149. return;
  11150. }
  11151. party_leave(sd);
  11152. }
  11153. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11154. /// 0103 <account id>.L <char name>.24B
  11155. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11156. {
  11157. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11158. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11159. clif_displaymessage(fd, msg_txt(sd,227));
  11160. return;
  11161. }
  11162. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11163. RFIFOCP(fd,info->pos[1]));
  11164. }
  11165. /// Request to change party options.
  11166. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11167. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11168. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11169. {
  11170. struct party_data *p;
  11171. int i,expflag;
  11172. int cmd = RFIFOW(fd,0);
  11173. struct s_packet_db* info = &packet_db[cmd];
  11174. if( !sd->status.party_id )
  11175. return;
  11176. p = party_search(sd->status.party_id);
  11177. if( p == NULL )
  11178. return;
  11179. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11180. if( i == MAX_PARTY )
  11181. return; //Shouldn't happen
  11182. if( !p->party.member[i].leader )
  11183. return;
  11184. expflag = RFIFOL(fd,info->pos[0]);
  11185. if(cmd == 0x0102){ //Client can't change the item-field
  11186. party_changeoption(sd, expflag, p->party.item);
  11187. }
  11188. else {
  11189. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11190. party_changeoption(sd, expflag, itemflag);
  11191. }
  11192. }
  11193. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11194. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11195. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11196. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11197. // validate packet and retrieve name and message
  11198. if( !clif_process_message( sd, false, name, message, output ) )
  11199. return;
  11200. party_send_message(sd, output, strlen(output) + 1 );
  11201. }
  11202. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11203. /// 07da <account id>.L
  11204. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11205. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11206. }
  11207. /// Party Booking in KRO [Spiria]
  11208. ///
  11209. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11210. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11211. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11212. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11213. short level = RFIFOW(fd,info->pos[0]);
  11214. short mapid = RFIFOW(fd,info->pos[1]);
  11215. int idxpbj = info->pos[2];
  11216. short job[MAX_PARTY_BOOKING_JOBS];
  11217. int i;
  11218. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11219. job[i] = RFIFOB(fd,idxpbj+i*2);
  11220. party_booking_register(sd, level, mapid, job);
  11221. }
  11222. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11223. /// 0803 <result>.W
  11224. /// result:
  11225. /// 0 = success
  11226. /// 1 = failure
  11227. /// 2 = already registered
  11228. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11229. {
  11230. int fd = sd->fd;
  11231. WFIFOHEAD(fd,packet_len(0x803));
  11232. WFIFOW(fd,0) = 0x803;
  11233. WFIFOW(fd,2) = flag;
  11234. WFIFOSET(fd,packet_len(0x803));
  11235. }
  11236. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11237. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11238. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11239. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11240. short level = RFIFOW(fd,info->pos[0]);
  11241. short mapid = RFIFOW(fd,info->pos[1]);
  11242. short job = RFIFOW(fd,info->pos[2]);
  11243. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11244. short resultcount = RFIFOW(fd,info->pos[4]);
  11245. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11246. }
  11247. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11248. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11249. /// more results:
  11250. /// 0 = no
  11251. /// 1 = yes
  11252. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11253. {
  11254. int i, j;
  11255. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11256. struct party_booking_ad_info *pb_ad;
  11257. WFIFOHEAD(fd,size*count + 5);
  11258. WFIFOW(fd,0) = 0x805;
  11259. WFIFOW(fd,2) = size*count + 5;
  11260. WFIFOB(fd,4) = more_result;
  11261. for(i=0; i<count; i++)
  11262. {
  11263. pb_ad = results[i];
  11264. WFIFOL(fd,i*size+5) = pb_ad->index;
  11265. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11266. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11267. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11268. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11269. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11270. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11271. }
  11272. WFIFOSET(fd,WFIFOW(fd,2));
  11273. }
  11274. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11275. /// 0806
  11276. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11277. {
  11278. if(party_booking_delete(sd))
  11279. clif_PartyBookingDeleteAck(sd, 0);
  11280. }
  11281. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11282. /// 0807 <result>.W
  11283. /// result:
  11284. /// 0 = success
  11285. /// 1 = success (auto-removed expired ad)
  11286. /// 2 = failure
  11287. /// 3 = nothing registered
  11288. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11289. {
  11290. int fd = sd->fd;
  11291. WFIFOHEAD(fd,packet_len(0x807));
  11292. WFIFOW(fd,0) = 0x807;
  11293. WFIFOW(fd,2) = flag;
  11294. WFIFOSET(fd,packet_len(0x807));
  11295. }
  11296. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11297. /// 0808 { <job>.W }*6
  11298. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11299. {
  11300. short job[MAX_PARTY_BOOKING_JOBS];
  11301. int i;
  11302. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11303. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11304. job[i] = RFIFOW(fd,idxpbu+i*2);
  11305. party_booking_update(sd, job);
  11306. }
  11307. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11308. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11309. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11310. {
  11311. int i;
  11312. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11313. if(pb_ad == NULL) return;
  11314. WBUFW(buf,0) = 0x809;
  11315. WBUFL(buf,2) = pb_ad->index;
  11316. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11317. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11318. WBUFW(buf,34) = pb_ad->p_detail.level;
  11319. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11320. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11321. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11322. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11323. }
  11324. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11325. /// 080a <index>.L { <job>.W }*6
  11326. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11327. {
  11328. int i;
  11329. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11330. if(pb_ad == NULL) return;
  11331. WBUFW(buf,0) = 0x80a;
  11332. WBUFL(buf,2) = pb_ad->index;
  11333. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11334. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11335. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11336. }
  11337. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11338. /// 080b <index>.L
  11339. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11340. {
  11341. uint8 buf[6];
  11342. WBUFW(buf,0) = 0x80b;
  11343. WBUFL(buf,2) = index;
  11344. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11345. }
  11346. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11347. /// 012e
  11348. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11349. {
  11350. vending_closevending(sd);
  11351. }
  11352. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11353. /// 0130 <account id>.L
  11354. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11355. {
  11356. if( sd->npc_id ) {// using an NPC
  11357. return;
  11358. }
  11359. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11360. }
  11361. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11362. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11363. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11364. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11365. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11366. int id = (int)RFIFOL(fd,info->pos[1]);
  11367. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11368. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11369. // whether it fails or not, the buy window is closed
  11370. sd->vended_id = 0;
  11371. }
  11372. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11373. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11374. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11375. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11376. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11377. int aid = (int)RFIFOL(fd,info->pos[1]);
  11378. int uid = (int)RFIFOL(fd,info->pos[2]);
  11379. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11380. vending_purchasereq(sd, aid, uid, data, len/4);
  11381. // whether it fails or not, the buy window is closed
  11382. sd->vended_id = 0;
  11383. }
  11384. /// Confirm or cancel the shop preparation window.
  11385. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11386. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11387. /// result:
  11388. /// 0 = canceled
  11389. /// 1 = open
  11390. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11391. int cmd = RFIFOW(fd,0);
  11392. struct s_packet_db* info = &packet_db[cmd];
  11393. short len = (short)RFIFOW(fd,info->pos[0]);
  11394. const char* message = RFIFOCP(fd,info->pos[1]);
  11395. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11396. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11397. len -= 84;
  11398. }
  11399. else { //(CZ_REQ_OPENSTORE2)
  11400. bool flag;
  11401. len -= 85;
  11402. flag = RFIFOB(fd,info->pos[2]) != 0;
  11403. if (!flag) {
  11404. sd->state.prevend = 0;
  11405. sd->state.workinprogress = WIP_DISABLE_NONE;
  11406. }
  11407. }
  11408. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11409. return;
  11410. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11411. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11412. return;
  11413. }
  11414. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11415. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11416. return;
  11417. }
  11418. if( message[0] == '\0' ) // invalid input
  11419. return;
  11420. vending_openvending(sd, message, data, len/8, NULL);
  11421. }
  11422. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11423. /// 0165 <char id>.L <guild name>.24B
  11424. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11425. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11426. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11427. name[NAME_LENGTH-1] = '\0';
  11428. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11429. clif_displaymessage(fd, msg_txt(sd,228));
  11430. return;
  11431. }
  11432. if(sd->clan){
  11433. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11434. return;
  11435. }
  11436. guild_create(sd, name);
  11437. }
  11438. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11439. /// 014d
  11440. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11441. {
  11442. clif_guild_masterormember(sd);
  11443. }
  11444. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11445. /// 014f <type>.L
  11446. /// type:
  11447. /// 0 = basic info
  11448. /// 1 = member manager
  11449. /// 2 = positions
  11450. /// 3 = skills
  11451. /// 4 = expulsion list
  11452. /// 5 = unknown (GM_ALLGUILDLIST)
  11453. /// 6 = notice
  11454. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11455. {
  11456. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11457. if( !sd->status.guild_id && !sd->bg_id )
  11458. return;
  11459. switch( type )
  11460. {
  11461. case 0: // Basic Information Guild, hostile alliance information
  11462. clif_guild_basicinfo(sd);
  11463. clif_guild_allianceinfo(sd);
  11464. break;
  11465. case 1: // Members list, list job title
  11466. clif_guild_positionnamelist(sd);
  11467. clif_guild_memberlist(sd);
  11468. break;
  11469. case 2: // List job title, title information list
  11470. clif_guild_positionnamelist(sd);
  11471. clif_guild_positioninfolist(sd);
  11472. break;
  11473. case 3: // Skill list
  11474. clif_guild_skillinfo(sd);
  11475. break;
  11476. case 4: // Expulsion list
  11477. clif_guild_expulsionlist(sd);
  11478. break;
  11479. default:
  11480. ShowError("clif: guild request info: unknown type %d\n", type);
  11481. break;
  11482. }
  11483. }
  11484. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11485. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11486. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11487. {
  11488. int i;
  11489. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11490. int len = RFIFOW(fd,info->pos[0]);
  11491. int idxgpos = info->pos[1];
  11492. if(!sd->state.gmaster_flag)
  11493. return;
  11494. for(i = idxgpos; i < len; i += 40 ){
  11495. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11496. }
  11497. }
  11498. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11499. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11500. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11501. {
  11502. int i;
  11503. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11504. int len = RFIFOW(fd,info->pos[0]);
  11505. int idxgpos = info->pos[1];
  11506. if(!sd->state.gmaster_flag)
  11507. return;
  11508. // Guild leadership change
  11509. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11510. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11511. clif_msg(sd, GUILD_MASTER_WOE);
  11512. return;
  11513. }
  11514. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11515. clif_msg(sd, GUILD_MASTER_DELAY);
  11516. return;
  11517. }
  11518. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11519. return;
  11520. }
  11521. for(i=idxgpos;i<len;i+=12){
  11522. int position = RFIFOL(fd,i+8);
  11523. if( position > 0 ){
  11524. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11525. }
  11526. }
  11527. }
  11528. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11529. /// 0151 <guild id>.L
  11530. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11531. {
  11532. struct guild* g;
  11533. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11534. if( (g = guild_search(guild_id)) != NULL )
  11535. clif_guild_emblem(sd,g);
  11536. }
  11537. /// Validates data of a guild emblem (compressed bitmap)
  11538. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11539. EMBVALIDATE_SUCCESS = 0,
  11540. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11541. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11542. };
  11543. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11544. {
  11545. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11546. unsigned long buf_len = sizeof(buf);
  11547. int offset = 0;
  11548. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11549. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11550. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11551. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11552. ))
  11553. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11554. if(battle_config.emblem_transparency_limit != 100) {
  11555. int i, transcount = 1, tmp[3];
  11556. for(i = offset; i < buf_len-1; i++) {
  11557. int j = i%3;
  11558. tmp[j] = RBUFL(buf,i);
  11559. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11560. transcount++;
  11561. }
  11562. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11563. return EMBVALIDATE_ERR_TRANSPARENCY;
  11564. }
  11565. return EMBVALIDATE_SUCCESS;
  11566. }
  11567. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11568. /// 0153 <packet len>.W <emblem data>.?B
  11569. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11570. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11571. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11572. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11573. int emb_val=0;
  11574. if( !emblem_len || !sd->state.gmaster_flag )
  11575. return;
  11576. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11577. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11578. return;
  11579. }
  11580. emb_val = clif_validate_emblem(emblem, emblem_len);
  11581. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11582. 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);
  11583. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11584. return;
  11585. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11586. char output[128];
  11587. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11588. 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"
  11589. return;
  11590. }
  11591. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11592. }
  11593. /// Guild notice update request (CZ_GUILD_NOTICE).
  11594. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11595. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11596. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11597. int guild_id = RFIFOL(fd,info->pos[0]);
  11598. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11599. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11600. if(!sd->state.gmaster_flag)
  11601. return;
  11602. // compensate for some client defects when using multilanguage mode
  11603. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11604. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11605. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11606. guild_change_notice(sd, guild_id, msg1, msg2);
  11607. }
  11608. // Helper function for guild invite functions
  11609. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11610. {
  11611. if (t_sd == NULL) // not online or does not exist
  11612. return 1;
  11613. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11614. clif_displaymessage(fd, msg_txt(sd,228));
  11615. return 1;
  11616. }
  11617. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11618. clif_noask_sub(sd, t_sd, 2);
  11619. return 1;
  11620. }
  11621. // Players in a clan can not join a guild
  11622. if(t_sd && t_sd->clan){
  11623. return 1;
  11624. }
  11625. guild_invite(sd, t_sd);
  11626. return 0;
  11627. }
  11628. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11629. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11630. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11631. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11632. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11633. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11634. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11635. if (clif_sub_guild_invite(fd, sd, t_sd))
  11636. return;
  11637. }
  11638. /// Guild invite request (/guildinvite)
  11639. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11640. void
  11641. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11642. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11643. if (clif_sub_guild_invite(fd, sd, t_sd))
  11644. return;
  11645. }
  11646. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11647. /// 016b <guild id>.L <answer>.L
  11648. /// answer:
  11649. /// 0 = refuse
  11650. /// 1 = accept
  11651. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11652. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11653. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11654. RFIFOL(fd,info->pos[1]));
  11655. }
  11656. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11657. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11658. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11659. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11660. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11661. clif_displaymessage(fd, msg_txt(sd,228));
  11662. return;
  11663. }
  11664. if( sd->bg_id ) {
  11665. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11666. return;
  11667. }
  11668. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11669. RFIFOL(fd,info->pos[1]),
  11670. RFIFOL(fd,info->pos[2]),
  11671. RFIFOCP(fd,info->pos[3]));
  11672. }
  11673. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11674. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11675. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11676. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11677. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11678. { // Guild locked.
  11679. clif_displaymessage(fd, msg_txt(sd,228));
  11680. return;
  11681. }
  11682. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11683. RFIFOL(fd,info->pos[1]),
  11684. RFIFOL(fd,info->pos[2]),
  11685. RFIFOCP(fd,info->pos[3]));
  11686. }
  11687. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11688. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11689. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11690. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11691. // validate packet and retrieve name and message
  11692. if( !clif_process_message( sd, false, name, message, output ) )
  11693. return;
  11694. if( sd->bg_id )
  11695. bg_send_message(sd, output, strlen(output) );
  11696. else
  11697. guild_send_message(sd, output, strlen(output) );
  11698. }
  11699. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11700. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11701. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11702. {
  11703. struct map_session_data *t_sd;
  11704. if(!sd->state.gmaster_flag)
  11705. return;
  11706. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11707. clif_displaymessage(fd, msg_txt(sd,228));
  11708. return;
  11709. }
  11710. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11711. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11712. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11713. // @noask [LuzZza]
  11714. if(t_sd && t_sd->state.noask) {
  11715. clif_noask_sub(sd, t_sd, 3);
  11716. return;
  11717. }
  11718. guild_reqalliance(sd,t_sd);
  11719. }
  11720. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11721. /// 0172 <inviter account id>.L <answer>.L
  11722. /// answer:
  11723. /// 0 = refuse
  11724. /// 1 = accept
  11725. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11726. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11727. guild_reply_reqalliance(sd,
  11728. RFIFOL(fd,info->pos[0]),
  11729. RFIFOL(fd,info->pos[1]));
  11730. }
  11731. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11732. /// 0183 <opponent guild id>.L <relation>.L
  11733. /// relation:
  11734. /// 0 = Ally
  11735. /// 1 = Enemy
  11736. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11737. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11738. if(!sd->state.gmaster_flag)
  11739. return;
  11740. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11741. clif_displaymessage(fd, msg_txt(sd,228));
  11742. return;
  11743. }
  11744. guild_delalliance(sd,
  11745. RFIFOL(fd,info->pos[0]),
  11746. RFIFOL(fd,info->pos[1]));
  11747. }
  11748. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11749. /// 0180 <account id>.L
  11750. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11751. {
  11752. struct map_session_data *t_sd;
  11753. if(!sd->state.gmaster_flag)
  11754. return;
  11755. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11756. clif_displaymessage(fd, msg_txt(sd,228));
  11757. return;
  11758. }
  11759. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11760. // @noask [LuzZza]
  11761. if(t_sd && t_sd->state.noask) {
  11762. clif_noask_sub(sd, t_sd, 4);
  11763. return;
  11764. }
  11765. guild_opposition(sd,t_sd);
  11766. }
  11767. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11768. /// 015d <key>.40B
  11769. /// key:
  11770. /// now guild name; might have been (intended) email, since the
  11771. /// field name and size is same as the one in CH_DELETE_CHAR.
  11772. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11773. {
  11774. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11775. clif_displaymessage(fd, msg_txt(sd,228));
  11776. return;
  11777. }
  11778. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11779. }
  11780. /// Pet
  11781. ///
  11782. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11783. /// 01a1 <type>.B
  11784. /// type:
  11785. /// 0 = pet information
  11786. /// 1 = feed
  11787. /// 2 = performance
  11788. /// 3 = return to egg
  11789. /// 4 = unequip accessory
  11790. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11791. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11792. }
  11793. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11794. /// 019f <id>.L
  11795. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11796. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11797. }
  11798. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11799. /// 01a7 <index>.W
  11800. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11801. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11802. return;
  11803. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11804. clif_menuskill_clear(sd);
  11805. }
  11806. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11807. /// 01a9 <data>.L
  11808. /// data:
  11809. /// is either emotion (@see enum emotion_type) or a compound value
  11810. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11811. /// entry (given in parentheses) in data\pettalktable.xml
  11812. /// act id:
  11813. /// 0 = feeding
  11814. /// 1 = hunting
  11815. /// 2 = danger
  11816. /// 3 = dead
  11817. /// 4 = normal (stand)
  11818. /// 5 = special performance (perfor_s)
  11819. /// 6 = level up (levelup)
  11820. /// 7 = performance 1 (perfor_1)
  11821. /// 8 = performance 2 (perfor_2)
  11822. /// 9 = performance 3 (perfor_3)
  11823. /// 10 = log-in greeting (connect)
  11824. /// hungry value:
  11825. /// 0 = very hungry (hungry)
  11826. /// 1 = hungry (bit_hungry)
  11827. /// 2 = satisfied (noting)
  11828. /// 3 = stuffed (full)
  11829. /// 4 = full (so_full)
  11830. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11831. {
  11832. if(sd->pd)
  11833. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11834. }
  11835. /// Request to change pet's name (CZ_RENAME_PET).
  11836. /// 01a5 <name>.24B
  11837. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11838. {
  11839. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11840. }
  11841. /// /kill (CZ_DISCONNECT_CHARACTER).
  11842. /// Request to disconnect a character.
  11843. /// 00cc <account id>.L
  11844. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11845. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11846. {
  11847. struct block_list *target;
  11848. int tid;
  11849. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11850. target = map_id2bl(tid);
  11851. if (!target) {
  11852. clif_GM_kickack(sd, 0);
  11853. return;
  11854. }
  11855. switch (target->type) {
  11856. case BL_PC:
  11857. {
  11858. char command[NAME_LENGTH+6];
  11859. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11860. is_atcommand(fd, sd, command, 1);
  11861. }
  11862. break;
  11863. /**
  11864. * This one does not invoke any atcommand, so we need to check for permissions.
  11865. */
  11866. case BL_MOB:
  11867. {
  11868. char command[100];
  11869. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11870. clif_GM_kickack(sd, 0);
  11871. return;
  11872. }
  11873. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11874. log_atcommand(sd, command);
  11875. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11876. }
  11877. break;
  11878. case BL_NPC:
  11879. {
  11880. struct npc_data* nd = (struct npc_data *)target;
  11881. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11882. npc_unload_duplicates(nd);
  11883. npc_unload(nd,true);
  11884. npc_read_event_script();
  11885. }
  11886. }
  11887. break;
  11888. default:
  11889. clif_GM_kickack(sd, 0);
  11890. }
  11891. }
  11892. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11893. /// Request to disconnect all characters.
  11894. /// 00ce
  11895. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11896. char cmd[15];
  11897. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11898. is_atcommand(fd, sd, cmd, 1);
  11899. }
  11900. /// /remove (CZ_REMOVE_AID).
  11901. /// Request to warp to a character with given login ID.
  11902. /// 01ba <account name>.24B
  11903. /// /shift (CZ_SHIFT).
  11904. /// Request to warp to a character with given name.
  11905. /// 01bb <char name>.24B
  11906. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11907. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11908. char *player_name;
  11909. char command[NAME_LENGTH+8];
  11910. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11911. player_name[NAME_LENGTH-1] = '\0';
  11912. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11913. is_atcommand(fd, sd, command, 1);
  11914. }
  11915. /// /remove (CZ_REMOVE_AID_SSO).
  11916. /// Request to warp to a character with given account ID.
  11917. /// 0843 <account id>.L
  11918. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11919. {
  11920. uint32 account_id;
  11921. struct map_session_data* pl_sd;
  11922. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11923. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11924. char command[NAME_LENGTH+8];
  11925. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11926. is_atcommand(fd, sd, command, 1);
  11927. }
  11928. }
  11929. /// /recall (CZ_RECALL).
  11930. /// Request to summon a player with given login ID to own position.
  11931. /// 01bc <account name>.24B
  11932. /// /summon (CZ_RECALL_GID).
  11933. /// Request to summon a player with given name to own position.
  11934. /// 01bd <char name>.24B
  11935. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11936. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11937. char *player_name;
  11938. char command [NAME_LENGTH+8];
  11939. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11940. player_name[NAME_LENGTH-1] = '\0';
  11941. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11942. is_atcommand(fd, sd, command, 1);
  11943. }
  11944. /// /recall (CZ_RECALL_SSO).
  11945. /// Request to summon a player with given account ID to own position.
  11946. /// 0842 <account id>.L
  11947. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11948. {
  11949. uint32 account_id;
  11950. struct map_session_data* pl_sd;
  11951. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11952. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11953. char command[NAME_LENGTH+8];
  11954. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11955. is_atcommand(fd, sd, command, 1);
  11956. }
  11957. }
  11958. /// /item /monster (CZ_ITEM_CREATE).
  11959. /// Request to execute GM commands.
  11960. /// Usage:
  11961. /// /item n - summon n monster or acquire n item/s
  11962. /// /item money - grants 2147483647 zenies
  11963. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11964. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11965. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11966. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11967. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11968. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11969. /// 013f <item/mob name>.24B
  11970. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11971. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11972. {
  11973. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11974. int mob_id = 0;
  11975. struct item_data *id = NULL;
  11976. struct mob_db *mob = NULL;
  11977. StringBuf command;
  11978. char *str;
  11979. //#if PACKETVER >= 20131218
  11980. // char str[100];
  11981. //#else
  11982. // char str[24];
  11983. //#endif
  11984. str = RFIFOCP(fd,info->pos[0]);
  11985. if (!str || str[0] == '\0')
  11986. return;
  11987. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11988. return;
  11989. trim(str);
  11990. // Zeny
  11991. if( strcmpi(str, "money") == 0 ) {
  11992. StringBuf_Init(&command);
  11993. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11994. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11995. StringBuf_Destroy(&command);
  11996. return;
  11997. }
  11998. // Item
  11999. if( (id = itemdb_searchname(str)) ) {
  12000. StringBuf_Init(&command);
  12001. if( !itemdb_isstackable2(id) ) //Nonstackable
  12002. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12003. else {
  12004. if (id->flag.guid)
  12005. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  12006. else
  12007. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  12008. }
  12009. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12010. StringBuf_Destroy(&command);
  12011. return;
  12012. }
  12013. // Monster
  12014. if ((mob_id = mobdb_searchname(str)) == 0)
  12015. mob_id = mobdb_checkid(atoi(str));
  12016. if( (mob = mob_db(mob_id)) ) {
  12017. StringBuf_Init(&command);
  12018. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12019. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12020. StringBuf_Destroy(&command);
  12021. return;
  12022. }
  12023. }
  12024. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12025. /// 019d <effect state>.L
  12026. /// effect state:
  12027. /// TODO: Any OPTION_* ?
  12028. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12029. char cmd[6];
  12030. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12031. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12032. is_atcommand(fd, sd, cmd, 1);
  12033. }
  12034. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12035. /// 0149 <account id>.L <type>.B <value>.W
  12036. /// type:
  12037. /// 0 = positive points
  12038. /// 1 = negative points
  12039. /// 2 = self mute (+10 minutes)
  12040. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12041. {
  12042. int id, type, value;
  12043. struct map_session_data *dstsd;
  12044. char command[NAME_LENGTH+15];
  12045. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12046. id = RFIFOL(fd,info->pos[0]);
  12047. type = RFIFOB(fd,info->pos[1]);
  12048. value = RFIFOW(fd,info->pos[2]);
  12049. if( type == 0 )
  12050. value = -value;
  12051. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12052. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12053. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12054. return;
  12055. dstsd = map_id2sd(id);
  12056. if( dstsd == NULL )
  12057. return;
  12058. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12059. is_atcommand(fd, sd, command, 1);
  12060. }
  12061. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12062. /// GM adjustment of a player's manner value by -60.
  12063. /// 0212 <char name>.24B
  12064. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12065. {
  12066. char command[NAME_LENGTH+15];
  12067. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12068. name[NAME_LENGTH-1] = '\0';
  12069. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12070. is_atcommand(fd, sd, command, 1);
  12071. }
  12072. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12073. /// 01e0 <account id>.L <account name>.24B
  12074. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12075. {
  12076. WFIFOHEAD(fd,packet_len(0x1e0));
  12077. WFIFOW(fd,0) = 0x1e0;
  12078. WFIFOL(fd,2) = account_id;
  12079. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12080. WFIFOSET(fd,packet_len(0x1e0));
  12081. }
  12082. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12083. /// 01df <account id>.L
  12084. //! TODO: Figure out how does this actually work
  12085. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12086. {
  12087. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12088. /*
  12089. char query[30];
  12090. safesnprintf(query,sizeof(query),"%d", account_id);
  12091. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12092. */
  12093. clif_account_name(fd, account_id, "");
  12094. }
  12095. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12096. /// GM single cell type change request.
  12097. /// 0198 <x>.W <y>.W <type>.W
  12098. /// type:
  12099. /// 0 = not walkable
  12100. /// 1 = walkable
  12101. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12102. {
  12103. int x,y,type;
  12104. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12105. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12106. return;
  12107. x = RFIFOW(fd,info->pos[0]);
  12108. y = RFIFOW(fd,info->pos[1]);
  12109. type = RFIFOW(fd,info->pos[2]);
  12110. map_setgatcell(sd->bl.m,x,y,type);
  12111. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12112. //FIXME: once players leave the map, the client 'forgets' this information.
  12113. }
  12114. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12115. /// Request to allow/deny whispers from a nick.
  12116. /// 00cf <nick>.24B <type>.B
  12117. /// type:
  12118. /// 0 = (/ex nick) deny speech from nick
  12119. /// 1 = (/in nick) allow speech from nick
  12120. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12121. {
  12122. char* nick;
  12123. uint8 type;
  12124. int i;
  12125. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12126. nick = RFIFOCP(fd,info->pos[0]);
  12127. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12128. type = RFIFOB(fd,info->pos[1]);
  12129. if( type == 0 ) { // Add name to ignore list (block)
  12130. if (strcmp(wisp_server_name, nick) == 0) {
  12131. clif_wisexin(sd, type, 1); // fail
  12132. return;
  12133. }
  12134. // try to find a free spot, while checking for duplicates at the same time
  12135. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12136. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12137. clif_wisexin(sd, type, 2); // too many blocks
  12138. return;
  12139. }
  12140. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12141. clif_wisexin(sd, type, 0); // Aegis reports success.
  12142. return;
  12143. }
  12144. //Insert in position i
  12145. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12146. } else { // Remove name from ignore list (unblock)
  12147. // find entry
  12148. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12149. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12150. clif_wisexin(sd, type, 1); // fail
  12151. return;
  12152. }
  12153. // move everything one place down to overwrite removed entry
  12154. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12155. // wipe last entry
  12156. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12157. }
  12158. clif_wisexin(sd, type, 0); // success
  12159. }
  12160. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12161. /// Request to allow/deny all whispers.
  12162. /// 00d0 <type>.B
  12163. /// type:
  12164. /// 0 = (/exall) deny all speech
  12165. /// 1 = (/inall) allow all speech
  12166. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12167. {
  12168. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12169. if( type == 0 ) {// Deny all
  12170. if( sd->state.ignoreAll ) {
  12171. flag = 1; // fail
  12172. } else {
  12173. sd->state.ignoreAll = 1;
  12174. flag = 0; // success
  12175. }
  12176. } else {//Unblock everyone
  12177. if( sd->state.ignoreAll ) {
  12178. sd->state.ignoreAll = 0;
  12179. flag = 0; // success
  12180. } else {
  12181. if (sd->ignore[0].name[0] != '\0')
  12182. { //Wipe the ignore list.
  12183. memset(sd->ignore, 0, sizeof(sd->ignore));
  12184. flag = 0; // success
  12185. } else {
  12186. flag = 1; // fail
  12187. }
  12188. }
  12189. }
  12190. clif_wisall(sd, type, flag);
  12191. }
  12192. /// Whisper ignore list (ZC_WHISPER_LIST).
  12193. /// 00d4 <packet len>.W { <char name>.24B }*
  12194. void clif_PMIgnoreList(struct map_session_data* sd)
  12195. {
  12196. int i, fd = sd->fd;
  12197. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12198. WFIFOW(fd,0) = 0xd4;
  12199. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12200. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12201. }
  12202. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12203. WFIFOSET(fd,WFIFOW(fd,2));
  12204. }
  12205. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12206. /// 00d3
  12207. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12208. {
  12209. clif_PMIgnoreList(sd);
  12210. }
  12211. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12212. /// 01e7
  12213. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12214. {
  12215. if (sd->state.doridori) return;
  12216. switch (sd->class_&MAPID_UPPERMASK) {
  12217. case MAPID_SOUL_LINKER:
  12218. case MAPID_STAR_GLADIATOR:
  12219. case MAPID_TAEKWON:
  12220. if (!sd->state.rest)
  12221. break;
  12222. case MAPID_SUPER_NOVICE:
  12223. case MAPID_SUPER_BABY:
  12224. case MAPID_SUPER_NOVICE_E:
  12225. case MAPID_SUPER_BABY_E:
  12226. sd->state.doridori=1;
  12227. break;
  12228. }
  12229. }
  12230. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12231. /// 01ed
  12232. /// Note: This packet is caused by 7 lines of any text, followed by
  12233. /// the prayer and an another line of any text. The prayer is
  12234. /// defined by lines 790~793 in data\msgstringtable.txt
  12235. /// "Dear angel, can you hear my voice?"
  12236. /// "I am" (space separated player name) "Super Novice~"
  12237. /// "Help me out~ Please~ T_T"
  12238. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12239. {
  12240. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12241. unsigned int next = pc_nextbaseexp(sd);
  12242. if( next ) {
  12243. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12244. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12245. 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]
  12246. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12247. }
  12248. }
  12249. }
  12250. }
  12251. /// Friends List
  12252. ///
  12253. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12254. /// 0206 <account id>.L <char id>.L <state>.B
  12255. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12256. /// state:
  12257. /// 0 = online
  12258. /// 1 = offline
  12259. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12260. {
  12261. int i, fd = sd->fd;
  12262. //Seek friend.
  12263. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12264. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12265. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12266. return; //Not found
  12267. WFIFOHEAD(fd,packet_len(0x206));
  12268. WFIFOW(fd, 0) = 0x206;
  12269. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12270. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12271. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12272. #if PACKETVER >= 20180221
  12273. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12274. #endif
  12275. WFIFOSET(fd, packet_len(0x206));
  12276. }
  12277. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12278. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12279. {
  12280. uint32 account_id, char_id, online;
  12281. account_id = va_arg(ap, int);
  12282. char_id = va_arg(ap, int);
  12283. online = va_arg(ap, int);
  12284. clif_friendslist_toggle(sd, account_id, char_id, online);
  12285. return 0;
  12286. }
  12287. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12288. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12289. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12290. void clif_friendslist_send(struct map_session_data *sd)
  12291. {
  12292. int i = 0, n, fd = sd->fd;
  12293. #if PACKETVER >= 20180221
  12294. const int size = 8;
  12295. #else
  12296. const int size = 8 + NAME_LENGTH;
  12297. #endif
  12298. // Send friends list
  12299. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12300. WFIFOW(fd, 0) = 0x201;
  12301. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12302. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12303. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12304. #if PACKETVER < 20180221
  12305. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12306. #endif
  12307. }
  12308. if (i) {
  12309. WFIFOW(fd,2) = 4 + size * i;
  12310. WFIFOSET(fd, WFIFOW(fd,2));
  12311. }
  12312. for (n = 0; n < i; n++) { //Sending the online players
  12313. if (map_charid2sd(sd->status.friends[n].char_id))
  12314. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12315. }
  12316. }
  12317. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12318. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12319. /// result:
  12320. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12321. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12322. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12323. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12324. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12325. {
  12326. int fd;
  12327. nullpo_retv(sd);
  12328. fd = sd->fd;
  12329. WFIFOHEAD(fd,packet_len(0x209));
  12330. WFIFOW(fd,0) = 0x209;
  12331. WFIFOW(fd,2) = type;
  12332. if (f_sd) {
  12333. WFIFOL(fd,4) = f_sd->status.account_id;
  12334. WFIFOL(fd,8) = f_sd->status.char_id;
  12335. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12336. }
  12337. WFIFOSET(fd, packet_len(0x209));
  12338. }
  12339. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12340. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12341. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12342. {
  12343. int fd = sd->fd;
  12344. WFIFOHEAD(fd,packet_len(0x207));
  12345. WFIFOW(fd,0) = 0x207;
  12346. WFIFOL(fd,2) = account_id;
  12347. WFIFOL(fd,6) = char_id;
  12348. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12349. WFIFOSET(fd,packet_len(0x207));
  12350. }
  12351. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12352. /// 0202 <name>.24B
  12353. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12354. {
  12355. struct map_session_data *f_sd;
  12356. int i;
  12357. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12358. // Friend doesn't exist (no player with this name)
  12359. if (f_sd == NULL) {
  12360. clif_displaymessage(fd, msg_txt(sd,3));
  12361. return;
  12362. }
  12363. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12364. return;
  12365. }
  12366. // ensure that the request player's friend list is not full
  12367. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12368. if( i == MAX_FRIENDS ){
  12369. clif_friendslist_reqack(sd, f_sd, 2);
  12370. return;
  12371. }
  12372. // @noask [LuzZza]
  12373. if(f_sd->state.noask) {
  12374. clif_noask_sub(sd, f_sd, 5);
  12375. return;
  12376. }
  12377. // Friend already exists
  12378. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12379. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12380. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12381. return;
  12382. }
  12383. }
  12384. f_sd->friend_req = sd->status.char_id;
  12385. sd->friend_req = f_sd->status.char_id;
  12386. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12387. }
  12388. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12389. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12390. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12391. /// reply:
  12392. /// 0 = rejected
  12393. /// 1 = accepted
  12394. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12395. {
  12396. struct map_session_data *f_sd;
  12397. uint32 account_id;
  12398. char reply;
  12399. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12400. account_id = RFIFOL(fd,info->pos[0]);
  12401. //char_id = RFIFOL(fd,info->pos[1]);
  12402. #if PACKETVER < 6
  12403. reply = RFIFOB(fd,info->pos[2]);
  12404. #else
  12405. reply = RFIFOL(fd,info->pos[2]);
  12406. #endif
  12407. if( sd->bl.id == account_id ) {// adding oneself as friend
  12408. return;
  12409. }
  12410. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12411. if (f_sd == NULL)
  12412. return;
  12413. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12414. clif_friendslist_reqack(f_sd, sd, 1);
  12415. else {
  12416. int i;
  12417. // Find an empty slot
  12418. for (i = 0; i < MAX_FRIENDS; i++)
  12419. if (f_sd->status.friends[i].char_id == 0)
  12420. break;
  12421. if (i == MAX_FRIENDS) {
  12422. clif_friendslist_reqack(f_sd, sd, 2);
  12423. return;
  12424. }
  12425. f_sd->status.friends[i].account_id = sd->status.account_id;
  12426. f_sd->status.friends[i].char_id = sd->status.char_id;
  12427. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12428. clif_friendslist_reqack(f_sd, sd, 0);
  12429. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12430. if (battle_config.friend_auto_add) {
  12431. // Also add f_sd to sd's friendlist.
  12432. for (i = 0; i < MAX_FRIENDS; i++) {
  12433. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12434. return; //No need to add anything.
  12435. if (sd->status.friends[i].char_id == 0)
  12436. break;
  12437. }
  12438. if (i == MAX_FRIENDS) {
  12439. clif_friendslist_reqack(sd, f_sd, 2);
  12440. return;
  12441. }
  12442. sd->status.friends[i].account_id = f_sd->status.account_id;
  12443. sd->status.friends[i].char_id = f_sd->status.char_id;
  12444. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12445. clif_friendslist_reqack(sd, f_sd, 0);
  12446. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12447. }
  12448. }
  12449. }
  12450. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12451. /// 0203 <account id>.L <char id>.L
  12452. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12453. {
  12454. struct map_session_data *f_sd = NULL;
  12455. uint32 account_id, char_id;
  12456. int i, j;
  12457. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12458. account_id = RFIFOL(fd,info->pos[0]);
  12459. char_id = RFIFOL(fd,info->pos[1]);
  12460. // Search friend
  12461. for (i = 0; i < MAX_FRIENDS &&
  12462. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12463. if (i == MAX_FRIENDS) {
  12464. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12465. return;
  12466. }
  12467. //remove from friend's list first
  12468. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12469. for (i = 0; i < MAX_FRIENDS &&
  12470. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12471. if (i != MAX_FRIENDS) {
  12472. // move all chars up
  12473. for(j = i + 1; j < MAX_FRIENDS; j++)
  12474. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12475. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12476. //should the guy be notified of some message? we should add it here if so
  12477. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12478. WFIFOW(f_sd->fd,0) = 0x20a;
  12479. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12480. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12481. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12482. }
  12483. } else { //friend not online -- ask char server to delete from his friendlist
  12484. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12485. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12486. return;
  12487. }
  12488. }
  12489. // We can now delete from original requester
  12490. for (i = 0; i < MAX_FRIENDS &&
  12491. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12492. // move all chars up
  12493. for(j = i + 1; j < MAX_FRIENDS; j++)
  12494. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12495. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12496. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12497. WFIFOHEAD(fd,packet_len(0x20a));
  12498. WFIFOW(fd,0) = 0x20a;
  12499. WFIFOL(fd,2) = account_id;
  12500. WFIFOL(fd,6) = char_id;
  12501. WFIFOSET(fd, packet_len(0x20a));
  12502. }
  12503. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12504. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12505. void clif_PVPInfo(struct map_session_data* sd)
  12506. {
  12507. int fd = sd->fd;
  12508. WFIFOHEAD(fd,packet_len(0x210));
  12509. WFIFOW(fd,0) = 0x210;
  12510. WFIFOL(fd,2) = sd->status.char_id;
  12511. WFIFOL(fd,6) = sd->status.account_id;
  12512. WFIFOL(fd,10) = sd->pvp_won; // times won
  12513. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12514. WFIFOL(fd,18) = sd->pvp_point;
  12515. WFIFOSET(fd, packet_len(0x210));
  12516. }
  12517. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12518. /// 020f <char id>.L <account id>.L
  12519. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12520. {
  12521. // TODO: Is there a way to use this on an another player (char/acc id)?
  12522. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12523. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12524. clif_PVPInfo(sd);
  12525. }
  12526. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12527. /// 0254 <which>.B
  12528. /// which: (unused atm for security purpose)
  12529. /// 0 = sun
  12530. /// 1 = moon
  12531. /// 2 = star
  12532. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12533. {
  12534. int i;
  12535. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12536. if (sd->menuskill_id != SG_FEEL)
  12537. return;
  12538. i = sd->menuskill_val-1;
  12539. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12540. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12541. sd->feel_map[i].m = sd->bl.m;
  12542. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12543. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12544. // clif_misceffect2(&sd->bl, 0x1b0);
  12545. // clif_misceffect2(&sd->bl, 0x21f);
  12546. clif_feel_info(sd, i, 0);
  12547. clif_menuskill_clear(sd);
  12548. }
  12549. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12550. /// 0253 <which>.B
  12551. /// which:
  12552. /// 0 = sun
  12553. /// 1 = moon
  12554. /// 2 = star
  12555. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12556. {
  12557. WFIFOHEAD(fd,packet_len(0x253));
  12558. WFIFOW(fd,0)=0x253;
  12559. WFIFOB(fd,2)=TOB(skill_lv-1);
  12560. WFIFOSET(fd, packet_len(0x253));
  12561. sd->menuskill_id = SG_FEEL;
  12562. sd->menuskill_val = skill_lv;
  12563. }
  12564. /// Request to change homunculus' name (CZ_RENAME_MER).
  12565. /// 0231 <name>.24B
  12566. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12567. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12568. }
  12569. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12570. /// 0234 <id>.L
  12571. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12572. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12573. struct block_list *bl = NULL;
  12574. struct unit_data *ud = NULL;
  12575. if( sd->md && sd->md->bl.id == id )
  12576. bl = &sd->md->bl;
  12577. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12578. bl = &sd->hd->bl; // Moving Homunculus
  12579. else
  12580. return;
  12581. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12582. ud = unit_bl2ud(bl);
  12583. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12584. }
  12585. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12586. /// 0232 <id>.L <position data>.3B
  12587. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12588. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12589. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12590. struct block_list *bl = NULL;
  12591. short x, y;
  12592. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12593. if( sd->md && sd->md->bl.id == id )
  12594. bl = &sd->md->bl; // Moving Mercenary
  12595. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12596. bl = &sd->hd->bl; // Moving Homunculus
  12597. else
  12598. return;
  12599. unit_walktoxy(bl, x, y, 4);
  12600. }
  12601. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12602. /// 0233 <id>.L <target id>.L <action>.B
  12603. /// action:
  12604. /// always 0
  12605. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12606. {
  12607. struct block_list *bl = NULL;
  12608. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12609. int id = RFIFOL(fd,info->pos[0]);
  12610. int target_id = RFIFOL(fd,info->pos[1]);
  12611. int action_type = RFIFOB(fd,info->pos[2]);
  12612. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12613. bl = &sd->hd->bl;
  12614. else if( sd->md && sd->md->bl.id == id )
  12615. bl = &sd->md->bl;
  12616. else return;
  12617. unit_stop_attack(bl);
  12618. unit_attack(bl, target_id, action_type != 0);
  12619. }
  12620. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12621. /// 022d <type>.W <command>.B
  12622. /// type:
  12623. /// always 0
  12624. /// command:
  12625. /// 0 = homunculus information
  12626. /// 1 = feed
  12627. /// 2 = delete
  12628. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12629. { //[orn]
  12630. int cmd = RFIFOW(fd,0);
  12631. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12632. if(!hom_is_active(sd->hd))
  12633. return;
  12634. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12635. }
  12636. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12637. /// 0292
  12638. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12639. {
  12640. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12641. uint8 hp = 100, sp = 100;
  12642. if (item_position < 0) {
  12643. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12644. // HP restored
  12645. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12646. sp = 0;
  12647. }
  12648. else
  12649. return;
  12650. }
  12651. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12652. return;
  12653. if (!status_revive(&sd->bl, hp, sp))
  12654. return;
  12655. if (item_position < 0)
  12656. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12657. else
  12658. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12659. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12660. }
  12661. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12662. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12663. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12664. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12665. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12666. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12667. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12668. void clif_check(int fd, struct map_session_data* pl_sd)
  12669. {
  12670. WFIFOHEAD(fd,packet_len(0x214));
  12671. WFIFOW(fd, 0) = 0x214;
  12672. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12673. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12674. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12675. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12676. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12677. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12678. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12679. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12680. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12681. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12682. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12683. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12684. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12685. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12686. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12687. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12688. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12689. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12690. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12691. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12692. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12693. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12694. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12695. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12696. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12697. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12698. WFIFOSET(fd,packet_len(0x214));
  12699. }
  12700. /// /check (CZ_REQ_STATUS_GM).
  12701. /// Request character's status values.
  12702. /// 0213 <char name>.24B
  12703. void clif_parse_Check(int fd, struct map_session_data *sd)
  12704. {
  12705. char charname[NAME_LENGTH];
  12706. struct map_session_data* pl_sd;
  12707. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12708. return;
  12709. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12710. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12711. {
  12712. return;
  12713. }
  12714. clif_check(fd, pl_sd);
  12715. }
  12716. /// MAIL SYSTEM
  12717. /// By Zephyrus
  12718. ///
  12719. /// Notification about the result of adding an item to mail
  12720. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12721. /// result:
  12722. /// 0 = success
  12723. /// 1 = failure
  12724. /// 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)
  12725. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12726. /// result:
  12727. /// 0 = success
  12728. /// 1 = over weight
  12729. /// 2 = fatal error
  12730. void clif_Mail_setattachment(struct map_session_data* sd, int index, int amount, uint8 flag)
  12731. {
  12732. int fd = sd->fd;
  12733. #if PACKETVER < 20150513
  12734. WFIFOHEAD(fd,packet_len(0x255));
  12735. WFIFOW(fd,0) = 0x255;
  12736. WFIFOW(fd,2) = index;
  12737. WFIFOB(fd,4) = flag;
  12738. WFIFOSET(fd,packet_len(0x255));
  12739. #else
  12740. struct item* item = &sd->inventory.u.items_inventory[index-2];
  12741. int i, total = 0;
  12742. WFIFOHEAD(fd, 53);
  12743. WFIFOW(fd, 0) = 0xa05;
  12744. WFIFOB(fd, 2) = flag;
  12745. WFIFOW(fd, 3) = index;
  12746. WFIFOW(fd, 5) = amount;
  12747. WFIFOW(fd, 7) = item->nameid;
  12748. WFIFOB(fd, 9) = itemtype(item->nameid);
  12749. WFIFOB(fd, 10) = item->identify;
  12750. WFIFOB(fd, 11) = item->attribute;
  12751. WFIFOB(fd, 12) = item->refine;
  12752. clif_addcards(WFIFOP(fd,13), item);
  12753. clif_add_random_options(WFIFOP(fd,21), item);
  12754. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  12755. if( sd->mail.item[i].nameid == 0 ){
  12756. break;
  12757. }
  12758. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12759. }
  12760. WFIFOW(fd, 46) = total;
  12761. // 5 empty unknown bytes
  12762. memset(WFIFOP(fd, 48), 0, 5);
  12763. WFIFOSET(fd, 53);
  12764. #endif
  12765. }
  12766. /// Notification about the result of retrieving a mail attachment
  12767. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12768. /// result:
  12769. /// 0 = success
  12770. /// 1 = failure
  12771. /// 2 = too many items
  12772. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12773. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12774. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12775. int fd = sd->fd;
  12776. #if PACKETVER < 20150513
  12777. WFIFOHEAD(fd,packet_len(0x245));
  12778. WFIFOW(fd,0) = 0x245;
  12779. WFIFOB(fd,2) = result;
  12780. WFIFOSET(fd,packet_len(0x245));
  12781. #else
  12782. switch( type ){
  12783. case MAIL_ATT_ITEM:
  12784. case MAIL_ATT_ZENY:
  12785. break;
  12786. default:
  12787. return;
  12788. }
  12789. WFIFOHEAD(fd, 12);
  12790. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12791. WFIFOQ(fd, 2) = msg->id;
  12792. WFIFOB(fd, 10) = msg->type;
  12793. WFIFOB(fd, 11) = result;
  12794. WFIFOSET(fd, 12);
  12795. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12796. #endif
  12797. }
  12798. /// Notification about the result of sending a mail
  12799. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12800. /// result:
  12801. /// 0 = success
  12802. /// 1 = recipinent does not exist
  12803. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12804. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12805. int fd = sd->fd;
  12806. #if PACKETVER < 20150513
  12807. WFIFOHEAD(fd,packet_len(0x249));
  12808. WFIFOW(fd,0) = 0x249;
  12809. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12810. WFIFOSET(fd,packet_len(0x249));
  12811. #else
  12812. WFIFOHEAD(fd, 3);
  12813. WFIFOW(fd, 0) = 0x9ed;
  12814. WFIFOB(fd, 2) = result;
  12815. WFIFOSET(fd, 3);
  12816. #endif
  12817. }
  12818. /// Notification about the result of deleting a mail.
  12819. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12820. /// result:
  12821. /// 0 = success
  12822. /// 1 = failure
  12823. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12824. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12825. int fd = sd->fd;
  12826. #if PACKETVER < 20150513
  12827. WFIFOHEAD(fd, packet_len(0x257));
  12828. WFIFOW(fd,0) = 0x257;
  12829. WFIFOL(fd,2) = msg->id;
  12830. WFIFOW(fd,6) = !success;
  12831. WFIFOSET(fd, packet_len(0x257));
  12832. #else
  12833. // This is only a success notification
  12834. if( success ){
  12835. WFIFOHEAD(fd, 11);
  12836. WFIFOW(fd, 0) = 0x9f6;
  12837. WFIFOB(fd, 2) = msg->type;
  12838. WFIFOQ(fd, 3) = msg->id;
  12839. WFIFOSET(fd, 11);
  12840. }
  12841. #endif
  12842. }
  12843. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12844. /// 0274 <mail id>.L <result>.W
  12845. /// result:
  12846. /// 0 = success
  12847. /// 1 = failure
  12848. void clif_Mail_return(int fd, int mail_id, short fail)
  12849. {
  12850. WFIFOHEAD(fd,packet_len(0x274));
  12851. WFIFOW(fd,0) = 0x274;
  12852. WFIFOL(fd,2) = mail_id;
  12853. WFIFOW(fd,6) = fail;
  12854. WFIFOSET(fd,packet_len(0x274));
  12855. }
  12856. /// Notification about new mail.
  12857. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12858. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12859. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12860. int fd = sd->fd;
  12861. #if PACKETVER < 20150513
  12862. WFIFOHEAD(fd,packet_len(0x24a));
  12863. WFIFOW(fd,0) = 0x24a;
  12864. WFIFOL(fd,2) = mail_id;
  12865. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12866. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12867. WFIFOSET(fd,packet_len(0x24a));
  12868. #else
  12869. WFIFOHEAD(fd,3);
  12870. WFIFOW(fd,0) = 0x9e7;
  12871. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12872. WFIFOSET(fd,3);
  12873. #endif
  12874. }
  12875. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12876. /// 0260 <type>.L
  12877. /// type:
  12878. /// 0 = open
  12879. /// 1 = close
  12880. void clif_Mail_window(int fd, int flag)
  12881. {
  12882. WFIFOHEAD(fd,packet_len(0x260));
  12883. WFIFOW(fd,0) = 0x260;
  12884. WFIFOL(fd,2) = flag;
  12885. WFIFOSET(fd,packet_len(0x260));
  12886. }
  12887. /// Lists mails stored in inbox.
  12888. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12889. /// read:
  12890. /// 0 = unread
  12891. /// 1 = read
  12892. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12893. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12894. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12895. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12896. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12897. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12898. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12899. #if PACKETVER < 20150513
  12900. int fd = sd->fd;
  12901. struct mail_data *md = &sd->mail.inbox;
  12902. struct mail_message *msg;
  12903. int len, i, j;
  12904. len = 8 + (73 * md->amount);
  12905. WFIFOHEAD(fd,len);
  12906. WFIFOW(fd,0) = 0x240;
  12907. WFIFOW(fd,2) = len;
  12908. WFIFOL(fd,4) = md->amount;
  12909. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12910. {
  12911. msg = &md->msg[i];
  12912. if (msg->id < 1)
  12913. continue;
  12914. WFIFOL(fd,8+73*j) = msg->id;
  12915. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12916. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12917. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12918. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12919. j++;
  12920. }
  12921. WFIFOSET(fd,len);
  12922. if( md->full ) {// TODO: is this official?
  12923. char output[100];
  12924. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12925. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  12926. }
  12927. #else
  12928. int fd = sd->fd;
  12929. struct mail_data *md = &sd->mail.inbox;
  12930. struct mail_message *msg;
  12931. int i, j, k, offset, titleLength;
  12932. uint8 mailType, amount, remaining;
  12933. uint32 now = (uint32)time(NULL);
  12934. #if PACKETVER >= 20170419
  12935. int cmd = 0xac2;
  12936. #elif PACKETVER >= 20160601
  12937. int cmd = 0xa7d;
  12938. #else
  12939. int cmd = 0x9f0;
  12940. #endif
  12941. if( battle_config.mail_daily_count ){
  12942. mail_refresh_remaining_amount(sd);
  12943. }
  12944. #if PACKETVER >= 20170419
  12945. // Always send all
  12946. i = md->amount;
  12947. #else
  12948. // If a starting mail id was sent
  12949. if( mailID != 0 ){
  12950. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  12951. // Unknown mail
  12952. if( i == md->amount ){
  12953. // Ignore the request for now
  12954. return; // TODO: Should we just show the first page instead?
  12955. }
  12956. // It was actually the oldest/first mail, there is no further page
  12957. if( i == 0 ){
  12958. return;
  12959. }
  12960. // We actually want the next/older mail
  12961. i -= 1;
  12962. }else{
  12963. i = md->amount;
  12964. }
  12965. #endif
  12966. // Count the remaining mails from the starting mail or the beginning
  12967. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  12968. for( j = i, remaining = 0; j >= 0; j-- ){
  12969. msg = &md->msg[j];
  12970. if (msg->id < 1)
  12971. continue;
  12972. #if PACKETVER < 20170419
  12973. if (msg->type != type)
  12974. continue;
  12975. #endif
  12976. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12977. continue;
  12978. remaining++;
  12979. }
  12980. #if PACKETVER >= 20170419
  12981. // Always send all
  12982. amount = remaining;
  12983. #else
  12984. if( remaining > MAIL_PAGE_SIZE ){
  12985. amount = MAIL_PAGE_SIZE;
  12986. }else{
  12987. amount = remaining;
  12988. }
  12989. #endif
  12990. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  12991. WFIFOW(fd, 0) = cmd;
  12992. #if PACKETVER >= 20170419
  12993. WFIFOB(fd, 4) = 1; // Unknown
  12994. offset = 5;
  12995. #else
  12996. WFIFOB(fd, 4) = type;
  12997. WFIFOB(fd, 5) = amount;
  12998. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  12999. offset = 7;
  13000. #endif
  13001. for( amount = 0; i >= 0; i-- ){
  13002. msg = &md->msg[i];
  13003. if (msg->id < 1)
  13004. continue;
  13005. #if PACKETVER < 20170419
  13006. if (msg->type != type)
  13007. continue;
  13008. #endif
  13009. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13010. continue;
  13011. #if PACKETVER >= 20170419
  13012. WFIFOB(fd, offset) = msg->type;
  13013. offset += 1;
  13014. #endif
  13015. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13016. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13017. mailType = MAIL_TYPE_TEXT; // Normal letter
  13018. if( msg->zeny > 0 ){
  13019. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13020. }
  13021. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13022. if( msg->item[k].nameid > 0 ){
  13023. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13024. break;
  13025. }
  13026. }
  13027. #if PACKETVER >= 20170419
  13028. // If it came from an npc?
  13029. if( !msg->send_id ){
  13030. mailType |= MAIL_TYPE_NPC;
  13031. }
  13032. #endif
  13033. WFIFOB(fd, offset + 9) = mailType;
  13034. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13035. #if PACKETVER < 20170419
  13036. // How much time has passed since you received the mail
  13037. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13038. offset += 4;
  13039. #endif
  13040. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13041. if( msg->scheduled_deletion > 0 ){
  13042. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13043. }else{
  13044. // Fake the scheduled deletion to one year in the future
  13045. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13046. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13047. }
  13048. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13049. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13050. offset += 40 + titleLength;
  13051. }
  13052. WFIFOW(fd, 2) = (int16)offset;
  13053. WFIFOSET(fd, offset);
  13054. #endif
  13055. }
  13056. /// Mail inbox list request.
  13057. /// 023f (CZ_MAIL_GET_LIST)
  13058. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13059. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13060. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13061. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13062. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13063. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13064. #if PACKETVER < 20150513
  13065. struct mail_data* md = &sd->mail.inbox;
  13066. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13067. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13068. else
  13069. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13070. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13071. mail_removezeny(sd, false);
  13072. #else
  13073. int cmd = RFIFOW(fd, 0);
  13074. #if PACKETVER < 20170419
  13075. uint8 openType = RFIFOB(fd, 2);
  13076. uint64 mailId = RFIFOQ(fd, 3);
  13077. #else
  13078. uint8 openType;
  13079. uint64 mailId = RFIFOQ(fd, 2);
  13080. int i;
  13081. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13082. if( i == MAIL_MAX_INBOX ){
  13083. openType = MAIL_INBOX_NORMAL;
  13084. mailId = 0;
  13085. }else{
  13086. openType = sd->mail.inbox.msg[i].type;
  13087. mailId = 0;
  13088. }
  13089. #endif
  13090. switch( openType ){
  13091. case MAIL_INBOX_NORMAL:
  13092. case MAIL_INBOX_ACCOUNT:
  13093. case MAIL_INBOX_RETURNED:
  13094. break;
  13095. default:
  13096. // Unknown type: ignore request
  13097. return;
  13098. }
  13099. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13100. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13101. return;
  13102. }
  13103. // If it is not a next page request
  13104. if( cmd != 0x9ee ){
  13105. mailId = 0;
  13106. }
  13107. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13108. #endif
  13109. }
  13110. /// Opens a mail
  13111. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13112. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13113. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13114. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13115. /// { }*n
  13116. // TODO: Packet description => for repeated block
  13117. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  13118. {
  13119. int i, fd = sd->fd;
  13120. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13121. if( i == MAIL_MAX_INBOX ) {
  13122. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13123. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13124. return;
  13125. } else {
  13126. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13127. struct item *item;
  13128. struct item_data *data;
  13129. int msg_len = strlen(msg->body), len;
  13130. #if PACKETVER >= 20150513
  13131. int offset, j, itemsize, count = 0;
  13132. #endif
  13133. if( msg_len == 0 ) {
  13134. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13135. msg_len = strlen(msg->body);
  13136. }
  13137. #if PACKETVER < 20150513
  13138. item = &msg->item[0];
  13139. len = 101 + msg_len;
  13140. WFIFOHEAD(fd,len);
  13141. WFIFOW(fd,0) = 0x242;
  13142. WFIFOW(fd,2) = len;
  13143. WFIFOL(fd,4) = msg->id;
  13144. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13145. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13146. WFIFOL(fd,72) = 0;
  13147. WFIFOL(fd,76) = msg->zeny;
  13148. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13149. WFIFOL(fd,80) = item->amount;
  13150. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  13151. WFIFOW(fd,86) = data->type;
  13152. WFIFOB(fd,88) = item->identify;
  13153. WFIFOB(fd,89) = item->attribute;
  13154. WFIFOB(fd,90) = item->refine;
  13155. WFIFOW(fd,91) = item->card[0];
  13156. WFIFOW(fd,93) = item->card[1];
  13157. WFIFOW(fd,95) = item->card[2];
  13158. WFIFOW(fd,97) = item->card[3];
  13159. } else // no item, set all to zero
  13160. memset(WFIFOP(fd,80), 0x00, 19);
  13161. WFIFOB(fd,99) = (unsigned char)msg_len;
  13162. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13163. WFIFOSET(fd,len);
  13164. #else
  13165. // Count the attached items
  13166. ARR_FIND( 0, MAIL_MAX_ITEM, count, msg->item[count].nameid == 0 );
  13167. msg_len += 1; // Zero Termination
  13168. itemsize = 24 + 5 * 5;
  13169. len = 24 + msg_len+1 + itemsize * count;
  13170. WFIFOHEAD(fd, len);
  13171. WFIFOW(fd, 0) = 0x9eb;
  13172. WFIFOW(fd, 2) = len;
  13173. WFIFOB(fd, 4) = msg->type;
  13174. WFIFOQ(fd, 5) = msg->id;
  13175. WFIFOW(fd, 13) = msg_len;
  13176. WFIFOQ(fd, 15) = msg->zeny;
  13177. WFIFOB(fd, 23) = (uint8)count; // item count
  13178. safestrncpy(WFIFOCP(fd, 24), msg->body, msg_len);
  13179. offset = 24 + msg_len;
  13180. for (j = 0; j < MAIL_MAX_ITEM; j++) {
  13181. item = &msg->item[j];
  13182. if (item->nameid > 0 && item->amount > 0 && (data = itemdb_exists(item->nameid)) != NULL) {
  13183. WFIFOW(fd, offset) = item->amount;
  13184. WFIFOW(fd, offset + 2) = (data->view_id) ? data->view_id : item->nameid;
  13185. WFIFOB(fd, offset + 4) = item->identify;
  13186. WFIFOB(fd, offset + 5) = item->attribute;
  13187. WFIFOB(fd, offset + 6) = item->refine;
  13188. clif_addcards(WFIFOP(fd, offset + 7), item);
  13189. // 4B unsigned long location
  13190. WFIFOB(fd, offset + 15 + 4) = data->type;
  13191. // 2B unsigned short wItemSpriteNumber
  13192. //WFIFOW(fd, offset + 15 + 5) = data->view_id;
  13193. // 2B unsigned short bindOnEquipType
  13194. clif_add_random_options(WFIFOP(fd, offset + 15 + 9 ), item);
  13195. offset += itemsize;
  13196. }
  13197. }
  13198. WFIFOSET(fd, len);
  13199. #endif
  13200. if (msg->status == MAIL_UNREAD) {
  13201. msg->status = MAIL_READ;
  13202. intif_Mail_read(mail_id);
  13203. clif_parse_Mail_refreshinbox(fd, sd);
  13204. sd->mail.inbox.unread--;
  13205. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13206. }
  13207. }
  13208. }
  13209. /// Request to open a mail.
  13210. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13211. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13212. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13213. #if PACKETVER < 20150513
  13214. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13215. #else
  13216. //uint8 openType = RFIFOB(fd, 2);
  13217. int mail_id = (int)RFIFOQ(fd, 3);
  13218. #endif
  13219. if( mail_id <= 0 )
  13220. return;
  13221. if( mail_invalid_operation(sd) )
  13222. return;
  13223. clif_Mail_read(sd, mail_id);
  13224. }
  13225. /// Allow a player to begin writing a mail
  13226. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13227. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13228. int fd = sd->fd;
  13229. WFIFOHEAD(fd, 27);
  13230. WFIFOW(fd, 0) = 0xa12;
  13231. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13232. WFIFOB(fd, 26) = success;
  13233. WFIFOSET(fd, 27);
  13234. }
  13235. /// Request to start writing a mail
  13236. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13237. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13238. char name[NAME_LENGTH];
  13239. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13240. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13241. clif_send_Mail_beginwrite_ack(sd, name, false);
  13242. return;
  13243. }
  13244. mail_clear(sd);
  13245. sd->state.mail_writing = true;
  13246. clif_send_Mail_beginwrite_ack(sd, name,true);
  13247. }
  13248. /// Notification that the client cancelled writing a mail
  13249. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13250. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13251. sd->state.mail_writing = false;
  13252. }
  13253. /// Give the client information about the recipient, if available
  13254. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13255. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13256. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13257. int fd = sd->fd;
  13258. #if PACKETVER <= 20160302
  13259. int cmd = 0xa14;
  13260. #else
  13261. int cmd = 0xa51;
  13262. #endif
  13263. WFIFOHEAD(fd, packet_len(cmd));
  13264. WFIFOW(fd, 0) = cmd;
  13265. WFIFOL(fd, 2) = char_id;
  13266. WFIFOW(fd, 6) = class_;
  13267. WFIFOW(fd, 8) = level;
  13268. #if PACKETVER >= 20160302
  13269. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13270. #endif
  13271. WFIFOSET(fd, packet_len(cmd));
  13272. }
  13273. /// Request information about the recipient
  13274. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13275. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13276. static char name[NAME_LENGTH];
  13277. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13278. intif_mail_checkreceiver(sd, name);
  13279. }
  13280. /// Request to receive mail's attachment.
  13281. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13282. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13283. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13284. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13285. int i;
  13286. struct mail_message* msg;
  13287. #if PACKETVER < 20150513
  13288. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13289. int attachment = MAIL_ATT_ALL;
  13290. #else
  13291. uint16 packet_id = RFIFOW(fd, 0);
  13292. int mail_id = (int)RFIFOQ(fd, 2);
  13293. //int openType = RFIFOB(fd, 10);
  13294. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13295. #endif
  13296. if( !chrif_isconnected() )
  13297. return;
  13298. if( mail_id <= 0 )
  13299. return;
  13300. if( mail_invalid_operation(sd) )
  13301. return;
  13302. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13303. if( i == MAIL_MAX_INBOX )
  13304. return;
  13305. msg = &sd->mail.inbox.msg[i];
  13306. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13307. attachment &= ~MAIL_ATT_ZENY;
  13308. }
  13309. if( attachment&MAIL_ATT_ITEM ){
  13310. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13311. // No items were found
  13312. if( i == MAIL_MAX_ITEM ){
  13313. attachment &= ~MAIL_ATT_ITEM;
  13314. }
  13315. }
  13316. // Either no attachment requested at all or there are no zeny or items in the mail
  13317. if( attachment == MAIL_ATT_NONE ){
  13318. return;
  13319. }
  13320. if( attachment&MAIL_ATT_ZENY ){
  13321. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13322. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13323. return;
  13324. }else{
  13325. // To make sure another request fails
  13326. msg->zeny = 0;
  13327. }
  13328. }
  13329. if( attachment&MAIL_ATT_ITEM ){
  13330. int new_ = 0, totalweight = 0;
  13331. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13332. struct item* item = &msg->item[i];
  13333. if( item->nameid > 0 && item->amount > 0 ){
  13334. struct item_data *data;
  13335. if((data = itemdb_exists(item->nameid)) == NULL)
  13336. continue;
  13337. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13338. case CHKADDITEM_NEW:
  13339. new_++;
  13340. break;
  13341. case CHKADDITEM_OVERAMOUNT:
  13342. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13343. return;
  13344. }
  13345. totalweight += data->weight * item->amount;
  13346. }
  13347. }
  13348. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13349. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13350. return;
  13351. }else if( pc_inventoryblank(sd) < new_ ){
  13352. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13353. return;
  13354. }
  13355. // To make sure another request fails
  13356. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13357. }
  13358. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13359. clif_Mail_read(sd, mail_id);
  13360. }
  13361. /// Request to delete a mail.
  13362. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13363. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13364. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13365. #if PACKETVER < 20150513
  13366. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13367. #else
  13368. //int openType = RFIFOB(fd, 2);
  13369. int mail_id = (int)RFIFOQ(fd, 3);
  13370. #endif
  13371. int i, j;
  13372. if( !chrif_isconnected() )
  13373. return;
  13374. if( mail_id <= 0 )
  13375. return;
  13376. if( mail_invalid_operation(sd) )
  13377. return;
  13378. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13379. if (i < MAIL_MAX_INBOX) {
  13380. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13381. // can't delete mail without removing zeny first
  13382. if( msg->zeny > 0 ){
  13383. clif_mail_delete(sd, msg, false);
  13384. return;
  13385. }
  13386. // can't delete mail without removing attachment(s) first
  13387. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13388. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13389. clif_mail_delete(sd, msg, false);
  13390. return;
  13391. }
  13392. }
  13393. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13394. sd->mail.inbox.unread--;
  13395. clif_Mail_new(sd,0,NULL,NULL);
  13396. }
  13397. }
  13398. }
  13399. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13400. /// 0273 <mail id>.L <receive name>.24B
  13401. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13402. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13403. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13404. int i;
  13405. if( mail_id <= 0 )
  13406. return;
  13407. if( mail_invalid_operation(sd) )
  13408. return;
  13409. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13410. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13411. intif_Mail_return(sd->status.char_id, mail_id);
  13412. else
  13413. clif_Mail_return(sd->fd, mail_id, 1);
  13414. }
  13415. /// Request to add an item or Zeny to mail.
  13416. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13417. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13418. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13419. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13420. int idx = RFIFOW(fd,info->pos[0]);
  13421. #if PACKETVER < 20150513
  13422. int amount = RFIFOL(fd,info->pos[1]);
  13423. #else
  13424. int amount = RFIFOW(fd,info->pos[1]);
  13425. #endif
  13426. unsigned char flag;
  13427. if( !chrif_isconnected() )
  13428. return;
  13429. if (idx < 0 || amount < 0 || idx >= MAX_INVENTORY)
  13430. return;
  13431. flag = mail_setitem(sd, idx, amount);
  13432. clif_Mail_setattachment(sd,idx,amount,flag);
  13433. }
  13434. /// Remove an item from a mail
  13435. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13436. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13437. int fd = sd->fd;
  13438. WFIFOHEAD(fd, 9);
  13439. WFIFOW(fd, 0) = 0xa07;
  13440. WFIFOB(fd, 2) = success;
  13441. WFIFOW(fd, 3) = index;
  13442. WFIFOW(fd, 5) = amount;
  13443. WFIFOW(fd, 7) = 0; // TODO: which weight? item weight? removed weight? remaining weight?
  13444. WFIFOSET(fd, 9);
  13445. }
  13446. /// Request to reset mail item and/or Zeny
  13447. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13448. /// type:
  13449. /// 0 = reset all
  13450. /// 1 = remove item
  13451. /// 2 = remove zeny
  13452. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13453. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13454. {
  13455. #if PACKETVER < 20150513
  13456. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13457. if (type == 0 || type == 1)
  13458. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13459. if (type == 0 || type == 2)
  13460. mail_removezeny(sd, false);
  13461. #else
  13462. uint16 index = RFIFOW(fd, 2);
  13463. uint16 count = RFIFOW(fd, 4);
  13464. mail_removeitem(sd,0,index,count);
  13465. #endif
  13466. }
  13467. /// Request to send mail
  13468. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13469. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13470. /// 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)
  13471. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13472. #if PACKETVER < 20150513
  13473. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13474. if( !chrif_isconnected() )
  13475. return;
  13476. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13477. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13478. return;
  13479. }
  13480. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13481. #else
  13482. unsigned short length;
  13483. static char receiver[NAME_LENGTH];
  13484. static char sender[NAME_LENGTH];
  13485. char *title;
  13486. char *text;
  13487. uint64 zeny;
  13488. uint16 titleLength;
  13489. uint16 textLength;
  13490. length = RFIFOW(fd, 2);
  13491. if( length < 0x3e ){
  13492. ShowWarning("Too short...\n");
  13493. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13494. return;
  13495. }
  13496. // Forged request without a begin writing packet?
  13497. if( !sd->state.mail_writing ){
  13498. return; // Ignore it
  13499. }
  13500. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13501. safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13502. zeny = RFIFOQ(fd, 52);
  13503. titleLength = RFIFOW(fd, 60);
  13504. textLength = RFIFOW(fd, 62);
  13505. title = (char*)aMalloc(titleLength);
  13506. text = (char*)aMalloc(textLength);
  13507. #if PACKETVER <= 20160330
  13508. safestrncpy(title, RFIFOCP(fd, 64), titleLength);
  13509. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), textLength);
  13510. #else
  13511. // 64 = <char id>.L
  13512. safestrncpy(title, RFIFOCP(fd, 68), titleLength);
  13513. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), textLength);
  13514. #endif
  13515. if( zeny > 0 ){
  13516. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13517. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13518. return;
  13519. }
  13520. }
  13521. mail_send(sd, receiver, title, text, textLength);
  13522. aFree(title);
  13523. aFree(text);
  13524. #endif
  13525. }
  13526. /// AUCTION SYSTEM
  13527. /// By Zephyrus
  13528. ///
  13529. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13530. /// 025f <type>.L
  13531. /// type:
  13532. /// 0 = open
  13533. /// 1 = close
  13534. void clif_Auction_openwindow(struct map_session_data *sd)
  13535. {
  13536. int fd = sd->fd;
  13537. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13538. return;
  13539. if( !battle_config.feature_auction )
  13540. return;
  13541. WFIFOHEAD(fd,packet_len(0x25f));
  13542. WFIFOW(fd,0) = 0x25f;
  13543. WFIFOL(fd,2) = 0;
  13544. WFIFOSET(fd,packet_len(0x25f));
  13545. }
  13546. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13547. /// 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 }*
  13548. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13549. {
  13550. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13551. struct auction_data auction;
  13552. struct item_data *item;
  13553. WFIFOHEAD(fd,12 + (count * 83));
  13554. WFIFOW(fd,0) = 0x252;
  13555. WFIFOW(fd,2) = 12 + (count * 83);
  13556. WFIFOL(fd,4) = pages;
  13557. WFIFOL(fd,8) = count;
  13558. for( i = 0; i < count; i++ ) {
  13559. int k = 12 + (i * 83);
  13560. memcpy(&auction, RBUFP(buf,i * len), len);
  13561. WFIFOL(fd,k) = auction.auction_id;
  13562. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13563. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  13564. WFIFOW(fd,28+k) = item->view_id;
  13565. else
  13566. WFIFOW(fd,28+k) = auction.item.nameid;
  13567. WFIFOL(fd,30+k) = auction.type;
  13568. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13569. WFIFOB(fd,36+k) = auction.item.identify;
  13570. WFIFOB(fd,37+k) = auction.item.attribute;
  13571. WFIFOB(fd,38+k) = auction.item.refine;
  13572. WFIFOW(fd,39+k) = auction.item.card[0];
  13573. WFIFOW(fd,41+k) = auction.item.card[1];
  13574. WFIFOW(fd,43+k) = auction.item.card[2];
  13575. WFIFOW(fd,45+k) = auction.item.card[3];
  13576. WFIFOL(fd,47+k) = auction.price;
  13577. WFIFOL(fd,51+k) = auction.buynow;
  13578. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13579. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13580. }
  13581. WFIFOSET(fd,WFIFOW(fd,2));
  13582. }
  13583. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13584. /// 0256 <index>.W <result>.B
  13585. /// result:
  13586. /// 0 = success
  13587. /// 1 = failure
  13588. static void clif_Auction_setitem(int fd, int index, bool fail)
  13589. {
  13590. WFIFOHEAD(fd,packet_len(0x256));
  13591. WFIFOW(fd,0) = 0x256;
  13592. WFIFOW(fd,2) = index;
  13593. WFIFOB(fd,4) = fail;
  13594. WFIFOSET(fd,packet_len(0x256));
  13595. }
  13596. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13597. /// 024b <type>.W
  13598. /// type:
  13599. /// 0 = create (any other action in auction window)
  13600. /// 1 = cancel (cancel pressed on register tab)
  13601. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13602. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13603. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13604. if( sd->auction.amount > 0 )
  13605. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13606. sd->auction.amount = 0;
  13607. }
  13608. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13609. /// 024c <index>.W <count>.L
  13610. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13611. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13612. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13613. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13614. struct item_data *item;
  13615. if( !battle_config.feature_auction )
  13616. return;
  13617. if( sd->auction.amount > 0 )
  13618. sd->auction.amount = 0;
  13619. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13620. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13621. return;
  13622. }
  13623. 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.
  13624. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13625. return;
  13626. }
  13627. 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) )
  13628. { // Consumable or pets are not allowed
  13629. clif_Auction_setitem(sd->fd, idx, true);
  13630. return;
  13631. }
  13632. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13633. !sd->inventory.u.items_inventory[idx].identify ||
  13634. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13635. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13636. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13637. clif_Auction_setitem(sd->fd, idx, true);
  13638. return;
  13639. }
  13640. sd->auction.index = idx;
  13641. sd->auction.amount = amount;
  13642. clif_Auction_setitem(fd, idx + 2, false);
  13643. }
  13644. /// Result from an auction action (ZC_AUCTION_RESULT).
  13645. /// 0250 <result>.B
  13646. /// result:
  13647. /// 0 = You have failed to bid into the auction
  13648. /// 1 = You have successfully bid in the auction
  13649. /// 2 = The auction has been canceled
  13650. /// 3 = An auction with at least one bidder cannot be canceled
  13651. /// 4 = You cannot register more than 5 items in an auction at a time
  13652. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13653. /// 6 = You have won the auction
  13654. /// 7 = You have failed to win the auction
  13655. /// 8 = You do not have enough Zeny
  13656. /// 9 = You cannot place more than 5 bids at a time
  13657. void clif_Auction_message(int fd, unsigned char flag)
  13658. {
  13659. WFIFOHEAD(fd,packet_len(0x250));
  13660. WFIFOW(fd,0) = 0x250;
  13661. WFIFOB(fd,2) = flag;
  13662. WFIFOSET(fd,packet_len(0x250));
  13663. }
  13664. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13665. /// 025e <result>.W
  13666. /// result:
  13667. /// 0 = You have ended the auction
  13668. /// 1 = You cannot end the auction
  13669. /// 2 = Auction ID is incorrect
  13670. void clif_Auction_close(int fd, unsigned char flag)
  13671. {
  13672. WFIFOHEAD(fd,packet_len(0x25e));
  13673. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13674. WFIFOW(fd,2) = flag;
  13675. WFIFOSET(fd,packet_len(0x25e));
  13676. }
  13677. /// Request to add an auction (CZ_AUCTION_ADD).
  13678. /// 024d <now money>.L <max money>.L <delete hour>.W
  13679. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13680. {
  13681. struct auction_data auction;
  13682. struct item_data *item;
  13683. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13684. if( !battle_config.feature_auction )
  13685. return;
  13686. auction.price = RFIFOL(fd,info->pos[0]);
  13687. auction.buynow = RFIFOL(fd,info->pos[1]);
  13688. auction.hours = RFIFOW(fd,info->pos[2]);
  13689. // Invalid Situations...
  13690. if( sd->auction.amount < 1 ) {
  13691. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13692. return;
  13693. }
  13694. if( auction.price >= auction.buynow ) {
  13695. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13696. return;
  13697. }
  13698. if( auction.hours < 1 || auction.hours > 48 ) {
  13699. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13700. return;
  13701. }
  13702. // Auction checks...
  13703. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13704. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13705. clif_Auction_message(fd, 2); // The auction has been canceled
  13706. return;
  13707. }
  13708. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13709. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13710. return;
  13711. }
  13712. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13713. auction.buynow = battle_config.auction_maximumprice;
  13714. if( auction.price >= auction.buynow )
  13715. auction.price = auction.buynow - 1;
  13716. }
  13717. auction.auction_id = 0;
  13718. auction.seller_id = sd->status.char_id;
  13719. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13720. auction.buyer_id = 0;
  13721. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13722. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13723. {
  13724. clif_Auction_message(fd, 2); // The auction has been canceled
  13725. return;
  13726. }
  13727. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13728. { // Just in case
  13729. clif_Auction_message(fd, 2); // The auction has been canceled
  13730. return;
  13731. }
  13732. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13733. auction.type = item->type;
  13734. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13735. auction.item.amount = 1;
  13736. auction.timestamp = 0;
  13737. if( !intif_Auction_register(&auction) )
  13738. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13739. else
  13740. {
  13741. int zeny = auction.hours*battle_config.auction_feeperhour;
  13742. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13743. sd->auction.amount = 0;
  13744. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13745. }
  13746. }
  13747. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13748. /// 024e <auction id>.L
  13749. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13750. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13751. intif_Auction_cancel(sd->status.char_id, auction_id);
  13752. }
  13753. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13754. /// 025d <auction id>.L
  13755. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13756. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13757. intif_Auction_close(sd->status.char_id, auction_id);
  13758. }
  13759. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13760. /// 024f <auction id>.L <money>.L
  13761. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13762. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13763. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13764. int bid = RFIFOL(fd,info->pos[1]);
  13765. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13766. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13767. return;
  13768. }
  13769. if( bid <= 0 )
  13770. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13771. else if( bid > sd->status.zeny )
  13772. clif_Auction_message(fd, 8); // You do not have enough zeny
  13773. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13774. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13775. else {
  13776. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13777. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13778. }
  13779. }
  13780. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13781. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13782. /// search type:
  13783. /// 0 = armor
  13784. /// 1 = weapon
  13785. /// 2 = card
  13786. /// 3 = misc
  13787. /// 4 = name search
  13788. /// 5 = auction id search
  13789. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13790. char search_text[NAME_LENGTH];
  13791. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13792. short type = RFIFOW(fd,info->pos[0]);
  13793. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13794. int page = RFIFOW(fd,info->pos[3]);
  13795. if( !battle_config.feature_auction )
  13796. return;
  13797. clif_parse_Auction_cancelreg(fd, sd);
  13798. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13799. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13800. }
  13801. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13802. /// 025c <type>.W
  13803. /// type:
  13804. /// 0 = sell (own auctions)
  13805. /// 1 = buy (own bids)
  13806. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13807. {
  13808. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13809. if( !battle_config.feature_auction )
  13810. return;
  13811. clif_parse_Auction_cancelreg(fd, sd);
  13812. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13813. }
  13814. /// CASH/POINT SHOP
  13815. ///
  13816. void clif_cashshop_open( struct map_session_data* sd ){
  13817. WFIFOHEAD( sd->fd, 10 );
  13818. WFIFOW( sd->fd, 0 ) = 0x845;
  13819. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13820. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13821. WFIFOSET( sd->fd, 10 );
  13822. }
  13823. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13824. sd->state.cashshop_open = true;
  13825. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13826. clif_cashshop_open( sd );
  13827. }
  13828. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13829. sd->state.cashshop_open = false;
  13830. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13831. // No need to do anything here
  13832. }
  13833. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13834. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13835. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13836. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13837. int j;
  13838. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13839. return;
  13840. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13841. WFIFOW(fd, 0) = 0x8c0;
  13842. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13843. WFIFOL(fd, 4) = tab;
  13844. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13845. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13846. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13847. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13848. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13849. }
  13850. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13851. }
  13852. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13853. void clif_cashshop_list( int fd ){
  13854. int tab;
  13855. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13856. int length = 8 + cash_shop_items[tab].count * 6;
  13857. int i, offset;
  13858. WFIFOHEAD( fd, length );
  13859. WFIFOW( fd, 0 ) = 0x8ca;
  13860. WFIFOW( fd, 2 ) = length;
  13861. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13862. WFIFOW( fd, 6 ) = tab;
  13863. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13864. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13865. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13866. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13867. }
  13868. WFIFOSET( fd, length );
  13869. }
  13870. }
  13871. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13872. if( !sd->status.cashshop_sent ) {
  13873. clif_cashshop_list( fd );
  13874. #if PACKETVER_SUPPORTS_SALES
  13875. sale_notify_login(sd);
  13876. #endif
  13877. sd->status.cashshop_sent = true;
  13878. }
  13879. }
  13880. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13881. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13882. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13883. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13884. {
  13885. int fd, i, cost[2] = { 0, 0 };
  13886. #if PACKETVER < 20070711
  13887. const int offset = 8;
  13888. #else
  13889. const int offset = 12;
  13890. #endif
  13891. nullpo_retv(sd);
  13892. nullpo_retv(nd);
  13893. fd = sd->fd;
  13894. sd->npc_shopid = nd->bl.id;
  13895. npc_shop_currency_type(sd, nd, cost, true);
  13896. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13897. WFIFOW(fd,0) = 0x287;
  13898. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13899. WFIFOL(fd,4) = cost[0];
  13900. #if PACKETVER >= 20070711
  13901. WFIFOL(fd,8) = cost[1];
  13902. #endif
  13903. for( i = 0; i < nd->u.shop.count; i++ ) {
  13904. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13905. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13906. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13907. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13908. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13909. }
  13910. WFIFOSET(fd,WFIFOW(fd,2));
  13911. }
  13912. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13913. /// 0289 <cash point>.L <error>.W
  13914. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13915. /// error:
  13916. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13917. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13918. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13919. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13920. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13921. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13922. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13923. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13924. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13925. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13926. {
  13927. int fd, cost[2] = { 0, 0 };
  13928. struct npc_data *nd;
  13929. nullpo_retv(sd);
  13930. fd = sd->fd;
  13931. nd = map_id2nd(sd->npc_shopid);
  13932. npc_shop_currency_type(sd, nd, cost, false);
  13933. WFIFOHEAD(fd, packet_len(0x289));
  13934. WFIFOW(fd,0) = 0x289;
  13935. WFIFOL(fd,2) = cost[0];
  13936. #if PACKETVER < 20070711
  13937. WFIFOW(fd,6) = TOW(error);
  13938. #else
  13939. WFIFOL(fd,6) = cost[1];
  13940. WFIFOW(fd,10) = TOW(error);
  13941. #endif
  13942. WFIFOSET(fd, packet_len(0x289));
  13943. }
  13944. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13945. WFIFOHEAD( sd->fd, 16 );
  13946. WFIFOW( sd->fd, 0 ) = 0x849;
  13947. WFIFOL( sd->fd, 2 ) = item_id;
  13948. WFIFOW( sd->fd, 6 ) = result;
  13949. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13950. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13951. WFIFOSET( sd->fd, 16 );
  13952. }
  13953. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13954. /// 0288 <name id>.W <amount>.W
  13955. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13956. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13957. /// 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)
  13958. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  13959. struct s_packet_db* info;
  13960. int cmd = RFIFOW(fd,0);
  13961. nullpo_retv(sd);
  13962. info = &packet_db[cmd];
  13963. if( sd->state.trading || !sd->npc_shopid ) {
  13964. clif_cashshop_ack(sd,1);
  13965. return;
  13966. }
  13967. else {
  13968. #if PACKETVER < 20101116
  13969. short nameid = RFIFOW(fd,info->pos[0]);
  13970. short amount = RFIFOW(fd,info->pos[1]);
  13971. int points = RFIFOL(fd,info->pos[2]);
  13972. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13973. #else
  13974. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13975. int len = RFIFOW(fd,info->pos[0]);
  13976. int points = RFIFOL(fd,info->pos[1]);
  13977. int count = RFIFOW(fd,info->pos[2]);
  13978. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13979. if( len < 10 || len != 10 + count * s_itl){
  13980. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13981. return;
  13982. }
  13983. if(cmd==0x848){
  13984. if (cashshop_buylist( sd, points, count, item_list))
  13985. clif_cashshop_ack(sd,0);
  13986. return;
  13987. } else {
  13988. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13989. return;
  13990. }
  13991. #endif
  13992. }
  13993. }
  13994. /// Adoption System
  13995. ///
  13996. /// Adoption message (ZC_BABYMSG).
  13997. /// 0216 <msg>.L
  13998. /// msg:
  13999. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14000. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14001. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14002. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14003. {
  14004. int fd = sd->fd;
  14005. WFIFOHEAD(fd,6);
  14006. WFIFOW(fd,0) = 0x216;
  14007. WFIFOL(fd,2) = type;
  14008. WFIFOSET(fd,6);
  14009. }
  14010. /// Adoption confirmation (ZC_REQ_BABY).
  14011. /// 01f6 <account id>.L <char id>.L <name>.B
  14012. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14013. {
  14014. int fd = sd->fd;
  14015. WFIFOHEAD(fd,34);
  14016. WFIFOW(fd,0) = 0x1f6;
  14017. WFIFOL(fd,2) = src->status.account_id;
  14018. WFIFOL(fd,6) = p_id;
  14019. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14020. WFIFOSET(fd,34);
  14021. }
  14022. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14023. /// 01f9 <account id>.L
  14024. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14025. {
  14026. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14027. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14028. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14029. {
  14030. tsd->adopt_invite = sd->status.account_id;
  14031. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14032. }
  14033. }
  14034. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14035. /// 01f7 <account id>.L <char id>.L <answer>.L
  14036. /// answer:
  14037. /// 0 = rejected
  14038. /// 1 = accepted
  14039. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14040. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14041. int p1_id = RFIFOL(fd,info->pos[0]);
  14042. int p2_id = RFIFOL(fd,info->pos[1]);
  14043. int result = RFIFOL(fd,info->pos[2]);
  14044. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14045. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14046. int pid = sd->adopt_invite;
  14047. sd->adopt_invite = 0;
  14048. if( p1_sd == NULL || p2_sd == NULL )
  14049. return; // Both players need to be online
  14050. if( pid != p1_sd->status.account_id )
  14051. return; // Incorrect values
  14052. if( result == 0 )
  14053. return; // Rejected
  14054. pc_adoption(p1_sd, p2_sd, sd);
  14055. }
  14056. /// Convex Mirror (ZC_BOSS_INFO).
  14057. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14058. /// infoType:
  14059. /// BOSS_INFO_NOT = No boss on this map.
  14060. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14061. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14062. /// BOSS_INFO_DEAD = Boss is dead.
  14063. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14064. {
  14065. int fd = sd->fd;
  14066. WFIFOHEAD(fd,70);
  14067. memset(WFIFOP(fd,0),0,70);
  14068. WFIFOW(fd,0) = 0x293;
  14069. switch (flag) {
  14070. case BOSS_INFO_NOT:
  14071. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14072. // No data required
  14073. break;
  14074. case BOSS_INFO_ALIVE:
  14075. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14076. // Update X/Y
  14077. WFIFOL(fd,3) = md->bl.x;
  14078. WFIFOL(fd,7) = md->bl.y;
  14079. break;
  14080. case BOSS_INFO_ALIVE_WITHMSG:
  14081. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14082. // Current X/Y
  14083. WFIFOL(fd,3) = md->bl.x;
  14084. WFIFOL(fd,7) = md->bl.y;
  14085. break;
  14086. case BOSS_INFO_DEAD:
  14087. {
  14088. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14089. unsigned int seconds;
  14090. int hours, minutes;
  14091. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  14092. hours = seconds / (60 * 60);
  14093. seconds = seconds - (60 * 60 * hours);
  14094. minutes = seconds / 60;
  14095. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14096. // Add respawn info
  14097. WFIFOW(fd,11) = hours; // Hours
  14098. WFIFOW(fd,13) = minutes; // Minutes
  14099. }
  14100. break;
  14101. }
  14102. if (md != NULL)
  14103. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14104. WFIFOSET(fd,70);
  14105. }
  14106. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14107. /// 02d6 <account id>.L
  14108. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14109. {
  14110. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14111. struct map_session_data* tsd = map_id2sd(aid);
  14112. if (!tsd)
  14113. return;
  14114. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14115. clif_viewequip_ack(sd, tsd);
  14116. else
  14117. clif_msg(sd, VIEW_EQUIP_FAIL);
  14118. }
  14119. /// Request to a configuration.
  14120. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14121. /// type: see enum e_config_type
  14122. /// flag:
  14123. /// false = disabled
  14124. /// true = enabled
  14125. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14126. int cmd = RFIFOW(fd,0);
  14127. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14128. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14129. switch( type ){
  14130. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14131. sd->status.show_equip = flag;
  14132. break;
  14133. case CONFIG_PET_AUTOFEED:
  14134. // TODO: Implement with pet evolution system
  14135. break;
  14136. case CONFIG_HOMUNCULUS_AUTOFEED:
  14137. // Player can not click this if he does not have a homunculus or it is vaporized
  14138. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14139. return;
  14140. }
  14141. sd->hd->homunculus.autofeed = flag;
  14142. break;
  14143. default:
  14144. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14145. return;
  14146. }
  14147. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14148. }
  14149. /// Request to change party invitation tick.
  14150. /// value:
  14151. /// 0 = disabled
  14152. /// 1 = enabled
  14153. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14154. {
  14155. bool flag = RFIFOB(fd,6) ? true : false;
  14156. sd->status.allow_party = flag;
  14157. clif_partytickack(sd, flag);
  14158. }
  14159. /// Questlog System [Kevin] [Inkfish]
  14160. ///
  14161. /**
  14162. * Safe check to init packet len & quest num for player.
  14163. * @param def_len
  14164. * @param info_len Length of each quest info.
  14165. * @param avail_quests Avail quests that player has.
  14166. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14167. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14168. **/
  14169. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14170. (*limit_out) = (0xFFFF - def_len) / info_len;
  14171. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14172. (*len_out) = ((*limit_out) * info_len) + def_len;
  14173. }
  14174. /// Sends list of all quest states
  14175. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14176. /// 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)
  14177. /// 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)
  14178. void clif_quest_send_list(struct map_session_data *sd)
  14179. {
  14180. int fd = sd->fd;
  14181. int i;
  14182. int offset = 8;
  14183. int limit = 0;
  14184. #if PACKETVER >= 20141022
  14185. #if PACKETVER >= 20150513
  14186. int size = 22 + NAME_LENGTH;
  14187. #else
  14188. int size = 10 + NAME_LENGTH;
  14189. #endif
  14190. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14191. WFIFOHEAD(fd,i);
  14192. #if PACKETVER >= 20150513
  14193. WFIFOW(fd, 0) = 0x9f8;
  14194. #else
  14195. WFIFOW(fd, 0) = 0x97a;
  14196. #endif
  14197. WFIFOL(fd, 4) = limit;
  14198. for (i = 0; i < limit; i++) {
  14199. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14200. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14201. offset += 4;
  14202. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14203. offset++;
  14204. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  14205. offset += 4;
  14206. WFIFOL(fd, offset) = sd->quest_log[i].time;
  14207. offset += 4;
  14208. WFIFOW(fd, offset) = qi->objectives_count;
  14209. offset += 2;
  14210. if( qi->objectives_count > 0 ){
  14211. int j;
  14212. struct mob_db *mob;
  14213. for( j = 0; j < qi->objectives_count; j++ ){
  14214. mob = mob_db(qi->objectives[j].mob);
  14215. #if PACKETVER >= 20150513
  14216. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14217. offset += 4;
  14218. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14219. offset += 4;
  14220. #endif
  14221. WFIFOL(fd, offset) = qi->objectives[j].mob;
  14222. offset += 4;
  14223. #if PACKETVER >= 20150513
  14224. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14225. offset += 2;
  14226. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14227. offset += 2;
  14228. #endif
  14229. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14230. offset += 2;
  14231. WFIFOW(fd, offset) = qi->objectives[j].count;
  14232. offset += 2;
  14233. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14234. offset += NAME_LENGTH;
  14235. }
  14236. }
  14237. }
  14238. WFIFOW(fd, 2) = offset;
  14239. WFIFOSET(fd, offset);
  14240. #else
  14241. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14242. WFIFOHEAD(fd,i);
  14243. WFIFOW(fd, 0) = 0x2b1;
  14244. WFIFOL(fd, 4) = limit;
  14245. for (i = 0; i < limit; i++) {
  14246. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14247. offset += 4;
  14248. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14249. offset += 1;
  14250. }
  14251. WFIFOW(fd, 2) = offset;
  14252. WFIFOSET(fd, offset);
  14253. #endif
  14254. }
  14255. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14256. /// 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
  14257. void clif_quest_send_mission(struct map_session_data *sd)
  14258. {
  14259. int fd = sd->fd;
  14260. int i, j, limit = 0;
  14261. int len = sd->avail_quests*104+8;
  14262. struct mob_db *mob;
  14263. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14264. WFIFOHEAD(fd, len);
  14265. WFIFOW(fd, 0) = 0x2b2;
  14266. WFIFOW(fd, 2) = len;
  14267. WFIFOL(fd, 4) = limit;
  14268. for (i = 0; i < limit; i++) {
  14269. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14270. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14271. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  14272. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  14273. WFIFOW(fd, i*104+20) = qi->objectives_count;
  14274. for (j = 0 ; j < qi->objectives_count; j++) {
  14275. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  14276. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14277. mob = mob_db(qi->objectives[j].mob);
  14278. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14279. }
  14280. }
  14281. WFIFOSET(fd, len);
  14282. }
  14283. /// Notification about a new quest
  14284. /// 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)
  14285. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14286. /// 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)
  14287. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14288. {
  14289. int fd = sd->fd;
  14290. int i, offset;
  14291. struct quest_db *qi = quest_search(qd->quest_id);
  14292. #if PACKETVER >= 20150513
  14293. int cmd = 0x9f9;
  14294. #else
  14295. int cmd = 0x2b3;
  14296. #endif
  14297. WFIFOHEAD(fd, packet_len(cmd));
  14298. WFIFOW(fd, 0) = cmd;
  14299. WFIFOL(fd, 2) = qd->quest_id;
  14300. WFIFOB(fd, 6) = qd->state;
  14301. WFIFOB(fd, 7) = qd->time - qi->time;
  14302. WFIFOL(fd, 11) = qd->time;
  14303. WFIFOW(fd, 15) = qi->objectives_count;
  14304. for (i = 0, offset = 17; i < qi->objectives_count; i++) {
  14305. struct mob_db *mob;
  14306. #if PACKETVER >= 20150513
  14307. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14308. offset += 4;
  14309. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14310. offset += 4;
  14311. #endif
  14312. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14313. offset += 4;
  14314. #if PACKETVER >= 20150513
  14315. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14316. offset += 2;
  14317. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14318. offset += 2;
  14319. #endif
  14320. WFIFOW(fd, offset) = qd->count[i];
  14321. offset += 2;
  14322. mob = mob_db(qi->objectives[i].mob);
  14323. safestrncpy(WFIFOCP(fd, offset), mob->jname, NAME_LENGTH);
  14324. offset += NAME_LENGTH;
  14325. }
  14326. WFIFOSET(fd, packet_len(cmd));
  14327. #if PACKETVER >= 20150513
  14328. int len = 4 + qi->objectives_count * 12;
  14329. WFIFOHEAD(fd, len);
  14330. WFIFOW(fd, 0) = 0x8fe;
  14331. WFIFOW(fd, 2) = len;
  14332. for( i = 0, offset = 4; i < qi->objectives_count; i++, offset += 12 ){
  14333. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14334. WFIFOL(fd, offset+4) = qi->objectives[i].mob;
  14335. WFIFOW(fd, offset + 10) = qi->objectives[i].count;
  14336. WFIFOW(fd, offset + 12) = qd->count[i];
  14337. }
  14338. WFIFOSET(fd, len);
  14339. #endif
  14340. }
  14341. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14342. /// 02b4 <quest id>.L
  14343. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14344. {
  14345. int fd = sd->fd;
  14346. WFIFOHEAD(fd, packet_len(0x2b4));
  14347. WFIFOW(fd, 0) = 0x2b4;
  14348. WFIFOL(fd, 2) = quest_id;
  14349. WFIFOSET(fd, packet_len(0x2b4));
  14350. }
  14351. /// Notification of an update to the hunting mission counter
  14352. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14353. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14354. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14355. {
  14356. int fd = sd->fd;
  14357. int i, offset;
  14358. struct quest_db *qi = quest_search(qd->quest_id);
  14359. int len = qi->objectives_count * 12 + 6;
  14360. #if PACKETVER >= 20150513
  14361. int cmd = 0x9fa;
  14362. #else
  14363. int cmd = 0x2b5;
  14364. #endif
  14365. WFIFOHEAD(fd, len);
  14366. WFIFOW(fd, 0) = cmd;
  14367. WFIFOW(fd, 4) = qi->objectives_count;
  14368. for (i = 0, offset = 6; i < qi->objectives_count; i++) {
  14369. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  14370. WFIFOL(fd, offset) = qd->quest_id;
  14371. offset += 4;
  14372. #if PACKETVER >= 20150513
  14373. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14374. offset += 4;
  14375. #else
  14376. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14377. offset += 4;
  14378. #endif
  14379. WFIFOW(fd, offset) = qi->objectives[i].count;
  14380. offset += 2;
  14381. WFIFOW(fd, offset) = qd->count[i];
  14382. offset += 2;
  14383. }
  14384. }
  14385. WFIFOW(fd, 2) = offset;
  14386. WFIFOSET(fd, offset);
  14387. }
  14388. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14389. /// 02b6 <quest id>.L <active>.B
  14390. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14391. {
  14392. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14393. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14394. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14395. }
  14396. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14397. /// 02b7 <quest id>.L <active>.B
  14398. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14399. {
  14400. int fd = sd->fd;
  14401. WFIFOHEAD(fd, packet_len(0x2b7));
  14402. WFIFOW(fd, 0) = 0x2b7;
  14403. WFIFOL(fd, 2) = quest_id;
  14404. WFIFOB(fd, 6) = active;
  14405. WFIFOSET(fd, packet_len(0x2b7));
  14406. }
  14407. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14408. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14409. /// effect:
  14410. /// 0 = none
  14411. /// 1 = exclamation mark icon
  14412. /// 2 = question mark icon
  14413. /// color:
  14414. /// 0 = yellow
  14415. /// 1 = orange
  14416. /// 2 = green
  14417. /// 3 = purple
  14418. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  14419. {
  14420. #if PACKETVER >= 20090218
  14421. int fd = sd->fd;
  14422. WFIFOHEAD(fd, packet_len(0x446));
  14423. WFIFOW(fd, 0) = 0x446;
  14424. WFIFOL(fd, 2) = bl->id;
  14425. WFIFOW(fd, 6) = bl->x;
  14426. WFIFOW(fd, 8) = bl->y;
  14427. WFIFOW(fd, 10) = effect;
  14428. WFIFOW(fd, 12) = color;
  14429. WFIFOSET(fd, packet_len(0x446));
  14430. #endif
  14431. }
  14432. /// Mercenary System
  14433. ///
  14434. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14435. /// 02a2 <var id>.W <value>.L
  14436. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14437. {
  14438. struct mercenary_data *md;
  14439. struct status_data *status;
  14440. int fd;
  14441. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14442. return;
  14443. fd = sd->fd;
  14444. status = &md->battle_status;
  14445. WFIFOHEAD(fd,packet_len(0x2a2));
  14446. WFIFOW(fd,0) = 0x2a2;
  14447. WFIFOW(fd,2) = type;
  14448. switch( type ) {
  14449. case SP_ATK1:
  14450. {
  14451. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14452. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14453. }
  14454. break;
  14455. case SP_MATK1:
  14456. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14457. break;
  14458. case SP_HIT:
  14459. WFIFOL(fd,4) = status->hit;
  14460. break;
  14461. case SP_CRITICAL:
  14462. WFIFOL(fd,4) = status->cri/10;
  14463. break;
  14464. case SP_DEF1:
  14465. WFIFOL(fd,4) = status->def;
  14466. break;
  14467. case SP_MDEF1:
  14468. WFIFOL(fd,4) = status->mdef;
  14469. break;
  14470. case SP_MERCFLEE:
  14471. WFIFOL(fd,4) = status->flee;
  14472. break;
  14473. case SP_ASPD:
  14474. WFIFOL(fd,4) = status->amotion;
  14475. break;
  14476. case SP_HP:
  14477. WFIFOL(fd,4) = status->hp;
  14478. break;
  14479. case SP_MAXHP:
  14480. WFIFOL(fd,4) = status->max_hp;
  14481. break;
  14482. case SP_SP:
  14483. WFIFOL(fd,4) = status->sp;
  14484. break;
  14485. case SP_MAXSP:
  14486. WFIFOL(fd,4) = status->max_sp;
  14487. break;
  14488. case SP_MERCKILLS:
  14489. WFIFOL(fd,4) = md->mercenary.kill_count;
  14490. break;
  14491. case SP_MERCFAITH:
  14492. WFIFOL(fd,4) = mercenary_get_faith(md);
  14493. break;
  14494. }
  14495. WFIFOSET(fd,packet_len(0x2a2));
  14496. }
  14497. /// Mercenary base status data (ZC_MER_INIT).
  14498. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14499. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14500. /// <calls>.L <kills>.L <atk range>.W
  14501. void clif_mercenary_info(struct map_session_data *sd)
  14502. {
  14503. int fd;
  14504. struct mercenary_data *md;
  14505. struct status_data *status;
  14506. int atk;
  14507. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14508. return;
  14509. fd = sd->fd;
  14510. status = &md->battle_status;
  14511. WFIFOHEAD(fd,packet_len(0x29b));
  14512. WFIFOW(fd,0) = 0x29b;
  14513. WFIFOL(fd,2) = md->bl.id;
  14514. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14515. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14516. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14517. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14518. WFIFOW(fd,10) = status->hit;
  14519. WFIFOW(fd,12) = status->cri/10;
  14520. WFIFOW(fd,14) = status->def;
  14521. WFIFOW(fd,16) = status->mdef;
  14522. WFIFOW(fd,18) = status->flee;
  14523. WFIFOW(fd,20) = status->amotion;
  14524. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14525. WFIFOW(fd,46) = md->db->lv;
  14526. WFIFOL(fd,48) = status->hp;
  14527. WFIFOL(fd,52) = status->max_hp;
  14528. WFIFOL(fd,56) = status->sp;
  14529. WFIFOL(fd,60) = status->max_sp;
  14530. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  14531. WFIFOW(fd,68) = mercenary_get_faith(md);
  14532. WFIFOL(fd,70) = mercenary_get_calls(md);
  14533. WFIFOL(fd,74) = md->mercenary.kill_count;
  14534. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14535. WFIFOSET(fd,packet_len(0x29b));
  14536. }
  14537. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14538. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14539. void clif_mercenary_skillblock(struct map_session_data *sd)
  14540. {
  14541. struct mercenary_data *md;
  14542. int fd, i, len = 4;
  14543. if( sd == NULL || (md = sd->md) == NULL )
  14544. return;
  14545. fd = sd->fd;
  14546. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14547. WFIFOW(fd,0) = 0x29d;
  14548. for( i = 0; i < MAX_MERCSKILL; i++ )
  14549. {
  14550. uint16 id;
  14551. short idx = -1;
  14552. if( (id = md->db->skill[i].id) == 0 )
  14553. continue;
  14554. if ((idx = mercenary_skill_get_index(id)) == -1)
  14555. continue;
  14556. WFIFOW(fd,len) = id;
  14557. WFIFOL(fd,len+2) = skill_get_inf(id);
  14558. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14559. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14560. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14561. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14562. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14563. len += 37;
  14564. }
  14565. WFIFOW(fd,2) = len;
  14566. WFIFOSET(fd,len);
  14567. }
  14568. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14569. /// 029f <command>.B
  14570. /// 1 = mercenary information
  14571. /// 2 = delete
  14572. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14573. {
  14574. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14575. if( sd->md == NULL )
  14576. return;
  14577. if( option == 2 ) mercenary_delete(sd->md, 2);
  14578. }
  14579. /// Mercenary Message
  14580. /// message:
  14581. /// 0 = Mercenary soldier's duty hour is over.
  14582. /// 1 = Your mercenary soldier has been killed.
  14583. /// 2 = Your mercenary soldier has been fired.
  14584. /// 3 = Your mercenary soldier has ran away.
  14585. void clif_mercenary_message(struct map_session_data* sd, int message){
  14586. clif_msg(sd, MERC_MSG_BASE + message);
  14587. }
  14588. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  14589. /// 0298 <name id>.W <seconds>.L
  14590. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  14591. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  14592. WFIFOHEAD(fd,packet_len(0x298));
  14593. WFIFOW(fd,0) = 0x298;
  14594. WFIFOW(fd,2) = nameid;
  14595. WFIFOL(fd,4) = seconds;
  14596. WFIFOSET(fd,packet_len(0x298));
  14597. }
  14598. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  14599. /// 0299 <index>.W <name id>.W
  14600. void clif_rental_expired(int fd, int index, unsigned short nameid)
  14601. { // '<ItemName>' item has been deleted from the Inventory
  14602. WFIFOHEAD(fd,packet_len(0x299));
  14603. WFIFOW(fd,0) = 0x299;
  14604. WFIFOW(fd,2) = index+2;
  14605. WFIFOW(fd,4) = nameid;
  14606. WFIFOSET(fd,packet_len(0x299));
  14607. }
  14608. /// Book Reading (ZC_READ_BOOK).
  14609. /// 0294 <book id>.L <page>.L
  14610. void clif_readbook(int fd, int book_id, int page)
  14611. {
  14612. WFIFOHEAD(fd,packet_len(0x294));
  14613. WFIFOW(fd,0) = 0x294;
  14614. WFIFOL(fd,2) = book_id;
  14615. WFIFOL(fd,6) = page;
  14616. WFIFOSET(fd,packet_len(0x294));
  14617. }
  14618. /// Battlegrounds
  14619. ///
  14620. /// Updates HP bar of a camp member.
  14621. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14622. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14623. void clif_bg_hp(struct map_session_data *sd) {
  14624. #if PACKETVER < 20140613
  14625. unsigned char buf[34];
  14626. const int cmd = 0x2e0;
  14627. #else
  14628. unsigned char buf[14];
  14629. const int cmd = 0xa0e;
  14630. #endif
  14631. nullpo_retv(sd);
  14632. WBUFW(buf,0) = cmd;
  14633. WBUFL(buf,2) = sd->status.account_id;
  14634. #if PACKETVER < 20140613
  14635. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14636. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14637. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14638. WBUFW(buf,32) = 100;
  14639. } else {
  14640. WBUFW(buf,30) = sd->battle_status.hp;
  14641. WBUFW(buf,32) = sd->battle_status.max_hp;
  14642. }
  14643. #else
  14644. if( sd->battle_status.max_hp > INT32_MAX ) {
  14645. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14646. WBUFL(buf,10) = 100;
  14647. } else {
  14648. WBUFL(buf,6) = sd->battle_status.hp;
  14649. WBUFL(buf,10) = sd->battle_status.max_hp;
  14650. }
  14651. #endif
  14652. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14653. }
  14654. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14655. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14656. void clif_bg_xy(struct map_session_data *sd)
  14657. {
  14658. unsigned char buf[36];
  14659. nullpo_retv(sd);
  14660. WBUFW(buf,0)=0x2df;
  14661. WBUFL(buf,2)=sd->status.account_id;
  14662. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14663. WBUFW(buf,30)=sd->status.class_;
  14664. WBUFW(buf,32)=sd->bl.x;
  14665. WBUFW(buf,34)=sd->bl.y;
  14666. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14667. }
  14668. void clif_bg_xy_remove(struct map_session_data *sd)
  14669. {
  14670. unsigned char buf[36];
  14671. nullpo_retv(sd);
  14672. WBUFW(buf,0)=0x2df;
  14673. WBUFL(buf,2)=sd->status.account_id;
  14674. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14675. WBUFW(buf,30)=0;
  14676. WBUFW(buf,32)=-1;
  14677. WBUFW(buf,34)=-1;
  14678. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14679. }
  14680. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  14681. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  14682. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  14683. {
  14684. struct map_session_data *sd;
  14685. unsigned char *buf;
  14686. if( (sd = bg_getavailablesd(bg)) == NULL )
  14687. return;
  14688. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  14689. WBUFW(buf,0) = 0x2dc;
  14690. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14691. WBUFL(buf,4) = src_id;
  14692. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14693. memcpy(WBUFP(buf,32), mes, len);
  14694. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14695. if( buf )
  14696. aFree(buf);
  14697. }
  14698. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  14699. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  14700. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14701. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14702. if( !clif_process_message( sd, false, name, message, output ) )
  14703. return;
  14704. bg_send_message(sd, output, strlen(output) );
  14705. }
  14706. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14707. /// 02de <camp A points>.W <camp B points>.W
  14708. void clif_bg_updatescore(int16 m)
  14709. {
  14710. struct block_list bl;
  14711. unsigned char buf[6];
  14712. struct map_data *mapdata = map_getmapdata(m);
  14713. bl.id = 0;
  14714. bl.type = BL_NUL;
  14715. bl.m = m;
  14716. WBUFW(buf,0) = 0x2de;
  14717. WBUFW(buf,2) = mapdata->bgscore_lion;
  14718. WBUFW(buf,4) = mapdata->bgscore_eagle;
  14719. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14720. }
  14721. void clif_bg_updatescore_single(struct map_session_data *sd)
  14722. {
  14723. int fd;
  14724. nullpo_retv(sd);
  14725. fd = sd->fd;
  14726. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  14727. WFIFOHEAD(fd,packet_len(0x2de));
  14728. WFIFOW(fd,0) = 0x2de;
  14729. WFIFOW(fd,2) = mapdata->bgscore_lion;
  14730. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  14731. WFIFOSET(fd,packet_len(0x2de));
  14732. }
  14733. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14734. /// 02dd <account id>.L <name>.24B <camp>.W
  14735. void clif_sendbgemblem_area(struct map_session_data *sd)
  14736. {
  14737. unsigned char buf[33];
  14738. nullpo_retv(sd);
  14739. WBUFW(buf, 0) = 0x2dd;
  14740. WBUFL(buf,2) = sd->bl.id;
  14741. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14742. WBUFW(buf,30) = sd->bg_id;
  14743. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14744. }
  14745. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14746. {
  14747. nullpo_retv(sd);
  14748. WFIFOHEAD(fd,32);
  14749. WFIFOW(fd,0) = 0x2dd;
  14750. WFIFOL(fd,2) = sd->bl.id;
  14751. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14752. WFIFOW(fd,30) = sd->bg_id;
  14753. WFIFOSET(fd,packet_len(0x2dd));
  14754. }
  14755. /// Custom Fonts (ZC_NOTIFY_FONT).
  14756. /// 02ef <account_id>.L <font id>.W
  14757. void clif_font(struct map_session_data *sd)
  14758. {
  14759. #if PACKETVER >= 20080102
  14760. unsigned char buf[8];
  14761. nullpo_retv(sd);
  14762. WBUFW(buf,0) = 0x2ef;
  14763. WBUFL(buf,2) = sd->bl.id;
  14764. WBUFW(buf,6) = sd->status.font;
  14765. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14766. #endif
  14767. }
  14768. /// Required to start the instancing information window on Client
  14769. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14770. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14771. void clif_instance_create(unsigned short instance_id, int num)
  14772. {
  14773. #if PACKETVER >= 20071128
  14774. struct instance_db *db = NULL;
  14775. struct map_session_data *sd = NULL;
  14776. enum send_target target = PARTY;
  14777. unsigned char buf[65];
  14778. instance_getsd(instance_id, &sd, &target);
  14779. if (!sd)
  14780. return;
  14781. db = instance_searchtype_db(instance_data[instance_id].type);
  14782. if (!db)
  14783. return;
  14784. WBUFW(buf,0) = 0x2cb;
  14785. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14786. WBUFW(buf,63) = num;
  14787. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14788. #endif
  14789. return;
  14790. }
  14791. /// To announce Instancing queue creation if no maps available
  14792. /// S 0x2cc <Standby Position>.W
  14793. void clif_instance_changewait(unsigned short instance_id, int num)
  14794. {
  14795. #if PACKETVER >= 20071128
  14796. struct map_session_data *sd = NULL;
  14797. enum send_target target = PARTY;
  14798. unsigned char buf[4];
  14799. instance_getsd(instance_id, &sd, &target);
  14800. if (!sd)
  14801. return;
  14802. WBUFW(buf,0) = 0x2cc;
  14803. WBUFW(buf,2) = num;
  14804. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14805. #endif
  14806. return;
  14807. }
  14808. /// Notify the current status to members
  14809. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14810. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14811. {
  14812. #if PACKETVER >= 20071128
  14813. struct instance_db *db = NULL;
  14814. struct map_session_data *sd = NULL;
  14815. enum send_target target = PARTY;
  14816. unsigned char buf[71];
  14817. instance_getsd(instance_id, &sd, &target);
  14818. if (!sd)
  14819. return;
  14820. db = instance_searchtype_db(instance_data[instance_id].type);
  14821. if (!db)
  14822. return;
  14823. WBUFW(buf,0) = 0x2cd;
  14824. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14825. WBUFL(buf,63) = limit1;
  14826. WBUFL(buf,67) = limit2;
  14827. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14828. #endif
  14829. return;
  14830. }
  14831. /// Notify a status change to members
  14832. /// S 0x2ce <Message ID>.L
  14833. /// 0 = Notification (EnterLimitDate update?)
  14834. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14835. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14836. /// 3 = The Memorial Dungeon has been removed.
  14837. /// 4 = Create failure (removes the instance window)
  14838. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14839. {
  14840. #if PACKETVER >= 20071128
  14841. struct map_session_data *sd = NULL;
  14842. enum send_target target = PARTY;
  14843. unsigned char buf[10];
  14844. instance_getsd(instance_id, &sd, &target);
  14845. if (!sd)
  14846. return;
  14847. WBUFW(buf,0) = 0x2ce;
  14848. WBUFL(buf,2) = type;
  14849. WBUFL(buf,6) = limit;
  14850. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14851. #endif
  14852. return;
  14853. }
  14854. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14855. /// 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
  14856. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14857. {
  14858. #if PACKETVER >= 20071002
  14859. unsigned char buf[22];
  14860. struct item_data* id = itemdb_search(item_data->nameid);
  14861. WBUFW(buf,0) = 0x2b8;
  14862. WBUFL(buf,2) = sd->status.account_id;
  14863. WBUFW(buf,6) = item_data->nameid;
  14864. WBUFB(buf,8) = item_data->identify;
  14865. WBUFB(buf,9) = item_data->attribute;
  14866. WBUFB(buf,10) = item_data->refine;
  14867. clif_addcards(WBUFP(buf,11), item_data);
  14868. WBUFW(buf,19) = id->equip; // equip location
  14869. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14870. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14871. #endif
  14872. }
  14873. /** Display gained exp.
  14874. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  14875. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  14876. * amount: INT32_MIN ~ INT32_MAX
  14877. * var id:
  14878. * SP_BASEEXP, SP_JOBEXP
  14879. * exp type:
  14880. * 0 = normal exp gained/lost
  14881. * 1 = quest exp gained/lost
  14882. * @param sd Player
  14883. * @param exp EXP value gained/loss
  14884. * @param type SP_BASEEXP, SP_JOBEXP
  14885. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14886. * @param lost True:if lossing EXP
  14887. */
  14888. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14889. {
  14890. int fd;
  14891. int offset;
  14892. #if PACKETVER >= 20170830
  14893. int cmd = 0xacc;
  14894. #else
  14895. int cmd = 0x7f6;
  14896. #endif
  14897. nullpo_retv(sd);
  14898. fd = sd->fd;
  14899. WFIFOHEAD(fd, packet_len(cmd));
  14900. WFIFOW(fd,0) = cmd;
  14901. WFIFOL(fd,2) = sd->bl.id;
  14902. #if PACKETVER >= 20170830
  14903. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  14904. offset = 4;
  14905. #else
  14906. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14907. offset = 0;
  14908. #endif
  14909. WFIFOW(fd,10+offset) = type;
  14910. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  14911. WFIFOSET(fd,packet_len(cmd));
  14912. }
  14913. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14914. /// type:
  14915. /// 0 = Displays 'value' for 5 seconds.
  14916. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14917. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14918. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14919. /// value:
  14920. /// 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).
  14921. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14922. {
  14923. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14924. WFIFOW(sd->fd,0) = 0x1b1;
  14925. WFIFOB(sd->fd,2) = type;
  14926. WFIFOL(sd->fd,3) = value;
  14927. WFIFOSET(sd->fd, packet_len(0x1b1));
  14928. }
  14929. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14930. /// 021d <state>.L
  14931. /// state:
  14932. /// 0 = Full effects
  14933. /// 1 = Reduced effects
  14934. ///
  14935. /// NOTE: The state is used on Aegis for sending skill unit packet
  14936. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14937. /// whenever possible. Due to the way the decision check is
  14938. /// constructed, this state tracking was rendered useless,
  14939. /// as the only skill unit, that is sent with 0x1c9 is
  14940. /// Graffiti.
  14941. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14942. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14943. sd->state.lesseffect = ( isLess != 0 );
  14944. }
  14945. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14946. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14947. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14948. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14949. int type = RFIFOL(fd,info->pos[1]);
  14950. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14951. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14952. if( sd->state.trading || sd->npc_shopid )
  14953. return;
  14954. if( flag == 0 || n == 0) {
  14955. clif_menuskill_clear(sd);
  14956. return; // Canceled by player.
  14957. }
  14958. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14959. clif_menuskill_clear(sd);
  14960. return; // Prevent hacking.
  14961. }
  14962. switch( type ) {
  14963. case 0: // Change Material
  14964. skill_changematerial(sd,n,item_list);
  14965. break;
  14966. case 1: // Level 1: Pure to Rough
  14967. case 2: // Level 2: Rough to Pure
  14968. skill_elementalanalysis(sd,n,type,item_list);
  14969. break;
  14970. }
  14971. clif_menuskill_clear(sd);
  14972. return;
  14973. }
  14974. /*==========================================
  14975. * Elemental System
  14976. *==========================================*/
  14977. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14978. struct elemental_data *ed;
  14979. struct status_data *status;
  14980. int fd;
  14981. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14982. return;
  14983. fd = sd->fd;
  14984. status = &ed->battle_status;
  14985. WFIFOHEAD(fd,8);
  14986. WFIFOW(fd,0) = 0x81e;
  14987. WFIFOW(fd,2) = type;
  14988. switch( type ) {
  14989. case SP_HP:
  14990. WFIFOL(fd,4) = status->hp;
  14991. break;
  14992. case SP_MAXHP:
  14993. WFIFOL(fd,4) = status->max_hp;
  14994. break;
  14995. case SP_SP:
  14996. WFIFOL(fd,4) = status->sp;
  14997. break;
  14998. case SP_MAXSP:
  14999. WFIFOL(fd,4) = status->max_sp;
  15000. break;
  15001. }
  15002. WFIFOSET(fd,8);
  15003. }
  15004. void clif_elemental_info(struct map_session_data *sd) {
  15005. int fd;
  15006. struct elemental_data *ed;
  15007. struct status_data *status;
  15008. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15009. return;
  15010. fd = sd->fd;
  15011. status = &ed->battle_status;
  15012. WFIFOHEAD(fd,22);
  15013. WFIFOW(fd, 0) = 0x81d;
  15014. WFIFOL(fd, 2) = ed->bl.id;
  15015. WFIFOL(fd, 6) = status->hp;
  15016. WFIFOL(fd,10) = status->max_hp;
  15017. WFIFOL(fd,14) = status->sp;
  15018. WFIFOL(fd,18) = status->max_sp;
  15019. WFIFOSET(fd,22);
  15020. }
  15021. /// Buying Store System
  15022. ///
  15023. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15024. /// 0810 <slots>.B
  15025. void clif_buyingstore_open(struct map_session_data* sd)
  15026. {
  15027. int fd = sd->fd;
  15028. WFIFOHEAD(fd,packet_len(0x810));
  15029. WFIFOW(fd,0) = 0x810;
  15030. WFIFOB(fd,2) = sd->buyingstore.slots;
  15031. WFIFOSET(fd,packet_len(0x810));
  15032. }
  15033. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15034. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15035. /// result:
  15036. /// 0 = cancel
  15037. /// 1 = open
  15038. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  15039. {
  15040. const unsigned int blocksize = 8;
  15041. uint8* itemlist;
  15042. char storename[MESSAGE_SIZE];
  15043. unsigned char result;
  15044. int zenylimit;
  15045. unsigned int count, packet_len;
  15046. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15047. packet_len = RFIFOW(fd,info->pos[0]);
  15048. // TODO: Make this check global for all variable length packets.
  15049. if( packet_len < 89 )
  15050. {// minimum packet length
  15051. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  15052. return;
  15053. }
  15054. zenylimit = RFIFOL(fd,info->pos[1]);
  15055. result = RFIFOL(fd,info->pos[2]);
  15056. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  15057. itemlist = RFIFOP(fd,info->pos[4]);
  15058. // so that buyingstore_create knows, how many elements it has access to
  15059. packet_len-= info->pos[4];
  15060. if( packet_len%blocksize )
  15061. {
  15062. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15063. return;
  15064. }
  15065. count = packet_len/blocksize;
  15066. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  15067. }
  15068. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15069. /// 0812 <result>.W <total weight>.L
  15070. /// result:
  15071. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15072. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15073. /// 8 = "No sale (purchase) information available." (0x705)
  15074. /// ? = nothing
  15075. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15076. {
  15077. int fd = sd->fd;
  15078. WFIFOHEAD(fd,packet_len(0x812));
  15079. WFIFOW(fd,0) = 0x812;
  15080. WFIFOW(fd,2) = result;
  15081. WFIFOL(fd,4) = weight;
  15082. WFIFOSET(fd,packet_len(0x812));
  15083. }
  15084. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15085. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15086. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  15087. {
  15088. int fd = sd->fd;
  15089. unsigned int i;
  15090. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  15091. WFIFOW(fd,0) = 0x813;
  15092. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  15093. WFIFOL(fd,4) = sd->bl.id;
  15094. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  15095. for( i = 0; i < sd->buyingstore.slots; i++ )
  15096. {
  15097. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  15098. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  15099. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  15100. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  15101. }
  15102. WFIFOSET(fd,WFIFOW(fd,2));
  15103. }
  15104. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15105. /// 0814 <account id>.L <store name>.80B
  15106. void clif_buyingstore_entry(struct map_session_data* sd)
  15107. {
  15108. uint8 buf[MESSAGE_SIZE+6];
  15109. WBUFW(buf,0) = 0x814;
  15110. WBUFL(buf,2) = sd->bl.id;
  15111. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15112. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15113. }
  15114. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15115. {
  15116. int fd = sd->fd;
  15117. WFIFOHEAD(fd,packet_len(0x814));
  15118. WFIFOW(fd,0) = 0x814;
  15119. WFIFOL(fd,2) = pl_sd->bl.id;
  15120. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15121. WFIFOSET(fd,packet_len(0x814));
  15122. }
  15123. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15124. /// 0815
  15125. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15126. {
  15127. buyingstore_close(sd);
  15128. }
  15129. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15130. /// 0816 <account id>.L
  15131. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15132. {
  15133. uint8 buf[6];
  15134. WBUFW(buf,0) = 0x816;
  15135. WBUFL(buf,2) = sd->bl.id;
  15136. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15137. }
  15138. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15139. {
  15140. int fd = sd->fd;
  15141. WFIFOHEAD(fd,packet_len(0x816));
  15142. WFIFOW(fd,0) = 0x816;
  15143. WFIFOL(fd,2) = pl_sd->bl.id;
  15144. WFIFOSET(fd,packet_len(0x816));
  15145. }
  15146. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15147. /// 0817 <account id>.L
  15148. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15149. {
  15150. uint32 account_id;
  15151. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15152. buyingstore_open(sd, account_id);
  15153. }
  15154. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  15155. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  15156. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  15157. {
  15158. int fd = sd->fd;
  15159. unsigned int i;
  15160. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  15161. WFIFOW(fd,0) = 0x818;
  15162. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  15163. WFIFOL(fd,4) = pl_sd->bl.id;
  15164. WFIFOL(fd,8) = pl_sd->buyer_id;
  15165. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  15166. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  15167. {
  15168. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  15169. 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.
  15170. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  15171. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  15172. }
  15173. WFIFOSET(fd,WFIFOW(fd,2));
  15174. }
  15175. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  15176. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  15177. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  15178. {
  15179. const unsigned int blocksize = 6;
  15180. uint8* itemlist;
  15181. uint32 account_id;
  15182. unsigned int count, packet_len, buyer_id;
  15183. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15184. packet_len = RFIFOW(fd,info->pos[0]);
  15185. if( packet_len < 12 )
  15186. {// minimum packet length
  15187. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  15188. return;
  15189. }
  15190. account_id = RFIFOL(fd,info->pos[1]);
  15191. buyer_id = RFIFOL(fd,info->pos[2]);
  15192. itemlist = RFIFOP(fd,info->pos[3]);
  15193. // so that buyingstore_trade knows, how many elements it has access to
  15194. packet_len-= info->pos[3];
  15195. if( packet_len%blocksize )
  15196. {
  15197. 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);
  15198. return;
  15199. }
  15200. count = packet_len/blocksize;
  15201. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  15202. }
  15203. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15204. /// 081a <result>.W
  15205. /// result:
  15206. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15207. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15208. /// ? = nothing
  15209. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15210. {
  15211. int fd = sd->fd;
  15212. WFIFOHEAD(fd,packet_len(0x81a));
  15213. WFIFOW(fd,0) = 0x81a;
  15214. WFIFOW(fd,2) = result;
  15215. WFIFOSET(fd,packet_len(0x81a));
  15216. }
  15217. /// Updates the zeny limit and an item in the buying store item list.
  15218. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15219. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15220. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  15221. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  15222. const int cmd = 0x81b;
  15223. #else
  15224. const int cmd = 0x9e6;
  15225. #endif
  15226. int offset = 0;
  15227. int fd = sd->fd;
  15228. WFIFOHEAD(fd,packet_len(cmd));
  15229. WFIFOW(fd,0) = cmd;
  15230. WFIFOW(fd,2) = nameid;
  15231. WFIFOW(fd,4) = amount; // amount of nameid received
  15232. #if PACKETVER >= 20141016
  15233. WFIFOL(fd,6) = zeny; // zeny
  15234. offset += 4;
  15235. #endif
  15236. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  15237. #if PACKETVER >= 20141016
  15238. WFIFOL(fd,10+offset) = char_id; // GID
  15239. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  15240. #endif
  15241. WFIFOSET(fd,packet_len(cmd));
  15242. }
  15243. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15244. /// 081c <index>.W <amount>.W <price>.L
  15245. /// message:
  15246. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15247. ///
  15248. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15249. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15250. {
  15251. int fd = sd->fd;
  15252. WFIFOHEAD(fd,packet_len(0x81c));
  15253. WFIFOW(fd,0) = 0x81c;
  15254. WFIFOW(fd,2) = index+2;
  15255. WFIFOW(fd,4) = amount;
  15256. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15257. WFIFOSET(fd,packet_len(0x81c));
  15258. }
  15259. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15260. /// 0824 <result>.W <name id>.W
  15261. /// result:
  15262. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15263. /// 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)
  15264. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15265. /// ? = nothing
  15266. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  15267. {
  15268. int fd = sd->fd;
  15269. WFIFOHEAD(fd,packet_len(0x824));
  15270. WFIFOW(fd,0) = 0x824;
  15271. WFIFOW(fd,2) = result;
  15272. WFIFOW(fd,4) = nameid;
  15273. WFIFOSET(fd,packet_len(0x824));
  15274. }
  15275. /// Search Store Info System
  15276. ///
  15277. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15278. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15279. /// type:
  15280. /// 0 = Vending
  15281. /// 1 = Buying Store
  15282. ///
  15283. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15284. /// amount of card slots. If the client does not know about the item it
  15285. /// cannot be searched.
  15286. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  15287. {
  15288. const unsigned int blocksize = 2;
  15289. const uint8* itemlist;
  15290. const uint8* cardlist;
  15291. unsigned char type;
  15292. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  15293. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15294. packet_len = RFIFOW(fd,info->pos[0]);
  15295. if( packet_len < 15 )
  15296. {// minimum packet length
  15297. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  15298. return;
  15299. }
  15300. type = RFIFOB(fd,info->pos[1]);
  15301. max_price = RFIFOL(fd,info->pos[2]);
  15302. min_price = RFIFOL(fd,info->pos[3]);
  15303. item_count = RFIFOB(fd,info->pos[4]);
  15304. card_count = RFIFOB(fd,info->pos[5]);
  15305. itemlist = RFIFOP(fd,info->pos[6]);
  15306. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  15307. // check, if there is enough data for the claimed count of items
  15308. packet_len-= info->pos[6];
  15309. if( packet_len%blocksize )
  15310. {
  15311. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15312. return;
  15313. }
  15314. count = packet_len/blocksize;
  15315. if( count < item_count+card_count )
  15316. {
  15317. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  15318. return;
  15319. }
  15320. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  15321. }
  15322. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15323. /// 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 }*
  15324. /// is first page:
  15325. /// 0 = appends to existing results
  15326. /// 1 = clears previous results before displaying this result set
  15327. /// is next page:
  15328. /// 0 = no "next" label
  15329. /// 1 = "next" label to retrieve more results
  15330. void clif_search_store_info_ack(struct map_session_data* sd)
  15331. {
  15332. #if PACKETVER >= 20150225
  15333. const unsigned int blocksize = MESSAGE_SIZE+26+5*5;
  15334. #else
  15335. const unsigned int blocksize = MESSAGE_SIZE+26;
  15336. #endif
  15337. int fd = sd->fd;
  15338. unsigned int i, start, end;
  15339. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  15340. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  15341. WFIFOHEAD(fd,7+(end-start)*blocksize);
  15342. WFIFOW(fd,0) = 0x836;
  15343. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  15344. WFIFOB(fd,4) = !sd->searchstore.pages;
  15345. WFIFOB(fd,5) = searchstore_querynext(sd);
  15346. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15347. for( i = start; i < end; i++ ) {
  15348. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15349. struct item it;
  15350. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  15351. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  15352. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  15353. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  15354. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  15355. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  15356. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  15357. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  15358. // make-up an item for clif_addcards
  15359. memset(&it, 0, sizeof(it));
  15360. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  15361. it.nameid = ssitem->nameid;
  15362. it.amount = ssitem->amount;
  15363. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  15364. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  15365. }
  15366. WFIFOSET(fd,WFIFOW(fd,2));
  15367. }
  15368. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15369. /// 0837 <reason>.B
  15370. /// reason:
  15371. /// 0 = "No matching stores were found." (0x70b)
  15372. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15373. /// 2 = "You cannot search anymore." (0x706)
  15374. /// 3 = "You cannot search yet." (0x708)
  15375. /// 4 = "No sale (purchase) information available." (0x705)
  15376. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15377. {
  15378. int fd = sd->fd;
  15379. WFIFOHEAD(fd,packet_len(0x837));
  15380. WFIFOW(fd,0) = 0x837;
  15381. WFIFOB(fd,2) = reason;
  15382. WFIFOSET(fd,packet_len(0x837));
  15383. }
  15384. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15385. /// 0838
  15386. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15387. {
  15388. searchstore_next(sd);
  15389. }
  15390. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15391. /// 083a <type>.W <remaining uses>.B
  15392. /// type:
  15393. /// 0 = Search Stores
  15394. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15395. void clif_open_search_store_info(struct map_session_data* sd)
  15396. {
  15397. int fd = sd->fd;
  15398. WFIFOHEAD(fd,packet_len(0x83a));
  15399. WFIFOW(fd,0) = 0x83a;
  15400. WFIFOW(fd,2) = sd->searchstore.effect;
  15401. #if PACKETVER > 20100701
  15402. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15403. #endif
  15404. WFIFOSET(fd,packet_len(0x83a));
  15405. }
  15406. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15407. /// 083b
  15408. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15409. {
  15410. searchstore_close(sd);
  15411. }
  15412. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15413. /// 083c <account id>.L <store id>.L <nameid>.W
  15414. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  15415. {
  15416. unsigned short nameid;
  15417. uint32 account_id, store_id;
  15418. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15419. account_id = RFIFOL(fd,info->pos[0]);
  15420. store_id = RFIFOL(fd,info->pos[1]);
  15421. nameid = RFIFOW(fd,info->pos[2]);
  15422. searchstore_click(sd, account_id, store_id, nameid);
  15423. }
  15424. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15425. /// 083d <xPos>.W <yPos>.W
  15426. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15427. {
  15428. int fd = sd->fd;
  15429. WFIFOHEAD(fd,packet_len(0x83d));
  15430. WFIFOW(fd,0) = 0x83d;
  15431. WFIFOW(fd,2) = x;
  15432. WFIFOW(fd,4) = y;
  15433. WFIFOSET(fd,packet_len(0x83d));
  15434. }
  15435. /// Parse function for packet debugging.
  15436. void clif_parse_debug(int fd,struct map_session_data *sd)
  15437. {
  15438. int cmd, packet_len;
  15439. // clif_parse ensures, that there is at least 2 bytes of data
  15440. cmd = RFIFOW(fd,0);
  15441. if( sd ) {
  15442. packet_len = packet_db[cmd].len;
  15443. if( packet_len == 0 )
  15444. {// unknown
  15445. packet_len = RFIFOREST(fd);
  15446. }
  15447. else if( packet_len == -1 )
  15448. {// variable length
  15449. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15450. }
  15451. 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);
  15452. }
  15453. else
  15454. {
  15455. packet_len = RFIFOREST(fd);
  15456. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15457. }
  15458. ShowDump(RFIFOP(fd,0), packet_len);
  15459. }
  15460. /*==========================================
  15461. * Server tells client to display a window similar to Magnifier (item) one
  15462. * Server populates the window with avilable elemental converter options according to player's inventory
  15463. *------------------------------------------*/
  15464. int clif_elementalconverter_list(struct map_session_data *sd) {
  15465. int i,c,view,fd;
  15466. nullpo_ret(sd);
  15467. /// Main client packet processing function
  15468. fd=sd->fd;
  15469. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  15470. WFIFOW(fd, 0)=0x1ad;
  15471. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  15472. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  15473. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  15474. WFIFOW(fd,c*2+ 4)= view;
  15475. else
  15476. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  15477. c++;
  15478. }
  15479. }
  15480. WFIFOW(fd,2) = c*2+4;
  15481. WFIFOSET(fd, WFIFOW(fd,2));
  15482. if (c > 0) {
  15483. sd->menuskill_id = SA_CREATECON;
  15484. sd->menuskill_val = c;
  15485. }
  15486. return 0;
  15487. }
  15488. /**
  15489. * Rune Knight
  15490. **/
  15491. void clif_millenniumshield(struct block_list *bl, short shields) {
  15492. #if PACKETVER >= 20081217
  15493. unsigned char buf[10];
  15494. WBUFW(buf,0) = 0x440;
  15495. WBUFL(buf,2) = bl->id;
  15496. WBUFW(buf,6) = shields;
  15497. WBUFW(buf,8) = 0;
  15498. clif_send(buf,packet_len(0x440),bl,AREA);
  15499. #endif
  15500. }
  15501. /**
  15502. * Warlock
  15503. **/
  15504. /*==========================================
  15505. * Spellbook list [LimitLine/3CeAM]
  15506. *------------------------------------------*/
  15507. int clif_spellbook_list(struct map_session_data *sd)
  15508. {
  15509. int i, c;
  15510. int fd;
  15511. nullpo_ret(sd);
  15512. fd = sd->fd;
  15513. WFIFOHEAD(fd, 8 * 8 + 8);
  15514. WFIFOW(fd,0) = 0x1ad;
  15515. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  15516. {
  15517. if( itemdb_is_spellbook2(sd->inventory.u.items_inventory[i].nameid) )
  15518. {
  15519. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15520. c++;
  15521. }
  15522. }
  15523. if( c > 0 )
  15524. {
  15525. WFIFOW(fd,2) = c * 2 + 4;
  15526. WFIFOSET(fd, WFIFOW(fd, 2));
  15527. sd->menuskill_id = WL_READING_SB;
  15528. sd->menuskill_val = c;
  15529. }
  15530. else{
  15531. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15532. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  15533. }
  15534. return 1;
  15535. }
  15536. /**
  15537. * Mechanic
  15538. **/
  15539. /*==========================================
  15540. * Magic Decoy Material List
  15541. *------------------------------------------*/
  15542. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  15543. int i, c;
  15544. int fd;
  15545. nullpo_ret(sd);
  15546. fd = sd->fd;
  15547. WFIFOHEAD(fd, 8 * 8 + 8);
  15548. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15549. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15550. if( itemdb_group_item_exists(IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid) ) {
  15551. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15552. c ++;
  15553. }
  15554. }
  15555. if( c > 0 ) {
  15556. sd->menuskill_id = NC_MAGICDECOY;
  15557. sd->menuskill_val = skill_lv;
  15558. sd->sc.comet_x = x;
  15559. sd->sc.comet_y = y;
  15560. WFIFOW(fd,2) = c * 2 + 4;
  15561. WFIFOSET(fd, WFIFOW(fd, 2));
  15562. } else {
  15563. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  15564. return 0;
  15565. }
  15566. return 1;
  15567. }
  15568. /*==========================================
  15569. * Guillotine Cross Poisons List
  15570. *------------------------------------------*/
  15571. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  15572. int i, c;
  15573. int fd;
  15574. nullpo_ret(sd);
  15575. fd = sd->fd;
  15576. WFIFOHEAD(fd, 8 * 8 + 8);
  15577. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15578. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15579. if( itemdb_group_item_exists(IG_POISON, sd->inventory.u.items_inventory[i].nameid) ) {
  15580. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15581. c ++;
  15582. }
  15583. }
  15584. if( c > 0 ) {
  15585. sd->menuskill_id = GC_POISONINGWEAPON;
  15586. sd->menuskill_val = skill_lv;
  15587. WFIFOW(fd,2) = c * 2 + 4;
  15588. WFIFOSET(fd, WFIFOW(fd, 2));
  15589. } else {
  15590. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  15591. return 0;
  15592. }
  15593. return 1;
  15594. }
  15595. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15596. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15597. int fd, i, c;
  15598. nullpo_ret(sd);
  15599. fd = sd->fd;
  15600. if( !fd )
  15601. return 0;
  15602. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15603. return 0;
  15604. WFIFOHEAD(fd, 2 * 6 + 4);
  15605. WFIFOW(fd,0) = 0x442;
  15606. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15607. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15608. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15609. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  15610. {
  15611. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15612. c++;
  15613. }
  15614. if( c > 0 ) {
  15615. WFIFOW(fd,2) = 8 + c * 2;
  15616. WFIFOL(fd,4) = c;
  15617. WFIFOSET(fd,WFIFOW(fd,2));
  15618. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15619. sd->menuskill_val = c;
  15620. } else {
  15621. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15622. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15623. }
  15624. return 1;
  15625. }
  15626. /*===========================================
  15627. * Skill list for Four Elemental Analysis
  15628. * and Change Material skills.
  15629. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15630. *------------------------------------------*/
  15631. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15632. #if PACKETVER >= 20090922
  15633. int fd = sd->fd;
  15634. nullpo_ret(sd);
  15635. sd->menuskill_id = skill_id; // To prevent hacking.
  15636. sd->menuskill_val = skill_lv;
  15637. if( skill_id == GN_CHANGEMATERIAL )
  15638. skill_lv = 0; // Changematerial
  15639. WFIFOHEAD(fd, packet_len(0x7e3));
  15640. WFIFOW(fd,0) = 0x7e3;
  15641. WFIFOL(fd,2) = skill_lv;
  15642. WFIFOL(fd,4) = 0;
  15643. WFIFOSET(fd, packet_len(0x7e3));
  15644. #endif
  15645. return 1;
  15646. }
  15647. /*==========================================
  15648. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  15649. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15650. * RFIFOL(fd,2) - type (currently not used)
  15651. *------------------------------------------*/
  15652. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15653. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15654. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15655. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  15656. return;
  15657. if( pc_istrading(sd) ) {
  15658. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  15659. clif_menuskill_clear(sd);
  15660. return;
  15661. }
  15662. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  15663. clif_menuskill_clear(sd);
  15664. }
  15665. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15666. /// 08cf <id>.L <type>.W <num>.W
  15667. void clif_spiritcharm(struct map_session_data *sd) {
  15668. unsigned char buf[10];
  15669. nullpo_retv(sd);
  15670. WBUFW(buf,0) = 0x08cf;
  15671. WBUFL(buf,2) = sd->bl.id;
  15672. WBUFW(buf,6) = sd->spiritcharm_type;
  15673. WBUFW(buf,8) = sd->spiritcharm;
  15674. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15675. }
  15676. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15677. /// 0907 <index>.W
  15678. ///
  15679. /// R 0908 <index>.w <type>.b
  15680. /// type:
  15681. /// 0 = move item to personal tab
  15682. /// 1 = move item to normal tab
  15683. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15684. #if PACKETVER >= 20111122
  15685. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15686. int index = RFIFOW(fd,info->pos[0]) - 2;
  15687. int type = RFIFOB(fd, info->pos[1]);
  15688. /* can't move while dead. */
  15689. if(pc_isdead(sd)) {
  15690. return;
  15691. }
  15692. if (index < 0 || index >= MAX_INVENTORY)
  15693. return;
  15694. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15695. sd->inventory.u.items_inventory[index].favorite = 0;
  15696. else if( type == 0 )
  15697. sd->inventory.u.items_inventory[index].favorite = 1;
  15698. else
  15699. return;/* nothing to do. */
  15700. clif_favorite_item(sd, index);
  15701. #endif
  15702. }
  15703. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15704. /// 0900 <index>.W <favorite>.B
  15705. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15706. int fd = sd->fd;
  15707. WFIFOHEAD(fd,packet_len(0x908));
  15708. WFIFOW(fd,0) = 0x908;
  15709. WFIFOW(fd,2) = index+2;
  15710. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15711. WFIFOSET(fd,packet_len(0x908));
  15712. }
  15713. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15714. void clif_snap( struct block_list *bl, short x, short y ) {
  15715. unsigned char buf[10];
  15716. WBUFW(buf,0) = 0x8d2;
  15717. WBUFL(buf,2) = bl->id;
  15718. WBUFW(buf,6) = x;
  15719. WBUFW(buf,8) = y;
  15720. if( disguised(bl) )
  15721. {
  15722. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15723. WBUFL(buf,2) = -bl->id;
  15724. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15725. } else
  15726. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15727. }
  15728. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15729. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15730. #if PACKETVER >= 20120404
  15731. WFIFOHEAD(fd,packet_len(0x977));
  15732. WFIFOW(fd,0) = 0x977;
  15733. WFIFOL(fd,2) = md->bl.id;
  15734. WFIFOL(fd,6) = md->status.hp;
  15735. WFIFOL(fd,10) = md->status.max_hp;
  15736. WFIFOSET(fd,packet_len(0x977));
  15737. #endif
  15738. }
  15739. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15740. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15741. return;
  15742. }
  15743. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15744. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15745. WFIFOW(sd->fd,0) = 0x2c9;
  15746. WFIFOB(sd->fd,2) = flag;
  15747. WFIFOSET(sd->fd, packet_len(0x2c9));
  15748. }
  15749. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15750. /// 0979 <world name>.24B <char name>.24B
  15751. void clif_ackworldinfo(struct map_session_data* sd) {
  15752. int fd;
  15753. nullpo_retv(sd);
  15754. fd = sd->fd;
  15755. WFIFOHEAD(fd,packet_len(0x979));
  15756. WFIFOW(fd,0)=0x979;
  15757. //AID -> world name ?
  15758. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15759. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15760. WFIFOSET(fd,packet_len(0x979));
  15761. }
  15762. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15763. /// 0978 <AID>.L
  15764. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15765. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15766. if(sd)
  15767. clif_ackworldinfo(sd);
  15768. }
  15769. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15770. /// 0447
  15771. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15772. //if(sd)
  15773. ;
  15774. }
  15775. /// req world info (CZ_CLIENT_VERSION)
  15776. /// 044A <version>.L
  15777. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15778. //if(sd)
  15779. ;
  15780. }
  15781. /// Ranking list
  15782. /// ranking pointlist { <name>.24B <point>.L }*10
  15783. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15784. struct fame_list* list;
  15785. int i, size = MAX_FAME_LIST;
  15786. switch(rankingtype) {
  15787. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15788. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15789. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15790. // PK currently unsupported
  15791. case RANK_KILLER: list = NULL; size = 0; break;
  15792. default:
  15793. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15794. return;
  15795. }
  15796. //Packet size limits this list to 10 elements. [Skotlex]
  15797. for (i = 0; i < min(10,size); i++) {
  15798. if (list[i].id > 0) {
  15799. const char* name;
  15800. if (strcmp(list[i].name, "-") == 0 &&
  15801. (name = map_charid2nick(list[i].id)) != NULL)
  15802. {
  15803. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15804. } else {
  15805. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15806. }
  15807. } else {
  15808. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15809. }
  15810. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15811. }
  15812. for(;i < 10; i++) { //In case the MAX is less than 10.
  15813. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15814. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15815. }
  15816. }
  15817. /// Request for the blacksmith ranklist.
  15818. /// /blacksmith command sends this packet to the server.
  15819. /// 0217 (CZ_BLACKSMITH_RANK)
  15820. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15821. clif_ranklist(sd,RANK_BLACKSMITH);
  15822. }
  15823. /// Request for the alchemist ranklist.
  15824. /// /alchemist command sends this packet to the server.
  15825. /// 0218 (CZ_ALCHEMIST_RANK)
  15826. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15827. clif_ranklist(sd,RANK_ALCHEMIST);
  15828. }
  15829. /// Request for the taekwon ranklist.
  15830. /// /taekwon command sends this packet to the server.
  15831. /// 0225 (CZ_TAEKWON_RANK)
  15832. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15833. clif_ranklist(sd,RANK_TAEKWON);
  15834. }
  15835. /// Request for the killer ranklist.
  15836. /// /pk command sends this packet to the server.
  15837. /// 0237 (CZ_KILLER_RANK)
  15838. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15839. clif_ranklist(sd,RANK_KILLER);
  15840. }
  15841. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15842. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15843. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15844. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15845. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15846. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15847. enum e_rank rank;
  15848. #if PACKETVER < 20130710
  15849. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15850. short cmd;
  15851. switch( rankingType ){
  15852. case RANK_BLACKSMITH: cmd = 0x219; break;
  15853. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15854. case RANK_TAEKWON: cmd = 0x226; break;
  15855. case RANK_KILLER: cmd = 0x238; break;
  15856. default:
  15857. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15858. return;
  15859. }
  15860. // Can be safely casted here, since we validated it before
  15861. rank = (enum e_rank)rankingType;
  15862. WBUFW(buf,0) = cmd;
  15863. clif_sub_ranklist(buf,2,sd,rank);
  15864. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  15865. #else
  15866. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  15867. int mypoint = 0;
  15868. switch( rankingType ){
  15869. case RANK_BLACKSMITH:
  15870. case RANK_ALCHEMIST:
  15871. case RANK_TAEKWON:
  15872. case RANK_KILLER:
  15873. break;
  15874. default:
  15875. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15876. return;
  15877. }
  15878. // Can be safely casted here, since we validated it before
  15879. rank = (enum e_rank)rankingType;
  15880. WBUFW(buf,0) = 0x97d;
  15881. WBUFW(buf,2) = rank;
  15882. clif_sub_ranklist(buf,4,sd,rank);
  15883. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15884. case MAPID_BLACKSMITH:
  15885. case MAPID_ALCHEMIST:
  15886. case MAPID_TAEKWON:
  15887. mypoint = sd->status.fame;
  15888. }
  15889. WBUFL(buf,284) = mypoint; //mypoint
  15890. clif_send(buf, 288, &sd->bl, SELF);
  15891. #endif
  15892. }
  15893. /*
  15894. * 097c <type> (CZ_REQ_RANKING)
  15895. * type
  15896. * 0: /blacksmith
  15897. * 1: /alchemist
  15898. * 2: /taekwon
  15899. * 3: /pk
  15900. * */
  15901. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15902. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15903. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15904. clif_ranklist(sd,rankingtype);
  15905. }
  15906. /// Updates the fame rank points for the given ranking.
  15907. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  15908. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  15909. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  15910. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15911. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15912. int fd=sd->fd;
  15913. #if PACKETVER < 20130710
  15914. short cmd;
  15915. switch(rankingtype){
  15916. case RANK_BLACKSMITH: cmd = 0x21b; break;
  15917. case RANK_ALCHEMIST: cmd = 0x21c; break;
  15918. case RANK_TAEKWON: cmd = 0x224; break;
  15919. default:
  15920. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15921. return;
  15922. }
  15923. WFIFOHEAD(fd,packet_len(cmd));
  15924. WFIFOW(fd,0) = cmd;
  15925. WFIFOL(fd,2) = point;
  15926. WFIFOL(fd,6) = sd->status.fame;
  15927. WFIFOSET(fd, packet_len(cmd));
  15928. #else
  15929. WFIFOHEAD(fd,packet_len(0x97e));
  15930. WFIFOW(fd,0) = 0x97e;
  15931. WFIFOW(fd,2) = rankingtype;
  15932. WFIFOL(fd,4) = point;
  15933. WFIFOL(fd,8) = sd->status.fame;
  15934. WFIFOSET(fd,packet_len(0x97e));
  15935. #endif
  15936. }
  15937. /**
  15938. * Transmit personal information to player. (rates)
  15939. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15940. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15941. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15942. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15943. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15944. * FIXME!
  15945. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15946. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15947. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15948. */
  15949. #ifdef VIP_ENABLE
  15950. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15951. if (sd) {
  15952. struct s_packet_db* info;
  15953. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15954. int cmd = 0, fd, i = 0;
  15955. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15956. int details_bexp[PINFO_MAX];
  15957. int details_drop[PINFO_MAX];
  15958. int details_penalty[PINFO_MAX];
  15959. /**
  15960. * Set for EXP
  15961. */
  15962. //0:PCRoom
  15963. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  15964. if (details_bexp[0] == 100 || !details_bexp[0])
  15965. details_bexp[0] = 0;
  15966. else {
  15967. if (details_bexp[0] < 100) {
  15968. details_bexp[0] = 100 - details_bexp[0];
  15969. details_bexp[0] = 0 - details_bexp[0];
  15970. }
  15971. else
  15972. details_bexp[0] = details_bexp[0] - 100;
  15973. }
  15974. //1:Premium
  15975. if (pc_isvip(sd)) {
  15976. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  15977. if (details_bexp[1] < 0)
  15978. details_bexp[1] = 0 - details_bexp[1];
  15979. }
  15980. else
  15981. details_bexp[1] = 0;
  15982. //2:Server
  15983. details_bexp[2] = battle_config.base_exp_rate;
  15984. if (details_bexp[2] == 100)
  15985. details_bexp[2] = 0;
  15986. else {
  15987. if (details_bexp[2] < 100) {
  15988. details_bexp[2] = 100 - details_bexp[2];
  15989. details_bexp[2] = 0 - details_bexp[2];
  15990. }
  15991. else
  15992. details_bexp[2] = details_bexp[2] - 100;
  15993. }
  15994. //3:TPLUS
  15995. details_bexp[3] = 0;
  15996. /* End - EXP set*/
  15997. /**
  15998. * Set for Drop rate
  15999. */
  16000. //0:PCRoom
  16001. details_drop[0] = 0;
  16002. //1:Premium
  16003. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16004. if (pc_isvip(sd)) {
  16005. if (details_drop[1] < 0)
  16006. details_drop[1] = 0 - details_drop[1];
  16007. }
  16008. else
  16009. details_drop[1] = 0;
  16010. //2:Server
  16011. details_drop[2] = battle_config.item_rate_common;
  16012. if (details_drop[2] == 100)
  16013. details_drop[2] = 0;
  16014. else {
  16015. if (details_drop[2] < 100) {
  16016. details_drop[2] = 100 - details_drop[2];
  16017. details_drop[2] = 0 - details_drop[2];
  16018. }
  16019. else
  16020. details_drop[2] = details_drop[2] - 100;
  16021. }
  16022. //3:TPLUS
  16023. details_drop[3] = 0;
  16024. /* End - Drop set*/
  16025. /**
  16026. * Set for Penalty rate
  16027. */
  16028. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16029. //0:PCRoom
  16030. details_penalty[0] = 0;
  16031. //1:Premium
  16032. if (pc_isvip(sd)) {
  16033. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16034. if (details_penalty[1] == 100)
  16035. details_penalty[1] = 0;
  16036. else {
  16037. if (details_penalty[1] < 100) {
  16038. details_penalty[1] = 100 - details_penalty[1];
  16039. details_penalty[1] = 0 - details_penalty[1];
  16040. }
  16041. else
  16042. details_penalty[1] = details_penalty[1] - 100;
  16043. }
  16044. }
  16045. else
  16046. details_penalty[1] = 0;
  16047. //2:Server
  16048. details_penalty[2] = battle_config.death_penalty_base;
  16049. if (details_penalty[2] == 100)
  16050. details_penalty[2] = 0;
  16051. else {
  16052. if (details_penalty[2] < 100) {
  16053. details_penalty[2] = 100 - details_penalty[2];
  16054. details_penalty[2] = 0 - details_penalty[2];
  16055. }
  16056. else
  16057. details_penalty[2] = details_penalty[2] - 100;
  16058. }
  16059. //3:TPLUS
  16060. details_penalty[3] = 0;
  16061. /* End - Penalty set*/
  16062. cmd = packet_db_ack[cmdtype];
  16063. info = &packet_db[cmd];
  16064. len = info->len; //this is the base len without details
  16065. if(!len) return; //version as packet disable
  16066. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16067. szdetails = 7;
  16068. factor = 1;
  16069. }
  16070. else if (cmd == 0x097b) {
  16071. tot_baseexp *= factor;
  16072. tot_drop *= factor;
  16073. tot_penalty *= factor;
  16074. }
  16075. fd = sd->fd;
  16076. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16077. WFIFOW(fd,0) = cmd;
  16078. for (i = 0; i < maxinfotype; i++) {
  16079. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16080. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16081. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16082. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16083. tot_baseexp += details_bexp[i]*factor;
  16084. tot_drop += details_penalty[i]*factor;
  16085. tot_penalty += details_drop[i]*factor;
  16086. len += szdetails;
  16087. }
  16088. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16089. if (cmd == 0x08cb) { //0x08cb version
  16090. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16091. WFIFOW(fd,info->pos[2]) = tot_drop;
  16092. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16093. }
  16094. else { //2013-08-07aRagexe uses 0x097b
  16095. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16096. WFIFOL(fd,info->pos[2]) = tot_drop;
  16097. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16098. }
  16099. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16100. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16101. WFIFOSET(fd,len);
  16102. }
  16103. }
  16104. #endif
  16105. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16106. char cmd[30];
  16107. int t_aid = RFIFOL(fd,2);
  16108. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16109. is_atcommand(fd, sd, cmd, 1);
  16110. }
  16111. /**
  16112. * Marks Crimson Marker target on mini-map to the caster
  16113. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16114. * @param fd
  16115. * @param bl Crimson Marker target
  16116. **/
  16117. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16118. struct s_packet_db* info;
  16119. int cmd = 0;
  16120. int16 len;
  16121. unsigned char buf[11];
  16122. nullpo_retv(sd);
  16123. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16124. if (!cmd)
  16125. cmd = 0x09C1; //default
  16126. info = &packet_db[cmd];
  16127. if (!(len = info->len))
  16128. return;
  16129. WBUFW(buf, 0) = cmd;
  16130. WBUFL(buf, info->pos[0]) = bl->id;
  16131. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16132. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16133. clif_send(buf, len, &sd->bl, SELF);
  16134. }
  16135. /**
  16136. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16137. **/
  16138. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16139. struct s_packet_db *info = NULL;
  16140. int cmd = 0;
  16141. nullpo_retv(sd);
  16142. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16143. info = &packet_db[cmd];
  16144. if (!cmd || !info->len)
  16145. return;
  16146. WFIFOHEAD(sd->fd, info->len);
  16147. WFIFOW(sd->fd, 0) = cmd;
  16148. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16149. WFIFOSET(sd->fd, info->len);
  16150. }
  16151. /**
  16152. * [Ind/Hercules]
  16153. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16154. **/
  16155. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16156. char buf[256];
  16157. size_t len;
  16158. nullpo_retv(bl);
  16159. if(!message)
  16160. return;
  16161. len = strlen(message)+1;
  16162. if( len > sizeof(buf)-8 ) {
  16163. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16164. len = sizeof(buf)-8;
  16165. }
  16166. WBUFW(buf,0) = 0x8b3;
  16167. WBUFW(buf,2) = (uint16)(len+8);
  16168. WBUFL(buf,4) = bl->id;
  16169. safestrncpy(WBUFCP(buf,8), message, len);
  16170. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16171. }
  16172. /**
  16173. * [Ind/Hercules]
  16174. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16175. **/
  16176. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16177. unsigned char buf[10];
  16178. nullpo_retv(sd);
  16179. WBUFW(buf,0) = 0x7fc;
  16180. WBUFL(buf,2) = prev_leader_aid;
  16181. WBUFL(buf,6) = new_leader_aid;
  16182. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16183. }
  16184. /**
  16185. * Sends a clan message to a player
  16186. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16187. **/
  16188. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16189. #if PACKETVER >= 20131223
  16190. struct map_session_data *sd;
  16191. uint8 buf[256];
  16192. if( len == 0 ){
  16193. return;
  16194. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16195. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16196. len = sizeof(buf)-5-NAME_LENGTH;
  16197. }
  16198. WBUFW(buf, 0) = 0x98e;
  16199. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16200. // 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
  16201. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16202. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16203. if((sd = clan_getavailablesd(clan)) != NULL)
  16204. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16205. #endif
  16206. }
  16207. /**
  16208. * Parses a clan message from a player.
  16209. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16210. **/
  16211. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16212. #if PACKETVER >= 20131223
  16213. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16214. // validate packet and retrieve name and message
  16215. if( !clif_process_message(sd, false, name, message, output ) )
  16216. return;
  16217. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16218. #endif
  16219. }
  16220. /**
  16221. * Sends the basic clan informations to the client.
  16222. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16223. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16224. **/
  16225. void clif_clan_basicinfo( struct map_session_data *sd ){
  16226. #if PACKETVER >= 20131223
  16227. int fd, offset, length, i, flag;
  16228. struct clan* clan;
  16229. char mapname[MAP_NAME_LENGTH_EXT];
  16230. nullpo_retv( sd );
  16231. nullpo_retv( clan = sd->clan );
  16232. // Check if the player has a valid session and is not autotrading
  16233. if( !clif_session_isValid( sd ) ){
  16234. return;
  16235. }
  16236. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16237. fd = sd->fd;
  16238. WFIFOHEAD(fd,length);
  16239. memset( WFIFOP(fd, 0), 0, length );
  16240. WFIFOW( fd, 0 ) = 0x98a;
  16241. WFIFOL( fd, 4 ) = clan->id;
  16242. offset = 8;
  16243. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16244. offset += NAME_LENGTH;
  16245. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16246. offset += NAME_LENGTH;
  16247. mapindex_getmapname_ext( clan->map, mapname );
  16248. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16249. offset += MAP_NAME_LENGTH_EXT;
  16250. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16251. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16252. for( flag = 0; flag < 2; flag++ ){
  16253. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16254. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16255. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16256. offset += NAME_LENGTH;
  16257. }
  16258. }
  16259. }
  16260. WFIFOW( fd, 2 ) = offset;
  16261. WFIFOSET(fd,offset);
  16262. #endif
  16263. }
  16264. /**
  16265. * Updates the online and maximum player count of a clan.
  16266. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16267. **/
  16268. void clif_clan_onlinecount( struct clan* clan ){
  16269. #if PACKETVER >= 20131223
  16270. uint8 buf[6];
  16271. struct map_session_data *sd;
  16272. WBUFW(buf,0) = 0x988;
  16273. WBUFW(buf,2) = clan->connect_member;
  16274. WBUFW(buf,4) = clan->max_member;
  16275. if((sd = clan_getavailablesd(clan)) != NULL)
  16276. clif_send(buf, 6, &sd->bl, CLAN);
  16277. #endif
  16278. }
  16279. /**
  16280. * Notifies the client that the player has left his clan.
  16281. * 0989 (ZC_ACK_CLAN_LEAVE)
  16282. **/
  16283. void clif_clan_leave( struct map_session_data* sd ){
  16284. #if PACKETVER >= 20131223
  16285. int fd;
  16286. nullpo_retv( sd );
  16287. if( !clif_session_isValid( sd ) ){
  16288. return;
  16289. }
  16290. fd = sd->fd;
  16291. WFIFOHEAD(fd,2);
  16292. WFIFOW(fd,0) = 0x989;
  16293. WFIFOSET(fd,2);
  16294. #endif
  16295. }
  16296. /**
  16297. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16298. * 0A2F <result>.B <title_id>.L
  16299. */
  16300. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16301. {
  16302. #if PACKETVER >= 20150513
  16303. int fd;
  16304. nullpo_retv(sd);
  16305. if (!clif_session_isValid(sd))
  16306. return;
  16307. fd = sd->fd;
  16308. WFIFOHEAD(fd, packet_len(0xa2f));
  16309. WFIFOW(fd, 0) = 0xa2f;
  16310. WFIFOB(fd, 2) = result;
  16311. WFIFOL(fd, 3) = title_id;
  16312. WFIFOSET(fd, packet_len(0xa2f));
  16313. #endif
  16314. }
  16315. /**
  16316. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16317. * 0A2E <title_id>.L
  16318. */
  16319. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16320. {
  16321. int title_id;
  16322. nullpo_retv(sd);
  16323. title_id = RFIFOL(fd, 2);
  16324. if( title_id == sd->status.title_id ){
  16325. // It is exactly the same as the old one
  16326. return;
  16327. }else if( title_id <= 0 ){
  16328. sd->status.title_id = 0;
  16329. }else{
  16330. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16331. clif_change_title_ack(sd, 1, title_id);
  16332. return;
  16333. }
  16334. sd->status.title_id = title_id;
  16335. }
  16336. clif_name_area(&sd->bl);
  16337. clif_change_title_ack(sd, 0, title_id);
  16338. }
  16339. #ifdef DUMP_UNKNOWN_PACKET
  16340. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16341. {
  16342. const char* packet_txt = "save/packet.txt";
  16343. FILE* fp;
  16344. time_t time_server;
  16345. struct tm *datetime;
  16346. char datestr[512];
  16347. time(&time_server); // get time in seconds since 1/1/1970
  16348. datetime = localtime(&time_server); // convert seconds in structure
  16349. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16350. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16351. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16352. if( sd ) {
  16353. 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);
  16354. } else {
  16355. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16356. }
  16357. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16358. fprintf(fp, "\n");
  16359. fclose(fp);
  16360. } else {
  16361. ShowError("Failed to write '%s'.\n", packet_txt);
  16362. // Dump on console instead
  16363. if( sd ) {
  16364. 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);
  16365. } else {
  16366. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16367. }
  16368. ShowDump(RFIFOP(fd,0), packet_len);
  16369. }
  16370. }
  16371. #endif
  16372. /// Roulette System
  16373. /// Author: Yommy
  16374. /// Opens the roulette window
  16375. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16376. void clif_roulette_open( struct map_session_data* sd ){
  16377. nullpo_retv(sd);
  16378. int fd = sd->fd;
  16379. WFIFOHEAD(fd,packet_len(0xa1a));
  16380. WFIFOW(fd,0) = 0xa1a;
  16381. WFIFOB(fd,2) = 0; // result
  16382. WFIFOL(fd,3) = 0; // serial
  16383. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16384. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16385. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  16386. WFIFOL(fd,11) = sd->roulette_point.gold;
  16387. WFIFOL(fd,15) = sd->roulette_point.silver;
  16388. WFIFOL(fd,19) = sd->roulette_point.bronze;
  16389. WFIFOSET(fd,packet_len(0xa1a));
  16390. }
  16391. /// Request to open the roulette window
  16392. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16393. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16394. nullpo_retv(sd);
  16395. if (!battle_config.feature_roulette) {
  16396. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16397. return;
  16398. }
  16399. clif_roulette_open(sd);
  16400. }
  16401. /// Sends the info about the available roulette rewards to the client
  16402. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16403. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16404. void clif_roulette_info( struct map_session_data* sd ){
  16405. nullpo_retv(sd);
  16406. int fd = sd->fd;
  16407. int len = 8; // Initialize to header size
  16408. #if PACKETVER < 20180516
  16409. int size = 8;
  16410. #else
  16411. int size = 12;
  16412. #endif
  16413. for( int i = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16414. len += (MAX_ROULETTE_COLUMNS - i) * size;
  16415. }
  16416. WFIFOHEAD(fd,len);
  16417. WFIFOW(fd,0) = 0xa1c;
  16418. WFIFOW(fd,2) = len;
  16419. WFIFOL(fd,4) = 1; // serial
  16420. for(int i = 0, offset = 8; i < MAX_ROULETTE_LEVEL; i++) {
  16421. for(int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  16422. WFIFOW(fd,offset + 0) = i;
  16423. WFIFOW(fd,offset + 2) = j;
  16424. #if PACKETVER < 20180516
  16425. WFIFOW(fd,offset + 4) = rd.nameid[i][j];
  16426. WFIFOW(fd,offset + 6) = rd.qty[i][j];
  16427. #else
  16428. WFIFOL(fd,offset + 4) = rd.nameid[i][j];
  16429. WFIFOL(fd,offset + 8) = rd.qty[i][j];
  16430. #endif
  16431. offset += size;
  16432. }
  16433. }
  16434. WFIFOSET(fd,len);
  16435. }
  16436. /// Request the roulette reward data
  16437. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16438. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16439. nullpo_retv(sd);
  16440. if (!battle_config.feature_roulette) {
  16441. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16442. return;
  16443. }
  16444. clif_roulette_info(sd);
  16445. }
  16446. /// Notification of the client that the roulette window was closed
  16447. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16448. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16449. nullpo_retv(sd);
  16450. if (!battle_config.feature_roulette) {
  16451. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16452. return;
  16453. }
  16454. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16455. }
  16456. /// Response to a item reward request
  16457. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16458. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16459. #if PACKETVER >= 20141016
  16460. nullpo_retv(sd);
  16461. int fd = sd->fd;
  16462. WFIFOHEAD(fd,packet_len(0xa22));
  16463. WFIFOW(fd,0) = 0xa22;
  16464. WFIFOB(fd,2) = type;
  16465. WFIFOW(fd,3) = 0; //! TODO: Additional item
  16466. WFIFOSET(fd,packet_len(0xa22));
  16467. #endif
  16468. }
  16469. /**
  16470. * Claim roulette reward
  16471. * @param sd Player
  16472. * @return 0:Success
  16473. **/
  16474. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16475. struct item it;
  16476. uint8 res = 1;
  16477. nullpo_retr(1, sd);
  16478. if (sd->roulette.prizeIdx < 0)
  16479. return RECV_ITEM_FAILED;
  16480. memset(&it, 0, sizeof(it));
  16481. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16482. it.identify = 1;
  16483. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16484. ; // onSuccess
  16485. }
  16486. sd->roulette.claimPrize = false;
  16487. sd->roulette.prizeStage = 0;
  16488. sd->roulette.prizeIdx = -1;
  16489. sd->roulette.stage = 0;
  16490. return res;
  16491. }
  16492. /// Update Roulette window with current stats
  16493. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16494. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID ){
  16495. nullpo_retv(sd);
  16496. int fd = sd->fd;
  16497. WFIFOHEAD(fd,packet_len(0xa20));
  16498. WFIFOW(fd,0) = 0xa20;
  16499. WFIFOB(fd,2) = result;
  16500. WFIFOW(fd,3) = stage;
  16501. WFIFOW(fd,5) = prizeIdx;
  16502. WFIFOW(fd,7) = bonusItemID;
  16503. WFIFOL(fd,9) = sd->roulette_point.gold;
  16504. WFIFOL(fd,13) = sd->roulette_point.silver;
  16505. WFIFOL(fd,17) = sd->roulette_point.bronze;
  16506. WFIFOSET(fd,packet_len(0xa20));
  16507. }
  16508. /// Request to start the roulette
  16509. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16510. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16511. enum GENERATE_ROULETTE_ACK result;
  16512. nullpo_retv(sd);
  16513. if (!battle_config.feature_roulette) {
  16514. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16515. return;
  16516. }
  16517. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16518. return;
  16519. }
  16520. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16521. sd->roulette.stage = 0;
  16522. sd->roulette.claimPrize = false;
  16523. sd->roulette.prizeStage = 0;
  16524. sd->roulette.prizeIdx = -1;
  16525. }
  16526. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16527. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16528. }else{
  16529. if (!sd->roulette.stage) {
  16530. if (sd->roulette_point.bronze > 0) {
  16531. sd->roulette_point.bronze -= 1;
  16532. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16533. } else if (sd->roulette_point.silver > 9) {
  16534. sd->roulette_point.silver -= 10;
  16535. sd->roulette.stage = 2;
  16536. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16537. } else if (sd->roulette_point.gold > 9) {
  16538. sd->roulette_point.gold -= 10;
  16539. sd->roulette.stage = 4;
  16540. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16541. }
  16542. }
  16543. sd->roulette.prizeStage = sd->roulette.stage;
  16544. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16545. sd->roulette.claimPrize = true;
  16546. sd->roulette.tick = gettick() + max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16547. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16548. result = GENERATE_ROULETTE_LOSING;
  16549. sd->roulette.stage = 0;
  16550. }else{
  16551. result = GENERATE_ROULETTE_SUCCESS;
  16552. sd->roulette.stage++;
  16553. }
  16554. }
  16555. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16556. }
  16557. /// Request to claim a prize
  16558. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16559. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16560. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16561. nullpo_retv(sd);
  16562. if (!battle_config.feature_roulette) {
  16563. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16564. return;
  16565. }
  16566. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16567. return;
  16568. }
  16569. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16570. switch (clif_roulette_getitem(sd)) {
  16571. case ADDITEM_SUCCESS:
  16572. type = RECV_ITEM_SUCCESS;
  16573. break;
  16574. case ADDITEM_INVALID:
  16575. case ADDITEM_OVERITEM:
  16576. case ADDITEM_OVERAMOUNT:
  16577. type = RECV_ITEM_OVERCOUNT;
  16578. break;
  16579. case ADDITEM_OVERWEIGHT:
  16580. type = RECV_ITEM_OVERWEIGHT;
  16581. break;
  16582. case ADDITEM_STACKLIMIT:
  16583. default:
  16584. type = RECV_ITEM_FAILED;
  16585. break;
  16586. }
  16587. }
  16588. clif_roulette_recvitem_ack(sd,type);
  16589. }
  16590. /// MERGE ITEM
  16591. /**
  16592. * Acknowledge the client about item merger result
  16593. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16594. * @param fd
  16595. * @param sd
  16596. **/
  16597. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16598. unsigned char buf[9];
  16599. struct s_packet_db *info = NULL;
  16600. short cmd = 0;
  16601. nullpo_retv(sd);
  16602. if (!clif_session_isValid(sd))
  16603. return;
  16604. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16605. return;
  16606. if (!(info = &packet_db[cmd]) || info->len == 0)
  16607. return;
  16608. WBUFW(buf, 0) = cmd;
  16609. WBUFW(buf, info->pos[0]) = index;
  16610. WBUFW(buf, info->pos[1]) = count;
  16611. WBUFB(buf, info->pos[2]) = type;
  16612. clif_send(buf, info->len, &sd->bl, SELF);
  16613. }
  16614. /**
  16615. * Check if item has the pair to be merged
  16616. * @param sd
  16617. * @param it Item
  16618. * @return True if has pair, False if not
  16619. **/
  16620. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16621. struct item *it_;
  16622. unsigned short i;
  16623. nullpo_retr(false, sd);
  16624. 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);
  16625. if (i < MAX_INVENTORY)
  16626. return true;
  16627. return false;
  16628. }
  16629. /**
  16630. * Check if item can be merged
  16631. * @param id Item Data
  16632. * @param it Item
  16633. * @return True if can be merged, False if not
  16634. **/
  16635. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16636. if (!id || !it)
  16637. return false;
  16638. if (id->type == IT_CASH)
  16639. return false;
  16640. if (!itemdb_isstackable2(id))
  16641. return false;
  16642. if (itemdb_isspecial(it->card[0]))
  16643. return false;
  16644. if (!it->unique_id)
  16645. return false;
  16646. return true;
  16647. }
  16648. /**
  16649. * Open available item to be merged.
  16650. * Only show 1 item in 1 process.
  16651. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16652. * @param sd
  16653. **/
  16654. void clif_merge_item_open(struct map_session_data *sd) {
  16655. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16656. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16657. int len = 0;
  16658. struct s_packet_db *info = NULL;
  16659. struct item *it;
  16660. nullpo_retv(sd);
  16661. if (!clif_session_isValid(sd))
  16662. return;
  16663. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16664. return;
  16665. if (!(info = &packet_db[cmd]) || info->len == 0)
  16666. return;
  16667. // Get entries
  16668. for (i = 0; i < MAX_INVENTORY; i++) {
  16669. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16670. continue;
  16671. if (clif_merge_item_has_pair(sd, it))
  16672. indexes[n++] = i;
  16673. }
  16674. if (n < 2) { // No item need to be merged
  16675. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16676. return;
  16677. }
  16678. WBUFW(buf, 0) = cmd;
  16679. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16680. for (i = 0; i < n; i++) {
  16681. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16682. }
  16683. clif_send(buf, len, &sd->bl, SELF);
  16684. }
  16685. /**
  16686. * Process item merger
  16687. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16688. * @param fd
  16689. * @param sd
  16690. **/
  16691. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16692. struct s_packet_db *info = NULL;
  16693. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16694. unsigned int count = 0;
  16695. struct item_data *id = NULL;
  16696. nullpo_retv(sd);
  16697. if (!clif_session_isValid(sd))
  16698. return;
  16699. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16700. return;
  16701. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16702. if (n < 2) { // No item need to be merged
  16703. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16704. return;
  16705. }
  16706. for (i = 0, j = 0; i < n; i++) {
  16707. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16708. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16709. continue;
  16710. indexes[j] = idx;
  16711. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16712. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16713. return;
  16714. }
  16715. count += sd->inventory.u.items_inventory[idx].amount;
  16716. j++;
  16717. }
  16718. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16719. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16720. return;
  16721. }
  16722. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16723. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16724. return;
  16725. }
  16726. // Merrrrge!!!!
  16727. for (i = 1; i < n; i++) {
  16728. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16729. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16730. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16731. sd->inventory_data[idx] = NULL;
  16732. clif_delitem(sd, idx, amt, 0);
  16733. }
  16734. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16735. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16736. }
  16737. /**
  16738. * Cancel item merge
  16739. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16740. * @param fd
  16741. * @param sd
  16742. **/
  16743. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16744. return; // Nothing todo yet
  16745. }
  16746. /**
  16747. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16748. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16749. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  16750. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16751. **/
  16752. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type) {
  16753. unsigned char buf[9 + NAME_LENGTH * 2];
  16754. unsigned short cmd = 0;
  16755. struct s_packet_db *info = NULL;
  16756. if (!(cmd = packet_db_ack[ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  16757. return;
  16758. if (!(info = &packet_db[cmd]) || info->len == 0)
  16759. return;
  16760. WBUFW(buf, 0) = 0x7fd;
  16761. WBUFB(buf, 4) = type;
  16762. WBUFW(buf, 5) = nameid;
  16763. WBUFB(buf, 7) = NAME_LENGTH;
  16764. if (battle_config.broadcast_hide_name) {
  16765. std::string dispname = std::string(char_name);
  16766. int hide = min(battle_config.broadcast_hide_name, dispname.length() - 1);
  16767. dispname.replace(dispname.length() - hide, hide, hide, '*');
  16768. safestrncpy(WBUFCP(buf, 8), dispname.c_str(), NAME_LENGTH);
  16769. }
  16770. else
  16771. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  16772. switch (type) {
  16773. case ITEMOBTAIN_TYPE_BOXITEM:
  16774. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  16775. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  16776. WBUFW(buf, 9 + NAME_LENGTH) = container;
  16777. break;
  16778. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16779. {
  16780. struct mob_db *db = mob_db(container);
  16781. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  16782. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  16783. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  16784. }
  16785. break;
  16786. case ITEMOBTAIN_TYPE_NPC:
  16787. default:
  16788. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  16789. break;
  16790. }
  16791. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  16792. }
  16793. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16794. /// 0A02 <view>.W
  16795. /// Value <flag> has the following effects:
  16796. /// 1: Open a Dress Room window.
  16797. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16798. #if PACKETVER >= 20150513
  16799. int fd = sd->fd;
  16800. nullpo_retv(sd);
  16801. WFIFOHEAD(fd, packet_len(0xa02));
  16802. WFIFOW(fd,0) = 0xa02;
  16803. WFIFOW(fd,2) = flag;
  16804. WFIFOSET(fd, packet_len(0xa02));
  16805. #endif
  16806. }
  16807. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16808. /// 0A35 <result>.W
  16809. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16810. #if PACKETVER >= 20150513
  16811. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16812. // Ignore the request
  16813. // - Invalid item index
  16814. // - Invalid item ID or item doesn't exist
  16815. // - Item is already identified
  16816. if (idx < 0 || idx >= MAX_INVENTORY ||
  16817. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16818. sd->inventory.u.items_inventory[idx].identify)
  16819. return;
  16820. // Ignore the request - No magnifiers in inventory
  16821. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16822. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16823. return;
  16824. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16825. return;
  16826. skill_identify(sd, idx);
  16827. #endif
  16828. }
  16829. /// Starts navigation to the given target on client side
  16830. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16831. #if PACKETVER >= 20111010
  16832. int fd = sd->fd;
  16833. WFIFOHEAD(fd,27);
  16834. WFIFOW(fd,0) = 0x08e2;
  16835. // How detailed will our navigation be?
  16836. if( mob_id > 0 ){
  16837. x = 0;
  16838. y = 0;
  16839. WFIFOB(fd,2) = 3; // monster with destination field
  16840. }else if( x > 0 && y > 0 ){
  16841. WFIFOB(fd,2) = 0; // with coordinates
  16842. }else{
  16843. x = 0;
  16844. y = 0;
  16845. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16846. }
  16847. // Which services can be used for transportation?
  16848. WFIFOB(fd,3) = flag;
  16849. // If this flag is set, the navigation window will not be opened up
  16850. WFIFOB(fd,4) = hideWindow;
  16851. // Target map
  16852. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  16853. // Target x
  16854. WFIFOW(fd,21) = x;
  16855. // Target y
  16856. WFIFOW(fd,23) = y;
  16857. // Target monster ID
  16858. WFIFOW(fd,25) = mob_id;
  16859. WFIFOSET(fd,27);
  16860. #endif
  16861. }
  16862. /// Send hat effects to the client (ZC_HAT_EFFECT).
  16863. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  16864. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  16865. #if PACKETVER >= 20150513
  16866. unsigned char* buf;
  16867. int len,i;
  16868. struct map_session_data *tsd;
  16869. struct block_list* tbl;
  16870. if( target == SELF ){
  16871. tsd = BL_CAST(BL_PC,bl);
  16872. tbl = &sd->bl;
  16873. }else{
  16874. tsd = sd;
  16875. tbl = bl;
  16876. }
  16877. if( !tsd->hatEffectCount )
  16878. return;
  16879. len = 9 + tsd->hatEffectCount * 2;
  16880. buf = (unsigned char*)aMalloc( len );
  16881. WBUFW(buf,0) = 0xa3b;
  16882. WBUFW(buf,2) = len;
  16883. WBUFL(buf,4) = tsd->bl.id;
  16884. WBUFB(buf,8) = 1;
  16885. for( i = 0; i < tsd->hatEffectCount; i++ ){
  16886. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  16887. }
  16888. clif_send(buf, len,tbl,target);
  16889. aFree(buf);
  16890. #endif
  16891. }
  16892. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  16893. #if PACKETVER >= 20150513
  16894. unsigned char buf[13];
  16895. WBUFW(buf,0) = 0xa3b;
  16896. WBUFW(buf,2) = 13;
  16897. WBUFL(buf,4) = sd->bl.id;
  16898. WBUFB(buf,8) = enable;
  16899. WBUFL(buf,9) = effectId;
  16900. clif_send(buf,13,&sd->bl,AREA);
  16901. #endif
  16902. }
  16903. /// Notify the client that a sale has started
  16904. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  16905. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16906. #if PACKETVER_SUPPORTS_SALES
  16907. unsigned char buf[8];
  16908. WBUFW(buf, 0) = 0x9b2;
  16909. WBUFW(buf, 2) = sale_item->nameid;
  16910. WBUFL(buf, 4) = (uint32)(sale_item->end - time(NULL)); // time in S
  16911. clif_send(buf, 8, bl, target);
  16912. #endif
  16913. }
  16914. /// Notify the clien that a sale has ended
  16915. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  16916. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16917. #if PACKETVER_SUPPORTS_SALES
  16918. unsigned char buf[4];
  16919. WBUFW(buf, 0) = 0x9b3;
  16920. WBUFW(buf, 2) = sale_item->nameid;
  16921. clif_send(buf, 4, bl, target);
  16922. #endif
  16923. }
  16924. /// Update the remaining amount of a sale item.
  16925. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  16926. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16927. #if PACKETVER_SUPPORTS_SALES
  16928. unsigned char buf[8];
  16929. WBUFW(buf, 0) = 0x9c4;
  16930. WBUFW(buf, 2) = sale_item->nameid;
  16931. WBUFL(buf, 4) = sale_item->amount;
  16932. clif_send(buf, 8, bl, target);
  16933. #endif
  16934. }
  16935. /// The client requested a refresh of the current remaining count of a sale item
  16936. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  16937. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  16938. #if PACKETVER_SUPPORTS_SALES
  16939. struct sale_item_data* sale;
  16940. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16941. return;
  16942. }
  16943. sale = sale_find_item( RFIFOW(fd, 6), true );
  16944. if( sale == NULL ){
  16945. return;
  16946. }
  16947. clif_sale_amount(sale, &sd->bl, SELF);
  16948. #endif
  16949. }
  16950. /// Opens the sale administration window on the client
  16951. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  16952. void clif_sale_open( struct map_session_data* sd ){
  16953. #if PACKETVER_SUPPORTS_SALES
  16954. nullpo_retv(sd);
  16955. if( sd->state.sale_open ){
  16956. return;
  16957. }
  16958. sd->state.sale_open = true;
  16959. int fd = sd->fd;
  16960. WFIFOHEAD(fd, 2);
  16961. WFIFOW(fd, 0) = 0x9b5;
  16962. WFIFOSET(fd, 2);
  16963. #endif
  16964. }
  16965. /// Client request to open the sale administration window.
  16966. /// This is sent by /limitedsale
  16967. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  16968. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  16969. #if PACKETVER_SUPPORTS_SALES
  16970. nullpo_retv(sd);
  16971. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16972. return;
  16973. }
  16974. char command[CHAT_SIZE_MAX];
  16975. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  16976. is_atcommand(fd, sd, command, 1);
  16977. #endif
  16978. }
  16979. /// Closes the sale administration window on the client.
  16980. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  16981. void clif_sale_close(struct map_session_data* sd) {
  16982. #if PACKETVER_SUPPORTS_SALES
  16983. nullpo_retv(sd);
  16984. if( !sd->state.sale_open ){
  16985. return;
  16986. }
  16987. sd->state.sale_open = false;
  16988. int fd = sd->fd;
  16989. WFIFOHEAD(fd, 2);
  16990. WFIFOW(fd, 0) = 0x9bd;
  16991. WFIFOSET(fd, 2);
  16992. #endif
  16993. }
  16994. /// Client request to close the sale administration window.
  16995. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  16996. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  16997. #if PACKETVER_SUPPORTS_SALES
  16998. nullpo_retv(sd);
  16999. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17000. return;
  17001. }
  17002. clif_sale_close(sd);
  17003. #endif
  17004. }
  17005. /// Reply to a item search request for item sale administration.
  17006. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17007. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17008. #if PACKETVER_SUPPORTS_SALES
  17009. int fd = sd->fd;
  17010. WFIFOHEAD(fd, 10);
  17011. WFIFOW(fd, 0) = 0x9ad;
  17012. if( item != NULL ){
  17013. WFIFOW(fd, 2) = 0;
  17014. WFIFOW(fd, 4) = item->nameid;
  17015. WFIFOL(fd, 6) = item->price;
  17016. }else{
  17017. WFIFOW(fd, 2) = 1;
  17018. WFIFOW(fd, 4) = 0;
  17019. WFIFOL(fd, 6) = 0;
  17020. }
  17021. WFIFOSET(fd, 10);
  17022. #endif
  17023. }
  17024. /// Search request for an item sale administration.
  17025. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17026. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17027. #if PACKETVER_SUPPORTS_SALES
  17028. char item_name[ITEM_NAME_LENGTH];
  17029. struct item_data *id = NULL;
  17030. nullpo_retv(sd);
  17031. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17032. return;
  17033. }
  17034. if( !sd->state.sale_open ){
  17035. return;
  17036. }
  17037. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17038. id = itemdb_searchname(item_name);
  17039. if( id ){
  17040. int i;
  17041. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17042. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17043. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17044. return;
  17045. }
  17046. }
  17047. }
  17048. // not found
  17049. clif_sale_search_reply( sd, NULL );
  17050. #endif
  17051. }
  17052. /// Reply if an item was successfully put on sale or not.
  17053. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17054. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17055. #if PACKETVER_SUPPORTS_SALES
  17056. int fd = sd->fd;
  17057. WFIFOHEAD(fd, 4);
  17058. WFIFOW(fd, 0) = 0x9af;
  17059. WFIFOW(fd, 2) = (uint16)result;
  17060. WFIFOSET(fd, 4);
  17061. #endif
  17062. }
  17063. /// A client request to put an item on sale.
  17064. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17065. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W
  17066. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17067. #if PACKETVER_SUPPORTS_SALES
  17068. int32 count;
  17069. int16 nameid;
  17070. int startTime;
  17071. int endTime;
  17072. uint16 sellingHours;
  17073. nullpo_retv(sd);
  17074. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17075. return;
  17076. }
  17077. if( !sd->state.sale_open ){
  17078. return;
  17079. }
  17080. nameid = RFIFOW(fd, 6);
  17081. count = RFIFOL(fd, 8);
  17082. startTime = RFIFOL(fd, 12);
  17083. #if PACKETVER >= 20150520
  17084. if( RFIFOW(fd,0) == 0xa3d )
  17085. sellingHours = RFIFOW(fd, 16);
  17086. else
  17087. #endif
  17088. sellingHours = RFIFOB(fd, 16);
  17089. endTime = startTime + sellingHours * 60 * 60;
  17090. clif_sale_add_reply( sd, sale_add_item(nameid,count,startTime,endTime) );
  17091. #endif
  17092. }
  17093. /// Reply to an item removal from sale.
  17094. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17095. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17096. #if PACKETVER_SUPPORTS_SALES
  17097. int fd = sd->fd;
  17098. WFIFOHEAD(fd, 4);
  17099. WFIFOW(fd, 0) = 0x9b1;
  17100. WFIFOW(fd, 2) = failed;
  17101. WFIFOSET(fd, 4);
  17102. #endif
  17103. }
  17104. /// Request to remove an item from sale.
  17105. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17106. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17107. #if PACKETVER_SUPPORTS_SALES
  17108. nullpo_retv(sd);
  17109. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17110. return;
  17111. }
  17112. if( !sd->state.sale_open ){
  17113. return;
  17114. }
  17115. clif_sale_remove_reply(sd, !sale_remove_item(RFIFOW(fd, 6)));
  17116. #endif
  17117. }
  17118. /// Achievement System
  17119. /// Author: Luxuri, Aleos
  17120. /**
  17121. * Sends all achievement data to the client (ZC_ALL_AG_LIST).
  17122. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17123. */
  17124. void clif_achievement_list_all(struct map_session_data *sd)
  17125. {
  17126. int i, j, len, fd, *info;
  17127. uint16 count = 0;
  17128. nullpo_retv(sd);
  17129. if (!battle_config.feature_achievement) {
  17130. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17131. return;
  17132. }
  17133. fd = sd->fd;
  17134. count = sd->achievement_data.count; // All achievements should be sent to the client
  17135. len = (50 * count) + 22;
  17136. if (len <= 22)
  17137. return;
  17138. info = achievement_level(sd, true);
  17139. WFIFOHEAD(fd,len);
  17140. WFIFOW(fd, 0) = 0xa23;
  17141. WFIFOW(fd, 2) = len;
  17142. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17143. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17144. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17145. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17146. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17147. for (i = 0; i < count; i++) {
  17148. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17149. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17150. for (j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17151. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17152. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17153. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17154. }
  17155. WFIFOSET(fd, len);
  17156. }
  17157. /**
  17158. * Sends a single achievement's data to the client (ZC_AG_UPDATE).
  17159. * 0a24 <packetType>.W <ACHPoint>.L
  17160. */
  17161. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17162. {
  17163. int fd, i, *info;
  17164. nullpo_retv(sd);
  17165. if (!battle_config.feature_achievement) {
  17166. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17167. return;
  17168. }
  17169. fd = sd->fd;
  17170. info = achievement_level(sd, true);
  17171. WFIFOHEAD(fd, packet_len(0xa24));
  17172. WFIFOW(fd, 0) = 0xa24;
  17173. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17174. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17175. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17176. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17177. if (ach) {
  17178. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17179. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17180. for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17181. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17182. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17183. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17184. } else
  17185. memset(WFIFOP(fd, 16), 0, 40);
  17186. WFIFOSET(fd, packet_len(0xa24));
  17187. }
  17188. /**
  17189. * Checks if an achievement reward can be rewarded (CZ_REQ_AG_REWARD).
  17190. * 0a25 <packetType>.W <achievementID>.L
  17191. */
  17192. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17193. {
  17194. nullpo_retv(sd);
  17195. if( sd->achievement_data.save )
  17196. intif_achievement_save(sd);
  17197. achievement_check_reward(sd, RFIFOL(fd,2));
  17198. }
  17199. /**
  17200. * Returns the result of achievement_check_reward (ZC_REQ_AG_REWARD_ACK).
  17201. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17202. */
  17203. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17204. {
  17205. WFIFOHEAD(fd, packet_len(0xa26));
  17206. WFIFOW(fd, 0) = 0xa26;
  17207. WFIFOB(fd, 2) = result;
  17208. WFIFOL(fd, 3) = achievement_id;
  17209. WFIFOSET(fd, packet_len(0xa26));
  17210. }
  17211. /*
  17212. * This packet is sent by /changedress or /nocosplay
  17213. *
  17214. * 0ae8
  17215. */
  17216. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17217. #if PACKETVER >= 20180103
  17218. char command[CHAT_SIZE_MAX];
  17219. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17220. is_atcommand( fd, sd, command, 1 );
  17221. #endif
  17222. }
  17223. /// Opens an UI window of the given type and initializes it with the given data
  17224. /// 0AE2 <type>.B <data>.L
  17225. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17226. nullpo_retv(sd);
  17227. int fd = sd->fd;
  17228. WFIFOHEAD(fd,packet_len(0xae2));
  17229. WFIFOW(fd,0) = 0xae2;
  17230. WFIFOB(fd,2) = ui_type;
  17231. WFIFOL(fd,3) = data;
  17232. WFIFOSET(fd,packet_len(0xae2));
  17233. }
  17234. /// Request to open an UI window of the given type
  17235. /// 0A68 <type>.B
  17236. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17237. switch( RFIFOB(fd,2) ){
  17238. case IN_UI_ATTENDANCE:
  17239. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17240. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17241. }else if( pc_attendance_enabled() ){
  17242. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17243. }else{
  17244. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17245. }
  17246. break;
  17247. }
  17248. }
  17249. /// Response for attedance request
  17250. /// 0AF0 <unknown>.L <data>.L
  17251. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17252. nullpo_retv(sd);
  17253. int fd = sd->fd;
  17254. WFIFOHEAD(fd,packet_len(0xAF0));
  17255. WFIFOW(fd,0) = 0xAF0;
  17256. WFIFOL(fd,2) = 0;
  17257. WFIFOL(fd,6) = data;
  17258. WFIFOSET(fd,packet_len(0xAF0));
  17259. }
  17260. /// Request from the client to retrieve today's attendance reward
  17261. /// 0AEF
  17262. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17263. pc_attendance_claim_reward(sd);
  17264. }
  17265. /// Send out the percentage of weight that causes it to be displayed in red.
  17266. /// 0ADE <percentage>.L
  17267. void clif_weight_limit( struct map_session_data* sd ){
  17268. #if PACKETVER >= 20171025
  17269. nullpo_retv(sd);
  17270. int fd = sd->fd;
  17271. WFIFOHEAD(fd, packet_len(0xADE));
  17272. WFIFOW(fd, 0) = 0xADE;
  17273. #ifdef RENEWAL
  17274. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17275. #else
  17276. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17277. #endif
  17278. WFIFOSET(fd, packet_len(0xADE));
  17279. #endif
  17280. }
  17281. enum e_private_airship_response : uint32{
  17282. PRIVATEAIRSHIP_OK,
  17283. PRIVATEAIRSHIP_RETRY,
  17284. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17285. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17286. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17287. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17288. };
  17289. /// Send out the response to a private airship request
  17290. /// 0A4A <response>.L
  17291. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17292. #if PACKETVER >= 20180321
  17293. nullpo_retv( sd );
  17294. int fd = sd->fd;
  17295. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17296. WFIFOW( fd, 0 ) = 0xA4A;
  17297. WFIFOL( fd, 2 ) = response;
  17298. WFIFOSET( fd, packet_len( 0xA4A ) );
  17299. #endif
  17300. }
  17301. /// Parses a request for a private airship
  17302. /// 0A49 <mapname>.16B <itemid>.W
  17303. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17304. #if PACKETVER >= 20180321
  17305. // Check if the feature is enabled
  17306. if( !battle_config.feature_privateairship ){
  17307. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17308. return;
  17309. }
  17310. // Check if the player is allowed to warp from the source map
  17311. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17312. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17313. return;
  17314. }
  17315. char mapname[MAP_NAME_LENGTH_EXT];
  17316. safestrncpy( mapname, RFIFOCP( fd, 2 ), MAP_NAME_LENGTH_EXT );
  17317. int16 mapindex = mapindex_name2id( mapname );
  17318. // Check if we know the mapname
  17319. if( mapindex < 0 ){
  17320. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17321. return;
  17322. }
  17323. int16 mapid = map_mapindex2mapid( mapindex );
  17324. // Check if the map is available on this server
  17325. if( mapid < 0 ){
  17326. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17327. return;
  17328. }
  17329. // Check if the player tried to warp to the map he is on
  17330. if( sd->bl.m == mapid ){
  17331. // This is blocked by the client, but just to be sure
  17332. return;
  17333. }
  17334. // This can only be a hack, so we prevent it
  17335. if( map_getmapdata( mapid )->instance_id ){
  17336. // Ignore requests to warp directly into a running instance
  17337. return;
  17338. }
  17339. // Check if the player is allowed to warp to the target map
  17340. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17341. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17342. return;
  17343. }
  17344. uint16 item_id = RFIFOW( fd, 2 + MAP_NAME_LENGTH_EXT );
  17345. // Check if the item sent by the client is known to us
  17346. if( !itemdb_group_item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17347. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17348. return;
  17349. }
  17350. int idx = pc_search_inventory( sd, item_id );
  17351. // Check if the player has the item at all
  17352. if( idx < 0 ){
  17353. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17354. return;
  17355. }
  17356. // Delete the chosen item
  17357. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17358. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17359. return;
  17360. }
  17361. // Warp the player to a random spot on the destination map
  17362. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17363. #endif
  17364. }
  17365. /// Sends out the usage history of the guild storage
  17366. /// 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
  17367. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17368. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17369. #if PACKETVER >= 20140205
  17370. nullpo_retv( sd );
  17371. int fd = sd->fd;
  17372. int size = 8;
  17373. int sub = 83;
  17374. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17375. size += log.size() * sub;
  17376. }else{
  17377. log.clear();
  17378. }
  17379. WFIFOHEAD(fd, size);
  17380. WFIFOW(fd, 0) = 0x9DA;
  17381. WFIFOW(fd, 2) = size;
  17382. WFIFOW(fd, 4) = result;
  17383. WFIFOW(fd, 6) = (uint16)log.size();
  17384. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17385. for (int offset = 8, i = 0; i < log.size(); i++, offset += sub) {
  17386. struct guild_log_entry& entry = log[i];
  17387. uint16 viewid = itemdb_viewid( entry.item.nameid );
  17388. WFIFOL(fd, offset) = entry.id;
  17389. WFIFOW(fd, offset + 4) = viewid > 0 ? viewid : entry.item.nameid;
  17390. WFIFOL(fd, offset + 6) = (uint16)(entry.amount > 0 ? entry.amount : (entry.amount * -1));
  17391. WFIFOB(fd, offset + 10) = entry.amount > 0; // action = true(put), false(get)
  17392. WFIFOL(fd, offset + 11) = entry.item.refine;
  17393. WFIFOQ(fd, offset + 15) = entry.item.unique_id;
  17394. WFIFOB(fd, offset + 23) = entry.item.identify;
  17395. WFIFOW(fd, offset + 24) = itemtype(entry.item.nameid);
  17396. clif_addcards(WFIFOP(fd, offset + 26), &entry.item);
  17397. safestrncpy(WFIFOCP(fd, offset + 34), entry.name, NAME_LENGTH);
  17398. safestrncpy(WFIFOCP(fd, offset + 34 + NAME_LENGTH), entry.time, NAME_LENGTH);
  17399. WFIFOB(fd, offset + 34 + 2 * NAME_LENGTH) = entry.item.attribute;
  17400. }
  17401. }
  17402. WFIFOSET(fd, size);
  17403. #endif
  17404. }
  17405. /*==========================================
  17406. * Main client packet processing function
  17407. *------------------------------------------*/
  17408. static int clif_parse(int fd)
  17409. {
  17410. int cmd, packet_len;
  17411. TBL_PC* sd;
  17412. int pnum;
  17413. #ifdef PACKET_OBFUSCATION
  17414. int cmd2;
  17415. #endif
  17416. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17417. // Note: "click masters" can do 80+ clicks in 10 seconds
  17418. 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]
  17419. { // begin main client packet processing loop
  17420. sd = (TBL_PC *)session[fd]->session_data;
  17421. if (session[fd]->flag.eof) {
  17422. if (sd) {
  17423. if (sd->state.autotrade) {
  17424. //Disassociate character from the socket connection.
  17425. session[fd]->session_data = NULL;
  17426. sd->fd = 0;
  17427. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17428. } else
  17429. if (sd->state.active) {
  17430. // Player logout display [Valaris]
  17431. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17432. clif_quitsave(fd, sd);
  17433. } else {
  17434. //Unusual logout (during log on/off/map-changer procedure)
  17435. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17436. map_quit(sd);
  17437. }
  17438. } else {
  17439. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17440. }
  17441. do_close(fd);
  17442. return 0;
  17443. }
  17444. if (RFIFOREST(fd) < 2)
  17445. return 0;
  17446. cmd = RFIFOW(fd, 0);
  17447. #ifdef PACKET_OBFUSCATION
  17448. // Check if it is a player that tries to connect to the map server.
  17449. if( sd ){
  17450. // Decrypt the current packet ID with the last key stored in the session.
  17451. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17452. }else{
  17453. // Store the original value for checking
  17454. cmd2 = cmd;
  17455. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17456. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17457. }
  17458. #endif
  17459. // filter out invalid / unsupported packets
  17460. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17461. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17462. #ifdef DUMP_INVALID_PACKET
  17463. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17464. #endif
  17465. #ifdef PACKET_OBFUSCATION_WARN
  17466. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17467. if( !sd ){
  17468. #ifdef PACKET_OBFUSCATION
  17469. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17470. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17471. }
  17472. #else
  17473. // Try to use the initial keys for the decryption of the packet ID.
  17474. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17475. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17476. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17477. }
  17478. #endif
  17479. }
  17480. #endif
  17481. set_eof(fd);
  17482. return 0;
  17483. }
  17484. // determine real packet length
  17485. packet_len = packet_db[cmd].len;
  17486. if (packet_len == -1) { // variable-length packet
  17487. if (RFIFOREST(fd) < 4)
  17488. return 0;
  17489. packet_len = RFIFOW(fd,2);
  17490. if (packet_len < 4 || packet_len > 32768) {
  17491. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17492. #ifdef DUMP_INVALID_PACKET
  17493. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17494. #endif
  17495. set_eof(fd);
  17496. return 0;
  17497. }
  17498. }
  17499. if ((int)RFIFOREST(fd) < packet_len)
  17500. return 0; // not enough data received to form the packet
  17501. #ifdef PACKET_OBFUSCATION
  17502. RFIFOW(fd, 0) = cmd;
  17503. if (sd)
  17504. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17505. #endif
  17506. if( packet_db[cmd].func == clif_parse_debug )
  17507. packet_db[cmd].func(fd, sd);
  17508. else if( packet_db[cmd].func != NULL ) {
  17509. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17510. ; //Only valid packet when there is no session
  17511. else
  17512. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17513. ; //Only valid packet when player is not on a map
  17514. else
  17515. packet_db[cmd].func(fd, sd);
  17516. }
  17517. #ifdef DUMP_UNKNOWN_PACKET
  17518. else DumpUnknown(fd,sd,cmd,packet_len);
  17519. #endif
  17520. RFIFOSKIP(fd, packet_len);
  17521. }; // main loop end
  17522. return 0;
  17523. }
  17524. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17525. va_list argp;
  17526. int i;
  17527. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17528. return;
  17529. packet_db[cmd].len = length;
  17530. packet_db[cmd].func = func;
  17531. va_start(argp, func);
  17532. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17533. int offset = va_arg(argp, int);
  17534. if( offset == 0 ){
  17535. break;
  17536. }
  17537. packet_db[cmd].pos[i] = offset;
  17538. }
  17539. if( i == MAX_PACKET_POS ){
  17540. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17541. }
  17542. va_end(argp);
  17543. }
  17544. /*==========================================
  17545. * Reads packets and setups its array reference
  17546. *------------------------------------------*/
  17547. void packetdb_readdb(){
  17548. memset(packet_db,0,sizeof(packet_db));
  17549. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17550. #include "clif_packetdb.hpp"
  17551. #include "clif_shuffle.hpp"
  17552. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17553. #ifdef PACKET_OBFUSCATION
  17554. 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]);
  17555. #else
  17556. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17557. #endif
  17558. }
  17559. /*==========================================
  17560. *
  17561. *------------------------------------------*/
  17562. void do_init_clif(void) {
  17563. const char* colors[COLOR_MAX] = {
  17564. "0x00FF00",
  17565. "0xFF0000",
  17566. "0xFFFFFF",
  17567. "0xFFFF00",
  17568. "0x00FFFF",
  17569. "0xB5FFB5",
  17570. };
  17571. int i;
  17572. /**
  17573. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17574. **/
  17575. for(i = 0; i < COLOR_MAX; i++) {
  17576. color_table[i] = strtoul(colors[i],NULL,0);
  17577. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17578. }
  17579. packetdb_readdb();
  17580. set_defaultparse(clif_parse);
  17581. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  17582. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  17583. exit(EXIT_FAILURE);
  17584. }
  17585. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  17586. add_timer_func_list(clif_delayquit, "clif_delayquit");
  17587. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  17588. }
  17589. void do_final_clif(void) {
  17590. ers_destroy(delay_clearunit_ers);
  17591. }