clif.c 325 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/malloc.h"
  7. #include "../common/version.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/showmsg.h"
  10. #include "../common/strlib.h"
  11. #include "../common/utils.h"
  12. #include "map.h"
  13. #include "chrif.h"
  14. #include "pc.h"
  15. #include "status.h"
  16. #include "npc.h"
  17. #include "itemdb.h"
  18. #include "chat.h"
  19. #include "trade.h"
  20. #include "storage.h"
  21. #include "script.h"
  22. #include "skill.h"
  23. #include "atcommand.h"
  24. #include "charcommand.h"
  25. #include "intif.h"
  26. #include "battle.h"
  27. #include "mob.h"
  28. #include "party.h"
  29. #include "unit.h"
  30. #include "guild.h"
  31. #include "vending.h"
  32. #include "pet.h"
  33. #include "mercenary.h" //[orn]
  34. #include "log.h"
  35. #include "irc.h"
  36. #include "clif.h"
  37. #include "mail.h"
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdarg.h>
  42. #include <time.h>
  43. #define DUMP_UNKNOWN_PACKET 0
  44. struct Clif_Config {
  45. int packet_db_ver; //Preferred packet version.
  46. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  47. } clif_config;
  48. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  49. //Converts item type in case of pet eggs.
  50. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  51. #define WBUFPOS(p,pos,x,y,dir) \
  52. do { \
  53. uint8 *__p = (p); \
  54. __p+=(pos); \
  55. __p[0] = (uint8)((x)>>2); \
  56. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  57. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  58. } while(0)
  59. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  60. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  61. do { \
  62. uint8 *__p = (p); \
  63. __p+=(pos); \
  64. __p[0]=(uint8)((x0)>>2); \
  65. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  66. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  67. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  68. __p[4]=(uint8)(y1); \
  69. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  70. } while(0)
  71. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  72. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  73. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  74. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  75. //To idenfity disguised characters.
  76. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  77. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  78. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  79. static char map_ip_str[128];
  80. static uint32 map_ip;
  81. static uint32 bind_ip = INADDR_ANY;
  82. static uint16 map_port = 5121;
  83. int map_fd;
  84. //These two will be used to verify the incoming player's validity.
  85. //It helps identify their client packet version correctly. [Skotlex]
  86. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  87. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  88. int clif_parse (int fd);
  89. /*==========================================
  90. * map鯖のip設定
  91. *------------------------------------------*/
  92. int clif_setip(const char* ip)
  93. {
  94. char ip_str[16];
  95. map_ip = host2ip(ip);
  96. if (!map_ip) {
  97. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  98. return 0;
  99. }
  100. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  101. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  102. return 1;
  103. }
  104. void clif_setbindip(const char* ip)
  105. {
  106. char ip_str[16];
  107. bind_ip = host2ip(ip);
  108. if (bind_ip) {
  109. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  110. } else {
  111. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  112. }
  113. }
  114. /*==========================================
  115. * map鯖のport設定
  116. *------------------------------------------*/
  117. void clif_setport(uint16 port)
  118. {
  119. map_port = port;
  120. }
  121. /*==========================================
  122. * map鯖のip読み出し
  123. *------------------------------------------*/
  124. uint32 clif_getip(void)
  125. {
  126. return map_ip;
  127. }
  128. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  129. uint32 clif_refresh_ip(void)
  130. {
  131. uint32 new_ip;
  132. new_ip = host2ip(map_ip_str);
  133. if (new_ip && new_ip != map_ip) {
  134. map_ip = new_ip;
  135. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  136. return map_ip;
  137. }
  138. return 0;
  139. }
  140. /*==========================================
  141. * map鯖のport読み出し
  142. *------------------------------------------*/
  143. uint16 clif_getport(void)
  144. {
  145. return map_port;
  146. }
  147. /*==========================================
  148. * Counts connected players.
  149. *------------------------------------------*/
  150. int clif_countusers(void)
  151. {
  152. int users = 0, i;
  153. struct map_session_data *sd;
  154. for(i = 0; i < fd_max; i++) {
  155. if (session[i] && session[i]->func_parse == clif_parse &&
  156. (sd = (struct map_session_data*)session[i]->session_data) &&
  157. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  158. users++;
  159. }
  160. return users;
  161. }
  162. /*==========================================
  163. * 全てのclientに対してfunc()実行
  164. *------------------------------------------*/
  165. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  166. {
  167. int i;
  168. va_list ap;
  169. struct map_session_data *sd;
  170. va_start(ap,func);
  171. for(i = 0; i < fd_max; i++) {
  172. if ( session[i] && session[i]->func_parse == clif_parse) {
  173. sd = (struct map_session_data*)session[i]->session_data;
  174. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  175. func(sd, ap);
  176. }
  177. }
  178. va_end(ap);
  179. return 0;
  180. }
  181. /*==========================================
  182. * clif_sendでAREA*指定時用
  183. *------------------------------------------*/
  184. int clif_send_sub(struct block_list *bl, va_list ap)
  185. {
  186. struct block_list *src_bl;
  187. struct map_session_data *sd;
  188. unsigned char *buf;
  189. int len, type, fd;
  190. nullpo_retr(0, bl);
  191. nullpo_retr(0, ap);
  192. nullpo_retr(0, sd = (struct map_session_data *)bl);
  193. fd = sd->fd;
  194. if (!fd) //Don't send to disconnected clients.
  195. return 0;
  196. buf = va_arg(ap,unsigned char*);
  197. len = va_arg(ap,int);
  198. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  199. type = va_arg(ap,int);
  200. switch(type)
  201. {
  202. case AREA_WOS:
  203. if (bl == src_bl)
  204. return 0;
  205. break;
  206. case AREA_WOC:
  207. if (sd->chatID || bl == src_bl)
  208. return 0;
  209. break;
  210. case AREA_WOSC:
  211. {
  212. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  213. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  214. return 0;
  215. }
  216. break;
  217. }
  218. if (session[fd] != NULL) {
  219. WFIFOHEAD(fd, len);
  220. if (WFIFOP(fd,0) == buf) {
  221. printf("WARNING: Invalid use of clif_send function\n");
  222. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  223. printf(" Please correct your code.\n");
  224. // don't send to not move the pointer of the packet for next sessions in the loop
  225. WFIFOSET(fd,0);//## TODO is this ok?
  226. } else {
  227. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  228. memcpy(WFIFOP(fd,0), buf, len);
  229. WFIFOSET(fd,len);
  230. }
  231. }
  232. }
  233. return 0;
  234. }
  235. /*==========================================
  236. *
  237. *------------------------------------------*/
  238. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  239. {
  240. int i;
  241. struct map_session_data *sd;
  242. struct party_data *p = NULL;
  243. struct guild *g = NULL;
  244. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  245. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  246. nullpo_retr(0, bl);
  247. BL_CAST(BL_PC, bl, sd);
  248. switch(type) {
  249. case ALL_CLIENT: //All player clients.
  250. for (i = 0; i < fd_max; i++) {
  251. if (session[i] && session[i]->func_parse == clif_parse &&
  252. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  253. sd->state.auth) {
  254. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  255. WFIFOHEAD(i, len);
  256. memcpy(WFIFOP(i,0), buf, len);
  257. WFIFOSET(i,len);
  258. }
  259. }
  260. }
  261. break;
  262. case ALL_SAMEMAP: //All players on the same map
  263. for(i = 0; i < fd_max; i++) {
  264. if (session[i] && session[i]->func_parse == clif_parse &&
  265. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  266. sd->state.auth && sd->bl.m == bl->m) {
  267. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  268. WFIFOHEAD(i,len);
  269. memcpy(WFIFOP(i,0), buf, len);
  270. WFIFOSET(i,len);
  271. }
  272. }
  273. }
  274. break;
  275. case AREA:
  276. case AREA_WOSC:
  277. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  278. clif_send (buf, len, bl, SELF);
  279. case AREA_WOC:
  280. case AREA_WOS:
  281. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  282. BL_PC, buf, len, bl, type);
  283. break;
  284. case AREA_CHAT_WOC:
  285. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  286. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  287. break;
  288. case CHAT:
  289. case CHAT_WOS:
  290. {
  291. struct chat_data *cd;
  292. if (sd) {
  293. cd = (struct chat_data*)map_id2bl(sd->chatID);
  294. } else if (bl->type == BL_CHAT) {
  295. cd = (struct chat_data*)bl;
  296. } else break;
  297. if (cd == NULL)
  298. break;
  299. for(i = 0; i < cd->users; i++) {
  300. if (type == CHAT_WOS && cd->usersd[i] == sd)
  301. continue;
  302. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  303. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  304. {
  305. WFIFOHEAD(fd,len);
  306. memcpy(WFIFOP(fd,0), buf, len);
  307. WFIFOSET(fd,len);
  308. }
  309. }
  310. }
  311. }
  312. break;
  313. case CHAT_MAINCHAT: //[LuzZza]
  314. for(i=1; i<fd_max; i++) {
  315. if (session[i] && session[i]->func_parse == clif_parse &&
  316. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  317. sd->state.mainchat && !sd->chatID && (fd=sd->fd))
  318. {
  319. WFIFOHEAD(fd,len);
  320. memcpy(WFIFOP(fd,0), buf, len);
  321. WFIFOSET(fd, len);
  322. }
  323. }
  324. break;
  325. case PARTY_AREA:
  326. case PARTY_AREA_WOS:
  327. x0 = bl->x - AREA_SIZE;
  328. y0 = bl->y - AREA_SIZE;
  329. x1 = bl->x + AREA_SIZE;
  330. y1 = bl->y + AREA_SIZE;
  331. case PARTY:
  332. case PARTY_WOS:
  333. case PARTY_SAMEMAP:
  334. case PARTY_SAMEMAP_WOS:
  335. if (sd && sd->status.party_id)
  336. p = party_search(sd->status.party_id);
  337. if (p) {
  338. for(i=0;i<MAX_PARTY;i++){
  339. if ((sd = p->data[i].sd) == NULL)
  340. continue;
  341. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  342. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  343. continue;
  344. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  345. continue;
  346. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  347. continue;
  348. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  349. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  350. continue;
  351. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  352. WFIFOHEAD(fd,len);
  353. memcpy(WFIFOP(fd,0), buf, len);
  354. WFIFOSET(fd,len);
  355. }
  356. }
  357. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  358. break;
  359. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  360. if (session[i] && session[i]->func_parse == clif_parse &&
  361. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  362. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  363. {
  364. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  365. WFIFOHEAD(fd,len);
  366. memcpy(WFIFOP(fd,0), buf, len);
  367. WFIFOSET(fd,len);
  368. }
  369. }
  370. }
  371. }
  372. break;
  373. case DUEL:
  374. case DUEL_WOS:
  375. if (!sd || !sd->duel_group) break; //Invalid usage.
  376. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  377. for (i = 0; i < fd_max; i++) {
  378. if (session[i] && session[i]->func_parse == clif_parse &&
  379. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  380. sd->state.auth && sd->duel_group == x0) {
  381. if (type == DUEL_WOS && bl->id == sd->bl.id)
  382. continue;
  383. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  384. WFIFOHEAD(i, len);
  385. memcpy(WFIFOP(i,0), buf, len);
  386. WFIFOSET(i,len);
  387. }
  388. }
  389. }
  390. break;
  391. case SELF:
  392. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  393. WFIFOHEAD(fd,len);
  394. memcpy(WFIFOP(fd,0), buf, len);
  395. WFIFOSET(fd,len);
  396. }
  397. break;
  398. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  399. case GUILD_AREA:
  400. case GUILD_AREA_WOS:
  401. x0 = bl->x - AREA_SIZE;
  402. y0 = bl->y - AREA_SIZE;
  403. x1 = bl->x + AREA_SIZE;
  404. y1 = bl->y + AREA_SIZE;
  405. case GUILD_SAMEMAP:
  406. case GUILD_SAMEMAP_WOS:
  407. case GUILD:
  408. case GUILD_WOS:
  409. if (sd && sd->status.guild_id)
  410. g = guild_search(sd->status.guild_id);
  411. if (g) {
  412. for(i = 0; i < g->max_member; i++) {
  413. if ((sd = g->member[i].sd) != NULL) {
  414. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  415. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  416. continue;
  417. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  418. continue;
  419. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  420. continue;
  421. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  422. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  423. continue;
  424. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  425. WFIFOHEAD(fd,len);
  426. memcpy(WFIFOP(fd,0), buf, len);
  427. WFIFOSET(fd,len);
  428. }
  429. }
  430. }
  431. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  432. break;
  433. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  434. if (session[i] && session[i]->func_parse == clif_parse &&
  435. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  436. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  437. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  438. WFIFOHEAD(fd,len);
  439. memcpy(WFIFOP(fd,0), buf, len);
  440. WFIFOSET(fd,len);
  441. }
  442. }
  443. }
  444. }
  445. break;
  446. default:
  447. if (battle_config.error_log)
  448. ShowError("clif_send: Unrecognized type %d\n",type);
  449. return -1;
  450. }
  451. return 0;
  452. }
  453. //
  454. // パケット作って送信
  455. //
  456. /*==========================================
  457. *
  458. *------------------------------------------*/
  459. int clif_authok(struct map_session_data *sd)
  460. {
  461. int fd;
  462. if (!sd->fd)
  463. return 0;
  464. fd = sd->fd;
  465. WFIFOHEAD(fd, packet_len(0x73));
  466. WFIFOW(fd, 0) = 0x73;
  467. WFIFOL(fd, 2) = gettick();
  468. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  469. WFIFOB(fd, 9) = 5; // ignored
  470. WFIFOB(fd,10) = 5; // ignored
  471. WFIFOSET(fd,packet_len(0x73));
  472. return 0;
  473. }
  474. /*==========================================
  475. * Authentication failed/disconnect client.
  476. *------------------------------------------
  477. * The client closes it's socket and displays a message according to type:
  478. * 1 - server closed -> MsgStringTable[4]
  479. * 2 - ID already logged in -> MsgStringTable[5]
  480. * 3 - timeout/too much lag -> MsgStringTable[241]
  481. * 4 - server full -> MsgStringTable[264]
  482. * 5 - underaged -> MsgStringTable[305]
  483. * 9 - too many connections from this ip -> MsgStringTable[529]
  484. * 10 - out of available time paid for -> MsgStringTable[530]
  485. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  486. * other - disconnected -> MsgStringTable[3]
  487. */
  488. int clif_authfail_fd(int fd, int type)
  489. {
  490. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  491. return 0;
  492. WFIFOHEAD(fd, packet_len(0x81));
  493. WFIFOW(fd,0) = 0x81;
  494. WFIFOB(fd,2) = type;
  495. WFIFOSET(fd,packet_len(0x81));
  496. clif_setwaitclose(fd);
  497. return 0;
  498. }
  499. /*==========================================
  500. * Used to know which is the max valid account/char id [Skotlex]
  501. *------------------------------------------*/
  502. void clif_updatemaxid(int account_id, int char_id)
  503. {
  504. max_account_id = account_id;
  505. max_char_id = char_id;
  506. }
  507. /*==========================================
  508. *
  509. *------------------------------------------*/
  510. int clif_charselectok(int id)
  511. {
  512. struct map_session_data* sd;
  513. int fd;
  514. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  515. return 1;
  516. fd = sd->fd;
  517. WFIFOHEAD(fd,packet_len(0xb3));
  518. WFIFOW(fd,0) = 0xb3;
  519. WFIFOB(fd,2) = 1;
  520. WFIFOSET(fd,packet_len(0xb3));
  521. return 0;
  522. }
  523. /*==========================================
  524. * Makes an item appear on the ground
  525. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  526. *------------------------------------------*/
  527. int clif_dropflooritem(struct flooritem_data* fitem)
  528. {
  529. uint8 buf[17];
  530. int view;
  531. nullpo_retr(0, fitem);
  532. if (fitem->item_data.nameid <= 0)
  533. return 0;
  534. WBUFW(buf, 0) = 0x9e;
  535. WBUFL(buf, 2) = fitem->bl.id;
  536. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  537. WBUFB(buf, 8) = fitem->item_data.identify;
  538. WBUFW(buf, 9) = fitem->bl.x;
  539. WBUFW(buf,11) = fitem->bl.y;
  540. WBUFB(buf,13) = fitem->subx;
  541. WBUFB(buf,14) = fitem->suby;
  542. WBUFW(buf,15) = fitem->item_data.amount;
  543. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  544. return 0;
  545. }
  546. /*==========================================
  547. *
  548. *------------------------------------------*/
  549. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  550. {
  551. unsigned char buf[16];
  552. nullpo_retr(0, fitem);
  553. WBUFW(buf,0) = 0xa1;
  554. WBUFL(buf,2) = fitem->bl.id;
  555. if (fd == 0) {
  556. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  557. } else {
  558. WFIFOHEAD(fd,packet_len(0xa1));
  559. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  560. WFIFOSET(fd,packet_len(0xa1));
  561. }
  562. return 0;
  563. }
  564. /*==========================================
  565. * make a unit (char, npc, mob, homun) disappear to one client
  566. * id : the id of the unit
  567. * type: 0 - moved out of sight
  568. * 1 - died
  569. * 2 - logged out
  570. * 3 - teleported / winged away
  571. * fd : the target client
  572. *------------------------------------------*/
  573. int clif_clearunit_single(int id, uint8 type, int fd)
  574. {
  575. WFIFOHEAD(fd, packet_len(0x80));
  576. WFIFOW(fd,0) = 0x80;
  577. WFIFOL(fd,2) = id;
  578. WFIFOB(fd,6) = type;
  579. WFIFOSET(fd, packet_len(0x80));
  580. return 0;
  581. }
  582. /*==========================================
  583. * make a unit (char, npc, mob, homun) disappear to all clients in area
  584. * type: 0 - moved out of sight
  585. * 1 - died
  586. * 2 - logged out
  587. * 3 - teleported / winged away
  588. *------------------------------------------*/
  589. int clif_clearunit_area(struct block_list* bl, uint8 type)
  590. {
  591. unsigned char buf[16];
  592. nullpo_retr(0, bl);
  593. WBUFW(buf,0) = 0x80;
  594. WBUFL(buf,2) = bl->id;
  595. WBUFB(buf,6) = type;
  596. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  597. if(disguised(bl)) {
  598. WBUFL(buf,2) = -bl->id;
  599. clif_send(buf, packet_len(0x80), bl, SELF);
  600. }
  601. return 0;
  602. }
  603. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, int data)
  604. {
  605. struct block_list *bl = (struct block_list *)id;
  606. clif_clearunit_area(bl, 0);
  607. aFree(bl);
  608. return 0;
  609. }
  610. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  611. {
  612. struct block_list *tbl;
  613. tbl = aMalloc(sizeof (struct block_list));
  614. memcpy (tbl, bl, sizeof (struct block_list));
  615. add_timer(tick, clif_clearunit_delayed_sub, (int)tbl, 0);
  616. return 0;
  617. }
  618. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  619. {
  620. #if PACKETVER > 3
  621. struct item_data *id;
  622. #endif
  623. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  624. {
  625. *rhand = *lhand = 0;
  626. return;
  627. }
  628. #if PACKETVER < 4
  629. *rhand = sd->status.weapon;
  630. *lhand = sd->status.shield;
  631. #else
  632. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  633. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  634. {
  635. id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  636. if (id->view_id > 0)
  637. *rhand = id->view_id;
  638. else
  639. *rhand = id->nameid;
  640. } else
  641. *rhand = 0;
  642. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  643. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  644. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  645. {
  646. id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  647. if (id->view_id > 0)
  648. *lhand = id->view_id;
  649. else
  650. *lhand = id->nameid;
  651. } else
  652. *lhand = 0;
  653. #endif
  654. }
  655. /*==========================================
  656. *
  657. *------------------------------------------*/
  658. static int clif_set0078(struct block_list* bl, unsigned char* buf)
  659. {
  660. struct status_change* sc;
  661. struct view_data* vd;
  662. int guild_id, emblem_id, dir, lv;
  663. nullpo_retr(0, bl);
  664. sc = status_get_sc(bl);
  665. vd = status_get_viewdata(bl);
  666. guild_id = status_get_guild_id(bl);
  667. emblem_id = status_get_emblem_id(bl);
  668. dir = unit_getdir(bl);
  669. lv = status_get_lv(bl);
  670. if(pcdb_checkid(vd->class_))
  671. {
  672. struct map_session_data* sd;
  673. BL_CAST(BL_PC, bl, sd);
  674. #if PACKETVER >= 7
  675. memset(buf,0,packet_len(0x22a));
  676. WBUFW(buf,0)=0x22a;
  677. WBUFL(buf,2)=bl->id;
  678. WBUFW(buf,6)=status_get_speed(bl);
  679. if (sc) {
  680. WBUFW(buf,8)=sc->opt1;
  681. WBUFW(buf,10)=sc->opt2;
  682. WBUFL(buf,12)=sc->option;
  683. WBUFL(buf,44)=sc->opt3;
  684. }
  685. WBUFW(buf,16)=vd->class_;
  686. WBUFW(buf,18)=vd->hair_style;
  687. WBUFW(buf,20)=vd->weapon;
  688. WBUFW(buf,22)=vd->shield;
  689. WBUFW(buf,24)=vd->head_bottom;
  690. WBUFW(buf,26)=vd->head_top;
  691. WBUFW(buf,28)=vd->head_mid;
  692. WBUFW(buf,30)=vd->hair_color;
  693. WBUFW(buf,32)=vd->cloth_color;
  694. WBUFW(buf,34)=sd?sd->head_dir:0;
  695. WBUFL(buf,36)=guild_id;
  696. WBUFW(buf,40)=emblem_id;
  697. if (sd) {
  698. WBUFW(buf,42)=sd->status.manner;
  699. WBUFB(buf,48)=sd->status.karma;
  700. }
  701. WBUFB(buf,49)=vd->sex;
  702. WBUFPOS(buf,50,bl->x,bl->y,dir);
  703. WBUFB(buf,53)=5;
  704. WBUFB(buf,54)=5;
  705. WBUFB(buf,55)=vd->dead_sit;
  706. WBUFW(buf,56)=clif_setlevel(lv);
  707. return packet_len(0x22a);
  708. #elif PACKETVER > 3
  709. memset(buf,0,packet_len(0x1d8));
  710. WBUFW(buf,0)=0x1d8;
  711. WBUFL(buf,2)=bl->id;
  712. WBUFW(buf,6)=status_get_speed(bl);
  713. if (sc) {
  714. WBUFW(buf,8)=sc->opt1;
  715. WBUFW(buf,10)=sc->opt2;
  716. WBUFW(buf,12)=sc->option;
  717. WBUFW(buf,42)=sc->opt3;
  718. }
  719. WBUFW(buf,14)=vd->class_;
  720. WBUFW(buf,16)=vd->hair_style;
  721. WBUFW(buf,18)=vd->weapon;
  722. WBUFW(buf,20)=vd->shield;
  723. WBUFW(buf,22)=vd->head_bottom;
  724. WBUFW(buf,24)=vd->head_top;
  725. WBUFW(buf,26)=vd->head_mid;
  726. WBUFW(buf,28)=vd->hair_color;
  727. WBUFW(buf,30)=vd->cloth_color;
  728. WBUFW(buf,32)=sd?sd->head_dir:0;
  729. WBUFL(buf,34)=guild_id;
  730. WBUFW(buf,38)=emblem_id;
  731. if (sd) {
  732. WBUFW(buf,40)=sd->status.manner;
  733. WBUFB(buf,44)=sd->status.karma;
  734. }
  735. WBUFB(buf,45)=vd->sex;
  736. WBUFPOS(buf,46,bl->x,bl->y,dir);
  737. WBUFB(buf,49)=5;
  738. WBUFB(buf,50)=5;
  739. WBUFB(buf,51)=vd->dead_sit;
  740. WBUFW(buf,52)=clif_setlevel(lv);
  741. return packet_len(0x1d8);
  742. #else
  743. memset(buf,0,packet_len(0x78));
  744. WBUFW(buf,0)=0x78;
  745. WBUFL(buf,2)=bl->id;
  746. WBUFW(buf,6)=status_get_speed(bl);
  747. if (sc) {
  748. WBUFW(buf,8)=sc->opt1;
  749. WBUFW(buf,10)=sc->opt2;
  750. WBUFW(buf,12)=sc->option;
  751. WBUFW(buf,42)=sc->opt3;
  752. }
  753. WBUFW(buf,14)=vd->class_;
  754. WBUFW(buf,16)=vd->hair_style;
  755. WBUFW(buf,18)=vd->weapon;
  756. WBUFW(buf,20)=vd->head_bottom;
  757. WBUFW(buf,22)=vd->shield;
  758. WBUFW(buf,24)=vd->head_top;
  759. WBUFW(buf,26)=vd->head_mid;
  760. WBUFW(buf,28)=vd->hair_color;
  761. WBUFW(buf,30)=vd->cloth_color;
  762. WBUFW(buf,32)=sd?sd->head_dir:0;
  763. WBUFL(buf,34)=guild_id;
  764. WBUFW(buf,38)=emblem_id;
  765. if (sd) {
  766. WBUFW(buf,40)=sd->status.manner;
  767. WBUFB(buf,44)=sd->status.karma;
  768. }
  769. WBUFB(buf,45)=vd->sex;
  770. WBUFPOS(buf,46,bl->x,bl->y,dir);
  771. WBUFB(buf,49)=5;
  772. WBUFB(buf,50)=5;
  773. WBUFB(buf,51)=vd->dead_sit;
  774. WBUFW(buf,52)=clif_setlevel(lv);
  775. return packet_len(0x78);
  776. #endif
  777. }
  778. //Non-player sprites need just a few fields filled.
  779. memset(buf,0,packet_len(0x78));
  780. WBUFW(buf,0)=0x78;
  781. WBUFL(buf,2)=bl->id;
  782. WBUFW(buf,6)=status_get_speed(bl);
  783. if (sc) {
  784. WBUFW(buf,8)=sc->opt1;
  785. WBUFW(buf,10)=sc->opt2;
  786. WBUFW(buf,12)=sc->option;
  787. WBUFW(buf,42)=sc->opt3;
  788. }
  789. WBUFW(buf,14)=vd->class_;
  790. WBUFW(buf,16)=vd->hair_style; //Required for pets (removes attack cursor)
  791. //18W: Weapon
  792. WBUFW(buf,20)=vd->head_bottom; //Pet armor (ignored by client)
  793. if (bl->type == BL_NPC && vd->class_ == FLAG_CLASS)
  794. { //The hell, why flags work like this?
  795. WBUFL(buf,22)=emblem_id;
  796. WBUFL(buf,26)=guild_id;
  797. }
  798. //22W: shield
  799. //24W: Head top
  800. //26W: Head mid
  801. //28W: Hair color
  802. //30W: Clothes color
  803. //32W: Head dir
  804. WBUFL(buf,34)=guild_id;
  805. WBUFW(buf,38)=emblem_id;
  806. //40W: Manner
  807. //44B: Karma
  808. //45B: Sex
  809. WBUFPOS(buf,46,bl->x,bl->y,dir);
  810. //49B: ???
  811. //50B: ???
  812. //51B: Sit/Stand
  813. WBUFW(buf,52)=clif_setlevel(lv);
  814. return packet_len(0x78);
  815. }
  816. /*==========================================
  817. * Prepares 'unit walking' packet
  818. *------------------------------------------*/
  819. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf)
  820. {
  821. struct status_change *sc;
  822. int guild_id, emblem_id, lv;
  823. nullpo_retr(0, bl);
  824. sc = status_get_sc(bl);
  825. guild_id = status_get_guild_id(bl);
  826. emblem_id = status_get_emblem_id(bl);
  827. lv = status_get_lv(bl);
  828. if(pcdb_checkid(vd->class_))
  829. {
  830. struct map_session_data* sd;
  831. BL_CAST(BL_PC, bl, sd);
  832. #if PACKETVER >= 7
  833. memset(buf,0,packet_len(0x22c));
  834. WBUFW(buf,0)=0x22c;
  835. WBUFL(buf,2)=bl->id;
  836. WBUFW(buf,6)=status_get_speed(bl);
  837. if (sc) {
  838. WBUFW(buf,8)= sc->opt1;
  839. WBUFW(buf,10)= sc->opt2;
  840. WBUFL(buf,12)= sc->option;
  841. WBUFL(buf,48)= sc->opt3;
  842. }
  843. WBUFW(buf,16)=vd->class_;
  844. WBUFW(buf,18)=vd->hair_style;
  845. WBUFW(buf,20)=vd->weapon;
  846. WBUFW(buf,22)=vd->shield;
  847. WBUFW(buf,24)=vd->head_bottom;
  848. WBUFL(buf,26)=gettick();
  849. WBUFW(buf,30)=vd->head_top;
  850. WBUFW(buf,32)=vd->head_mid;
  851. WBUFW(buf,34)=vd->hair_color;
  852. WBUFW(buf,36)=vd->cloth_color;
  853. WBUFW(buf,38)=sd?sd->head_dir:0;
  854. WBUFL(buf,40)=guild_id;
  855. WBUFW(buf,44)=emblem_id;
  856. if (sd) {
  857. WBUFW(buf,46)=sd->status.manner;
  858. WBUFB(buf,52)=sd->status.karma;
  859. }
  860. WBUFB(buf,53)=vd->sex;
  861. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  862. WBUFB(buf,60)=5;
  863. WBUFB(buf,61)=5;
  864. WBUFW(buf,62)=clif_setlevel(lv);
  865. return packet_len(0x22c);
  866. #elif PACKETVER > 3
  867. memset(buf,0,packet_len(0x1da));
  868. WBUFW(buf,0)=0x1da;
  869. WBUFL(buf,2)=bl->id;
  870. WBUFW(buf,6)=status_get_speed(bl);
  871. if (sc) {
  872. WBUFW(buf,8)=sc->opt1;
  873. WBUFW(buf,10)=sc->opt2;
  874. WBUFW(buf,12)=sc->option;
  875. WBUFW(buf,46)=sc->opt3;
  876. }
  877. WBUFW(buf,14)=vd->class_;
  878. WBUFW(buf,16)=vd->hair_style;
  879. WBUFW(buf,18)=vd->weapon;
  880. WBUFW(buf,20)=vd->shield;
  881. WBUFW(buf,22)=vd->head_bottom;
  882. WBUFL(buf,24)=gettick();
  883. WBUFW(buf,28)=vd->head_top;
  884. WBUFW(buf,30)=vd->head_mid;
  885. WBUFW(buf,32)=vd->hair_color;
  886. WBUFW(buf,34)=vd->cloth_color;
  887. WBUFW(buf,36)=sd?sd->head_dir:0;
  888. WBUFL(buf,38)=guild_id;
  889. WBUFW(buf,42)=emblem_id;
  890. if (sd) {
  891. WBUFW(buf,44)=sd->status.manner;
  892. WBUFB(buf,48)=sd->status.karma;
  893. }
  894. WBUFB(buf,49)=vd->sex;
  895. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  896. WBUFB(buf,56)=5;
  897. WBUFB(buf,57)=5;
  898. WBUFW(buf,58)=clif_setlevel(lv);
  899. return packet_len(0x1da);
  900. #else
  901. memset(buf,0,packet_len(0x7b));
  902. WBUFW(buf,0)=0x7b;
  903. WBUFL(buf,2)=bl->id;
  904. WBUFW(buf,6)=status_get_speed(bl);
  905. if (sc) {
  906. WBUFW(buf,8)=sc->opt1;
  907. WBUFW(buf,10)=sc->opt2;
  908. WBUFW(buf,12)=sc->option;
  909. WBUFW(buf,46)=sc->opt3;
  910. }
  911. WBUFW(buf,14)=vd->class_;
  912. WBUFW(buf,16)=vd->hair_style;
  913. WBUFW(buf,18)=vd->weapon;
  914. WBUFW(buf,20)=vd->head_bottom;
  915. WBUFL(buf,22)=gettick();
  916. WBUFW(buf,26)=vd->shield;
  917. WBUFW(buf,28)=vd->head_top;
  918. WBUFW(buf,30)=vd->head_mid;
  919. WBUFW(buf,32)=vd->hair_color;
  920. WBUFW(buf,34)=vd->cloth_color;
  921. WBUFW(buf,36)=sd?sd->head_dir:0;
  922. WBUFL(buf,38)=guild_id;
  923. WBUFW(buf,42)=emblem_id;
  924. if (sd) {
  925. WBUFW(buf,44)=sd->status.manner;
  926. WBUFB(buf,48)=sd->status.karma;
  927. }
  928. WBUFB(buf,49)=vd->sex;
  929. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  930. WBUFB(buf,56)=5;
  931. WBUFB(buf,57)=5;
  932. WBUFW(buf,58)=clif_setlevel(lv);
  933. return packet_len(0x7b);
  934. #endif
  935. }
  936. //Non-player sprites only require a few fields.
  937. #if PACKETVER >= 7
  938. memset(buf,0,packet_len(0x22c));
  939. WBUFW(buf,0)=0x22c;
  940. WBUFL(buf,2)=bl->id;
  941. WBUFW(buf,6)=status_get_speed(bl);
  942. if (sc) {
  943. WBUFW(buf,8)=sc->opt1;
  944. WBUFW(buf,10)=sc->opt2;
  945. WBUFL(buf,12)=sc->option;
  946. WBUFL(buf,48)=sc->opt3;
  947. }
  948. WBUFW(buf,16)=vd->class_;
  949. WBUFW(buf,18)=vd->hair_style; //Required for pets (removes attack cursor)
  950. //20L: Weapon/Shield
  951. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  952. WBUFL(buf,26)=gettick();
  953. //30W: Head top
  954. //32W: Head mid
  955. //34W: Hair color
  956. //36W: Cloth color
  957. //38W: Head dir
  958. WBUFL(buf,40)=guild_id;
  959. WBUFW(buf,44)=emblem_id;
  960. //46W: Manner
  961. //52B: Karma
  962. //53B: Sex
  963. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  964. //60B: ???
  965. //61B: ???
  966. WBUFW(buf,62)=clif_setlevel(lv);
  967. return packet_len(0x22c);
  968. #else
  969. memset(buf,0,packet_len(0x7b));
  970. WBUFW(buf,0)=0x7b;
  971. WBUFL(buf,2)=bl->id;
  972. WBUFW(buf,6)=status_get_speed(bl);
  973. if (sc) {
  974. WBUFW(buf,8)=sc->opt1;
  975. WBUFW(buf,10)=sc->opt2;
  976. WBUFW(buf,12)=sc->option;
  977. WBUFW(buf,46)=sc->opt3;
  978. }
  979. WBUFW(buf,14)=vd->class_;
  980. WBUFW(buf,16)=vd->hair_style; //Required for pets (removes attack cursor)
  981. //18W: Weapon
  982. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  983. WBUFL(buf,22)=gettick();
  984. //26W: Shield
  985. //28W: Head top
  986. //30W: Head mid
  987. //32W: Hair color
  988. //34W: Cloth color
  989. //36W: Head dir
  990. WBUFL(buf,38)=guild_id;
  991. WBUFW(buf,42)=emblem_id;
  992. //44W: Manner
  993. //46W: Opt3
  994. //48B: Karma
  995. //49B: Sex
  996. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  997. WBUFB(buf,56)=5;
  998. WBUFB(buf,57)=5;
  999. WBUFW(buf,58)=clif_setlevel(lv);
  1000. return packet_len(0x7b);
  1001. #endif
  1002. }
  1003. //Modifies the buffer for disguise characters and sends it to self.
  1004. //Flag = 0: change id to negative, buf will have disguise data.
  1005. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1006. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1007. //But no longer holds true for those packet of PACKETVER 7.
  1008. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag)
  1009. {
  1010. if (flag) {
  1011. WBUFL(buf,2)=sd->bl.id;
  1012. #if PACKETVER >= 7
  1013. switch (WBUFW(buf,0)) {
  1014. case 0x22c:
  1015. case 0x22b:
  1016. case 0x22a:
  1017. WBUFL(buf,12)=OPTION_INVISIBLE;
  1018. WBUFW(buf,16)=sd->status.class_;
  1019. break;
  1020. default:
  1021. #endif
  1022. WBUFW(buf,12)=OPTION_INVISIBLE;
  1023. WBUFW(buf,14)=sd->status.class_;
  1024. #if PACKETVER >= 7
  1025. break;
  1026. }
  1027. #endif
  1028. } else {
  1029. WBUFL(buf,2)=-sd->bl.id;
  1030. }
  1031. clif_send(buf, len, &sd->bl, SELF);
  1032. }
  1033. /*==========================================
  1034. * クラスチェンジ typeはMobの場合は1で他は0?
  1035. *------------------------------------------*/
  1036. int clif_class_change(struct block_list *bl,int class_,int type)
  1037. {
  1038. unsigned char buf[16];
  1039. nullpo_retr(0, bl);
  1040. if(!pcdb_checkid(class_)) {
  1041. WBUFW(buf,0)=0x1b0;
  1042. WBUFL(buf,2)=bl->id;
  1043. WBUFB(buf,6)=type;
  1044. WBUFL(buf,7)=class_;
  1045. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1046. }
  1047. return 0;
  1048. }
  1049. /*==========================================
  1050. *
  1051. *------------------------------------------*/
  1052. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1053. {
  1054. WFIFOHEAD(fd, packet_len(0x1e1));
  1055. WFIFOW(fd,0)=0x1e1;
  1056. WFIFOL(fd,2)=sd->bl.id;
  1057. WFIFOW(fd,6)=sd->spiritball;
  1058. WFIFOSET(fd, packet_len(0x1e1));
  1059. }
  1060. // new and improved weather display [Valaris]
  1061. static void clif_weather_sub(int fd, int id, int type)
  1062. {
  1063. WFIFOHEAD(fd,packet_len(0x1f3));
  1064. WFIFOW(fd,0) = 0x1f3;
  1065. WFIFOL(fd,2) = id;
  1066. WFIFOL(fd,6) = type;
  1067. WFIFOSET(fd,packet_len(0x1f3));
  1068. }
  1069. /*==========================================
  1070. *
  1071. *------------------------------------------*/
  1072. static void clif_weather_check(struct map_session_data *sd)
  1073. {
  1074. int m = sd->bl.m, fd = sd->fd;
  1075. if (map[m].flag.snow
  1076. || map[m].flag.clouds
  1077. || map[m].flag.fog
  1078. || map[m].flag.fireworks
  1079. || map[m].flag.sakura
  1080. || map[m].flag.leaves
  1081. || map[m].flag.rain
  1082. || map[m].flag.clouds2)
  1083. {
  1084. if (map[m].flag.snow)
  1085. clif_weather_sub(fd, sd->bl.id, 162);
  1086. if (map[m].flag.clouds)
  1087. clif_weather_sub(fd, sd->bl.id, 233);
  1088. if (map[m].flag.clouds2)
  1089. clif_weather_sub(fd, sd->bl.id, 516);
  1090. if (map[m].flag.fog)
  1091. clif_weather_sub(fd, sd->bl.id, 515);
  1092. if (map[m].flag.fireworks) {
  1093. clif_weather_sub(fd, sd->bl.id, 297);
  1094. clif_weather_sub(fd, sd->bl.id, 299);
  1095. clif_weather_sub(fd, sd->bl.id, 301);
  1096. }
  1097. if (map[m].flag.sakura)
  1098. clif_weather_sub(fd, sd->bl.id, 163);
  1099. if (map[m].flag.leaves)
  1100. clif_weather_sub(fd, sd->bl.id, 333);
  1101. if (map[m].flag.rain)
  1102. clif_weather_sub(fd, sd->bl.id, 161);
  1103. }
  1104. }
  1105. int clif_weather(int m)
  1106. {
  1107. int i;
  1108. struct map_session_data *sd=NULL;
  1109. for(i = 0; i < fd_max; i++) {
  1110. if (session[i] && session[i]->func_parse == clif_parse &&
  1111. (sd = session[i]->session_data) != NULL &&
  1112. sd->state.auth && sd->bl.m == m) {
  1113. clif_weather_check(sd);
  1114. }
  1115. }
  1116. return 0;
  1117. }
  1118. int clif_spawn(struct block_list *bl)
  1119. {
  1120. unsigned char buf[128];
  1121. struct view_data *vd;
  1122. nullpo_retr(0, bl);
  1123. vd = status_get_viewdata(bl);
  1124. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1125. return 0;
  1126. if (pcdb_checkid(vd->class_))
  1127. { // player spawn packet
  1128. clif_set0078(bl, buf);
  1129. switch(WBUFW(buf,0))
  1130. {
  1131. case 0x78: //Convert to 0x79
  1132. WBUFW(buf, 0) = 0x79;
  1133. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1134. clif_send(buf, packet_len(0x79), bl, AREA_WOS);
  1135. if (disguised(bl))
  1136. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x79), 0);
  1137. break;
  1138. #if PACKETVER > 3
  1139. case 0x1d8: //Convert to 0x1d9
  1140. WBUFW(buf, 0) = 0x1d9;
  1141. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1142. clif_send(buf, packet_len(0x1d9), bl, AREA_WOS);
  1143. if (disguised(bl))
  1144. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x1d9), 0);
  1145. break;
  1146. #endif
  1147. #if PACKETVER >= 7
  1148. case 0x22a: //Convert to 0x22b
  1149. WBUFW(buf, 0) = 0x22b;
  1150. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1151. clif_send(buf, packet_len(0x22b), bl, AREA_WOS);
  1152. if (disguised(bl))
  1153. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x22b), 0);
  1154. break;
  1155. #endif
  1156. }
  1157. } else { // npc/mob/pet/homun spawn packet
  1158. struct status_change *sc = status_get_sc(bl);
  1159. memset(buf,0,sizeof(buf));
  1160. WBUFW(buf,0)=0x7c;
  1161. WBUFL(buf,2)=bl->id;
  1162. WBUFW(buf,6)=status_get_speed(bl);
  1163. if (sc) {
  1164. WBUFW(buf,8)=sc->opt1;
  1165. WBUFW(buf,10)=sc->opt2;
  1166. WBUFW(buf,12)=sc->option;
  1167. }
  1168. WBUFW(buf,14)=vd->hair_style; //Required for pets (removes attack cursor)
  1169. //16W: Weapon
  1170. WBUFW(buf,18)=vd->head_bottom; //Pet armor (ignored by client)
  1171. WBUFW(buf,20)=vd->class_;
  1172. //22W: Shield
  1173. //24W: Head top
  1174. //26W: Head mid
  1175. //28W: Hair color
  1176. //30W: Cloth color
  1177. //32W: Head dir
  1178. //34B: karma
  1179. //35B: Sex
  1180. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1181. //39B: ???
  1182. //40B: ???
  1183. clif_send(buf,packet_len(0x7c),bl,AREA_WOS);
  1184. if (disguised(bl)) {
  1185. WBUFL(buf,2)=-bl->id;
  1186. clif_send(buf,packet_len(0x7c),bl,SELF);
  1187. }
  1188. }
  1189. if (vd->cloth_color)
  1190. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1191. switch (bl->type)
  1192. {
  1193. case BL_PC:
  1194. {
  1195. TBL_PC *sd = ((TBL_PC*)bl);
  1196. if (sd->spiritball > 0)
  1197. clif_spiritball(sd);
  1198. if(sd->state.size==2) // tiny/big players [Valaris]
  1199. clif_specialeffect(bl,423,AREA);
  1200. else if(sd->state.size==1)
  1201. clif_specialeffect(bl,421,AREA);
  1202. }
  1203. break;
  1204. case BL_MOB:
  1205. {
  1206. TBL_MOB *md = ((TBL_MOB*)bl);
  1207. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1208. clif_specialeffect(&md->bl,423,AREA);
  1209. else if(md->special_state.size==1)
  1210. clif_specialeffect(&md->bl,421,AREA);
  1211. }
  1212. break;
  1213. case BL_PET:
  1214. if (vd->head_bottom)
  1215. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1216. break;
  1217. }
  1218. return 0;
  1219. }
  1220. //[orn]
  1221. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1222. {
  1223. struct status_data *status;
  1224. unsigned char buf[128];
  1225. nullpo_retr(0, hd);
  1226. status = &hd->battle_status;
  1227. memset(buf,0,packet_len(0x22e));
  1228. WBUFW(buf,0)=0x22e;
  1229. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1230. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1231. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1232. WBUFW(buf,27)=hd->homunculus.level;
  1233. WBUFW(buf,29)=hd->homunculus.hunger;
  1234. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1235. WBUFW(buf,33)=0; // equip id
  1236. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1237. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1238. WBUFW(buf,39)=status->hit;
  1239. if (battle_config.hom_setting&0x10)
  1240. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1241. else
  1242. WBUFW(buf,41)=status->cri/10;
  1243. WBUFW(buf,43)=status->def + status->vit ;
  1244. WBUFW(buf,45)=status->mdef;
  1245. WBUFW(buf,47)=status->flee;
  1246. WBUFW(buf,49)=(flag)?0:status->amotion;
  1247. if (status->max_hp > SHRT_MAX) {
  1248. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1249. WBUFW(buf,53) = 100;
  1250. } else {
  1251. WBUFW(buf,51)=status->hp;
  1252. WBUFW(buf,53)=status->max_hp;
  1253. }
  1254. if (status->max_sp > SHRT_MAX) {
  1255. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1256. WBUFW(buf,57) = 100;
  1257. } else {
  1258. WBUFW(buf,55)=status->sp;
  1259. WBUFW(buf,57)=status->max_sp;
  1260. }
  1261. WBUFL(buf,59)=hd->homunculus.exp;
  1262. WBUFL(buf,63)=hd->exp_next;
  1263. WBUFW(buf,67)=hd->homunculus.skillpts;
  1264. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1265. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1266. return 0;
  1267. }
  1268. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1269. { //[orn]
  1270. int fd = sd->fd;
  1271. WFIFOHEAD(fd, packet_len(0x230));
  1272. nullpo_retv(sd->hd);
  1273. WFIFOW(fd,0)=0x230;
  1274. WFIFOW(fd,2)=type;
  1275. WFIFOL(fd,4)=sd->hd->bl.id;
  1276. WFIFOL(fd,8)=param;
  1277. WFIFOSET(fd,packet_len(0x230));
  1278. return;
  1279. }
  1280. int clif_homskillinfoblock(struct map_session_data *sd)
  1281. { //[orn]
  1282. struct homun_data *hd;
  1283. int fd = sd->fd;
  1284. int i,j,len=4,id;
  1285. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1286. hd = sd->hd;
  1287. if ( !hd )
  1288. return 0 ;
  1289. WFIFOW(fd,0)=0x235;
  1290. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1291. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1292. j = id - HM_SKILLBASE - 1 ;
  1293. WFIFOW(fd,len ) = id ;
  1294. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1295. WFIFOW(fd,len+4) = 0 ;
  1296. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1297. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1298. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1299. strncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1300. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1301. len+=37;
  1302. }
  1303. }
  1304. WFIFOW(fd,2)=len;
  1305. WFIFOSET(fd,len);
  1306. return 0;
  1307. }
  1308. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1309. { //[orn]
  1310. struct homun_data *hd;
  1311. int fd=sd->fd, skillid;
  1312. WFIFOHEAD(fd, packet_len(0x239));
  1313. nullpo_retv(sd);
  1314. skillid = skill_num - HM_SKILLBASE - 1;
  1315. hd=sd->hd;
  1316. WFIFOW(fd,0) = 0x239;
  1317. WFIFOW(fd,2) = skill_num;
  1318. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1319. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1320. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1321. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1322. WFIFOSET(fd,packet_len(0x239));
  1323. return;
  1324. }
  1325. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1326. {
  1327. int fd=sd->fd;
  1328. WFIFOHEAD(fd,packet_len(0x22f));
  1329. WFIFOW(fd,0)=0x22f;
  1330. WFIFOB(fd,2)=fail;
  1331. WFIFOW(fd,3)=foodid;
  1332. WFIFOSET(fd,packet_len(0x22f));
  1333. return 0;
  1334. }
  1335. /*==========================================
  1336. *
  1337. *------------------------------------------*/
  1338. int clif_walkok(struct map_session_data *sd)
  1339. {
  1340. int fd=sd->fd;
  1341. WFIFOHEAD(fd, packet_len(0x87));
  1342. WFIFOW(fd,0)=0x87;
  1343. WFIFOL(fd,2)=gettick();
  1344. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1345. WFIFOSET(fd,packet_len(0x87));
  1346. return 0;
  1347. }
  1348. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1349. {
  1350. unsigned char buf[256];
  1351. int len;
  1352. len = clif_set007b(bl,vd,ud,buf);
  1353. clif_send(buf,len,bl,AREA_WOS);
  1354. if (disguised(bl))
  1355. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1356. if(vd->cloth_color)
  1357. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1358. switch(bl->type)
  1359. {
  1360. case BL_PC:
  1361. {
  1362. TBL_PC *sd = ((TBL_PC*)bl);
  1363. // clif_movepc(sd);
  1364. if(sd->state.size==2) // tiny/big players [Valaris]
  1365. clif_specialeffect(&sd->bl,423,AREA);
  1366. else if(sd->state.size==1)
  1367. clif_specialeffect(&sd->bl,421,AREA);
  1368. }
  1369. break;
  1370. case BL_MOB:
  1371. {
  1372. TBL_MOB *md = ((TBL_MOB*)bl);
  1373. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1374. clif_specialeffect(&md->bl,423,AREA);
  1375. else if(md->special_state.size==1)
  1376. clif_specialeffect(&md->bl,421,AREA);
  1377. }
  1378. break;
  1379. }
  1380. return;
  1381. }
  1382. /// Move the unit (does nothing if the client has no info about the unit)
  1383. /// Note: unit must not be self
  1384. void clif_move(struct unit_data *ud)
  1385. {
  1386. unsigned char buf[16];
  1387. struct view_data* vd;
  1388. struct block_list* bl = ud->bl;
  1389. vd = status_get_viewdata(bl);
  1390. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1391. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1392. if (ud->state.speed_changed) {
  1393. // Since we don't know how to update the speed of other objects,
  1394. // use the old walk packet to update the data.
  1395. ud->state.speed_changed = 0;
  1396. clif_move2(bl, vd, ud);
  1397. return;
  1398. }
  1399. WBUFW(buf,0)=0x86;
  1400. WBUFL(buf,2)=bl->id;
  1401. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1402. WBUFL(buf,12)=gettick();
  1403. clif_send(buf, 16, bl, AREA_WOS);
  1404. if (disguised(bl))
  1405. clif_setdisguise((TBL_PC*)bl, buf, 16, 0);
  1406. }
  1407. /*==========================================
  1408. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1409. *------------------------------------------*/
  1410. static int clif_delayquit(int tid, unsigned int tick, int id, int data)
  1411. {
  1412. struct map_session_data *sd = NULL;
  1413. //Remove player from map server
  1414. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1415. map_quit(sd);
  1416. return 0;
  1417. }
  1418. /*==========================================
  1419. *
  1420. *------------------------------------------*/
  1421. void clif_quitsave(int fd,struct map_session_data *sd)
  1422. {
  1423. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1424. !battle_config.prevent_logout ||
  1425. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1426. map_quit(sd);
  1427. else if (sd->fd)
  1428. { //Disassociate session from player (session is deleted after this function was called)
  1429. //And set a timer to make him quit later.
  1430. session[sd->fd]->session_data = NULL;
  1431. sd->fd = 0;
  1432. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1433. }
  1434. }
  1435. /*==========================================
  1436. *
  1437. *------------------------------------------*/
  1438. static int clif_waitclose(int tid, unsigned int tick, int id, int data)
  1439. {
  1440. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1441. set_eof(id);
  1442. return 0;
  1443. }
  1444. /*==========================================
  1445. *
  1446. *------------------------------------------*/
  1447. void clif_setwaitclose(int fd)
  1448. {
  1449. struct map_session_data *sd;
  1450. // if player is not already in the game (double connection probably)
  1451. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1452. // limited timer, just to send information.
  1453. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1454. } else
  1455. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1456. }
  1457. /*==========================================
  1458. *
  1459. *------------------------------------------*/
  1460. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1461. {
  1462. int fd;
  1463. nullpo_retv(sd);
  1464. fd = sd->fd;
  1465. WFIFOHEAD(fd,packet_len(0x91));
  1466. WFIFOW(fd,0) = 0x91;
  1467. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1468. WFIFOW(fd,18) = x;
  1469. WFIFOW(fd,20) = y;
  1470. WFIFOSET(fd,packet_len(0x91));
  1471. }
  1472. /*==========================================
  1473. * Tells the client to connect to another map-server
  1474. *------------------------------------------*/
  1475. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1476. {
  1477. int fd;
  1478. nullpo_retv(sd);
  1479. fd = sd->fd;
  1480. WFIFOHEAD(fd,packet_len(0x92));
  1481. WFIFOW(fd,0) = 0x92;
  1482. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1483. WFIFOW(fd,18) = x;
  1484. WFIFOW(fd,20) = y;
  1485. WFIFOL(fd,22) = htonl(ip);
  1486. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1487. WFIFOSET(fd,packet_len(0x92));
  1488. }
  1489. int clif_blown(struct block_list *bl)
  1490. {
  1491. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1492. // return clif_fixpos(bl);
  1493. return clif_slide(bl, bl->x, bl->y);
  1494. }
  1495. /*==========================================
  1496. *
  1497. *------------------------------------------*/
  1498. int clif_fixpos(struct block_list *bl)
  1499. {
  1500. unsigned char buf[16];
  1501. nullpo_retr(0, bl);
  1502. WBUFW(buf,0)=0x88;
  1503. WBUFL(buf,2)=bl->id;
  1504. WBUFW(buf,6)=bl->x;
  1505. WBUFW(buf,8)=bl->y;
  1506. clif_send(buf, packet_len(0x88), bl, AREA);
  1507. if (disguised(bl)) {
  1508. WBUFL(buf,2)=-bl->id;
  1509. clif_send(buf, packet_len(0x88), bl, SELF);
  1510. }
  1511. return 0;
  1512. }
  1513. /*==========================================
  1514. *
  1515. *------------------------------------------*/
  1516. int clif_npcbuysell(struct map_session_data* sd, int id)
  1517. {
  1518. int fd;
  1519. nullpo_retr(0, sd);
  1520. fd=sd->fd;
  1521. WFIFOHEAD(fd, packet_len(0xc4));
  1522. WFIFOW(fd,0)=0xc4;
  1523. WFIFOL(fd,2)=id;
  1524. WFIFOSET(fd,packet_len(0xc4));
  1525. return 0;
  1526. }
  1527. /*==========================================
  1528. *
  1529. *------------------------------------------*/
  1530. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1531. {
  1532. struct item_data *id;
  1533. int fd,i,val;
  1534. nullpo_retr(0, sd);
  1535. nullpo_retr(0, nd);
  1536. fd=sd->fd;
  1537. WFIFOHEAD(fd, 200 * 11 + 4);
  1538. WFIFOW(fd,0)=0xc6;
  1539. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1540. id = itemdb_search(nd->u.shop_item[i].nameid);
  1541. val=nd->u.shop_item[i].value;
  1542. WFIFOL(fd,4+i*11)=val;
  1543. if (!id->flag.value_notdc)
  1544. val=pc_modifybuyvalue(sd,val);
  1545. WFIFOL(fd,8+i*11)=val;
  1546. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1547. if (id->view_id > 0)
  1548. WFIFOW(fd,13+i*11)=id->view_id;
  1549. else
  1550. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1551. }
  1552. WFIFOW(fd,2)=i*11+4;
  1553. WFIFOSET(fd,WFIFOW(fd,2));
  1554. return 0;
  1555. }
  1556. /*==========================================
  1557. *
  1558. *------------------------------------------*/
  1559. int clif_selllist(struct map_session_data *sd)
  1560. {
  1561. int fd,i,c=0,val;
  1562. nullpo_retr(0, sd);
  1563. fd=sd->fd;
  1564. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1565. WFIFOW(fd,0)=0xc7;
  1566. for(i=0;i<MAX_INVENTORY;i++) {
  1567. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1568. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1569. continue;
  1570. val=sd->inventory_data[i]->value_sell;
  1571. if (val < 0)
  1572. continue;
  1573. WFIFOW(fd,4+c*10)=i+2;
  1574. WFIFOL(fd,6+c*10)=val;
  1575. if (!sd->inventory_data[i]->flag.value_notoc)
  1576. val=pc_modifysellvalue(sd,val);
  1577. WFIFOL(fd,10+c*10)=val;
  1578. c++;
  1579. }
  1580. }
  1581. WFIFOW(fd,2)=c*10+4;
  1582. WFIFOSET(fd,WFIFOW(fd,2));
  1583. return 0;
  1584. }
  1585. /*==========================================
  1586. *
  1587. *------------------------------------------*/
  1588. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1589. {
  1590. int fd = sd->fd;
  1591. int slen = strlen(mes) + 9;
  1592. WFIFOHEAD(fd, slen);
  1593. WFIFOW(fd,0)=0xb4;
  1594. WFIFOW(fd,2)=slen;
  1595. WFIFOL(fd,4)=npcid;
  1596. strcpy((char*)WFIFOP(fd,8),mes);
  1597. WFIFOSET(fd,WFIFOW(fd,2));
  1598. return 0;
  1599. }
  1600. /*==========================================
  1601. *
  1602. *------------------------------------------*/
  1603. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1604. {
  1605. int fd;
  1606. nullpo_retr(0, sd);
  1607. fd=sd->fd;
  1608. WFIFOHEAD(fd, packet_len(0xb5));
  1609. WFIFOW(fd,0)=0xb5;
  1610. WFIFOL(fd,2)=npcid;
  1611. WFIFOSET(fd,packet_len(0xb5));
  1612. return 0;
  1613. }
  1614. /*==========================================
  1615. *
  1616. *------------------------------------------*/
  1617. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1618. {
  1619. int fd;
  1620. nullpo_retr(0, sd);
  1621. fd=sd->fd;
  1622. WFIFOHEAD(fd, packet_len(0xb6));
  1623. WFIFOW(fd,0)=0xb6;
  1624. WFIFOL(fd,2)=npcid;
  1625. WFIFOSET(fd,packet_len(0xb6));
  1626. return 0;
  1627. }
  1628. /*==========================================
  1629. *
  1630. *------------------------------------------*/
  1631. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1632. {
  1633. int fd = sd->fd;
  1634. WFIFOHEAD(fd, packet_len(0x78));
  1635. sd->state.using_fake_npc = 1;
  1636. memset(WFIFOP(fd,0), 0, packet_len(0x78));
  1637. WFIFOW(fd,0)=0x78;
  1638. WFIFOL(fd,2)=npcid;
  1639. WFIFOW(fd,14)=111;
  1640. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1641. WFIFOB(fd,49)=5;
  1642. WFIFOB(fd,50)=5;
  1643. WFIFOSET(fd, packet_len(0x78));
  1644. return;
  1645. }
  1646. /*==========================================
  1647. *
  1648. *------------------------------------------*/
  1649. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1650. {
  1651. int fd = sd->fd;
  1652. int slen = strlen(mes) + 8;
  1653. struct block_list *bl = NULL;
  1654. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1655. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1656. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1657. clif_sendfakenpc(sd, npcid);
  1658. WFIFOHEAD(fd, slen);
  1659. WFIFOW(fd,0)=0xb7;
  1660. WFIFOW(fd,2)=slen;
  1661. WFIFOL(fd,4)=npcid;
  1662. strcpy((char*)WFIFOP(fd,8),mes);
  1663. WFIFOSET(fd,WFIFOW(fd,2));
  1664. return 0;
  1665. }
  1666. /*==========================================
  1667. *
  1668. *------------------------------------------*/
  1669. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1670. {
  1671. int fd;
  1672. struct block_list *bl = NULL;
  1673. nullpo_retr(0, sd);
  1674. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1675. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1676. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1677. clif_sendfakenpc(sd, npcid);
  1678. fd=sd->fd;
  1679. WFIFOHEAD(fd, packet_len(0x142));
  1680. WFIFOW(fd,0)=0x142;
  1681. WFIFOL(fd,2)=npcid;
  1682. WFIFOSET(fd,packet_len(0x142));
  1683. return 0;
  1684. }
  1685. /*==========================================
  1686. *
  1687. *------------------------------------------*/
  1688. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1689. {
  1690. int fd;
  1691. struct block_list *bl = NULL;
  1692. nullpo_retr(0, sd);
  1693. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1694. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1695. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1696. clif_sendfakenpc(sd, npcid);
  1697. fd=sd->fd;
  1698. WFIFOHEAD(fd, packet_len(0x1d4));
  1699. WFIFOW(fd,0)=0x1d4;
  1700. WFIFOL(fd,2)=npcid;
  1701. WFIFOSET(fd,packet_len(0x1d4));
  1702. return 0;
  1703. }
  1704. /// npc_id is ignored in the client
  1705. /// type=2 : Remove viewpoint
  1706. /// type=other : Show viewpoint
  1707. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1708. {
  1709. int fd;
  1710. nullpo_retr(0, sd);
  1711. fd=sd->fd;
  1712. WFIFOHEAD(fd, packet_len(0x144));
  1713. WFIFOW(fd,0)=0x144;
  1714. WFIFOL(fd,2)=npc_id;
  1715. WFIFOL(fd,6)=type;
  1716. WFIFOL(fd,10)=x;
  1717. WFIFOL(fd,14)=y;
  1718. WFIFOB(fd,18)=id;
  1719. WFIFOL(fd,19)=color;
  1720. WFIFOSET(fd,packet_len(0x144));
  1721. return 0;
  1722. }
  1723. /*==========================================
  1724. *
  1725. *------------------------------------------*/
  1726. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1727. {
  1728. int fd;
  1729. nullpo_retr(0, sd);
  1730. fd=sd->fd;
  1731. WFIFOHEAD(fd, packet_len(0x1b3));
  1732. WFIFOW(fd,0)=0x1b3;
  1733. strncpy((char*)WFIFOP(fd,2),image,64);
  1734. WFIFOB(fd,66)=type;
  1735. WFIFOSET(fd,packet_len(0x1b3));
  1736. return 0;
  1737. }
  1738. /*==========================================
  1739. * Fills in card data from the given item and into the buffer. [Skotlex]
  1740. *------------------------------------------*/
  1741. static void clif_addcards(unsigned char* buf, struct item* item)
  1742. {
  1743. int i=0,j;
  1744. if( item == NULL ) { //Blank data
  1745. WBUFW(buf,0) = 0;
  1746. WBUFW(buf,2) = 0;
  1747. WBUFW(buf,4) = 0;
  1748. WBUFW(buf,6) = 0;
  1749. return;
  1750. }
  1751. if( item->card[0] == CARD0_PET ) { //pet eggs
  1752. WBUFW(buf,0) = 0;
  1753. WBUFW(buf,2) = 0;
  1754. WBUFW(buf,4) = 0;
  1755. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1756. return;
  1757. }
  1758. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1759. WBUFW(buf,0) = item->card[0];
  1760. WBUFW(buf,2) = item->card[1];
  1761. WBUFW(buf,4) = item->card[2];
  1762. WBUFW(buf,6) = item->card[3];
  1763. return;
  1764. }
  1765. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1766. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1767. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1768. //Normal items.
  1769. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1770. WBUFW(buf,0) = j;
  1771. else
  1772. WBUFW(buf,0) = item->card[i];
  1773. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1774. WBUFW(buf,2) = j;
  1775. else
  1776. WBUFW(buf,2) = item->card[i];
  1777. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1778. WBUFW(buf,4) = j;
  1779. else
  1780. WBUFW(buf,4) = item->card[i];
  1781. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1782. WBUFW(buf,6) = j;
  1783. else
  1784. WBUFW(buf,6) = item->card[i];
  1785. }
  1786. /*==========================================
  1787. *
  1788. *------------------------------------------*/
  1789. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1790. {
  1791. int fd;
  1792. nullpo_retr(0, sd);
  1793. fd = sd->fd;
  1794. if (!session_isActive(fd)) //Sasuke-
  1795. return 0;
  1796. WFIFOHEAD(fd,packet_len(0xa0));
  1797. if(fail) {
  1798. WFIFOW(fd,0)=0xa0;
  1799. WFIFOW(fd,2)=n+2;
  1800. WFIFOW(fd,4)=amount;
  1801. WFIFOW(fd,6)=0;
  1802. WFIFOB(fd,8)=0;
  1803. WFIFOB(fd,9)=0;
  1804. WFIFOB(fd,10)=0;
  1805. WFIFOW(fd,11)=0;
  1806. WFIFOW(fd,13)=0;
  1807. WFIFOW(fd,15)=0;
  1808. WFIFOW(fd,17)=0;
  1809. WFIFOW(fd,19)=0;
  1810. WFIFOB(fd,21)=0;
  1811. WFIFOB(fd,22)=fail;
  1812. } else {
  1813. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1814. return 1;
  1815. WFIFOW(fd,0)=0xa0;
  1816. WFIFOW(fd,2)=n+2;
  1817. WFIFOW(fd,4)=amount;
  1818. if (sd->inventory_data[n]->view_id > 0)
  1819. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1820. else
  1821. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1822. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1823. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1824. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1825. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1826. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1827. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1828. WFIFOB(fd,22)=fail;
  1829. }
  1830. WFIFOSET(fd,packet_len(0xa0));
  1831. return 0;
  1832. }
  1833. /*==========================================
  1834. *
  1835. *------------------------------------------*/
  1836. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1837. {
  1838. int fd;
  1839. nullpo_retr(0, sd);
  1840. fd=sd->fd;
  1841. WFIFOHEAD(fd, packet_len(0xaf));
  1842. WFIFOW(fd,0)=0xaf;
  1843. WFIFOW(fd,2)=n+2;
  1844. WFIFOW(fd,4)=amount;
  1845. WFIFOSET(fd,packet_len(0xaf));
  1846. return 0;
  1847. }
  1848. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1849. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1850. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1851. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1852. {
  1853. if (id->view_id > 0)
  1854. WBUFW(buf,n)=id->view_id;
  1855. else
  1856. WBUFW(buf,n)=i->nameid;
  1857. WBUFB(buf,n+2)=itemtype(id->type);
  1858. WBUFB(buf,n+3)=i->identify;
  1859. if (equip >= 0) { //Equippable item
  1860. WBUFW(buf,n+4)=equip;
  1861. WBUFW(buf,n+6)=i->equip;
  1862. WBUFB(buf,n+8)=i->attribute;
  1863. WBUFB(buf,n+9)=i->refine;
  1864. } else { //Stackable item.
  1865. WBUFW(buf,n+4)=i->amount;
  1866. if (equip == -2 && id->equip == EQP_AMMO)
  1867. WBUFW(buf,n+6)=EQP_AMMO;
  1868. else
  1869. WBUFW(buf,n+6)=0;
  1870. }
  1871. }
  1872. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1873. void clif_inventorylist(struct map_session_data *sd)
  1874. {
  1875. int i,n,ne,fd = sd->fd,arrow=-1;
  1876. unsigned char *buf;
  1877. unsigned char bufe[MAX_INVENTORY*20+4];
  1878. #if PACKETVER < 5
  1879. const int s = 10; //Entry size.
  1880. #else
  1881. const int s = 18;
  1882. #endif
  1883. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1884. buf = WFIFOP(fd,0);
  1885. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1886. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1887. continue;
  1888. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1889. { //Non-stackable (Equippable)
  1890. WBUFW(bufe,ne*20+4)=i+2;
  1891. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1892. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1893. ne++;
  1894. } else { //Stackable.
  1895. WBUFW(buf,n*s+4)=i+2;
  1896. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1897. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1898. sd->status.inventory[i].equip)
  1899. arrow=i;
  1900. #if PACKETVER >= 5
  1901. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1902. #endif
  1903. n++;
  1904. }
  1905. }
  1906. if (n) {
  1907. #if PACKETVER < 5
  1908. WBUFW(buf,0)=0xa3;
  1909. #else
  1910. WBUFW(buf,0)=0x1ee;
  1911. #endif
  1912. WBUFW(buf,2)=4+n*s;
  1913. WFIFOSET(fd,WFIFOW(fd,2));
  1914. }
  1915. if(arrow >= 0)
  1916. clif_arrowequip(sd,arrow);
  1917. if(ne){
  1918. WBUFW(bufe,0)=0xa4;
  1919. WBUFW(bufe,2)=4+ne*20;
  1920. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1921. }
  1922. }
  1923. //Required when items break/get-repaired. Only sends equippable item list.
  1924. void clif_equiplist(struct map_session_data *sd)
  1925. {
  1926. int i,n,fd = sd->fd;
  1927. unsigned char *buf;
  1928. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1929. buf = WFIFOP(fd,0);
  1930. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1931. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1932. continue;
  1933. if(itemdb_isstackable2(sd->inventory_data[i]))
  1934. continue;
  1935. //Equippable
  1936. WBUFW(buf,n*20+4)=i+2;
  1937. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1938. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1939. n++;
  1940. }
  1941. if (n) {
  1942. WBUFW(buf,0)=0xa4;
  1943. WBUFW(buf,2)=4+n*20;
  1944. WFIFOSET(fd,WFIFOW(fd,2));
  1945. }
  1946. }
  1947. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1948. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1949. {
  1950. struct item_data *id;
  1951. int i,n,ne,fd=sd->fd;
  1952. unsigned char *buf;
  1953. unsigned char bufe[MAX_STORAGE*20+4];
  1954. #if PACKETVER < 5
  1955. const int s = 10; //Entry size.
  1956. #else
  1957. const int s = 18;
  1958. #endif
  1959. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1960. buf = WFIFOP(fd,0);
  1961. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1962. if(stor->storage_[i].nameid<=0)
  1963. continue;
  1964. id = itemdb_search(stor->storage_[i].nameid);
  1965. if(!itemdb_isstackable2(id))
  1966. { //Equippable
  1967. WBUFW(bufe,ne*20+4)=i+1;
  1968. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1969. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1970. ne++;
  1971. } else { //Stackable
  1972. WBUFW(buf,n*s+4)=i+1;
  1973. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1974. #if PACKETVER >= 5
  1975. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1976. #endif
  1977. n++;
  1978. }
  1979. }
  1980. if(n){
  1981. #if PACKETVER < 5
  1982. WBUFW(buf,0)=0xa5;
  1983. #else
  1984. WBUFW(buf,0)=0x1f0;
  1985. #endif
  1986. WBUFW(buf,2)=4+n*s;
  1987. WFIFOSET(fd,WFIFOW(fd,2));
  1988. }
  1989. if(ne){
  1990. WBUFW(bufe,0)=0xa6;
  1991. WBUFW(bufe,2)=4+ne*20;
  1992. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1993. }
  1994. }
  1995. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1996. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1997. {
  1998. struct item_data *id;
  1999. int i,n,ne,fd=sd->fd;
  2000. unsigned char *buf;
  2001. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  2002. #if PACKETVER < 5
  2003. const int s = 10; //Entry size.
  2004. #else
  2005. const int s = 18;
  2006. #endif
  2007. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  2008. buf = WFIFOP(fd,0);
  2009. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  2010. if(stor->storage_[i].nameid<=0)
  2011. continue;
  2012. id = itemdb_search(stor->storage_[i].nameid);
  2013. if(!itemdb_isstackable2(id))
  2014. { //Equippable
  2015. WBUFW(bufe,ne*20+4)=i+1;
  2016. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2017. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2018. ne++;
  2019. } else { //Stackable
  2020. WBUFW(buf,n*s+4)=i+1;
  2021. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2022. #if PACKETVER >= 5
  2023. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2024. #endif
  2025. n++;
  2026. }
  2027. }
  2028. if(n){
  2029. #if PACKETVER < 5
  2030. WBUFW(buf,0)=0xa5;
  2031. #else
  2032. WBUFW(buf,0)=0x1f0;
  2033. #endif
  2034. WBUFW(buf,2)=4+n*s;
  2035. WFIFOSET(fd,WFIFOW(fd,2));
  2036. }
  2037. if(ne){
  2038. WBUFW(bufe,0)=0xa6;
  2039. WBUFW(bufe,2)=4+ne*20;
  2040. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2041. }
  2042. }
  2043. void clif_cartlist(struct map_session_data *sd)
  2044. {
  2045. struct item_data *id;
  2046. int i,n,ne,fd=sd->fd;
  2047. unsigned char *buf;
  2048. unsigned char bufe[MAX_CART*20+4];
  2049. #if PACKETVER < 5
  2050. const int s = 10; //Entry size.
  2051. #else
  2052. const int s = 18;
  2053. #endif
  2054. WFIFOHEAD(fd, MAX_CART * s + 4);
  2055. buf = WFIFOP(fd,0);
  2056. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2057. if(sd->status.cart[i].nameid<=0)
  2058. continue;
  2059. id = itemdb_search(sd->status.cart[i].nameid);
  2060. if(!itemdb_isstackable2(id))
  2061. { //Equippable
  2062. WBUFW(bufe,ne*20+4)=i+2;
  2063. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2064. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2065. ne++;
  2066. } else { //Stackable
  2067. WBUFW(buf,n*s+4)=i+2;
  2068. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2069. #if PACKETVER >= 5
  2070. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2071. #endif
  2072. n++;
  2073. }
  2074. }
  2075. if(n){
  2076. #if PACKETVER < 5
  2077. WBUFW(buf,0)=0x123;
  2078. #else
  2079. WBUFW(buf,0)=0x1ef;
  2080. #endif
  2081. WBUFW(buf,2)=4+n*s;
  2082. WFIFOSET(fd,WFIFOW(fd,2));
  2083. }
  2084. if(ne){
  2085. WBUFW(bufe,0)=0x122;
  2086. WBUFW(bufe,2)=4+ne*20;
  2087. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2088. }
  2089. return;
  2090. }
  2091. /// Client behaviour:
  2092. /// Closes the cart storage and removes all it's items from memory.
  2093. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2094. void clif_clearcart(int fd)
  2095. {
  2096. WFIFOHEAD(fd, packet_len(0x12b));
  2097. WFIFOW(fd,0) = 0x12b;
  2098. }
  2099. // Guild XY locators [Valaris]
  2100. int clif_guild_xy(struct map_session_data *sd)
  2101. {
  2102. unsigned char buf[10];
  2103. nullpo_retr(0, sd);
  2104. WBUFW(buf,0)=0x1eb;
  2105. WBUFL(buf,2)=sd->status.account_id;
  2106. WBUFW(buf,6)=sd->bl.x;
  2107. WBUFW(buf,8)=sd->bl.y;
  2108. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2109. return 0;
  2110. }
  2111. /*==========================================
  2112. * Sends x/y dot to a single fd. [Skotlex]
  2113. *------------------------------------------*/
  2114. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2115. {
  2116. WFIFOHEAD(fd,packet_len(0x1eb));
  2117. WFIFOW(fd,0)=0x1eb;
  2118. WFIFOL(fd,2)=sd->status.account_id;
  2119. WFIFOW(fd,6)=sd->bl.x;
  2120. WFIFOW(fd,8)=sd->bl.y;
  2121. WFIFOSET(fd,packet_len(0x1eb));
  2122. return 0;
  2123. }
  2124. // Guild XY locators [Valaris]
  2125. int clif_guild_xy_remove(struct map_session_data *sd)
  2126. {
  2127. unsigned char buf[10];
  2128. nullpo_retr(0, sd);
  2129. WBUFW(buf,0)=0x1eb;
  2130. WBUFL(buf,2)=sd->status.account_id;
  2131. WBUFW(buf,6)=-1;
  2132. WBUFW(buf,8)=-1;
  2133. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2134. return 0;
  2135. }
  2136. /*==========================================
  2137. * ステータスを送りつける
  2138. * 表示専用数字はこの中で計算して送る
  2139. *------------------------------------------*/
  2140. int clif_updatestatus(struct map_session_data *sd,int type)
  2141. {
  2142. int fd,len=8;
  2143. nullpo_retr(0, sd);
  2144. fd=sd->fd;
  2145. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2146. return 0;
  2147. WFIFOHEAD(fd, 14);
  2148. WFIFOW(fd,0)=0xb0;
  2149. WFIFOW(fd,2)=type;
  2150. switch(type){
  2151. // 00b0
  2152. case SP_WEIGHT:
  2153. pc_updateweightstatus(sd);
  2154. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2155. WFIFOW(fd,2)=type;
  2156. WFIFOL(fd,4)=sd->weight;
  2157. break;
  2158. case SP_MAXWEIGHT:
  2159. WFIFOL(fd,4)=sd->max_weight;
  2160. break;
  2161. case SP_SPEED:
  2162. WFIFOL(fd,4)=sd->battle_status.speed;
  2163. break;
  2164. case SP_BASELEVEL:
  2165. WFIFOL(fd,4)=sd->status.base_level;
  2166. break;
  2167. case SP_JOBLEVEL:
  2168. WFIFOL(fd,4)=sd->status.job_level;
  2169. break;
  2170. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2171. WFIFOL(fd,4)=sd->status.karma;
  2172. break;
  2173. case SP_MANNER:
  2174. WFIFOL(fd,4)=sd->status.manner;
  2175. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2176. break;
  2177. case SP_STATUSPOINT:
  2178. WFIFOL(fd,4)=sd->status.status_point;
  2179. break;
  2180. case SP_SKILLPOINT:
  2181. WFIFOL(fd,4)=sd->status.skill_point;
  2182. break;
  2183. case SP_HIT:
  2184. WFIFOL(fd,4)=sd->battle_status.hit;
  2185. break;
  2186. case SP_FLEE1:
  2187. WFIFOL(fd,4)=sd->battle_status.flee;
  2188. break;
  2189. case SP_FLEE2:
  2190. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2191. break;
  2192. case SP_MAXHP:
  2193. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2194. break;
  2195. case SP_MAXSP:
  2196. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2197. break;
  2198. case SP_HP:
  2199. WFIFOL(fd,4)=sd->battle_status.hp;
  2200. if (battle_config.disp_hpmeter)
  2201. clif_hpmeter(sd);
  2202. if (!battle_config.party_hp_mode && sd->status.party_id)
  2203. clif_party_hp(sd);
  2204. break;
  2205. case SP_SP:
  2206. WFIFOL(fd,4)=sd->battle_status.sp;
  2207. break;
  2208. case SP_ASPD:
  2209. WFIFOL(fd,4)=sd->battle_status.amotion;
  2210. break;
  2211. case SP_ATK1:
  2212. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2213. break;
  2214. case SP_DEF1:
  2215. WFIFOL(fd,4)=sd->battle_status.def;
  2216. break;
  2217. case SP_MDEF1:
  2218. WFIFOL(fd,4)=sd->battle_status.mdef;
  2219. break;
  2220. case SP_ATK2:
  2221. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2222. break;
  2223. case SP_DEF2:
  2224. WFIFOL(fd,4)=sd->battle_status.def2;
  2225. break;
  2226. case SP_MDEF2:
  2227. //negative check (in case you have something like Berserk active)
  2228. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2229. if (len < 0) len = 0;
  2230. WFIFOL(fd,4)= len;
  2231. len = 8;
  2232. break;
  2233. case SP_CRITICAL:
  2234. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2235. break;
  2236. case SP_MATK1:
  2237. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2238. break;
  2239. case SP_MATK2:
  2240. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2241. break;
  2242. case SP_ZENY:
  2243. WFIFOW(fd,0)=0xb1;
  2244. WFIFOL(fd,4)=sd->status.zeny - sd->mail.zeny;
  2245. break;
  2246. case SP_BASEEXP:
  2247. WFIFOW(fd,0)=0xb1;
  2248. WFIFOL(fd,4)=sd->status.base_exp;
  2249. break;
  2250. case SP_JOBEXP:
  2251. WFIFOW(fd,0)=0xb1;
  2252. WFIFOL(fd,4)=sd->status.job_exp;
  2253. break;
  2254. case SP_NEXTBASEEXP:
  2255. WFIFOW(fd,0)=0xb1;
  2256. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2257. break;
  2258. case SP_NEXTJOBEXP:
  2259. WFIFOW(fd,0)=0xb1;
  2260. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2261. break;
  2262. // 00be 終了
  2263. case SP_USTR:
  2264. case SP_UAGI:
  2265. case SP_UVIT:
  2266. case SP_UINT:
  2267. case SP_UDEX:
  2268. case SP_ULUK:
  2269. WFIFOW(fd,0)=0xbe;
  2270. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2271. len=5;
  2272. break;
  2273. // 013a 終了
  2274. case SP_ATTACKRANGE:
  2275. WFIFOW(fd,0)=0x13a;
  2276. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2277. len=4;
  2278. break;
  2279. // 0141 終了
  2280. case SP_STR:
  2281. WFIFOW(fd,0)=0x141;
  2282. WFIFOL(fd,2)=type;
  2283. WFIFOL(fd,6)=sd->status.str;
  2284. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2285. len=14;
  2286. break;
  2287. case SP_AGI:
  2288. WFIFOW(fd,0)=0x141;
  2289. WFIFOL(fd,2)=type;
  2290. WFIFOL(fd,6)=sd->status.agi;
  2291. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2292. len=14;
  2293. break;
  2294. case SP_VIT:
  2295. WFIFOW(fd,0)=0x141;
  2296. WFIFOL(fd,2)=type;
  2297. WFIFOL(fd,6)=sd->status.vit;
  2298. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2299. len=14;
  2300. break;
  2301. case SP_INT:
  2302. WFIFOW(fd,0)=0x141;
  2303. WFIFOL(fd,2)=type;
  2304. WFIFOL(fd,6)=sd->status.int_;
  2305. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2306. len=14;
  2307. break;
  2308. case SP_DEX:
  2309. WFIFOW(fd,0)=0x141;
  2310. WFIFOL(fd,2)=type;
  2311. WFIFOL(fd,6)=sd->status.dex;
  2312. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2313. len=14;
  2314. break;
  2315. case SP_LUK:
  2316. WFIFOW(fd,0)=0x141;
  2317. WFIFOL(fd,2)=type;
  2318. WFIFOL(fd,6)=sd->status.luk;
  2319. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2320. len=14;
  2321. break;
  2322. case SP_CARTINFO:
  2323. WFIFOW(fd,0)=0x121;
  2324. WFIFOW(fd,2)=sd->cart_num;
  2325. WFIFOW(fd,4)=MAX_CART;
  2326. WFIFOL(fd,6)=sd->cart_weight;
  2327. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2328. len=14;
  2329. break;
  2330. default:
  2331. if(battle_config.error_log)
  2332. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2333. return 1;
  2334. }
  2335. WFIFOSET(fd,len);
  2336. return 0;
  2337. }
  2338. int clif_changestatus(struct block_list *bl,int type,int val)
  2339. {
  2340. unsigned char buf[12];
  2341. struct map_session_data *sd = NULL;
  2342. nullpo_retr(0, bl);
  2343. if(bl->type == BL_PC)
  2344. sd = (struct map_session_data *)bl;
  2345. if(sd){
  2346. WBUFW(buf,0)=0x1ab;
  2347. WBUFL(buf,2)=bl->id;
  2348. WBUFW(buf,6)=type;
  2349. switch(type){
  2350. case SP_MANNER:
  2351. WBUFL(buf,8)=val;
  2352. break;
  2353. default:
  2354. if(battle_config.error_log)
  2355. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2356. return 1;
  2357. }
  2358. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2359. }
  2360. return 0;
  2361. }
  2362. /*==========================================
  2363. *
  2364. *------------------------------------------*/
  2365. void clif_changelook(struct block_list *bl,int type,int val)
  2366. {
  2367. unsigned char buf[16];
  2368. struct map_session_data* sd = NULL;
  2369. struct view_data* vd;
  2370. nullpo_retv(bl);
  2371. BL_CAST(BL_PC, bl, sd);
  2372. vd = status_get_viewdata(bl);
  2373. //nullpo_ret(vd);
  2374. if( vd ) //temp hack to let Warp Portal change appearance
  2375. switch(type)
  2376. {
  2377. case LOOK_WEAPON:
  2378. if (sd)
  2379. {
  2380. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2381. val = vd->weapon;
  2382. }
  2383. else vd->weapon = val;
  2384. break;
  2385. case LOOK_SHIELD:
  2386. if (sd)
  2387. {
  2388. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2389. val = vd->shield;
  2390. }
  2391. else vd->shield = val;
  2392. break;
  2393. case LOOK_BASE:
  2394. vd->class_ = val;
  2395. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2396. vd->weapon = vd->shield = 0;
  2397. if (vd->cloth_color && (
  2398. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2399. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2400. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2401. ))
  2402. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2403. break;
  2404. case LOOK_HAIR:
  2405. vd->hair_style = val;
  2406. break;
  2407. case LOOK_HEAD_BOTTOM:
  2408. vd->head_bottom = val;
  2409. break;
  2410. case LOOK_HEAD_TOP:
  2411. vd->head_top = val;
  2412. break;
  2413. case LOOK_HEAD_MID:
  2414. vd->head_mid = val;
  2415. break;
  2416. case LOOK_HAIR_COLOR:
  2417. vd->hair_color = val;
  2418. break;
  2419. case LOOK_CLOTHES_COLOR:
  2420. if (val && (
  2421. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2422. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2423. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2424. ))
  2425. val = 0;
  2426. vd->cloth_color = val;
  2427. break;
  2428. case LOOK_SHOES:
  2429. #if PACKETVER > 3
  2430. if (sd) {
  2431. int n;
  2432. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2433. if(sd->inventory_data[n]->view_id > 0)
  2434. val = sd->inventory_data[n]->view_id;
  2435. else
  2436. val = sd->status.inventory[n].nameid;
  2437. }
  2438. val = 0;
  2439. }
  2440. #endif
  2441. //Shoes? No packet uses this....
  2442. break;
  2443. }
  2444. #if PACKETVER < 4
  2445. WBUFW(buf,0)=0xc3;
  2446. WBUFL(buf,2)=bl->id;
  2447. WBUFB(buf,6)=type;
  2448. WBUFB(buf,7)=val;
  2449. clif_send(buf,packet_len(0xc3),bl,AREA);
  2450. #else
  2451. WBUFW(buf,0)=0x1d7;
  2452. WBUFL(buf,2)=bl->id;
  2453. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2454. WBUFB(buf,6)=LOOK_WEAPON;
  2455. WBUFW(buf,7)=vd->weapon;
  2456. WBUFW(buf,9)=vd->shield;
  2457. } else {
  2458. WBUFB(buf,6)=type;
  2459. WBUFW(buf,7)=val;
  2460. WBUFW(buf,9)=0;
  2461. }
  2462. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2463. #endif
  2464. }
  2465. //Sends a change-base-look packet required for traps as they are triggered.
  2466. void clif_changetraplook(struct block_list *bl,int val)
  2467. {
  2468. unsigned char buf[32];
  2469. #if PACKETVER < 4
  2470. WBUFW(buf,0)=0xc3;
  2471. WBUFL(buf,2)=bl->id;
  2472. WBUFB(buf,6)=LOOK_BASE;
  2473. WBUFB(buf,7)=val;
  2474. clif_send(buf,packet_len(0xc3),bl,AREA);
  2475. #else
  2476. WBUFW(buf,0)=0x1d7;
  2477. WBUFL(buf,2)=bl->id;
  2478. WBUFB(buf,6)=LOOK_BASE;
  2479. WBUFW(buf,7)=val;
  2480. WBUFW(buf,9)=0;
  2481. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2482. #endif
  2483. }
  2484. //For the stupid cloth-dye bug. Resends the given view data
  2485. //to the area specified by bl.
  2486. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2487. {
  2488. unsigned char buf[32];
  2489. #if PACKETVER < 4
  2490. WBUFW(buf,0)=0xc3;
  2491. WBUFL(buf,2)=id;
  2492. WBUFB(buf,6)=type;
  2493. WBUFB(buf,7)=val;
  2494. clif_send(buf,packet_len(0xc3),bl,area);
  2495. #else
  2496. WBUFW(buf,0)=0x1d7;
  2497. WBUFL(buf,2)=id;
  2498. WBUFB(buf,6)=type;
  2499. WBUFW(buf,7)=val;
  2500. WBUFW(buf,9)=0;
  2501. clif_send(buf,packet_len(0x1d7),bl,area);
  2502. #endif
  2503. return;
  2504. }
  2505. /*==========================================
  2506. *
  2507. *------------------------------------------*/
  2508. int clif_initialstatus(struct map_session_data *sd)
  2509. {
  2510. int fd;
  2511. unsigned char *buf;
  2512. nullpo_retr(0, sd);
  2513. fd=sd->fd;
  2514. WFIFOHEAD(fd,packet_len(0xbd));
  2515. buf=WFIFOP(fd,0);
  2516. WBUFW(buf,0)=0xbd;
  2517. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2518. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2519. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2520. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2521. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2522. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2523. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2524. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2525. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2526. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2527. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2528. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2529. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2530. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2531. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2532. WBUFW(buf,20) = sd->battle_status.matk_max;
  2533. WBUFW(buf,22) = sd->battle_status.matk_min;
  2534. WBUFW(buf,24) = sd->battle_status.def; // def
  2535. WBUFW(buf,26) = sd->battle_status.def2;
  2536. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2537. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2538. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2539. WBUFW(buf,30) = fd;
  2540. fd = sd->fd;
  2541. WBUFW(buf,32) = sd->battle_status.hit;
  2542. WBUFW(buf,34) = sd->battle_status.flee;
  2543. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2544. WBUFW(buf,38) = sd->battle_status.cri/10;
  2545. WBUFW(buf,40) = sd->status.karma;
  2546. WBUFW(buf,42) = sd->status.manner;
  2547. WFIFOSET(fd,packet_len(0xbd));
  2548. clif_updatestatus(sd,SP_STR);
  2549. clif_updatestatus(sd,SP_AGI);
  2550. clif_updatestatus(sd,SP_VIT);
  2551. clif_updatestatus(sd,SP_INT);
  2552. clif_updatestatus(sd,SP_DEX);
  2553. clif_updatestatus(sd,SP_LUK);
  2554. clif_updatestatus(sd,SP_ATTACKRANGE);
  2555. clif_updatestatus(sd,SP_ASPD);
  2556. return 0;
  2557. }
  2558. /*==========================================
  2559. *矢装備
  2560. *------------------------------------------*/
  2561. int clif_arrowequip(struct map_session_data *sd,int val)
  2562. {
  2563. int fd;
  2564. nullpo_retr(0, sd);
  2565. pc_stop_attack(sd); // [Valaris]
  2566. fd=sd->fd;
  2567. WFIFOHEAD(fd, packet_len(0x013c));
  2568. WFIFOW(fd,0)=0x013c;
  2569. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2570. WFIFOSET(fd,packet_len(0x013c));
  2571. return 0;
  2572. }
  2573. /// Ammunition action message.
  2574. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2575. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2576. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2577. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2578. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2579. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2580. int clif_arrow_fail(struct map_session_data *sd,int type)
  2581. {
  2582. int fd;
  2583. nullpo_retr(0, sd);
  2584. fd=sd->fd;
  2585. WFIFOHEAD(fd, packet_len(0x013b));
  2586. WFIFOW(fd,0)=0x013b;
  2587. WFIFOW(fd,2)=type;
  2588. WFIFOSET(fd,packet_len(0x013b));
  2589. return 0;
  2590. }
  2591. /*==========================================
  2592. * 作成可能 矢リスト送信
  2593. *------------------------------------------*/
  2594. int clif_arrow_create_list(struct map_session_data *sd)
  2595. {
  2596. int i, c, j;
  2597. int fd;
  2598. nullpo_retr(0, sd);
  2599. fd = sd->fd;
  2600. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2601. WFIFOW(fd,0) = 0x1ad;
  2602. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2603. if (skill_arrow_db[i].nameid > 0 &&
  2604. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2605. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2606. {
  2607. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2608. WFIFOW(fd,c*2+4) = j;
  2609. else
  2610. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2611. c++;
  2612. }
  2613. }
  2614. WFIFOW(fd,2) = c*2+4;
  2615. WFIFOSET(fd, WFIFOW(fd,2));
  2616. if (c > 0) {
  2617. sd->menuskill_id = AC_MAKINGARROW;
  2618. sd->menuskill_val = c;
  2619. }
  2620. return 0;
  2621. }
  2622. /*==========================================
  2623. *
  2624. *------------------------------------------*/
  2625. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2626. {
  2627. int fd;
  2628. nullpo_retr(0, sd);
  2629. fd=sd->fd;
  2630. WFIFOHEAD(fd,packet_len(0xbc));
  2631. WFIFOW(fd,0)=0xbc;
  2632. WFIFOW(fd,2)=type;
  2633. WFIFOB(fd,4)=ok;
  2634. WFIFOB(fd,5)=val;
  2635. WFIFOSET(fd,packet_len(0xbc));
  2636. return 0;
  2637. }
  2638. /*==========================================
  2639. *
  2640. *------------------------------------------*/
  2641. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2642. {
  2643. int fd;
  2644. nullpo_retr(0, sd);
  2645. fd=sd->fd;
  2646. WFIFOHEAD(fd,packet_len(0xaa));
  2647. WFIFOW(fd,0)=0xaa;
  2648. WFIFOW(fd,2)=n+2;
  2649. WFIFOW(fd,4)=pos;
  2650. WFIFOB(fd,6)=ok;
  2651. WFIFOSET(fd,packet_len(0xaa));
  2652. return 0;
  2653. }
  2654. /*==========================================
  2655. *
  2656. *------------------------------------------*/
  2657. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2658. {
  2659. int fd;
  2660. nullpo_retr(0, sd);
  2661. fd=sd->fd;
  2662. WFIFOHEAD(fd,packet_len(0xac));
  2663. WFIFOW(fd,0)=0xac;
  2664. WFIFOW(fd,2)=n+2;
  2665. WFIFOW(fd,4)=pos;
  2666. WFIFOB(fd,6)=ok;
  2667. WFIFOSET(fd,packet_len(0xac));
  2668. return 0;
  2669. }
  2670. /*==========================================
  2671. *
  2672. *------------------------------------------*/
  2673. int clif_misceffect(struct block_list* bl,int type)
  2674. {
  2675. unsigned char buf[32];
  2676. nullpo_retr(0, bl);
  2677. WBUFW(buf,0) = 0x19b;
  2678. WBUFL(buf,2) = bl->id;
  2679. WBUFL(buf,6) = type;
  2680. clif_send(buf,packet_len(0x19b),bl,AREA);
  2681. return 0;
  2682. }
  2683. int clif_misceffect2(struct block_list *bl, int type)
  2684. {
  2685. unsigned char buf[24];
  2686. nullpo_retr(0, bl);
  2687. memset(buf, 0, packet_len(0x1f3));
  2688. WBUFW(buf,0) = 0x1f3;
  2689. WBUFL(buf,2) = bl->id;
  2690. WBUFL(buf,6) = type;
  2691. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2692. return 0;
  2693. }
  2694. /*==========================================
  2695. * 表示オプション変更
  2696. *------------------------------------------*/
  2697. int clif_changeoption(struct block_list* bl)
  2698. {
  2699. unsigned char buf[32];
  2700. struct status_change *sc;
  2701. nullpo_retr(0, bl);
  2702. sc = status_get_sc(bl);
  2703. if (!sc) return 0; //How can an option change if there's no sc?
  2704. #if PACKETVER >= 7
  2705. WBUFW(buf,0) = 0x229;
  2706. WBUFL(buf,2) = bl->id;
  2707. WBUFW(buf,6) = sc->opt1;
  2708. WBUFW(buf,8) = sc->opt2;
  2709. WBUFL(buf,10) = sc->option;
  2710. WBUFB(buf,14) = 0; // PK???
  2711. if(disguised(bl)) {
  2712. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2713. WBUFL(buf,2) = -bl->id;
  2714. clif_send(buf,packet_len(0x229),bl,SELF);
  2715. WBUFL(buf,2) = bl->id;
  2716. WBUFL(buf,10) = OPTION_INVISIBLE;
  2717. clif_send(buf,packet_len(0x229),bl,SELF);
  2718. } else
  2719. clif_send(buf,packet_len(0x229),bl,AREA);
  2720. #else
  2721. WBUFW(buf,0) = 0x119;
  2722. WBUFL(buf,2) = bl->id;
  2723. WBUFW(buf,6) = sc->opt1;
  2724. WBUFW(buf,8) = sc->opt2;
  2725. WBUFW(buf,10) = sc->option;
  2726. WBUFB(buf,12) = 0; // ??
  2727. if(disguised(bl)) {
  2728. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2729. WBUFL(buf,2) = -bl->id;
  2730. clif_send(buf,packet_len(0x119),bl,SELF);
  2731. WBUFL(buf,2) = bl->id;
  2732. WBUFW(buf,10) = OPTION_INVISIBLE;
  2733. clif_send(buf,packet_len(0x119),bl,SELF);
  2734. } else
  2735. clif_send(buf,packet_len(0x119),bl,AREA);
  2736. #endif
  2737. return 0;
  2738. }
  2739. int clif_changeoption2(struct block_list* bl)
  2740. {
  2741. unsigned char buf[20];
  2742. struct status_change *sc;
  2743. sc = status_get_sc(bl);
  2744. if (!sc) return 0; //How can an option change if there's no sc?
  2745. WBUFW(buf,0) = 0x28a;
  2746. WBUFL(buf,2) = bl->id;
  2747. WBUFL(buf,6) = sc->option;
  2748. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2749. WBUFL(buf,14) = sc->opt3;
  2750. if(disguised(bl)) {
  2751. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2752. WBUFL(buf,2) = -bl->id;
  2753. clif_send(buf,packet_len(0x28a),bl,SELF);
  2754. WBUFL(buf,2) = bl->id;
  2755. WBUFL(buf,6) = OPTION_INVISIBLE;
  2756. clif_send(buf,packet_len(0x28a),bl,SELF);
  2757. } else
  2758. clif_send(buf,packet_len(0x28a),bl,AREA);
  2759. return 0;
  2760. }
  2761. /*==========================================
  2762. *
  2763. *------------------------------------------*/
  2764. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2765. {
  2766. nullpo_retr(0, sd);
  2767. if(!ok) {
  2768. int fd=sd->fd;
  2769. WFIFOHEAD(fd,packet_len(0xa8));
  2770. WFIFOW(fd,0)=0xa8;
  2771. WFIFOW(fd,2)=index+2;
  2772. WFIFOW(fd,4)=amount;
  2773. WFIFOB(fd,6)=ok;
  2774. WFIFOSET(fd,packet_len(0xa8));
  2775. }
  2776. else {
  2777. #if PACKETVER < 3
  2778. int fd=sd->fd;
  2779. WFIFOHEAD(fd,packet_len(0xa8));
  2780. WFIFOW(fd,0)=0xa8;
  2781. WFIFOW(fd,2)=index+2;
  2782. WFIFOW(fd,4)=amount;
  2783. WFIFOB(fd,6)=ok;
  2784. WFIFOSET(fd,packet_len(0xa8));
  2785. #else
  2786. unsigned char buf[32];
  2787. WBUFW(buf,0)=0x1c8;
  2788. WBUFW(buf,2)=index+2;
  2789. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2790. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2791. else
  2792. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2793. WBUFL(buf,6)=sd->bl.id;
  2794. WBUFW(buf,10)=amount;
  2795. WBUFB(buf,12)=ok;
  2796. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2797. #endif
  2798. }
  2799. return 0;
  2800. }
  2801. /*==========================================
  2802. * Inform client whether chatroom creation was successful or not
  2803. * R 00d6 <fail>.B
  2804. *------------------------------------------*/
  2805. void clif_createchat(struct map_session_data* sd, int fail)
  2806. {
  2807. int fd;
  2808. nullpo_retv(sd);
  2809. fd = sd->fd;
  2810. WFIFOHEAD(fd,packet_len(0xd6));
  2811. WFIFOW(fd,0) = 0xd6;
  2812. WFIFOB(fd,2) = fail;
  2813. WFIFOSET(fd,packet_len(0xd6));
  2814. }
  2815. /*==========================================
  2816. * Display a chat above the owner
  2817. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2818. *------------------------------------------*/
  2819. int clif_dispchat(struct chat_data* cd, int fd)
  2820. {
  2821. unsigned char buf[128];
  2822. uint8 type;
  2823. if( cd == NULL || cd->owner == NULL )
  2824. return 1;
  2825. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2826. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2827. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2828. : 1;
  2829. WBUFW(buf, 0) = 0xd7;
  2830. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2831. WBUFL(buf, 4) = cd->owner->id;
  2832. WBUFL(buf, 8) = cd->bl.id;
  2833. WBUFW(buf,12) = cd->limit;
  2834. WBUFW(buf,14) = cd->users;
  2835. WBUFB(buf,16) = type;
  2836. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2837. if( fd ) {
  2838. WFIFOHEAD(fd,WBUFW(buf,2));
  2839. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2840. WFIFOSET(fd,WBUFW(buf,2));
  2841. } else {
  2842. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2843. }
  2844. return 0;
  2845. }
  2846. /*==========================================
  2847. * Chatroom properties adjustment
  2848. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2849. *------------------------------------------*/
  2850. int clif_changechatstatus(struct chat_data* cd)
  2851. {
  2852. unsigned char buf[128];
  2853. if( cd == NULL || cd->usersd[0] == NULL )
  2854. return 1;
  2855. WBUFW(buf, 0) = 0xdf;
  2856. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2857. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2858. WBUFL(buf, 8) = cd->bl.id;
  2859. WBUFW(buf,12) = cd->limit;
  2860. WBUFW(buf,14) = cd->users;
  2861. WBUFB(buf,16) = cd->pub;
  2862. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2863. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2864. return 0;
  2865. }
  2866. /*==========================================
  2867. *
  2868. *------------------------------------------*/
  2869. int clif_clearchat(struct chat_data *cd,int fd)
  2870. {
  2871. unsigned char buf[32];
  2872. nullpo_retr(0, cd);
  2873. WBUFW(buf,0) = 0xd8;
  2874. WBUFL(buf,2) = cd->bl.id;
  2875. if( fd ) {
  2876. WFIFOHEAD(fd,packet_len(0xd8));
  2877. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2878. WFIFOSET(fd,packet_len(0xd8));
  2879. } else {
  2880. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2881. }
  2882. return 0;
  2883. }
  2884. /*==========================================
  2885. *
  2886. *------------------------------------------*/
  2887. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2888. {
  2889. int fd;
  2890. nullpo_retr(0, sd);
  2891. fd = sd->fd;
  2892. WFIFOHEAD(fd,packet_len(0xda));
  2893. WFIFOW(fd,0) = 0xda;
  2894. WFIFOB(fd,2) = fail;
  2895. WFIFOSET(fd,packet_len(0xda));
  2896. return 0;
  2897. }
  2898. /*==========================================
  2899. *
  2900. *------------------------------------------*/
  2901. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2902. {
  2903. int fd;
  2904. int i;
  2905. nullpo_retr(0, sd);
  2906. nullpo_retr(0, cd);
  2907. fd = sd->fd;
  2908. if (!session_isActive(fd))
  2909. return 0;
  2910. WFIFOHEAD(fd, 8 + (28*cd->users));
  2911. WFIFOW(fd, 0) = 0xdb;
  2912. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2913. WFIFOL(fd, 4) = cd->bl.id;
  2914. for (i = 0; i < cd->users; i++) {
  2915. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2916. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2917. }
  2918. WFIFOSET(fd, WFIFOW(fd, 2));
  2919. return 0;
  2920. }
  2921. /*==========================================
  2922. *
  2923. *------------------------------------------*/
  2924. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2925. {
  2926. unsigned char buf[32];
  2927. nullpo_retr(0, sd);
  2928. nullpo_retr(0, cd);
  2929. WBUFW(buf, 0) = 0x0dc;
  2930. WBUFW(buf, 2) = cd->users;
  2931. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2932. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2933. return 0;
  2934. }
  2935. /*==========================================
  2936. * Announce the new owner
  2937. * R 00e1 <index>.l <nick>.24B
  2938. *------------------------------------------*/
  2939. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2940. {
  2941. unsigned char buf[64];
  2942. nullpo_retv(sd);
  2943. nullpo_retv(cd);
  2944. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2945. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2946. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2947. WBUFW(buf, 0) = 0xe1;
  2948. WBUFL(buf, 2) = 1;
  2949. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2950. WBUFW(buf,30) = 0xe1;
  2951. WBUFL(buf,32) = 0;
  2952. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2953. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2954. }
  2955. /*==========================================
  2956. * Notify about user leaving the chatroom
  2957. * R 00dd <index>.w <nick>.24B <flag>.B
  2958. *------------------------------------------*/
  2959. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2960. {
  2961. unsigned char buf[32];
  2962. nullpo_retv(sd);
  2963. nullpo_retv(cd);
  2964. WBUFW(buf, 0) = 0xdd;
  2965. WBUFW(buf, 2) = cd->users-1;
  2966. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2967. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2968. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2969. }
  2970. /*==========================================
  2971. * Opens a trade request window from char 'name'
  2972. * R 00e5 <nick>.24B
  2973. *------------------------------------------*/
  2974. void clif_traderequest(struct map_session_data* sd, const char* name)
  2975. {
  2976. int fd;
  2977. nullpo_retv(sd);
  2978. fd = sd->fd;
  2979. WFIFOHEAD(fd,packet_len(0xe5));
  2980. WFIFOW(fd,0) = 0xe5;
  2981. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2982. WFIFOSET(fd,packet_len(0xe5));
  2983. }
  2984. /*==========================================
  2985. * 取り引き要求応答
  2986. *------------------------------------------*/
  2987. void clif_tradestart(struct map_session_data* sd, int type)
  2988. {
  2989. int fd;
  2990. nullpo_retv(sd);
  2991. fd = sd->fd;
  2992. WFIFOHEAD(fd,packet_len(0xe7));
  2993. WFIFOW(fd,0) = 0xe7;
  2994. WFIFOB(fd,2) = type;
  2995. WFIFOSET(fd,packet_len(0xe7));
  2996. }
  2997. /*==========================================
  2998. * 相手方からのアイテム追加
  2999. *------------------------------------------*/
  3000. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3001. {
  3002. int fd;
  3003. nullpo_retv(sd);
  3004. nullpo_retv(tsd);
  3005. fd = tsd->fd;
  3006. WFIFOHEAD(fd,packet_len(0xe9));
  3007. WFIFOW(fd,0) = 0xe9;
  3008. WFIFOL(fd,2) = amount;
  3009. if( index == 0 )
  3010. {
  3011. WFIFOW(fd,6) = 0; // type id
  3012. WFIFOB(fd,8) = 0; //identify flag
  3013. WFIFOB(fd,9) = 0; // attribute
  3014. WFIFOB(fd,10)= 0; //refine
  3015. WFIFOW(fd,11)= 0; //card (4w)
  3016. WFIFOW(fd,13)= 0; //card (4w)
  3017. WFIFOW(fd,15)= 0; //card (4w)
  3018. WFIFOW(fd,17)= 0; //card (4w)
  3019. }
  3020. else
  3021. {
  3022. index -= 2; //index fix
  3023. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3024. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3025. else
  3026. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3027. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3028. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3029. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3030. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3031. }
  3032. WFIFOSET(fd,packet_len(0xe9));
  3033. }
  3034. /*==========================================
  3035. * アイテム追加成功/失敗
  3036. *------------------------------------------*/
  3037. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3038. {
  3039. int fd;
  3040. nullpo_retv(sd);
  3041. fd = sd->fd;
  3042. WFIFOHEAD(fd,packet_len(0xea));
  3043. WFIFOW(fd,0) = 0xea;
  3044. WFIFOW(fd,2) = index;
  3045. WFIFOB(fd,4) = fail;
  3046. WFIFOSET(fd,packet_len(0xea));
  3047. }
  3048. /*==========================================
  3049. * 取り引きok押し
  3050. *------------------------------------------*/
  3051. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3052. {
  3053. int fd;
  3054. nullpo_retv(sd);
  3055. fd = sd->fd;
  3056. WFIFOHEAD(fd,packet_len(0xec));
  3057. WFIFOW(fd,0) = 0xec;
  3058. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  3059. WFIFOSET(fd,packet_len(0xec));
  3060. }
  3061. /*==========================================
  3062. * 取り引きがキャンセルされました
  3063. *------------------------------------------*/
  3064. void clif_tradecancelled(struct map_session_data* sd)
  3065. {
  3066. int fd;
  3067. nullpo_retv(sd);
  3068. fd = sd->fd;
  3069. WFIFOHEAD(fd,packet_len(0xee));
  3070. WFIFOW(fd,0) = 0xee;
  3071. WFIFOSET(fd,packet_len(0xee));
  3072. }
  3073. /*==========================================
  3074. * 取り引き完了
  3075. *------------------------------------------*/
  3076. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3077. {
  3078. int fd;
  3079. nullpo_retv(sd);
  3080. fd = sd->fd;
  3081. WFIFOHEAD(fd,packet_len(0xf0));
  3082. WFIFOW(fd,0) = 0xf0;
  3083. WFIFOB(fd,2) = fail;
  3084. WFIFOSET(fd,packet_len(0xf0));
  3085. }
  3086. /*==========================================
  3087. * カプラ倉庫のアイテム数を更新
  3088. *------------------------------------------*/
  3089. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3090. {
  3091. int fd;
  3092. nullpo_retr(0, sd);
  3093. nullpo_retr(0, stor);
  3094. fd=sd->fd;
  3095. WFIFOHEAD(fd,packet_len(0xf2));
  3096. WFIFOW(fd,0) = 0xf2; // update storage amount
  3097. WFIFOW(fd,2) = stor->storage_amount; //items
  3098. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3099. WFIFOSET(fd,packet_len(0xf2));
  3100. return 0;
  3101. }
  3102. /*==========================================
  3103. * カプラ倉庫にアイテムを追加する
  3104. *------------------------------------------*/
  3105. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3106. {
  3107. int view,fd;
  3108. nullpo_retr(0, sd);
  3109. nullpo_retr(0, stor);
  3110. fd=sd->fd;
  3111. WFIFOHEAD(fd,packet_len(0xf4));
  3112. WFIFOW(fd,0) =0xf4; // Storage item added
  3113. WFIFOW(fd,2) =index+1; // index
  3114. WFIFOL(fd,4) =amount; // amount
  3115. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3116. WFIFOW(fd,8) =view;
  3117. else
  3118. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3119. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3120. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3121. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3122. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3123. WFIFOSET(fd,packet_len(0xf4));
  3124. return 0;
  3125. }
  3126. /*==========================================
  3127. *
  3128. *------------------------------------------*/
  3129. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3130. {
  3131. int fd;
  3132. nullpo_retr(0, sd);
  3133. nullpo_retr(0, stor);
  3134. fd=sd->fd;
  3135. WFIFOHEAD(fd,packet_len(0xf2));
  3136. WFIFOW(fd,0) = 0xf2; // update storage amount
  3137. WFIFOW(fd,2) = stor->storage_amount; //items
  3138. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3139. WFIFOSET(fd,packet_len(0xf2));
  3140. return 0;
  3141. }
  3142. /*==========================================
  3143. *
  3144. *------------------------------------------*/
  3145. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3146. {
  3147. int view,fd;
  3148. nullpo_retr(0, sd);
  3149. nullpo_retr(0, stor);
  3150. fd=sd->fd;
  3151. WFIFOHEAD(fd,packet_len(0xf4));
  3152. WFIFOW(fd,0) =0xf4; // Storage item added
  3153. WFIFOW(fd,2) =index+1; // index
  3154. WFIFOL(fd,4) =amount; // amount
  3155. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3156. WFIFOW(fd,8) =view;
  3157. else
  3158. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3159. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3160. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3161. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3162. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3163. WFIFOSET(fd,packet_len(0xf4));
  3164. return 0;
  3165. }
  3166. /*==========================================
  3167. * カプラ倉庫からアイテムを取り去る
  3168. *------------------------------------------*/
  3169. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3170. {
  3171. int fd;
  3172. nullpo_retr(0, sd);
  3173. fd=sd->fd;
  3174. WFIFOHEAD(fd,packet_len(0xf6));
  3175. WFIFOW(fd,0)=0xf6; // Storage item removed
  3176. WFIFOW(fd,2)=index+1;
  3177. WFIFOL(fd,4)=amount;
  3178. WFIFOSET(fd,packet_len(0xf6));
  3179. return 0;
  3180. }
  3181. /*==========================================
  3182. * カプラ倉庫を閉じる
  3183. *------------------------------------------*/
  3184. int clif_storageclose(struct map_session_data *sd)
  3185. {
  3186. int fd;
  3187. nullpo_retr(0, sd);
  3188. fd=sd->fd;
  3189. WFIFOHEAD(fd,packet_len(0xf8));
  3190. WFIFOW(fd,0)=0xf8; // Storage Closed
  3191. WFIFOSET(fd,packet_len(0xf8));
  3192. return 0;
  3193. }
  3194. //
  3195. // callback系 ?
  3196. //
  3197. /*==========================================
  3198. * PC表示
  3199. *------------------------------------------*/
  3200. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3201. {
  3202. int len;
  3203. if(dstsd->chatID)
  3204. {
  3205. struct chat_data *cd;
  3206. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3207. if(cd && cd->usersd[0]==dstsd)
  3208. clif_dispchat(cd,sd->fd);
  3209. }
  3210. if(dstsd->vender_id)
  3211. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3212. if(dstsd->spiritball > 0)
  3213. clif_spiritball_single(sd->fd, dstsd);
  3214. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3215. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3216. )
  3217. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3218. if(dstsd->status.manner < 0)
  3219. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3220. // pvp circle for duel [LuzZza]
  3221. /*
  3222. if(dstsd->duel_group)
  3223. clif_specialeffect(&dstsd->bl, 159, 4);
  3224. */
  3225. }
  3226. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3227. {
  3228. struct unit_data *ud;
  3229. struct view_data *vd;
  3230. int len, fd = sd->fd;
  3231. vd = status_get_viewdata(bl);
  3232. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3233. return;
  3234. ud = unit_bl2ud(bl);
  3235. if (ud && ud->walktimer != -1)
  3236. {
  3237. #if PACKETVER >= 7
  3238. WFIFOHEAD(fd, packet_len(0x22c));
  3239. #elif PACKETVER > 3
  3240. WFIFOHEAD(fd, packet_len(0x1da));
  3241. #else
  3242. WFIFOHEAD(fd, packet_len(0x7b));
  3243. #endif
  3244. len = clif_set007b(bl,vd,ud,WFIFOP(fd,0));
  3245. WFIFOSET(fd,len);
  3246. } else {
  3247. #if PACKETVER >= 7
  3248. WFIFOHEAD(fd,packet_len(0x22a));
  3249. #elif PACKETVER > 3
  3250. WFIFOHEAD(fd,packet_len(0x1d8));
  3251. #else
  3252. WFIFOHEAD(fd,packet_len(0x78));
  3253. #endif
  3254. len = clif_set0078(bl,WFIFOP(fd,0));
  3255. WFIFOSET(fd,len);
  3256. }
  3257. if (vd->cloth_color)
  3258. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3259. switch (bl->type)
  3260. { // FIXME: 'AREA' causes unneccessary spam since this should be 1:1 communication [ultramage]
  3261. case BL_PC:
  3262. {
  3263. TBL_PC* tsd = (TBL_PC*)bl;
  3264. clif_getareachar_pc(sd, tsd);
  3265. if(tsd->state.size==2) // tiny/big players [Valaris]
  3266. clif_specialeffect(bl,423,AREA);
  3267. else if(tsd->state.size==1)
  3268. clif_specialeffect(bl,421,AREA);
  3269. }
  3270. break;
  3271. case BL_NPC:
  3272. {
  3273. if(((TBL_NPC*)bl)->chat_id)
  3274. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3275. }
  3276. break;
  3277. case BL_MOB:
  3278. {
  3279. TBL_MOB* md = (TBL_MOB*)bl;
  3280. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3281. clif_specialeffect(bl,423,AREA);
  3282. else if(md->special_state.size==1)
  3283. clif_specialeffect(bl,421,AREA);
  3284. }
  3285. break;
  3286. case BL_PET:
  3287. if (vd->head_bottom)
  3288. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3289. break;
  3290. }
  3291. }
  3292. /*==========================================
  3293. * Estimates walk delay based on the damage criteria. [Skotlex]
  3294. *------------------------------------------*/
  3295. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3296. {
  3297. if (type == 4 || type == 9 || damage <=0)
  3298. return 0;
  3299. if (bl->type == BL_PC) {
  3300. if (battle_config.pc_walk_delay_rate != 100)
  3301. delay = delay*battle_config.pc_walk_delay_rate/100;
  3302. } else
  3303. if (battle_config.walk_delay_rate != 100)
  3304. delay = delay*battle_config.walk_delay_rate/100;
  3305. if (div_ > 1) //Multi-hit skills mean higher delays.
  3306. delay += battle_config.multihit_delay*(div_-1);
  3307. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3308. }
  3309. /*==========================================
  3310. * Sends a 'damage' packet (src performs action on dst)
  3311. * R 008a <src ID>.l <dst ID>.l <server tick>.l <src speed>.l <dst speed>.l <param1>.w <param2>.w <type>.B <param3>.w
  3312. *
  3313. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3314. * type=01 pick up item
  3315. * type=02 sit down
  3316. * type=03 stand up
  3317. * type=04 reflected/absorbed damage?
  3318. * type=08 double attack
  3319. * type=09 don't display flinch animation (endure)
  3320. * type=0a critical hit
  3321. * type=0b lucky dodge
  3322. *------------------------------------------*/
  3323. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int damage, int div, int type, int damage2)
  3324. {
  3325. unsigned char buf[256];
  3326. struct status_change *sc;
  3327. nullpo_retr(0, src);
  3328. nullpo_retr(0, dst);
  3329. sc = status_get_sc(dst);
  3330. if(sc && sc->count) {
  3331. if(type != 4 && dst->type == BL_PC && sc->data[SC_ENDURE].timer != -1 && !map_flag_gvg(dst->m))
  3332. type = 9;
  3333. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3334. if(damage > 0) damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3335. if(damage2 > 0) damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3336. }
  3337. }
  3338. WBUFW(buf,0)=0x8a;
  3339. WBUFL(buf,2)=src->id;
  3340. WBUFL(buf,6)=dst->id;
  3341. WBUFL(buf,10)=tick;
  3342. WBUFL(buf,14)=sdelay;
  3343. WBUFL(buf,18)=ddelay;
  3344. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3345. WBUFW(buf,22)=damage?div:0;
  3346. WBUFW(buf,27)=damage2?div:0;
  3347. } else {
  3348. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3349. WBUFW(buf,27)=damage2;
  3350. }
  3351. WBUFW(buf,24)=div;
  3352. WBUFB(buf,26)=type;
  3353. clif_send(buf,packet_len(0x8a),src,AREA);
  3354. if(disguised(src)) {
  3355. WBUFL(buf,2) = -src->id;
  3356. if(damage > 0) WBUFW(buf,22) = -1;
  3357. if(damage2 > 0) WBUFW(buf,27) = -1;
  3358. clif_send(buf,packet_len(0x8a),src,SELF);
  3359. }
  3360. if (disguised(dst)) {
  3361. WBUFL(buf,6) = -dst->id;
  3362. if (disguised(src)) WBUFL(buf,2) = src->id;
  3363. else {
  3364. if(damage > 0) WBUFW(buf,22) = -1;
  3365. if(damage2 > 0) WBUFW(buf,27) = -1;
  3366. }
  3367. clif_send(buf,packet_len(0x8a),dst,SELF);
  3368. }
  3369. //Return adjusted can't walk delay for further processing.
  3370. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3371. }
  3372. /*==========================================
  3373. * src picks up dst
  3374. *------------------------------------------*/
  3375. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3376. {
  3377. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3378. unsigned char buf[32];
  3379. nullpo_retv(src);
  3380. nullpo_retv(dst);
  3381. WBUFW(buf, 0) = 0x8a;
  3382. WBUFL(buf, 2) = src->id;
  3383. WBUFL(buf, 6) = dst->id;
  3384. WBUFB(buf,26) = 1;
  3385. clif_send(buf, packet_len(0x8a), src, AREA);
  3386. }
  3387. /*==========================================
  3388. * inform clients in area that `bl` is sitting
  3389. *------------------------------------------*/
  3390. void clif_sitting(struct block_list* bl)
  3391. {
  3392. unsigned char buf[32];
  3393. nullpo_retv(bl);
  3394. WBUFW(buf, 0) = 0x8a;
  3395. WBUFL(buf, 2) = bl->id;
  3396. WBUFB(buf,26) = 2;
  3397. clif_send(buf, packet_len(0x8a), bl, AREA);
  3398. if(disguised(bl)) {
  3399. WBUFL(buf, 2) = - bl->id;
  3400. clif_send(buf, packet_len(0x8a), bl, SELF);
  3401. }
  3402. }
  3403. /*==========================================
  3404. * inform clients in area that `bl` is standing
  3405. *------------------------------------------*/
  3406. void clif_standing(struct block_list* bl)
  3407. {
  3408. unsigned char buf[32];
  3409. nullpo_retv(bl);
  3410. WBUFW(buf, 0) = 0x8a;
  3411. WBUFL(buf, 2) = bl->id;
  3412. WBUFB(buf,26) = 3;
  3413. clif_send(buf, packet_len(0x8a), bl, AREA);
  3414. if(disguised(bl)) {
  3415. WBUFL(buf, 2) = - bl->id;
  3416. clif_send(buf, packet_len(0x8a), bl, SELF);
  3417. }
  3418. }
  3419. /*==========================================
  3420. * Inform client(s) about a map-cell change
  3421. *------------------------------------------*/
  3422. void clif_changemapcell(int fd, struct block_list* pos, int type, enum send_target target)
  3423. {
  3424. unsigned char buf[32];
  3425. nullpo_retv(pos);
  3426. WBUFW(buf,0) = 0x192;
  3427. WBUFW(buf,2) = pos->x;
  3428. WBUFW(buf,4) = pos->y;
  3429. WBUFW(buf,6) = type;
  3430. mapindex_getmapname_ext(map[pos->m].name,(char*)WBUFP(buf,8));
  3431. if( fd )
  3432. {
  3433. WFIFOHEAD(fd,packet_len(0x192));
  3434. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3435. WFIFOSET(fd,packet_len(0x192));
  3436. }
  3437. else
  3438. clif_send(buf,packet_len(0x192),pos,target);
  3439. }
  3440. /*==========================================
  3441. *
  3442. *------------------------------------------*/
  3443. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3444. {
  3445. int view,fd;
  3446. fd=sd->fd;
  3447. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3448. WFIFOHEAD(fd,packet_len(0x9d));
  3449. WFIFOW(fd,0)=0x9d;
  3450. WFIFOL(fd,2)=fitem->bl.id;
  3451. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3452. WFIFOW(fd,6)=view;
  3453. else
  3454. WFIFOW(fd,6)=fitem->item_data.nameid;
  3455. WFIFOB(fd,8)=fitem->item_data.identify;
  3456. WFIFOW(fd,9)=fitem->bl.x;
  3457. WFIFOW(fd,11)=fitem->bl.y;
  3458. WFIFOW(fd,13)=fitem->item_data.amount;
  3459. WFIFOB(fd,15)=fitem->subx;
  3460. WFIFOB(fd,16)=fitem->suby;
  3461. WFIFOSET(fd,packet_len(0x9d));
  3462. }
  3463. /*==========================================
  3464. * 場所スキルエフェクトが視界に入る
  3465. *------------------------------------------*/
  3466. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3467. {
  3468. int fd = sd->fd;
  3469. #if PACKETVER >= 3
  3470. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3471. WFIFOHEAD(fd,packet_len(0x1c9));
  3472. WFIFOW(fd, 0)=0x1c9;
  3473. WFIFOL(fd, 2)=unit->bl.id;
  3474. WFIFOL(fd, 6)=unit->group->src_id;
  3475. WFIFOW(fd,10)=unit->bl.x;
  3476. WFIFOW(fd,12)=unit->bl.y;
  3477. WFIFOB(fd,14)=unit->group->unit_id;
  3478. WFIFOB(fd,15)=1;
  3479. WFIFOB(fd,16)=1;
  3480. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3481. WFIFOSET(fd,packet_len(0x1c9));
  3482. return;
  3483. }
  3484. #endif
  3485. WFIFOHEAD(fd,packet_len(0x11f));
  3486. WFIFOW(fd, 0)=0x11f;
  3487. WFIFOL(fd, 2)=unit->bl.id;
  3488. WFIFOL(fd, 6)=unit->group->src_id;
  3489. WFIFOW(fd,10)=unit->bl.x;
  3490. WFIFOW(fd,12)=unit->bl.y;
  3491. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3492. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3493. else
  3494. WFIFOB(fd,14)=unit->group->unit_id;
  3495. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3496. WFIFOSET(fd,packet_len(0x11f));
  3497. if(unit->group->skill_id == WZ_ICEWALL)
  3498. clif_changemapcell(fd,&unit->bl,5,SELF);
  3499. }
  3500. /*==========================================
  3501. * 場所スキルエフェクトが視界から消える
  3502. *------------------------------------------*/
  3503. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3504. {
  3505. nullpo_retv(unit);
  3506. WFIFOHEAD(fd,packet_len(0x120));
  3507. WFIFOW(fd, 0)=0x120;
  3508. WFIFOL(fd, 2)=unit->bl.id;
  3509. WFIFOSET(fd,packet_len(0x120));
  3510. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3511. clif_changemapcell(fd,&unit->bl,unit->val2,SELF);
  3512. }
  3513. /*==========================================
  3514. * 場所スキルエフェクト削除
  3515. *------------------------------------------*/
  3516. void clif_skill_delunit(struct skill_unit *unit)
  3517. {
  3518. unsigned char buf[16];
  3519. nullpo_retv(unit);
  3520. WBUFW(buf, 0)=0x120;
  3521. WBUFL(buf, 2)=unit->bl.id;
  3522. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3523. }
  3524. /*==========================================
  3525. * Unknown... trap related?
  3526. * Sent when an object gets ankle-snared
  3527. * Only affects units with class [139,153] client-side
  3528. * R 01ac <object id>.l
  3529. *------------------------------------------*/
  3530. void clif_01ac(struct block_list* bl)
  3531. {
  3532. unsigned char buf[6];
  3533. nullpo_retv(bl);
  3534. WBUFW(buf,0) = 0x1ac;
  3535. WBUFL(buf,2) = bl->id;
  3536. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3537. }
  3538. /*==========================================
  3539. *
  3540. *------------------------------------------*/
  3541. int clif_getareachar(struct block_list* bl,va_list ap)
  3542. {
  3543. struct map_session_data *sd;
  3544. nullpo_retr(0, bl);
  3545. nullpo_retr(0, ap);
  3546. sd=va_arg(ap,struct map_session_data*);
  3547. if (sd == NULL || !sd->fd || session[sd->fd] == NULL)
  3548. return 0;
  3549. switch(bl->type){
  3550. case BL_ITEM:
  3551. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3552. break;
  3553. case BL_SKILL:
  3554. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3555. break;
  3556. default:
  3557. if(&sd->bl == bl)
  3558. break;
  3559. clif_getareachar_unit(sd,bl);
  3560. break;
  3561. }
  3562. return 0;
  3563. }
  3564. /*==========================================
  3565. * tbl has gone out of view-size of bl
  3566. *------------------------------------------*/
  3567. int clif_outsight(struct block_list *bl,va_list ap)
  3568. {
  3569. struct block_list *tbl;
  3570. struct view_data *vd;
  3571. TBL_PC *sd, *tsd;
  3572. tbl=va_arg(ap,struct block_list*);
  3573. if(bl == tbl) return 0;
  3574. BL_CAST(BL_PC, bl, sd);
  3575. BL_CAST(BL_PC, tbl, tsd);
  3576. if (tsd && tsd->fd)
  3577. { //tsd has lost sight of the bl object.
  3578. switch(bl->type){
  3579. case BL_PC:
  3580. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3581. clif_clearunit_single(bl->id,0,tsd->fd);
  3582. if(sd->chatID){
  3583. struct chat_data *cd;
  3584. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3585. if(cd->usersd[0]==sd)
  3586. clif_dispchat(cd,tsd->fd);
  3587. }
  3588. if(sd->vender_id)
  3589. clif_closevendingboard(bl,tsd->fd);
  3590. break;
  3591. case BL_ITEM:
  3592. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3593. break;
  3594. case BL_SKILL:
  3595. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3596. break;
  3597. default:
  3598. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3599. clif_clearunit_single(bl->id,0,tsd->fd);
  3600. break;
  3601. }
  3602. }
  3603. if (sd && sd->fd)
  3604. { //sd is watching tbl go out of view.
  3605. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3606. clif_clearunit_single(tbl->id,0,sd->fd);
  3607. }
  3608. return 0;
  3609. }
  3610. /*==========================================
  3611. * tbl has come into view of bl
  3612. *------------------------------------------*/
  3613. int clif_insight(struct block_list *bl,va_list ap)
  3614. {
  3615. struct block_list *tbl;
  3616. TBL_PC *sd, *tsd;
  3617. tbl=va_arg(ap,struct block_list*);
  3618. if (bl == tbl) return 0;
  3619. BL_CAST(BL_PC, bl, sd);
  3620. BL_CAST(BL_PC, tbl, tsd);
  3621. if (tsd && tsd->fd)
  3622. { //Tell tsd that bl entered into his view
  3623. switch(bl->type){
  3624. case BL_ITEM:
  3625. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3626. break;
  3627. case BL_SKILL:
  3628. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3629. break;
  3630. default:
  3631. clif_getareachar_unit(tsd,bl);
  3632. break;
  3633. }
  3634. }
  3635. if (sd && sd->fd)
  3636. { //Tell sd that tbl walked into his view
  3637. clif_getareachar_unit(sd,tbl);
  3638. }
  3639. return 0;
  3640. }
  3641. /*==========================================
  3642. *
  3643. *------------------------------------------*/
  3644. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3645. {
  3646. int fd,id;
  3647. nullpo_retr(0, sd);
  3648. fd=sd->fd;
  3649. if( (id=sd->status.skill[skillid].id) <= 0 )
  3650. return 0;
  3651. WFIFOHEAD(fd,packet_len(0x147));
  3652. WFIFOW(fd,0)=0x147;
  3653. WFIFOW(fd,2) = id;
  3654. if(type < 0)
  3655. WFIFOW(fd,4) = skill_get_inf(id);
  3656. else
  3657. WFIFOW(fd,4) = type;
  3658. WFIFOW(fd,6) = 0;
  3659. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3660. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3661. if(range < 0)
  3662. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3663. WFIFOW(fd,12)= range;
  3664. strncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3665. if(sd->status.skill[skillid].flag ==0)
  3666. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3667. else
  3668. WFIFOB(fd,38) = 0;
  3669. WFIFOSET(fd,packet_len(0x147));
  3670. return 0;
  3671. }
  3672. /*==========================================
  3673. * スキルリストを送信する
  3674. *------------------------------------------*/
  3675. int clif_skillinfoblock(struct map_session_data *sd)
  3676. {
  3677. int fd;
  3678. int i,c,len,id;
  3679. nullpo_retr(0, sd);
  3680. fd=sd->fd;
  3681. if (!fd) return 0;
  3682. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3683. WFIFOW(fd,0) = 0x10f;
  3684. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3685. {
  3686. if( (id = sd->status.skill[i].id) != 0 )
  3687. {
  3688. WFIFOW(fd,len) = id;
  3689. WFIFOW(fd,len+2) = skill_get_inf(id);
  3690. WFIFOW(fd,len+4) = 0;
  3691. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3692. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3693. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3694. strncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3695. if(sd->status.skill[i].flag == 0)
  3696. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3697. else
  3698. WFIFOB(fd,len+36) = 0;
  3699. len += 37;
  3700. c++;
  3701. }
  3702. }
  3703. WFIFOW(fd,2)=len;
  3704. WFIFOSET(fd,len);
  3705. return 1;
  3706. }
  3707. /*==========================================
  3708. * スキル割り振り通知
  3709. *------------------------------------------*/
  3710. int clif_skillup(struct map_session_data *sd,int skill_num)
  3711. {
  3712. int fd;
  3713. nullpo_retr(0, sd);
  3714. fd=sd->fd;
  3715. WFIFOHEAD(fd,packet_len(0x10e));
  3716. WFIFOW(fd,0) = 0x10e;
  3717. WFIFOW(fd,2) = skill_num;
  3718. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3719. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3720. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3721. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3722. WFIFOSET(fd,packet_len(0x10e));
  3723. return 0;
  3724. }
  3725. /*==========================================
  3726. * スキル詠唱エフェクトを送信する
  3727. *------------------------------------------*/
  3728. int clif_skillcasting(struct block_list* bl,
  3729. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3730. {
  3731. unsigned char buf[32];
  3732. WBUFW(buf,0) = 0x13e;
  3733. WBUFL(buf,2) = src_id;
  3734. WBUFL(buf,6) = dst_id;
  3735. WBUFW(buf,10) = dst_x;
  3736. WBUFW(buf,12) = dst_y;
  3737. WBUFW(buf,14) = skill_num;
  3738. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3739. WBUFL(buf,20) = casttime;
  3740. clif_send(buf,packet_len(0x13e), bl, AREA);
  3741. if (disguised(bl)) {
  3742. WBUFL(buf,2) = -src_id;
  3743. WBUFL(buf,20) = 0;
  3744. clif_send(buf,packet_len(0x13e), bl, SELF);
  3745. }
  3746. return 0;
  3747. }
  3748. /*==========================================
  3749. *
  3750. *------------------------------------------*/
  3751. int clif_skillcastcancel(struct block_list* bl)
  3752. {
  3753. unsigned char buf[16];
  3754. nullpo_retr(0, bl);
  3755. WBUFW(buf,0) = 0x1b9;
  3756. WBUFL(buf,2) = bl->id;
  3757. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3758. return 0;
  3759. }
  3760. /// only when type==0:
  3761. /// if(skill_id==NV_BASIC)
  3762. /// btype==0 "skill failed" MsgStringTable[159]
  3763. /// btype==1 "no emotions" MsgStringTable[160]
  3764. /// btype==2 "no sit" MsgStringTable[161]
  3765. /// btype==3 "no chat" MsgStringTable[162]
  3766. /// btype==4 "no party" MsgStringTable[163]
  3767. /// btype==5 "no shout" MsgStringTable[164]
  3768. /// btype==6 "no PKing" MsgStringTable[165]
  3769. /// btype==7 "no alligning" MsgStringTable[383]
  3770. /// btype>=8: ignored
  3771. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3772. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3773. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3774. /// otherwise "skill failed" MsgStringTable[204]
  3775. /// btype irrelevant
  3776. /// type==1 "insufficient SP" MsgStringTable[202]
  3777. /// type==2 "insufficient HP" MsgStringTable[203]
  3778. /// type==3 "insufficient materials" MsgStringTable[808]
  3779. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3780. /// type==5 "insufficient zeny" MsgStringTable[233]
  3781. /// type==6 "wrong weapon" MsgStringTable[239]
  3782. /// type==7 "red gemstone needed" MsgStringTable[246]
  3783. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3784. /// type==9 "overweight" MsgStringTable[580]
  3785. /// type==10 "skill failed" MsgStringTable[285]
  3786. /// type>=11 ignored
  3787. ///
  3788. /// if(success!=0) doesn't display any of the previous messages
  3789. /// Note: when this packet is received an unknown flag is always set to 0,
  3790. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3791. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3792. {
  3793. int fd;
  3794. if (!sd) { //Since this is the most common nullpo....
  3795. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3796. return 0;
  3797. }
  3798. fd=sd->fd;
  3799. if (!fd) return 0;
  3800. if(battle_config.display_skill_fail&1)
  3801. return 0; //Disable all skill failed messages
  3802. if(type==0x4 && !sd->state.showdelay)
  3803. return 0; //Disable delay failed messages
  3804. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3805. return 0;
  3806. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3807. return 0;
  3808. WFIFOHEAD(fd,packet_len(0x110));
  3809. WFIFOW(fd,0) = 0x110;
  3810. WFIFOW(fd,2) = skill_id;
  3811. WFIFOL(fd,4) = btype;
  3812. WFIFOB(fd,8) = 0;// success?
  3813. WFIFOB(fd,9) = type;
  3814. WFIFOSET(fd,packet_len(0x110));
  3815. return 1;
  3816. }
  3817. /*==========================================
  3818. * skill attack effect and damage
  3819. * R 01de <skill ID>.w <src ID>.l <dst ID>.l <tick>.l <src delay>.l <dst delay>.l <damage>.l <skillv>.w <div>.w <type>.B
  3820. *------------------------------------------*/
  3821. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3822. {
  3823. unsigned char buf[64];
  3824. struct status_change *sc;
  3825. nullpo_retr(0, src);
  3826. nullpo_retr(0, dst);
  3827. sc = status_get_sc(dst);
  3828. if(sc && sc->count) {
  3829. if(type != 4 && dst->type == BL_PC && sc->data[SC_ENDURE].timer != -1 && !map_flag_gvg(dst->m))
  3830. type = 9;
  3831. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3832. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3833. }
  3834. #if PACKETVER < 3
  3835. WBUFW(buf,0)=0x114;
  3836. WBUFW(buf,2)=skill_id;
  3837. WBUFL(buf,4)=src->id;
  3838. WBUFL(buf,8)=dst->id;
  3839. WBUFL(buf,12)=tick;
  3840. WBUFL(buf,16)=sdelay;
  3841. WBUFL(buf,20)=ddelay;
  3842. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3843. WBUFW(buf,24)=damage?div:0;
  3844. } else {
  3845. WBUFW(buf,24)=damage;
  3846. }
  3847. WBUFW(buf,26)=skill_lv;
  3848. WBUFW(buf,28)=div;
  3849. WBUFB(buf,30)=type;
  3850. clif_send(buf,packet_len(0x114),src,AREA);
  3851. if(disguised(src)) {
  3852. WBUFL(buf,4)=-src->id;
  3853. if(damage > 0)
  3854. WBUFW(buf,24)=-1;
  3855. clif_send(buf,packet_len(0x114),src,SELF);
  3856. }
  3857. if (disguised(dst)) {
  3858. WBUFL(buf,8)=-dst->id;
  3859. if (disguised(src))
  3860. WBUFL(buf,4)=src->id;
  3861. else if(damage > 0)
  3862. WBUFW(buf,24)=-1;
  3863. clif_send(buf,packet_len(0x114),dst,SELF);
  3864. }
  3865. #else
  3866. WBUFW(buf,0)=0x1de;
  3867. WBUFW(buf,2)=skill_id;
  3868. WBUFL(buf,4)=src->id;
  3869. WBUFL(buf,8)=dst->id;
  3870. WBUFL(buf,12)=tick;
  3871. WBUFL(buf,16)=sdelay;
  3872. WBUFL(buf,20)=ddelay;
  3873. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3874. WBUFL(buf,24)=damage?div:0;
  3875. } else {
  3876. WBUFL(buf,24)=damage;
  3877. }
  3878. WBUFW(buf,28)=skill_lv;
  3879. WBUFW(buf,30)=div;
  3880. WBUFB(buf,32)=type;
  3881. clif_send(buf,packet_len(0x1de),src,AREA);
  3882. if(disguised(src)) {
  3883. WBUFL(buf,4)=-src->id;
  3884. if(damage > 0)
  3885. WBUFL(buf,24)=-1;
  3886. clif_send(buf,packet_len(0x1de),src,SELF);
  3887. }
  3888. if (disguised(dst)) {
  3889. WBUFL(buf,8)=-dst->id;
  3890. if (disguised(src))
  3891. WBUFL(buf,4)=src->id;
  3892. else if(damage > 0)
  3893. WBUFL(buf,24)=-1;
  3894. clif_send(buf,packet_len(0x1de),dst,SELF);
  3895. }
  3896. #endif
  3897. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3898. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3899. }
  3900. /*==========================================
  3901. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3902. *------------------------------------------*/
  3903. /*
  3904. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3905. {
  3906. unsigned char buf[64];
  3907. struct status_change *sc;
  3908. nullpo_retr(0, src);
  3909. nullpo_retr(0, dst);
  3910. type = (type>0)?type:skill_get_hit(skill_id);
  3911. type = clif_calc_delay(type, ddelay);
  3912. sc = status_get_sc(dst);
  3913. if(sc && sc->count) {
  3914. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3915. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3916. }
  3917. WBUFW(buf,0)=0x115;
  3918. WBUFW(buf,2)=skill_id;
  3919. WBUFL(buf,4)=src->id;
  3920. WBUFL(buf,8)=dst->id;
  3921. WBUFL(buf,12)=tick;
  3922. WBUFL(buf,16)=sdelay;
  3923. WBUFL(buf,20)=ddelay;
  3924. WBUFW(buf,24)=dst->x;
  3925. WBUFW(buf,26)=dst->y;
  3926. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3927. WBUFW(buf,28)=damage?div:0;
  3928. } else {
  3929. WBUFW(buf,28)=damage;
  3930. }
  3931. WBUFW(buf,30)=skill_lv;
  3932. WBUFW(buf,32)=div;
  3933. WBUFB(buf,34)=type;
  3934. clif_send(buf,packet_len(0x115),src,AREA);
  3935. if(disguised(src)) {
  3936. WBUFL(buf,4)=-src->id;
  3937. if(damage > 0)
  3938. WBUFW(buf,28)=-1;
  3939. clif_send(buf,packet_len(0x115),src,SELF);
  3940. }
  3941. if (disguised(dst)) {
  3942. WBUFL(buf,8)=-dst->id;
  3943. if (disguised(src))
  3944. WBUFL(buf,4)=src->id;
  3945. else if(damage > 0)
  3946. WBUFW(buf,28)=-1;
  3947. clif_send(buf,packet_len(0x115),dst,SELF);
  3948. }
  3949. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3950. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3951. }
  3952. */
  3953. /*==========================================
  3954. * 支援/回復スキルエフェクト
  3955. *------------------------------------------*/
  3956. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3957. {
  3958. unsigned char buf[32];
  3959. nullpo_retr(0, dst);
  3960. WBUFW(buf,0)=0x11a;
  3961. WBUFW(buf,2)=skill_id;
  3962. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3963. WBUFL(buf,6)=dst->id;
  3964. WBUFL(buf,10)=src?src->id:0;
  3965. WBUFB(buf,14)=fail;
  3966. clif_send(buf,packet_len(0x11a),dst,AREA);
  3967. if (disguised(dst)) {
  3968. WBUFL(buf,6)=-dst->id;
  3969. clif_send(buf,packet_len(0x11a),dst,SELF);
  3970. }
  3971. if(src && disguised(src)) {
  3972. WBUFL(buf,10)=-src->id;
  3973. if (disguised(dst))
  3974. WBUFL(buf,6)=dst->id;
  3975. clif_send(buf,packet_len(0x11a),src,SELF);
  3976. }
  3977. return fail;
  3978. }
  3979. /*==========================================
  3980. * 場所スキルエフェクト
  3981. *------------------------------------------*/
  3982. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3983. {
  3984. unsigned char buf[32];
  3985. nullpo_retr(0, src);
  3986. WBUFW(buf,0)=0x117;
  3987. WBUFW(buf,2)=skill_id;
  3988. WBUFL(buf,4)=src->id;
  3989. WBUFW(buf,8)=val;
  3990. WBUFW(buf,10)=x;
  3991. WBUFW(buf,12)=y;
  3992. WBUFL(buf,14)=tick;
  3993. clif_send(buf,packet_len(0x117),src,AREA);
  3994. if(disguised(src)) {
  3995. WBUFL(buf,4)=-src->id;
  3996. clif_send(buf,packet_len(0x117),src,SELF);
  3997. }
  3998. return 0;
  3999. }
  4000. /*==========================================
  4001. * 場所スキルエフェクト表示
  4002. *------------------------------------------*/
  4003. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4004. void clif_skill_setunit(struct skill_unit *unit)
  4005. {
  4006. unsigned char buf[128];
  4007. nullpo_retv(unit);
  4008. #if PACKETVER >= 3
  4009. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4010. WBUFW(buf, 0)=0x1c9;
  4011. WBUFL(buf, 2)=unit->bl.id;
  4012. WBUFL(buf, 6)=unit->group->src_id;
  4013. WBUFW(buf,10)=unit->bl.x;
  4014. WBUFW(buf,12)=unit->bl.y;
  4015. WBUFB(buf,14)=unit->group->unit_id;
  4016. WBUFB(buf,15)=1;
  4017. WBUFB(buf,16)=1;
  4018. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4019. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4020. return;
  4021. }
  4022. #endif
  4023. WBUFW(buf, 0)=0x11f;
  4024. WBUFL(buf, 2)=unit->bl.id;
  4025. WBUFL(buf, 6)=unit->group->src_id;
  4026. WBUFW(buf,10)=unit->bl.x;
  4027. WBUFW(buf,12)=unit->bl.y;
  4028. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4029. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4030. else
  4031. WBUFB(buf,14)=unit->group->unit_id;
  4032. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4033. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4034. }
  4035. /*==========================================
  4036. * ワープ場所選択
  4037. *------------------------------------------*/
  4038. void clif_skill_warppoint(struct map_session_data* sd, short skill_num, short skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  4039. {
  4040. int fd;
  4041. nullpo_retv(sd);
  4042. fd = sd->fd;
  4043. WFIFOHEAD(fd,packet_len(0x11c));
  4044. WFIFOW(fd,0) = 0x11c;
  4045. WFIFOW(fd,2) = skill_num;
  4046. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4047. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4048. else // normal map name
  4049. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4050. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4051. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4052. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4053. WFIFOSET(fd,packet_len(0x11c));
  4054. sd->menuskill_id = skill_num;
  4055. if (skill_num == AL_WARP)
  4056. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4057. else
  4058. sd->menuskill_val = skill_lv;
  4059. }
  4060. /*==========================================
  4061. * メモ応答
  4062. *------------------------------------------*/
  4063. int clif_skill_memo(struct map_session_data *sd,int flag)
  4064. {
  4065. int fd;
  4066. nullpo_retr(0, sd);
  4067. fd=sd->fd;
  4068. WFIFOHEAD(fd,packet_len(0x11e));
  4069. WFIFOW(fd,0)=0x11e;
  4070. WFIFOB(fd,2)=flag;
  4071. WFIFOSET(fd,packet_len(0x11e));
  4072. return 0;
  4073. }
  4074. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4075. {
  4076. int fd;
  4077. nullpo_retr(0, sd);
  4078. fd=sd->fd;
  4079. WFIFOHEAD(fd,packet_len(0x189));
  4080. WFIFOW(fd,0)=0x189;
  4081. WFIFOW(fd,2)=flag;
  4082. WFIFOSET(fd,packet_len(0x189));
  4083. return 0;
  4084. }
  4085. /*==========================================
  4086. * モンスター情報
  4087. *------------------------------------------*/
  4088. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4089. {
  4090. struct status_data *status;
  4091. unsigned char buf[64];
  4092. int i;//, fix;
  4093. nullpo_retr(0, sd);
  4094. nullpo_retr(0, dst);
  4095. if(dst->type!=BL_MOB )
  4096. return 0;
  4097. status = status_get_status_data(dst);
  4098. WBUFW(buf, 0)=0x18c;
  4099. WBUFW(buf, 2)=status_get_class(dst);
  4100. WBUFW(buf, 4)=status_get_lv(dst);
  4101. WBUFW(buf, 6)=status->size;
  4102. WBUFL(buf, 8)=status->hp;
  4103. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4104. +(battle_config.estimation_type&2?status->def2:0);
  4105. WBUFW(buf,14)=status->race;
  4106. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4107. +(battle_config.estimation_type&2?status->mdef2:0);
  4108. WBUFW(buf,18)= status->def_ele;
  4109. for(i=0;i<9;i++)
  4110. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4111. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4112. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4113. clif_send(buf,packet_len(0x18c),&sd->bl,
  4114. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4115. return 0;
  4116. }
  4117. /*==========================================
  4118. * アイテム合成可能リスト
  4119. *------------------------------------------*/
  4120. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4121. {
  4122. int i,c,view,fd;
  4123. nullpo_retr(0, sd);
  4124. if(sd->menuskill_id == AM_PHARMACY)
  4125. return 0; //Avoid resending the menu twice or more times...
  4126. fd=sd->fd;
  4127. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4128. WFIFOW(fd, 0)=0x18d;
  4129. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4130. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4131. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4132. WFIFOW(fd,c*8+ 4)= view;
  4133. else
  4134. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4135. WFIFOW(fd,c*8+ 6)= 0x0012;
  4136. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4137. c++;
  4138. }
  4139. }
  4140. WFIFOW(fd, 2)=c*8+8;
  4141. WFIFOSET(fd,WFIFOW(fd,2));
  4142. if(c > 0) {
  4143. sd->menuskill_id = AM_PHARMACY;
  4144. sd->menuskill_val = trigger;
  4145. return 1;
  4146. }
  4147. return 0;
  4148. }
  4149. /*==========================================
  4150. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4151. *------------------------------------------*/
  4152. int clif_status_load(struct block_list *bl,int type, int flag)
  4153. {
  4154. int fd;
  4155. if (type == SI_BLANK) //It shows nothing on the client...
  4156. return 0;
  4157. if (bl->type != BL_PC)
  4158. return 0;
  4159. fd = ((struct map_session_data*)bl)->fd;
  4160. WFIFOHEAD(fd,packet_len(0x196));
  4161. WFIFOW(fd,0)=0x0196;
  4162. WFIFOW(fd,2)=type;
  4163. WFIFOL(fd,4)=bl->id;
  4164. WFIFOB(fd,8)=flag; //Status start
  4165. WFIFOSET(fd, packet_len(0x196));
  4166. return 0;
  4167. }
  4168. /*==========================================
  4169. * 状態異常アイコン/メッセージ表示
  4170. *------------------------------------------*/
  4171. int clif_status_change(struct block_list *bl,int type,int flag)
  4172. {
  4173. unsigned char buf[16];
  4174. if (type == SI_BLANK) //It shows nothing on the client...
  4175. return 0;
  4176. nullpo_retr(0, bl);
  4177. WBUFW(buf,0)=0x0196;
  4178. WBUFW(buf,2)=type;
  4179. WBUFL(buf,4)=bl->id;
  4180. WBUFB(buf,8)=flag;
  4181. clif_send(buf,packet_len(0x196),bl,AREA);
  4182. return 0;
  4183. }
  4184. /*==========================================
  4185. * Send message (modified by [Yor])
  4186. *------------------------------------------*/
  4187. int clif_displaymessage(const int fd, const char* mes)
  4188. {
  4189. // invalid pointer?
  4190. nullpo_retr(-1, mes);
  4191. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4192. if (fd == 0)
  4193. return 0;
  4194. else {
  4195. int len_mes = strlen(mes);
  4196. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4197. WFIFOHEAD(fd, 5 + len_mes);
  4198. WFIFOW(fd,0) = 0x8e;
  4199. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4200. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4201. WFIFOSET(fd, 5 + len_mes);
  4202. }
  4203. }
  4204. return 0;
  4205. }
  4206. /*==========================================
  4207. * 天の声を送信する
  4208. *------------------------------------------*/
  4209. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  4210. {
  4211. unsigned char *buf;
  4212. int lp;
  4213. lp = (flag & 0x10) ? 8 : 4;
  4214. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4215. WBUFW(buf,0) = 0x9a;
  4216. WBUFW(buf,2) = len + lp;
  4217. WBUFL(buf,4) = 0x65756c62; //"blue":
  4218. memcpy(WBUFP(buf,lp), mes, len);
  4219. flag &= 0x07;
  4220. clif_send(buf, WBUFW(buf,2), bl,
  4221. (flag == 1) ? ALL_SAMEMAP :
  4222. (flag == 2) ? AREA :
  4223. (flag == 3) ? SELF :
  4224. ALL_CLIENT);
  4225. if(buf) aFree(buf);
  4226. if(use_irc && irc_announce_flag && !flag)
  4227. irc_announce(mes);
  4228. return 0;
  4229. }
  4230. /*==========================================
  4231. * グローバルメッセージ
  4232. *------------------------------------------*/
  4233. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4234. {
  4235. char buf[100];
  4236. int len;
  4237. nullpo_retv(bl);
  4238. if(!message)
  4239. return;
  4240. len = strlen(message)+1;
  4241. WBUFW(buf,0)=0x8d;
  4242. WBUFW(buf,2)=len+8;
  4243. WBUFL(buf,4)=bl->id;
  4244. strncpy((char *) WBUFP(buf,8),message,len);
  4245. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4246. }
  4247. /*==========================================
  4248. * Send main chat message [LuzZza]
  4249. *------------------------------------------*/
  4250. void clif_MainChatMessage(const char* message)
  4251. {
  4252. char buf[200];
  4253. int len;
  4254. if(!message)
  4255. return;
  4256. len = strlen(message)+1;
  4257. if (len+8 > sizeof(buf)) {
  4258. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4259. len = sizeof(buf)-8;
  4260. }
  4261. WBUFW(buf,0)=0x8d;
  4262. WBUFW(buf,2)=len+8;
  4263. WBUFL(buf,4)=0;
  4264. strncpy((char *) WBUFP(buf,8),message,len);
  4265. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4266. }
  4267. /*==========================================
  4268. * Does an announce message in the given color.
  4269. *------------------------------------------*/
  4270. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4271. {
  4272. unsigned char *buf;
  4273. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4274. WBUFW(buf,0) = 0x1c3;
  4275. WBUFW(buf,2) = len + 16;
  4276. WBUFL(buf,4) = color;
  4277. WBUFW(buf,8) = 0x190; //Font style? Type?
  4278. WBUFW(buf,10) = 0x0c; //12? Font size?
  4279. WBUFL(buf,12) = 0; //Unknown!
  4280. memcpy(WBUFP(buf,16), mes, len);
  4281. flag &= 0x07;
  4282. clif_send(buf, WBUFW(buf,2), bl,
  4283. (flag == 1) ? ALL_SAMEMAP :
  4284. (flag == 2) ? AREA :
  4285. (flag == 3) ? SELF :
  4286. ALL_CLIENT);
  4287. if(buf) aFree(buf);
  4288. return 0;
  4289. }
  4290. /*==========================================
  4291. * HPSP回復エフェクトを送信する
  4292. *------------------------------------------*/
  4293. int clif_heal(int fd,int type,int val)
  4294. {
  4295. WFIFOHEAD(fd,packet_len(0x13d));
  4296. WFIFOW(fd,0)=0x13d;
  4297. WFIFOW(fd,2)=type;
  4298. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4299. WFIFOSET(fd,packet_len(0x13d));
  4300. return 0;
  4301. }
  4302. /*==========================================
  4303. * 復活する
  4304. *------------------------------------------*/
  4305. int clif_resurrection(struct block_list *bl,int type)
  4306. {
  4307. unsigned char buf[16];
  4308. nullpo_retr(0, bl);
  4309. WBUFW(buf,0)=0x148;
  4310. WBUFL(buf,2)=bl->id;
  4311. WBUFW(buf,6)=type;
  4312. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4313. if (disguised(bl))
  4314. clif_spawn(bl);
  4315. return 0;
  4316. }
  4317. /*==========================================
  4318. * PVP実装?(仮)
  4319. *------------------------------------------*/
  4320. int clif_set0199(int fd,int type)
  4321. {
  4322. WFIFOHEAD(fd,packet_len(0x199));
  4323. WFIFOW(fd,0)=0x199;
  4324. WFIFOW(fd,2)=type;
  4325. WFIFOSET(fd,packet_len(0x199));
  4326. return 0;
  4327. }
  4328. /*==========================================
  4329. * PVP実装?(仮)
  4330. *------------------------------------------*/
  4331. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4332. {
  4333. int fd = sd->fd;
  4334. if(type == 2) {
  4335. WFIFOHEAD(fd,packet_len(0x19a));
  4336. WFIFOW(fd,0) = 0x19a;
  4337. WFIFOL(fd,2) = sd->bl.id;
  4338. WFIFOL(fd,6) = pvprank;
  4339. WFIFOL(fd,10) = pvpnum;
  4340. WFIFOSET(fd,packet_len(0x19a));
  4341. } else {
  4342. unsigned char buf[32];
  4343. WBUFW(buf,0) = 0x19a;
  4344. WBUFL(buf,2) = sd->bl.id;
  4345. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4346. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4347. else
  4348. WBUFL(buf,6) = pvprank;
  4349. WBUFL(buf,10) = pvpnum;
  4350. if(sd->sc.option&OPTION_INVISIBLE)
  4351. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4352. else if(!type)
  4353. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4354. else
  4355. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4356. }
  4357. return 0;
  4358. }
  4359. /*==========================================
  4360. *
  4361. *------------------------------------------*/
  4362. int clif_send0199(int map,int type)
  4363. {
  4364. struct block_list bl;
  4365. unsigned char buf[16];
  4366. bl.id = 0;
  4367. bl.type = BL_NUL;
  4368. bl.m = map;
  4369. WBUFW(buf,0)=0x199;
  4370. WBUFW(buf,2)=type;
  4371. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4372. return 0;
  4373. }
  4374. /*==========================================
  4375. * 精錬エフェクトを送信する
  4376. *------------------------------------------*/
  4377. void clif_refine(int fd, int fail, int index, int val)
  4378. {
  4379. WFIFOHEAD(fd,packet_len(0x188));
  4380. WFIFOW(fd,0)=0x188;
  4381. WFIFOW(fd,2)=fail;
  4382. WFIFOW(fd,4)=index+2;
  4383. WFIFOW(fd,6)=val;
  4384. WFIFOSET(fd,packet_len(0x188));
  4385. }
  4386. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4387. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4388. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4389. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4390. void clif_upgrademessage(int fd, int result, int item_id)
  4391. {
  4392. WFIFOHEAD(fd,packet_len(0x223));
  4393. WFIFOW(fd,0)=0x223;
  4394. WFIFOL(fd,2)=result;
  4395. WFIFOW(fd,6)=item_id;
  4396. WFIFOSET(fd,packet_len(0x223));
  4397. }
  4398. /*==========================================
  4399. * Wisp/page is transmitted to the destination player
  4400. * R 0097 <len>.w <nick>.24B <message>.?B
  4401. *------------------------------------------*/
  4402. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4403. {
  4404. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4405. WFIFOW(fd,0) = 0x97;
  4406. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4407. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4408. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4409. WFIFOSET(fd,WFIFOW(fd,2));
  4410. return 0;
  4411. }
  4412. /*==========================================
  4413. * Inform the player about the result of his whisper action
  4414. * R 0098 <type>.B
  4415. * 0: success to send wisper
  4416. * 1: target character is not loged in
  4417. * 2: ignored by target
  4418. * 3: everyone ignored by target
  4419. *------------------------------------------*/
  4420. int clif_wis_end(int fd, int flag)
  4421. {
  4422. WFIFOHEAD(fd,packet_len(0x98));
  4423. WFIFOW(fd,0) = 0x98;
  4424. WFIFOW(fd,2) = flag;
  4425. WFIFOSET(fd,packet_len(0x98));
  4426. return 0;
  4427. }
  4428. /*==========================================
  4429. * キャラID名前引き結果を送信する
  4430. *------------------------------------------*/
  4431. int clif_solved_charname(int fd, int charid, const char* name)
  4432. {
  4433. WFIFOHEAD(fd,packet_len(0x194));
  4434. WFIFOW(fd,0)=0x194;
  4435. WFIFOL(fd,2)=charid;
  4436. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4437. WFIFOSET(fd,packet_len(0x194));
  4438. return 0;
  4439. }
  4440. /*==========================================
  4441. * カードの挿入可能リストを返す
  4442. *------------------------------------------*/
  4443. int clif_use_card(struct map_session_data *sd,int idx)
  4444. {
  4445. int i,c,ep;
  4446. int fd=sd->fd;
  4447. nullpo_retr(0, sd);
  4448. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4449. return 0;
  4450. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4451. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4452. ep=sd->inventory_data[idx]->equip;
  4453. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4454. WFIFOW(fd,0)=0x017b;
  4455. for(i=c=0;i<MAX_INVENTORY;i++){
  4456. int j;
  4457. if(sd->inventory_data[i] == NULL)
  4458. continue;
  4459. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4460. continue;
  4461. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4462. continue;
  4463. if(sd->status.inventory[i].identify==0 ) //Not identified
  4464. continue;
  4465. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4466. continue;
  4467. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4468. continue;
  4469. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4470. if( sd->status.inventory[i].card[j]==0 )
  4471. break;
  4472. }
  4473. if(j==sd->inventory_data[i]->slot) // No room
  4474. continue;
  4475. WFIFOW(fd,4+c*2)=i+2;
  4476. c++;
  4477. }
  4478. WFIFOW(fd,2)=4+c*2;
  4479. WFIFOSET(fd,WFIFOW(fd,2));
  4480. return 0;
  4481. }
  4482. /*==========================================
  4483. * カードの挿入終了
  4484. *------------------------------------------*/
  4485. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4486. {
  4487. int fd;
  4488. nullpo_retr(0, sd);
  4489. fd=sd->fd;
  4490. WFIFOHEAD(fd,packet_len(0x17d));
  4491. WFIFOW(fd,0)=0x17d;
  4492. WFIFOW(fd,2)=idx_equip+2;
  4493. WFIFOW(fd,4)=idx_card+2;
  4494. WFIFOB(fd,6)=flag;
  4495. WFIFOSET(fd,packet_len(0x17d));
  4496. return 0;
  4497. }
  4498. /*==========================================
  4499. * 鑑定可能アイテムリスト送信
  4500. *------------------------------------------*/
  4501. int clif_item_identify_list(struct map_session_data *sd)
  4502. {
  4503. int i,c;
  4504. int fd;
  4505. nullpo_retr(0, sd);
  4506. fd=sd->fd;
  4507. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4508. WFIFOW(fd,0)=0x177;
  4509. for(i=c=0;i<MAX_INVENTORY;i++){
  4510. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4511. WFIFOW(fd,c*2+4)=i+2;
  4512. c++;
  4513. }
  4514. }
  4515. if(c > 0) {
  4516. WFIFOW(fd,2)=c*2+4;
  4517. WFIFOSET(fd,WFIFOW(fd,2));
  4518. sd->menuskill_id = MC_IDENTIFY;
  4519. sd->menuskill_val = c;
  4520. }
  4521. return 0;
  4522. }
  4523. /*==========================================
  4524. * 鑑定結果
  4525. *------------------------------------------*/
  4526. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4527. {
  4528. int fd;
  4529. nullpo_retr(0, sd);
  4530. fd=sd->fd;
  4531. WFIFOHEAD(fd,packet_len(0x179));
  4532. WFIFOW(fd, 0)=0x179;
  4533. WFIFOW(fd, 2)=idx+2;
  4534. WFIFOB(fd, 4)=flag;
  4535. WFIFOSET(fd,packet_len(0x179));
  4536. return 0;
  4537. }
  4538. /*==========================================
  4539. * 修理可能アイテムリスト送信
  4540. *------------------------------------------*/
  4541. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4542. {
  4543. int i,c;
  4544. int fd;
  4545. int nameid;
  4546. nullpo_retr(0, sd);
  4547. nullpo_retr(0, dstsd);
  4548. fd=sd->fd;
  4549. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4550. WFIFOW(fd,0)=0x1fc;
  4551. for(i=c=0;i<MAX_INVENTORY;i++){
  4552. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4553. WFIFOW(fd,c*13+4) = i;
  4554. WFIFOW(fd,c*13+6) = nameid;
  4555. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4556. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4557. WFIFOB(fd,c*13+16)= c;
  4558. c++;
  4559. }
  4560. }
  4561. if(c > 0) {
  4562. WFIFOW(fd,2)=c*13+4;
  4563. WFIFOSET(fd,WFIFOW(fd,2));
  4564. sd->menuskill_id = BS_REPAIRWEAPON;
  4565. sd->menuskill_val = dstsd->bl.id;
  4566. }else
  4567. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4568. return 0;
  4569. }
  4570. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4571. {
  4572. int view,fd;
  4573. nullpo_retr(0, sd);
  4574. fd=sd->fd;
  4575. WFIFOHEAD(fd,packet_len(0x1fe));
  4576. WFIFOW(fd, 0)=0x1fe;
  4577. if((view = itemdb_viewid(nameid)) > 0)
  4578. WFIFOW(fd, 2)=view;
  4579. else
  4580. WFIFOW(fd, 2)=nameid;
  4581. WFIFOB(fd, 4)=flag;
  4582. WFIFOSET(fd,packet_len(0x1fe));
  4583. return 0;
  4584. }
  4585. /*==========================================
  4586. * Weapon Refining - Taken from jAthena
  4587. *------------------------------------------*/
  4588. int clif_item_refine_list(struct map_session_data *sd)
  4589. {
  4590. int i,c;
  4591. int fd;
  4592. int skilllv;
  4593. int wlv;
  4594. int refine_item[5];
  4595. nullpo_retr(0, sd);
  4596. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4597. fd=sd->fd;
  4598. refine_item[0] = -1;
  4599. refine_item[1] = pc_search_inventory(sd,1010);
  4600. refine_item[2] = pc_search_inventory(sd,1011);
  4601. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4602. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4603. WFIFOW(fd,0)=0x221;
  4604. for(i=c=0;i<MAX_INVENTORY;i++){
  4605. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4606. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4607. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4608. WFIFOW(fd,c*13+ 4)=i+2;
  4609. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4610. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4611. WFIFOW(fd,c*13+10)=0;
  4612. WFIFOB(fd,c*13+12)=c;
  4613. c++;
  4614. }
  4615. }
  4616. WFIFOW(fd,2)=c*13+4;
  4617. WFIFOSET(fd,WFIFOW(fd,2));
  4618. if (c > 0) {
  4619. sd->menuskill_id = WS_WEAPONREFINE;
  4620. sd->menuskill_val = skilllv;
  4621. }
  4622. return 0;
  4623. }
  4624. /*==========================================
  4625. * アイテムによる一時的なスキル効果
  4626. *------------------------------------------*/
  4627. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4628. {
  4629. int fd;
  4630. nullpo_retr(0, sd);
  4631. fd=sd->fd;
  4632. WFIFOHEAD(fd,packet_len(0x147));
  4633. WFIFOW(fd, 0)=0x147;
  4634. WFIFOW(fd, 2)=skillid;
  4635. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4636. WFIFOW(fd, 6)=0;
  4637. WFIFOW(fd, 8)=skilllv;
  4638. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4639. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4640. strncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4641. WFIFOB(fd,38)=0;
  4642. WFIFOSET(fd,packet_len(0x147));
  4643. return 0;
  4644. }
  4645. /*==========================================
  4646. * カートにアイテム追加
  4647. *------------------------------------------*/
  4648. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4649. {
  4650. int view,fd;
  4651. unsigned char *buf;
  4652. nullpo_retr(0, sd);
  4653. fd=sd->fd;
  4654. WFIFOHEAD(fd,packet_len(0x124));
  4655. buf=WFIFOP(fd,0);
  4656. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4657. return 1;
  4658. WBUFW(buf,0)=0x124;
  4659. WBUFW(buf,2)=n+2;
  4660. WBUFL(buf,4)=amount;
  4661. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4662. WBUFW(buf,8)=view;
  4663. else
  4664. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4665. WBUFB(buf,10)=sd->status.cart[n].identify;
  4666. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4667. WBUFB(buf,12)=sd->status.cart[n].refine;
  4668. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4669. WFIFOSET(fd,packet_len(0x124));
  4670. return 0;
  4671. }
  4672. /*==========================================
  4673. * カートからアイテム削除
  4674. *------------------------------------------*/
  4675. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4676. {
  4677. int fd;
  4678. nullpo_retr(0, sd);
  4679. fd=sd->fd;
  4680. WFIFOHEAD(fd,packet_len(0x125));
  4681. WFIFOW(fd,0)=0x125;
  4682. WFIFOW(fd,2)=n+2;
  4683. WFIFOL(fd,4)=amount;
  4684. WFIFOSET(fd,packet_len(0x125));
  4685. return 0;
  4686. }
  4687. /*==========================================
  4688. * Opens the shop creation menu.
  4689. * R 012d <num>.w
  4690. * 'num' is the number of allowed item slots
  4691. *------------------------------------------*/
  4692. void clif_openvendingreq(struct map_session_data* sd, int num)
  4693. {
  4694. int fd;
  4695. nullpo_retv(sd);
  4696. fd = sd->fd;
  4697. WFIFOHEAD(fd,packet_len(0x12d));
  4698. WFIFOW(fd,0) = 0x12d;
  4699. WFIFOW(fd,2) = num;
  4700. WFIFOSET(fd,packet_len(0x12d));
  4701. }
  4702. /*==========================================
  4703. * Displays a vending board to target/area
  4704. * R 0131 <ID>.l <message>.80B
  4705. *------------------------------------------*/
  4706. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4707. {
  4708. unsigned char buf[128];
  4709. nullpo_retv(bl);
  4710. WBUFW(buf,0) = 0x131;
  4711. WBUFL(buf,2) = bl->id;
  4712. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4713. if( fd ) {
  4714. WFIFOHEAD(fd,packet_len(0x131));
  4715. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4716. WFIFOSET(fd,packet_len(0x131));
  4717. } else {
  4718. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4719. }
  4720. }
  4721. /*==========================================
  4722. * Removes a vending board from screen
  4723. *------------------------------------------*/
  4724. void clif_closevendingboard(struct block_list* bl, int fd)
  4725. {
  4726. unsigned char buf[16];
  4727. nullpo_retv(bl);
  4728. WBUFW(buf,0) = 0x132;
  4729. WBUFL(buf,2) = bl->id;
  4730. if( fd ) {
  4731. WFIFOHEAD(fd,packet_len(0x132));
  4732. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4733. WFIFOSET(fd,packet_len(0x132));
  4734. } else {
  4735. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4736. }
  4737. }
  4738. /*==========================================
  4739. * Sends a list of items in a shop
  4740. * R 0133 <len>.w <ID>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
  4741. *------------------------------------------*/
  4742. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4743. {
  4744. int i,fd;
  4745. int count;
  4746. struct map_session_data* vsd;
  4747. nullpo_retv(sd);
  4748. nullpo_retv(vending);
  4749. nullpo_retv(vsd=map_id2sd(id));
  4750. fd = sd->fd;
  4751. count = vsd->vend_num;
  4752. WFIFOHEAD(fd, 8+count*22);
  4753. WFIFOW(fd,0) = 0x133;
  4754. WFIFOW(fd,2) = 8+count*22;
  4755. WFIFOL(fd,4) = id;
  4756. for( i = 0; i < count; i++ )
  4757. {
  4758. int index = vending[i].index;
  4759. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4760. WFIFOL(fd, 8+i*22) = vending[i].value;
  4761. WFIFOW(fd,12+i*22) = vending[i].amount;
  4762. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4763. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4764. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4765. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4766. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4767. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4768. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4769. }
  4770. WFIFOSET(fd,WFIFOW(fd,2));
  4771. }
  4772. /*==========================================
  4773. * Shop purchase failure
  4774. * R 0135 <index>.w <amount>.w <fail>.B
  4775. * fail=1 - not enough zeny
  4776. * fail=2 - overweight
  4777. * fail=4 - out of stock
  4778. * fail=5 - "cannot use an npc shop while in a trade"
  4779. *------------------------------------------*/
  4780. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4781. {
  4782. int fd;
  4783. nullpo_retv(sd);
  4784. fd = sd->fd;
  4785. WFIFOHEAD(fd,packet_len(0x135));
  4786. WFIFOW(fd,0) = 0x135;
  4787. WFIFOW(fd,2) = index+2;
  4788. WFIFOW(fd,4) = amount;
  4789. WFIFOB(fd,6) = fail;
  4790. WFIFOSET(fd,packet_len(0x135));
  4791. }
  4792. /*==========================================
  4793. * Shop creation success
  4794. * R 0136 <len>.w <ID>.l {<value>.l <index>.w <amount>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B*
  4795. *------------------------------------------*/
  4796. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4797. {
  4798. int i,fd;
  4799. int count;
  4800. nullpo_retv(sd);
  4801. fd = sd->fd;
  4802. count = sd->vend_num;
  4803. WFIFOHEAD(fd, 8+count*22);
  4804. WFIFOW(fd,0) = 0x136;
  4805. WFIFOW(fd,2) = 8+count*22;
  4806. WFIFOL(fd,4) = id;
  4807. for( i = 0; i < count; i++ )
  4808. {
  4809. int index = vending[i].index;
  4810. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4811. WFIFOL(fd, 8+i*22) = vending[i].value;
  4812. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4813. WFIFOW(fd,14+i*22) = vending[i].amount;
  4814. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4815. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4816. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4817. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4818. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4819. clif_addcards(WFIFOP(fd,22+count*22), &sd->status.cart[index]);
  4820. }
  4821. WFIFOSET(fd,WFIFOW(fd,2));
  4822. }
  4823. /*==========================================
  4824. * Inform merchant that someone has bought an item.
  4825. * R 0137 <index>.w <amount>.w
  4826. *------------------------------------------*/
  4827. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4828. {
  4829. int fd;
  4830. nullpo_retv(sd);
  4831. fd = sd->fd;
  4832. WFIFOHEAD(fd,packet_len(0x137));
  4833. WFIFOW(fd,0) = 0x137;
  4834. WFIFOW(fd,2) = index+2;
  4835. WFIFOW(fd,4) = amount;
  4836. WFIFOSET(fd,packet_len(0x137));
  4837. }
  4838. /// Result of organizing a party.
  4839. /// S 00FA <result>.B
  4840. ///
  4841. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4842. /// result=1 : MsgStringTable[78]="party name already exists"
  4843. /// result=2 : MsgStringTable[79]="already in a party"
  4844. /// result=other : nothing
  4845. int clif_party_created(struct map_session_data *sd,int result)
  4846. {
  4847. int fd;
  4848. nullpo_retr(0, sd);
  4849. fd=sd->fd;
  4850. WFIFOHEAD(fd,packet_len(0xfa));
  4851. WFIFOW(fd,0)=0xfa;
  4852. WFIFOB(fd,2)=result;
  4853. WFIFOSET(fd,packet_len(0xfa));
  4854. return 0;
  4855. }
  4856. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4857. {
  4858. unsigned char buf[96];
  4859. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4860. int i;
  4861. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++);
  4862. if (i >= MAX_PARTY) return 0; //Should never happen...
  4863. sd = p->data[i].sd;
  4864. }
  4865. WBUFW(buf, 0) = 0x1e9;
  4866. WBUFL(buf, 2) = sd->status.account_id;
  4867. WBUFL(buf, 6) = 0; //Apparently setting this to 1 makes you adoptable.
  4868. WBUFW(buf,10) = sd->bl.x;
  4869. WBUFW(buf,12) = sd->bl.y;
  4870. WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline.
  4871. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4872. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4873. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4874. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4875. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4876. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4877. return 1;
  4878. }
  4879. /*==========================================
  4880. * Sends party information
  4881. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4882. *------------------------------------------*/
  4883. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4884. {
  4885. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4886. struct map_session_data* party_sd = NULL;
  4887. int i, c;
  4888. nullpo_retr(0, p);
  4889. WBUFW(buf,0) = 0xfb;
  4890. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4891. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4892. {
  4893. struct party_member* m = &p->party.member[i];
  4894. if(!m->account_id) continue;
  4895. if(party_sd == NULL) party_sd = p->data[i].sd;
  4896. WBUFL(buf,28+c*46) = m->account_id;
  4897. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4898. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4899. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4900. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4901. c++;
  4902. }
  4903. WBUFW(buf,2) = 28+c*46;
  4904. if(sd) { // send only to self
  4905. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4906. } else if (party_sd) { // send to whole party
  4907. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4908. }
  4909. return 0;
  4910. }
  4911. /*==========================================
  4912. * パーティ勧誘
  4913. *------------------------------------------*/
  4914. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4915. {
  4916. int fd;
  4917. struct party_data *p;
  4918. nullpo_retr(0, sd);
  4919. nullpo_retr(0, tsd);
  4920. fd=tsd->fd;
  4921. if( (p=party_search(sd->status.party_id))==NULL )
  4922. return 0;
  4923. WFIFOHEAD(fd,packet_len(0xfe));
  4924. WFIFOW(fd,0)=0xfe;
  4925. WFIFOL(fd,2)=sd->status.account_id;
  4926. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4927. WFIFOSET(fd,packet_len(0xfe));
  4928. return 0;
  4929. }
  4930. /*==========================================
  4931. * Party invitation result. Flag values are:
  4932. * 0 -> char is already in a party
  4933. * 1 -> party invite was rejected
  4934. * 2 -> party invite was accepted
  4935. * 3 -> party is full
  4936. * 4 -> char of the same account already joined the party
  4937. *------------------------------------------*/
  4938. int clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4939. {
  4940. int fd;
  4941. nullpo_retr(0, sd);
  4942. fd=sd->fd;
  4943. WFIFOHEAD(fd,packet_len(0xfd));
  4944. WFIFOW(fd,0)=0xfd;
  4945. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  4946. WFIFOB(fd,26)=flag;
  4947. WFIFOSET(fd,packet_len(0xfd));
  4948. return 0;
  4949. }
  4950. /*==========================================
  4951. * パーティ設定送信
  4952. * flag & 0x001=exp変更ミス
  4953. * 0x010=item変更ミス
  4954. * 0x100=一人にのみ送信
  4955. *------------------------------------------*/
  4956. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4957. {
  4958. unsigned char buf[16];
  4959. nullpo_retr(0, p);
  4960. if(!sd && flag==0){
  4961. int i;
  4962. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4963. if (i < MAX_PARTY)
  4964. sd = p->data[i].sd;
  4965. }
  4966. if(!sd) return 0;
  4967. WBUFW(buf,0)=0x101;
  4968. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4969. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4970. WBUFW(buf,4)=0;
  4971. if(flag==0)
  4972. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4973. else
  4974. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4975. return 0;
  4976. }
  4977. /*==========================================
  4978. * パーティ脱退(脱退前に呼ぶこと)
  4979. *------------------------------------------*/
  4980. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4981. {
  4982. unsigned char buf[64];
  4983. int i;
  4984. nullpo_retr(0, p);
  4985. if(!sd && (flag&0xf0)==0)
  4986. {
  4987. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4988. if (i < MAX_PARTY)
  4989. sd = p->data[i].sd;
  4990. }
  4991. if(!sd) return 0;
  4992. WBUFW(buf,0)=0x105;
  4993. WBUFL(buf,2)=account_id;
  4994. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4995. WBUFB(buf,30)=flag&0x0f;
  4996. if((flag&0xf0)==0)
  4997. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4998. else
  4999. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5000. return 0;
  5001. }
  5002. /*==========================================
  5003. * パーティメッセージ送信
  5004. *------------------------------------------*/
  5005. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5006. {
  5007. struct map_session_data *sd;
  5008. int i;
  5009. nullpo_retr(0, p);
  5010. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5011. if(i < MAX_PARTY){
  5012. unsigned char buf[1024];
  5013. sd = p->data[i].sd;
  5014. WBUFW(buf,0)=0x109;
  5015. WBUFW(buf,2)=len+8;
  5016. WBUFL(buf,4)=account_id;
  5017. memcpy(WBUFP(buf,8),mes,len);
  5018. clif_send(buf,len+8,&sd->bl,PARTY);
  5019. }
  5020. return 0;
  5021. }
  5022. /*==========================================
  5023. * パーティ座標通知
  5024. *------------------------------------------*/
  5025. int clif_party_xy(struct map_session_data *sd)
  5026. {
  5027. unsigned char buf[16];
  5028. nullpo_retr(0, sd);
  5029. WBUFW(buf,0)=0x107;
  5030. WBUFL(buf,2)=sd->status.account_id;
  5031. WBUFW(buf,6)=sd->bl.x;
  5032. WBUFW(buf,8)=sd->bl.y;
  5033. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5034. return 0;
  5035. }
  5036. /*==========================================
  5037. * Sends x/y dot to a single fd. [Skotlex]
  5038. *------------------------------------------*/
  5039. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5040. {
  5041. WFIFOHEAD(fd,packet_len(0x107));
  5042. WFIFOW(fd,0)=0x107;
  5043. WFIFOL(fd,2)=sd->status.account_id;
  5044. WFIFOW(fd,6)=sd->bl.x;
  5045. WFIFOW(fd,8)=sd->bl.y;
  5046. WFIFOSET(fd,packet_len(0x107));
  5047. return 0;
  5048. }
  5049. /*==========================================
  5050. * パーティHP通知
  5051. *------------------------------------------*/
  5052. int clif_party_hp(struct map_session_data *sd)
  5053. {
  5054. unsigned char buf[16];
  5055. nullpo_retr(0, sd);
  5056. WBUFW(buf,0)=0x106;
  5057. WBUFL(buf,2)=sd->status.account_id;
  5058. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5059. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5060. WBUFW(buf,8) = 100;
  5061. } else {
  5062. WBUFW(buf,6) = sd->battle_status.hp;
  5063. WBUFW(buf,8) = sd->battle_status.max_hp;
  5064. }
  5065. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  5066. return 0;
  5067. }
  5068. /*==========================================
  5069. * Sends HP bar to a single fd. [Skotlex]
  5070. *------------------------------------------*/
  5071. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5072. {
  5073. WFIFOHEAD(fd,packet_len(0x106));
  5074. WFIFOW(fd,0) = 0x106;
  5075. WFIFOL(fd,2) = id;
  5076. if( maxhp > SHRT_MAX )
  5077. {// To correctly display the %hp bar. [Skotlex]
  5078. WFIFOW(fd,6) = hp/(maxhp/100);
  5079. WFIFOW(fd,8) = 100;
  5080. } else {
  5081. WFIFOW(fd,6) = hp;
  5082. WFIFOW(fd,8) = maxhp;
  5083. }
  5084. WFIFOSET(fd, packet_len(0x106));
  5085. }
  5086. /*==========================================
  5087. * GMへ場所とHP通知
  5088. *------------------------------------------*/
  5089. int clif_hpmeter(struct map_session_data *sd)
  5090. {
  5091. struct map_session_data *sd2;
  5092. unsigned char buf[16];
  5093. int i, x0, y0, x1, y1;
  5094. int level;
  5095. nullpo_retr(0, sd);
  5096. x0 = sd->bl.x - AREA_SIZE;
  5097. y0 = sd->bl.y - AREA_SIZE;
  5098. x1 = sd->bl.x + AREA_SIZE;
  5099. y1 = sd->bl.y + AREA_SIZE;
  5100. WBUFW(buf,0) = 0x106;
  5101. WBUFL(buf,2) = sd->status.account_id;
  5102. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5103. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5104. WBUFW(buf,8) = 100;
  5105. } else {
  5106. WBUFW(buf,6) = sd->battle_status.hp;
  5107. WBUFW(buf,8) = sd->battle_status.max_hp;
  5108. }
  5109. for (i = 0; i < fd_max; i++) {
  5110. if (session[i] && session[i]->func_parse == clif_parse &&
  5111. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5112. sd != sd2 && sd2->state.auth) {
  5113. if (sd2->bl.m != sd->bl.m ||
  5114. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5115. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5116. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5117. level < pc_isGM(sd))
  5118. continue;
  5119. WFIFOHEAD (i, packet_len(0x106));
  5120. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  5121. WFIFOSET (i, packet_len(0x106));
  5122. }
  5123. }
  5124. return 0;
  5125. }
  5126. /*==========================================
  5127. * パーティ場所移動(未使用)
  5128. *------------------------------------------*/
  5129. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  5130. {
  5131. unsigned char buf[128];
  5132. nullpo_retv(sd);
  5133. nullpo_retv(p);
  5134. WBUFW(buf, 0) = 0x104;
  5135. WBUFL(buf, 2) = sd->status.account_id;
  5136. WBUFL(buf, 6) = 0;
  5137. WBUFW(buf,10) = sd->bl.x;
  5138. WBUFW(buf,12) = sd->bl.y;
  5139. WBUFB(buf,14) = !online;
  5140. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5141. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5142. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5143. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5144. }
  5145. /*==========================================
  5146. * 攻撃するために移動が必要
  5147. *------------------------------------------*/
  5148. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5149. {
  5150. int fd;
  5151. nullpo_retr(0, sd);
  5152. nullpo_retr(0, bl);
  5153. fd=sd->fd;
  5154. WFIFOHEAD(fd,packet_len(0x139));
  5155. WFIFOW(fd, 0)=0x139;
  5156. WFIFOL(fd, 2)=bl->id;
  5157. WFIFOW(fd, 6)=bl->x;
  5158. WFIFOW(fd, 8)=bl->y;
  5159. WFIFOW(fd,10)=sd->bl.x;
  5160. WFIFOW(fd,12)=sd->bl.y;
  5161. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5162. WFIFOSET(fd,packet_len(0x139));
  5163. return 0;
  5164. }
  5165. /*==========================================
  5166. * 製造エフェクト
  5167. *------------------------------------------*/
  5168. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5169. {
  5170. int fd;
  5171. nullpo_retr(0, sd);
  5172. fd = sd->fd;
  5173. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5174. WFIFOHEAD(fd,packet_len(0x18f));
  5175. WFIFOW(fd, 0)=0x18f;
  5176. WFIFOW(fd, 2)=flag;
  5177. WFIFOW(fd, 4)=(itemdb_viewid(nameid)||nameid);
  5178. WFIFOSET(fd,packet_len(0x18f));
  5179. return 0;
  5180. }
  5181. // pet
  5182. int clif_catch_process(struct map_session_data *sd)
  5183. {
  5184. int fd;
  5185. nullpo_retr(0, sd);
  5186. fd=sd->fd;
  5187. WFIFOHEAD(fd,packet_len(0x19e));
  5188. WFIFOW(fd,0)=0x19e;
  5189. WFIFOSET(fd,packet_len(0x19e));
  5190. return 0;
  5191. }
  5192. int clif_pet_roulette(struct map_session_data *sd,int data)
  5193. {
  5194. int fd;
  5195. nullpo_retr(0, sd);
  5196. fd=sd->fd;
  5197. WFIFOHEAD(fd,packet_len(0x1a0));
  5198. WFIFOW(fd,0)=0x1a0;
  5199. WFIFOB(fd,2)=data;
  5200. WFIFOSET(fd,packet_len(0x1a0));
  5201. return 0;
  5202. }
  5203. /*==========================================
  5204. * pet卵リスト作成
  5205. *------------------------------------------*/
  5206. int clif_sendegg(struct map_session_data *sd)
  5207. {
  5208. //R 01a6 <len>.w <index>.w*
  5209. int i,n=0,fd;
  5210. nullpo_retr(0, sd);
  5211. fd=sd->fd;
  5212. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5213. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5214. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5215. return 0;
  5216. }
  5217. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5218. WFIFOW(fd,0)=0x1a6;
  5219. if(sd->status.pet_id <= 0) {
  5220. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5221. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5222. sd->inventory_data[i]->type!=IT_PETEGG ||
  5223. sd->status.inventory[i].amount<=0)
  5224. continue;
  5225. WFIFOW(fd,n*2+4)=i+2;
  5226. n++;
  5227. }
  5228. }
  5229. WFIFOW(fd,2)=4+n*2;
  5230. WFIFOSET(fd,WFIFOW(fd,2));
  5231. sd->menuskill_id = SA_TAMINGMONSTER;
  5232. sd->menuskill_val = -1;
  5233. return 0;
  5234. }
  5235. /*==========================================
  5236. * Sends a specific pet data update.
  5237. * type = 0 -> param = 0 (initial data)
  5238. * type = 1 -> param = intimacy value
  5239. * type = 2 -> param = hungry value
  5240. * type = 3 -> param = accessory id
  5241. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5242. * type = 5 -> param = hairstyle number
  5243. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5244. *------------------------------------------*/
  5245. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5246. {
  5247. uint8 buf[16];
  5248. nullpo_retr(0, pd);
  5249. WBUFW(buf,0) = 0x1a4;
  5250. WBUFB(buf,2) = type;
  5251. WBUFL(buf,3) = pd->bl.id;
  5252. WBUFL(buf,7) = param;
  5253. if (sd)
  5254. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5255. else
  5256. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5257. return 0;
  5258. }
  5259. int clif_send_petstatus(struct map_session_data *sd)
  5260. {
  5261. int fd;
  5262. struct s_pet *pet;
  5263. nullpo_retr(0, sd);
  5264. nullpo_retr(0, sd->pd);
  5265. fd=sd->fd;
  5266. pet = &sd->pd->pet;
  5267. WFIFOHEAD(fd,packet_len(0x1a2));
  5268. WFIFOW(fd,0)=0x1a2;
  5269. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5270. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5271. WFIFOW(fd,27)=pet->level;
  5272. WFIFOW(fd,29)=pet->hungry;
  5273. WFIFOW(fd,31)=pet->intimate;
  5274. WFIFOW(fd,33)=pet->equip;
  5275. WFIFOSET(fd,packet_len(0x1a2));
  5276. return 0;
  5277. }
  5278. /*==========================================
  5279. *
  5280. *------------------------------------------*/
  5281. int clif_pet_emotion(struct pet_data *pd,int param)
  5282. {
  5283. unsigned char buf[16];
  5284. nullpo_retr(0, pd);
  5285. memset(buf,0,packet_len(0x1aa));
  5286. WBUFW(buf,0)=0x1aa;
  5287. WBUFL(buf,2)=pd->bl.id;
  5288. if(param >= 100 && pd->petDB->talk_convert_class) {
  5289. if(pd->petDB->talk_convert_class < 0)
  5290. return 0;
  5291. else if(pd->petDB->talk_convert_class > 0) {
  5292. param -= (pd->pet.class_ - 100)*100;
  5293. param += (pd->petDB->talk_convert_class - 100)*100;
  5294. }
  5295. }
  5296. WBUFL(buf,6)=param;
  5297. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5298. return 0;
  5299. }
  5300. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5301. {
  5302. int fd;
  5303. nullpo_retr(0, sd);
  5304. fd=sd->fd;
  5305. WFIFOHEAD(fd,packet_len(0x1a3));
  5306. WFIFOW(fd,0)=0x1a3;
  5307. WFIFOB(fd,2)=fail;
  5308. WFIFOW(fd,3)=foodid;
  5309. WFIFOSET(fd,packet_len(0x1a3));
  5310. return 0;
  5311. }
  5312. /*==========================================
  5313. * オートスペル リスト送信
  5314. *------------------------------------------*/
  5315. int clif_autospell(struct map_session_data *sd,int skilllv)
  5316. {
  5317. int fd;
  5318. nullpo_retr(0, sd);
  5319. fd=sd->fd;
  5320. WFIFOHEAD(fd,packet_len(0x1cd));
  5321. WFIFOW(fd, 0)=0x1cd;
  5322. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5323. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5324. else
  5325. WFIFOL(fd,2)= 0x00000000;
  5326. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5327. WFIFOL(fd,6)= MG_COLDBOLT;
  5328. else
  5329. WFIFOL(fd,6)= 0x00000000;
  5330. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5331. WFIFOL(fd,10)= MG_FIREBOLT;
  5332. else
  5333. WFIFOL(fd,10)= 0x00000000;
  5334. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5335. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5336. else
  5337. WFIFOL(fd,14)= 0x00000000;
  5338. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5339. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5340. else
  5341. WFIFOL(fd,18)= 0x00000000;
  5342. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5343. WFIFOL(fd,22)= MG_FIREBALL;
  5344. else
  5345. WFIFOL(fd,22)= 0x00000000;
  5346. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5347. WFIFOL(fd,26)= MG_FROSTDIVER;
  5348. else
  5349. WFIFOL(fd,26)= 0x00000000;
  5350. WFIFOSET(fd,packet_len(0x1cd));
  5351. sd->menuskill_id = SA_AUTOSPELL;
  5352. sd->menuskill_val = skilllv;
  5353. return 0;
  5354. }
  5355. /*==========================================
  5356. * ディボーションの青い糸
  5357. *------------------------------------------*/
  5358. int clif_devotion(struct map_session_data *sd)
  5359. {
  5360. unsigned char buf[56];
  5361. int i,n;
  5362. nullpo_retr(0, sd);
  5363. WBUFW(buf,0)=0x1cf;
  5364. WBUFL(buf,2)=sd->bl.id;
  5365. for(i=0,n=0;i<5;i++) {
  5366. if (!sd->devotion[i])
  5367. continue;
  5368. WBUFL(buf,6+4*n)=sd->devotion[i];
  5369. n++;
  5370. }
  5371. for(;n<5;n++)
  5372. WBUFL(buf,6+4*n)=0;
  5373. WBUFB(buf,26)=8;
  5374. WBUFB(buf,27)=0;
  5375. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5376. return 0;
  5377. }
  5378. int clif_marionette(struct block_list *src, struct block_list *target)
  5379. {
  5380. unsigned char buf[56];
  5381. int n;
  5382. WBUFW(buf,0)=0x1cf;
  5383. WBUFL(buf,2)=src->id;
  5384. for(n=0;n<5;n++)
  5385. WBUFL(buf,6+4*n)=0;
  5386. if (target) //The target goes on the second slot.
  5387. WBUFL(buf,6+4) = target->id;
  5388. WBUFB(buf,26)=8;
  5389. WBUFB(buf,27)=0;
  5390. clif_send(buf,packet_len(0x1cf),src,AREA);
  5391. return 0;
  5392. }
  5393. /*==========================================
  5394. * 氣球
  5395. *------------------------------------------*/
  5396. int clif_spiritball(struct map_session_data *sd)
  5397. {
  5398. unsigned char buf[16];
  5399. nullpo_retr(0, sd);
  5400. WBUFW(buf,0)=0x1d0;
  5401. WBUFL(buf,2)=sd->bl.id;
  5402. WBUFW(buf,6)=sd->spiritball;
  5403. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5404. return 0;
  5405. }
  5406. /*==========================================
  5407. *
  5408. *------------------------------------------*/
  5409. int clif_combo_delay(struct block_list *bl,int wait)
  5410. {
  5411. unsigned char buf[32];
  5412. nullpo_retr(0, bl);
  5413. WBUFW(buf,0)=0x1d2;
  5414. WBUFL(buf,2)=bl->id;
  5415. WBUFL(buf,6)=wait;
  5416. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5417. return 0;
  5418. }
  5419. /*==========================================
  5420. *白刃取り
  5421. *------------------------------------------*/
  5422. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5423. int _bool)
  5424. {
  5425. unsigned char buf[32];
  5426. nullpo_retr(0, src);
  5427. nullpo_retr(0, dst);
  5428. WBUFW(buf,0)=0x1d1;
  5429. WBUFL(buf,2)=src->id;
  5430. WBUFL(buf,6)=dst->id;
  5431. WBUFL(buf,10)=_bool;
  5432. clif_send(buf,packet_len(0x1d1),src,AREA);
  5433. return 0;
  5434. }
  5435. /*==========================================
  5436. * MVPエフェクト
  5437. *------------------------------------------*/
  5438. int clif_mvp_effect(struct map_session_data *sd)
  5439. {
  5440. unsigned char buf[16];
  5441. nullpo_retr(0, sd);
  5442. WBUFW(buf,0)=0x10c;
  5443. WBUFL(buf,2)=sd->bl.id;
  5444. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5445. return 0;
  5446. }
  5447. /*==========================================
  5448. * MVPアイテム所得
  5449. *------------------------------------------*/
  5450. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5451. {
  5452. int view,fd;
  5453. nullpo_retr(0, sd);
  5454. fd=sd->fd;
  5455. WFIFOHEAD(fd,packet_len(0x10a));
  5456. WFIFOW(fd,0)=0x10a;
  5457. if((view = itemdb_viewid(nameid)) > 0)
  5458. WFIFOW(fd,2)=view;
  5459. else
  5460. WFIFOW(fd,2)=nameid;
  5461. WFIFOSET(fd,packet_len(0x10a));
  5462. return 0;
  5463. }
  5464. /*==========================================
  5465. * MVP経験値所得
  5466. *------------------------------------------*/
  5467. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5468. {
  5469. int fd;
  5470. nullpo_retr(0, sd);
  5471. fd=sd->fd;
  5472. WFIFOHEAD(fd,packet_len(0x10b));
  5473. WFIFOW(fd,0)=0x10b;
  5474. WFIFOL(fd,2)=exp;
  5475. WFIFOSET(fd,packet_len(0x10b));
  5476. return 0;
  5477. }
  5478. /*==========================================
  5479. * ギルド作成可否通知
  5480. *------------------------------------------*/
  5481. int clif_guild_created(struct map_session_data *sd,int flag)
  5482. {
  5483. int fd;
  5484. nullpo_retr(0, sd);
  5485. fd=sd->fd;
  5486. WFIFOHEAD(fd,packet_len(0x167));
  5487. WFIFOW(fd,0)=0x167;
  5488. WFIFOB(fd,2)=flag;
  5489. WFIFOSET(fd,packet_len(0x167));
  5490. return 0;
  5491. }
  5492. /*==========================================
  5493. * ギルド所属通知
  5494. *------------------------------------------*/
  5495. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5496. {
  5497. int ps,fd;
  5498. nullpo_retr(0, sd);
  5499. nullpo_retr(0, g);
  5500. fd=sd->fd;
  5501. ps=guild_getposition(sd,g);
  5502. WFIFOHEAD(fd,packet_len(0x16c));
  5503. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5504. WFIFOW(fd,0)=0x16c;
  5505. WFIFOL(fd,2)=g->guild_id;
  5506. WFIFOL(fd,6)=g->emblem_id;
  5507. WFIFOL(fd,10)=g->position[ps].mode;
  5508. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5509. WFIFOSET(fd,packet_len(0x16c));
  5510. return 0;
  5511. }
  5512. /*==========================================
  5513. * ギルドメンバログイン通知
  5514. *------------------------------------------*/
  5515. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5516. {
  5517. unsigned char buf[64];
  5518. nullpo_retr(0, g);
  5519. WBUFW(buf, 0)=0x16d;
  5520. WBUFL(buf, 2)=g->member[idx].account_id;
  5521. WBUFL(buf, 6)=g->member[idx].char_id;
  5522. WBUFL(buf,10)=flag;
  5523. if(g->member[idx].sd==NULL){
  5524. struct map_session_data *sd=guild_getavailablesd(g);
  5525. if(sd!=NULL)
  5526. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5527. }else
  5528. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5529. return 0;
  5530. }
  5531. // Function `clif_guild_memberlogin_notice` sends info about
  5532. // logins and logouts of a guild member to the rest members.
  5533. // But at the 1st time (after a player login or map changing)
  5534. // the client won't show the message.
  5535. // So I suggest use this function for sending "first-time-info"
  5536. // to some player on entering the game or changing location.
  5537. // At next time the client would always show the message.
  5538. // The function sends all the statuses in the single packet
  5539. // to economize traffic. [LuzZza]
  5540. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5541. {
  5542. struct guild *g;
  5543. unsigned char buf[14*128];
  5544. int i, count=0, p_len;
  5545. nullpo_retr(0, sd);
  5546. p_len = packet_len(0x16d);
  5547. if(!(g = guild_search(sd->status.guild_id)))
  5548. return 0;
  5549. for(i=0; i<g->max_member; i++) {
  5550. if(g->member[i].account_id > 0 &&
  5551. g->member[i].account_id != sd->status.account_id) {
  5552. WBUFW(buf,count*p_len) = 0x16d;
  5553. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5554. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5555. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5556. count++;
  5557. }
  5558. }
  5559. clif_send(buf, p_len*count, &sd->bl, SELF);
  5560. return 0;
  5561. }
  5562. /*==========================================
  5563. * ギルドマスター通知(14dへの応答)
  5564. *------------------------------------------*/
  5565. int clif_guild_masterormember(struct map_session_data *sd)
  5566. {
  5567. int fd;
  5568. nullpo_retr(0, sd);
  5569. fd=sd->fd;
  5570. WFIFOHEAD(fd,packet_len(0x14e));
  5571. WFIFOW(fd,0) = 0x14e;
  5572. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5573. WFIFOSET(fd,packet_len(0x14e));
  5574. return 0;
  5575. }
  5576. /*==========================================
  5577. * Basic Info (Territories [Valaris])
  5578. *------------------------------------------*/
  5579. int clif_guild_basicinfo(struct map_session_data *sd)
  5580. {
  5581. int fd,i,t;
  5582. struct guild *g;
  5583. struct guild_castle *gc=NULL;
  5584. nullpo_retr(0, sd);
  5585. fd=sd->fd;
  5586. g=guild_search(sd->status.guild_id);
  5587. if(g==NULL)
  5588. return 0;
  5589. WFIFOHEAD(fd,packet_len(0x1b6));
  5590. WFIFOW(fd, 0)=0x1b6;//0x150;
  5591. WFIFOL(fd, 2)=g->guild_id;
  5592. WFIFOL(fd, 6)=g->guild_lv;
  5593. WFIFOL(fd,10)=g->connect_member;
  5594. WFIFOL(fd,14)=g->max_member;
  5595. WFIFOL(fd,18)=g->average_lv;
  5596. WFIFOL(fd,22)=g->exp;
  5597. WFIFOL(fd,26)=g->next_exp;
  5598. WFIFOL(fd,30)=0; // Tax Points
  5599. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5600. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5601. WFIFOL(fd,42)=g->emblem_id;
  5602. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5603. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5604. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5605. {
  5606. gc = guild_castle_search(i);
  5607. if(gc && g->guild_id == gc->guild_id)
  5608. t++;
  5609. }
  5610. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5611. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5612. return 0;
  5613. }
  5614. /*==========================================
  5615. * ギルド同盟/敵対情報
  5616. *------------------------------------------*/
  5617. int clif_guild_allianceinfo(struct map_session_data *sd)
  5618. {
  5619. int fd,i,c;
  5620. struct guild *g;
  5621. nullpo_retr(0, sd);
  5622. fd=sd->fd;
  5623. g=guild_search(sd->status.guild_id);
  5624. if(g==NULL)
  5625. return 0;
  5626. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5627. WFIFOW(fd, 0)=0x14c;
  5628. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5629. struct guild_alliance *a=&g->alliance[i];
  5630. if(a->guild_id>0){
  5631. WFIFOL(fd,c*32+4)=a->opposition;
  5632. WFIFOL(fd,c*32+8)=a->guild_id;
  5633. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5634. c++;
  5635. }
  5636. }
  5637. WFIFOW(fd, 2)=c*32+4;
  5638. WFIFOSET(fd,WFIFOW(fd,2));
  5639. return 0;
  5640. }
  5641. /*==========================================
  5642. * ギルドメンバーリスト
  5643. *------------------------------------------*/
  5644. int clif_guild_memberlist(struct map_session_data *sd)
  5645. {
  5646. int fd;
  5647. int i,c;
  5648. struct guild *g;
  5649. nullpo_retr(0, sd);
  5650. fd=sd->fd;
  5651. if (!fd)
  5652. return 0;
  5653. g=guild_search(sd->status.guild_id);
  5654. if(g==NULL)
  5655. return 0;
  5656. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5657. WFIFOW(fd, 0)=0x154;
  5658. for(i=0,c=0;i<g->max_member;i++){
  5659. struct guild_member *m=&g->member[i];
  5660. if(m->account_id==0)
  5661. continue;
  5662. WFIFOL(fd,c*104+ 4)=m->account_id;
  5663. WFIFOL(fd,c*104+ 8)=m->char_id;
  5664. WFIFOW(fd,c*104+12)=m->hair;
  5665. WFIFOW(fd,c*104+14)=m->hair_color;
  5666. WFIFOW(fd,c*104+16)=m->gender;
  5667. WFIFOW(fd,c*104+18)=m->class_;
  5668. WFIFOW(fd,c*104+20)=m->lv;
  5669. WFIFOL(fd,c*104+22)=m->exp;
  5670. WFIFOL(fd,c*104+26)=m->online;
  5671. WFIFOL(fd,c*104+30)=m->position;
  5672. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5673. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5674. c++;
  5675. }
  5676. WFIFOW(fd, 2)=c*104+4;
  5677. WFIFOSET(fd,WFIFOW(fd,2));
  5678. return 0;
  5679. }
  5680. /*==========================================
  5681. * ギルド役職名リスト
  5682. *------------------------------------------*/
  5683. int clif_guild_positionnamelist(struct map_session_data *sd)
  5684. {
  5685. int i,fd;
  5686. struct guild *g;
  5687. nullpo_retr(0, sd);
  5688. fd=sd->fd;
  5689. g=guild_search(sd->status.guild_id);
  5690. if(g==NULL)
  5691. return 0;
  5692. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5693. WFIFOW(fd, 0)=0x166;
  5694. for(i=0;i<MAX_GUILDPOSITION;i++){
  5695. WFIFOL(fd,i*28+4)=i;
  5696. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5697. }
  5698. WFIFOW(fd,2)=i*28+4;
  5699. WFIFOSET(fd,WFIFOW(fd,2));
  5700. return 0;
  5701. }
  5702. /*==========================================
  5703. * ギルド役職情報リスト
  5704. *------------------------------------------*/
  5705. int clif_guild_positioninfolist(struct map_session_data *sd)
  5706. {
  5707. int i,fd;
  5708. struct guild *g;
  5709. nullpo_retr(0, sd);
  5710. fd=sd->fd;
  5711. g=guild_search(sd->status.guild_id);
  5712. if(g==NULL)
  5713. return 0;
  5714. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5715. WFIFOW(fd, 0)=0x160;
  5716. for(i=0;i<MAX_GUILDPOSITION;i++){
  5717. struct guild_position *p=&g->position[i];
  5718. WFIFOL(fd,i*16+ 4)=i;
  5719. WFIFOL(fd,i*16+ 8)=p->mode;
  5720. WFIFOL(fd,i*16+12)=i;
  5721. WFIFOL(fd,i*16+16)=p->exp_mode;
  5722. }
  5723. WFIFOW(fd, 2)=i*16+4;
  5724. WFIFOSET(fd,WFIFOW(fd,2));
  5725. return 0;
  5726. }
  5727. /*==========================================
  5728. * ギルド役職変更通知
  5729. *------------------------------------------*/
  5730. int clif_guild_positionchanged(struct guild *g,int idx)
  5731. {
  5732. struct map_session_data *sd;
  5733. unsigned char buf[128];
  5734. nullpo_retr(0, g);
  5735. WBUFW(buf, 0)=0x174;
  5736. WBUFW(buf, 2)=44;
  5737. WBUFL(buf, 4)=idx;
  5738. WBUFL(buf, 8)=g->position[idx].mode;
  5739. WBUFL(buf,12)=idx;
  5740. WBUFL(buf,16)=g->position[idx].exp_mode;
  5741. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5742. if( (sd=guild_getavailablesd(g))!=NULL )
  5743. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5744. return 0;
  5745. }
  5746. /*==========================================
  5747. * ギルドメンバ変更通知
  5748. *------------------------------------------*/
  5749. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5750. {
  5751. struct map_session_data *sd;
  5752. unsigned char buf[64];
  5753. nullpo_retr(0, g);
  5754. WBUFW(buf, 0)=0x156;
  5755. WBUFW(buf, 2)=16;
  5756. WBUFL(buf, 4)=g->member[idx].account_id;
  5757. WBUFL(buf, 8)=g->member[idx].char_id;
  5758. WBUFL(buf,12)=g->member[idx].position;
  5759. if( (sd=guild_getavailablesd(g))!=NULL )
  5760. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5761. return 0;
  5762. }
  5763. /*==========================================
  5764. * ギルドエンブレム送信
  5765. *------------------------------------------*/
  5766. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5767. {
  5768. int fd;
  5769. nullpo_retr(0, sd);
  5770. nullpo_retr(0, g);
  5771. fd=sd->fd;
  5772. if(g->emblem_len<=0)
  5773. return 0;
  5774. WFIFOHEAD(fd,g->emblem_len+12);
  5775. WFIFOW(fd,0)=0x152;
  5776. WFIFOW(fd,2)=g->emblem_len+12;
  5777. WFIFOL(fd,4)=g->guild_id;
  5778. WFIFOL(fd,8)=g->emblem_id;
  5779. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5780. WFIFOSET(fd,WFIFOW(fd,2));
  5781. return 0;
  5782. }
  5783. /*==========================================
  5784. * Send guild skills
  5785. *------------------------------------------*/
  5786. int clif_guild_skillinfo(struct map_session_data* sd)
  5787. {
  5788. int fd;
  5789. struct guild* g;
  5790. int i,c;
  5791. nullpo_retr(0, sd);
  5792. fd = sd->fd;
  5793. g = guild_search(sd->status.guild_id);
  5794. if(g == NULL)
  5795. return 0;
  5796. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  5797. WFIFOW(fd,0) = 0x0162;
  5798. WFIFOW(fd,4) = g->skill_point;
  5799. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5800. {
  5801. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5802. {
  5803. int id = g->skill[i].id;
  5804. WFIFOW(fd,c*37+ 6) = id;
  5805. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  5806. WFIFOW(fd,c*37+10) = 0;
  5807. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  5808. WFIFOW(fd,c*37+14) = skill_get_sp(id, g->skill[i].lv);
  5809. WFIFOW(fd,c*37+16) = skill_get_range(id, g->skill[i].lv);
  5810. strncpy((char*)WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH);
  5811. WFIFOB(fd,c*37+42)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5812. c++;
  5813. }
  5814. }
  5815. WFIFOW(fd,2) = c*37 + 6;
  5816. WFIFOSET(fd,WFIFOW(fd,2));
  5817. return 0;
  5818. }
  5819. /*==========================================
  5820. * Sends guild notice to client
  5821. * R 016f <str1z>.60B <str2z>.120B
  5822. *------------------------------------------*/
  5823. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5824. {
  5825. int fd;
  5826. nullpo_retr(0, sd);
  5827. nullpo_retr(0, g);
  5828. fd = sd->fd;
  5829. if ( !session_isActive(fd) )
  5830. return 0;
  5831. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5832. return 0;
  5833. WFIFOHEAD(fd,packet_len(0x16f));
  5834. WFIFOW(fd,0) = 0x16f;
  5835. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5836. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5837. WFIFOSET(fd,packet_len(0x16f));
  5838. return 0;
  5839. }
  5840. /*==========================================
  5841. * ギルドメンバ勧誘
  5842. *------------------------------------------*/
  5843. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5844. {
  5845. int fd;
  5846. nullpo_retr(0, sd);
  5847. nullpo_retr(0, g);
  5848. fd=sd->fd;
  5849. WFIFOHEAD(fd,packet_len(0x16a));
  5850. WFIFOW(fd,0)=0x16a;
  5851. WFIFOL(fd,2)=g->guild_id;
  5852. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5853. WFIFOSET(fd,packet_len(0x16a));
  5854. return 0;
  5855. }
  5856. /*==========================================
  5857. * ギルドメンバ勧誘結果
  5858. *------------------------------------------*/
  5859. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5860. {
  5861. int fd;
  5862. nullpo_retr(0, sd);
  5863. fd=sd->fd;
  5864. WFIFOHEAD(fd,packet_len(0x169));
  5865. WFIFOW(fd,0)=0x169;
  5866. WFIFOB(fd,2)=flag;
  5867. WFIFOSET(fd,packet_len(0x169));
  5868. return 0;
  5869. }
  5870. /*==========================================
  5871. * ギルドメンバ脱退通知
  5872. *------------------------------------------*/
  5873. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5874. {
  5875. unsigned char buf[128];
  5876. nullpo_retr(0, sd);
  5877. WBUFW(buf, 0)=0x15a;
  5878. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5879. memcpy(WBUFP(buf,26),mes,40);
  5880. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5881. return 0;
  5882. }
  5883. /*==========================================
  5884. * ギルドメンバ追放通知
  5885. *------------------------------------------*/
  5886. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  5887. int account_id)
  5888. {
  5889. unsigned char buf[128];
  5890. nullpo_retr(0, sd);
  5891. WBUFW(buf, 0)=0x15c;
  5892. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5893. memcpy(WBUFP(buf,26),mes,40);
  5894. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  5895. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5896. return 0;
  5897. }
  5898. /*==========================================
  5899. * ギルド追放メンバリスト
  5900. *------------------------------------------*/
  5901. int clif_guild_expulsionlist(struct map_session_data *sd)
  5902. {
  5903. int fd;
  5904. int i,c;
  5905. struct guild *g;
  5906. nullpo_retr(0, sd);
  5907. fd=sd->fd;
  5908. g=guild_search(sd->status.guild_id);
  5909. if(g==NULL)
  5910. return 0;
  5911. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  5912. WFIFOW(fd,0)=0x163;
  5913. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5914. struct guild_expulsion *e=&g->expulsion[i];
  5915. if(e->account_id>0){
  5916. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  5917. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  5918. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  5919. c++;
  5920. }
  5921. }
  5922. WFIFOW(fd,2)=c*88+4;
  5923. WFIFOSET(fd,WFIFOW(fd,2));
  5924. return 0;
  5925. }
  5926. /*==========================================
  5927. * ギルド会話
  5928. *------------------------------------------*/
  5929. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5930. {
  5931. struct map_session_data *sd;
  5932. unsigned char *buf;
  5933. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5934. WBUFW(buf, 0) = 0x17f;
  5935. WBUFW(buf, 2) = len + 4;
  5936. memcpy(WBUFP(buf,4), mes, len);
  5937. if ((sd = guild_getavailablesd(g)) != NULL)
  5938. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5939. if(buf) aFree(buf);
  5940. return 0;
  5941. }
  5942. /*==========================================
  5943. * ギルドスキル割り振り通知
  5944. *------------------------------------------*/
  5945. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5946. {
  5947. int fd;
  5948. nullpo_retr(0, sd);
  5949. fd=sd->fd;
  5950. WFIFOHEAD(fd,11);
  5951. WFIFOW(fd,0) = 0x10e;
  5952. WFIFOW(fd,2) = skill_num;
  5953. WFIFOW(fd,4) = lv;
  5954. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5955. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5956. WFIFOB(fd,10) = 1;
  5957. WFIFOSET(fd,11);
  5958. return 0;
  5959. }
  5960. /*==========================================
  5961. * ギルド同盟要請
  5962. *------------------------------------------*/
  5963. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5964. {
  5965. int fd;
  5966. nullpo_retr(0, sd);
  5967. fd=sd->fd;
  5968. WFIFOHEAD(fd,packet_len(0x171));
  5969. WFIFOW(fd,0)=0x171;
  5970. WFIFOL(fd,2)=account_id;
  5971. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5972. WFIFOSET(fd,packet_len(0x171));
  5973. return 0;
  5974. }
  5975. /*==========================================
  5976. * Reply to alliance request.
  5977. * Flag values are:
  5978. * 0: Already allied.
  5979. * 1: You rejected the offer.
  5980. * 2: You accepted the offer.
  5981. * 3: They have too any alliances
  5982. * 4: You have too many alliances.
  5983. *------------------------------------------*/
  5984. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5985. {
  5986. int fd;
  5987. nullpo_retr(0, sd);
  5988. fd=sd->fd;
  5989. WFIFOHEAD(fd,packet_len(0x173));
  5990. WFIFOW(fd,0)=0x173;
  5991. WFIFOL(fd,2)=flag;
  5992. WFIFOSET(fd,packet_len(0x173));
  5993. return 0;
  5994. }
  5995. /*==========================================
  5996. * ギルド関係解消通知
  5997. *------------------------------------------*/
  5998. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5999. {
  6000. int fd;
  6001. nullpo_retr(0, sd);
  6002. fd = sd->fd;
  6003. if (fd <= 0)
  6004. return 0;
  6005. WFIFOHEAD(fd,packet_len(0x184));
  6006. WFIFOW(fd,0)=0x184;
  6007. WFIFOL(fd,2)=guild_id;
  6008. WFIFOL(fd,6)=flag;
  6009. WFIFOSET(fd,packet_len(0x184));
  6010. return 0;
  6011. }
  6012. /*==========================================
  6013. * ギルド敵対結果
  6014. *------------------------------------------*/
  6015. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6016. {
  6017. int fd;
  6018. nullpo_retr(0, sd);
  6019. fd=sd->fd;
  6020. WFIFOHEAD(fd,packet_len(0x181));
  6021. WFIFOW(fd,0)=0x181;
  6022. WFIFOB(fd,2)=flag;
  6023. WFIFOSET(fd,packet_len(0x181));
  6024. return 0;
  6025. }
  6026. /*==========================================
  6027. * ギルド関係追加
  6028. *------------------------------------------*/
  6029. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6030. {
  6031. unsigned char buf[64];
  6032. WBUFW(fd,0)=0x185;
  6033. WBUFL(fd,2)=g->alliance[idx].opposition;
  6034. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6035. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6036. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6037. return 0;
  6038. }*/
  6039. /*==========================================
  6040. * ギルド解散通知
  6041. *------------------------------------------*/
  6042. int clif_guild_broken(struct map_session_data *sd,int flag)
  6043. {
  6044. int fd;
  6045. nullpo_retr(0, sd);
  6046. fd=sd->fd;
  6047. WFIFOHEAD(fd,packet_len(0x15e));
  6048. WFIFOW(fd,0)=0x15e;
  6049. WFIFOL(fd,2)=flag;
  6050. WFIFOSET(fd,packet_len(0x15e));
  6051. return 0;
  6052. }
  6053. /*==========================================
  6054. * エモーション
  6055. *------------------------------------------*/
  6056. void clif_emotion(struct block_list *bl,int type)
  6057. {
  6058. unsigned char buf[8];
  6059. nullpo_retv(bl);
  6060. WBUFW(buf,0)=0xc0;
  6061. WBUFL(buf,2)=bl->id;
  6062. WBUFB(buf,6)=type;
  6063. clif_send(buf,packet_len(0xc0),bl,AREA);
  6064. }
  6065. /*==========================================
  6066. * トーキーボックス
  6067. *------------------------------------------*/
  6068. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6069. {
  6070. unsigned char buf[86];
  6071. nullpo_retv(bl);
  6072. WBUFW(buf,0) = 0x191;
  6073. WBUFL(buf,2) = bl->id;
  6074. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6075. clif_send(buf,packet_len(0x191),bl,AREA);
  6076. }
  6077. /*==========================================
  6078. * 結婚エフェクト
  6079. *------------------------------------------*/
  6080. void clif_wedding_effect(struct block_list *bl)
  6081. {
  6082. unsigned char buf[6];
  6083. nullpo_retv(bl);
  6084. WBUFW(buf,0) = 0x1ea;
  6085. WBUFL(buf,2) = bl->id;
  6086. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6087. }
  6088. /*==========================================
  6089. * あなたに逢いたい使用時名前叫び
  6090. *------------------------------------------
  6091. void clif_callpartner(struct map_session_data *sd)
  6092. {
  6093. unsigned char buf[26];
  6094. char *p;
  6095. nullpo_retv(sd);
  6096. if(sd->status.partner_id){
  6097. WBUFW(buf,0)=0x1e6;
  6098. p = map_charid2nick(sd->status.partner_id);
  6099. if(p){
  6100. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6101. }else{
  6102. map_reqchariddb(sd,sd->status.partner_id);
  6103. chrif_searchcharid(sd->status.partner_id);
  6104. WBUFB(buf,2) = 0;
  6105. }
  6106. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6107. }
  6108. return;
  6109. }
  6110. */
  6111. /*==========================================
  6112. * Adopt baby [Celest]
  6113. *------------------------------------------*/
  6114. void clif_adopt_process(struct map_session_data *sd)
  6115. {
  6116. int fd;
  6117. nullpo_retv(sd);
  6118. fd=sd->fd;
  6119. WFIFOHEAD(fd,packet_len(0x1f8));
  6120. WFIFOW(fd,0)=0x1f8;
  6121. WFIFOSET(fd,packet_len(0x1f8));
  6122. }
  6123. /*==========================================
  6124. * Marry [DracoRPG]
  6125. *------------------------------------------*/
  6126. void clif_marriage_process(struct map_session_data *sd)
  6127. {
  6128. int fd;
  6129. nullpo_retv(sd);
  6130. fd=sd->fd;
  6131. WFIFOHEAD(fd,packet_len(0x1e4));
  6132. WFIFOW(fd,0)=0x1e4;
  6133. WFIFOSET(fd,packet_len(0x1e4));
  6134. }
  6135. /*==========================================
  6136. * Notice of divorce
  6137. *------------------------------------------*/
  6138. void clif_divorced(struct map_session_data* sd, const char* name)
  6139. {
  6140. int fd;
  6141. nullpo_retv(sd);
  6142. fd=sd->fd;
  6143. WFIFOHEAD(fd,packet_len(0x205));
  6144. WFIFOW(fd,0)=0x205;
  6145. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6146. WFIFOSET(fd, packet_len(0x205));
  6147. }
  6148. /*==========================================
  6149. *
  6150. *------------------------------------------*/
  6151. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd)
  6152. {
  6153. nullpo_retv(sd);
  6154. WFIFOHEAD(fd,packet_len(0x1f6));
  6155. WFIFOW(fd,0)=0x1f6;
  6156. WFIFOSET(fd, packet_len(0x1f6));
  6157. }
  6158. /*==========================================
  6159. *
  6160. *------------------------------------------*/
  6161. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  6162. {
  6163. nullpo_retv(sd);
  6164. WFIFOHEAD(fd,packet_len(0x1e2));
  6165. WFIFOW(fd,0)=0x1e2;
  6166. WFIFOSET(fd, packet_len(0x1e2));
  6167. }
  6168. /*==========================================
  6169. *
  6170. *------------------------------------------*/
  6171. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6172. {
  6173. int fd;
  6174. nullpo_retr(0, sd);
  6175. fd = sd->fd;
  6176. if (!fd || !len) return 0; //Disconnected player.
  6177. WFIFOHEAD(fd, len+5);
  6178. WFIFOW(fd, 0) = 0x17f;
  6179. WFIFOW(fd, 2) = len + 5;
  6180. memcpy(WFIFOP(fd,4), mes, len);
  6181. WFIFOSET(fd, WFIFOW(fd,2));
  6182. return 1;
  6183. }
  6184. /*==========================================
  6185. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6186. *------------------------------------------*/
  6187. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6188. {
  6189. unsigned char buf[1024];
  6190. if (!len) return;
  6191. WBUFW(buf, 0) = 0x17f;
  6192. WBUFW(buf, 2) = len + 5;
  6193. memcpy(WBUFP(buf,4), mes, len);
  6194. clif_send(buf, WBUFW(buf,2), src, target);
  6195. return;
  6196. }
  6197. /*==========================================
  6198. *
  6199. *------------------------------------------*/
  6200. int clif_GM_kickack(struct map_session_data *sd, int id)
  6201. {
  6202. int fd;
  6203. nullpo_retr(0, sd);
  6204. fd = sd->fd;
  6205. WFIFOHEAD(fd,packet_len(0xcd));
  6206. WFIFOW(fd,0) = 0xcd;
  6207. WFIFOL(fd,2) = id;
  6208. WFIFOSET(fd, packet_len(0xcd));
  6209. return 0;
  6210. }
  6211. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6212. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6213. {
  6214. int fd = tsd->fd;
  6215. WFIFOHEAD(fd,packet_len(0x18b));
  6216. if(type)
  6217. clif_GM_kickack(sd,tsd->status.account_id);
  6218. if (!fd) {
  6219. map_quit(tsd);
  6220. return 0;
  6221. }
  6222. WFIFOW(fd,0) = 0x18b;
  6223. WFIFOW(fd,2) = 0;
  6224. WFIFOSET(fd,packet_len(0x18b));
  6225. clif_setwaitclose(fd);
  6226. return 0;
  6227. }
  6228. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6229. {
  6230. int fd;
  6231. nullpo_retr(0, sd);
  6232. nullpo_retr(0, tsd);
  6233. fd = tsd->fd;
  6234. if (fd <= 0)
  6235. return 0;
  6236. WFIFOHEAD(fd,packet_len(0x14b));
  6237. WFIFOW(fd,0) = 0x14b;
  6238. WFIFOB(fd,2) = 0;
  6239. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6240. WFIFOSET(fd, packet_len(0x14b));
  6241. return 0;
  6242. }
  6243. /*==========================================
  6244. *
  6245. *------------------------------------------*/
  6246. int clif_timedout(struct map_session_data *sd)
  6247. {
  6248. nullpo_retr(0, sd);
  6249. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6250. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6251. clif_setwaitclose(sd->fd); // Set session to EOF
  6252. return 0;
  6253. }
  6254. /*==========================================
  6255. * Wis拒否許可応答
  6256. *------------------------------------------*/
  6257. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6258. {
  6259. int fd;
  6260. nullpo_retr(0, sd);
  6261. fd=sd->fd;
  6262. WFIFOHEAD(fd,packet_len(0xd1));
  6263. WFIFOW(fd,0)=0xd1;
  6264. WFIFOB(fd,2)=type;
  6265. WFIFOB(fd,3)=flag;
  6266. WFIFOSET(fd,packet_len(0xd1));
  6267. return 0;
  6268. }
  6269. /*==========================================
  6270. * Wis全拒否許可応答
  6271. *------------------------------------------*/
  6272. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6273. {
  6274. int fd;
  6275. nullpo_retr(0, sd);
  6276. fd=sd->fd;
  6277. WFIFOHEAD(fd,packet_len(0xd2));
  6278. WFIFOW(fd,0)=0xd2;
  6279. WFIFOB(fd,2)=type;
  6280. WFIFOB(fd,3)=flag;
  6281. WFIFOSET(fd,packet_len(0xd2));
  6282. return 0;
  6283. }
  6284. /*==========================================
  6285. * サウンドエフェクト
  6286. *------------------------------------------*/
  6287. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6288. {
  6289. int fd;
  6290. nullpo_retv(sd);
  6291. nullpo_retv(bl);
  6292. fd = sd->fd;
  6293. WFIFOHEAD(fd,packet_len(0x1d3));
  6294. WFIFOW(fd,0) = 0x1d3;
  6295. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6296. WFIFOB(fd,26) = type;
  6297. WFIFOL(fd,27) = 0;
  6298. WFIFOL(fd,31) = bl->id;
  6299. WFIFOSET(fd,packet_len(0x1d3));
  6300. return;
  6301. }
  6302. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6303. {
  6304. unsigned char buf[40];
  6305. nullpo_retr(0, bl);
  6306. WBUFW(buf,0) = 0x1d3;
  6307. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6308. WBUFB(buf,26) = type;
  6309. WBUFL(buf,27) = 0;
  6310. WBUFL(buf,31) = bl->id;
  6311. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6312. return 0;
  6313. }
  6314. // displaying special effects (npcs, weather, etc) [Valaris]
  6315. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6316. {
  6317. unsigned char buf[24];
  6318. nullpo_retr(0, bl);
  6319. memset(buf, 0, packet_len(0x1f3));
  6320. WBUFW(buf,0) = 0x1f3;
  6321. WBUFL(buf,2) = bl->id;
  6322. WBUFL(buf,6) = type;
  6323. clif_send(buf, packet_len(0x1f3), bl, target);
  6324. if (disguised(bl)) {
  6325. WBUFL(buf,2) = -bl->id;
  6326. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6327. }
  6328. return 0;
  6329. }
  6330. // messages (from mobs/npcs) [Valaris]
  6331. int clif_message(struct block_list* bl, const char* msg)
  6332. {
  6333. unsigned short msg_len = strlen(msg) + 1;
  6334. uint8 buf[256];
  6335. nullpo_retr(0, bl);
  6336. WBUFW(buf,0) = 0x8d;
  6337. WBUFW(buf,2) = msg_len + 8;
  6338. WBUFL(buf,4) = bl->id;
  6339. memcpy(WBUFP(buf,8), msg, msg_len);
  6340. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6341. return 0;
  6342. }
  6343. // refresh the client's screen, getting rid of any effects
  6344. int clif_refresh(struct map_session_data *sd)
  6345. {
  6346. nullpo_retr(-1, sd);
  6347. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6348. clif_inventorylist(sd);
  6349. if(pc_iscarton(sd)) {
  6350. clif_cartlist(sd);
  6351. clif_updatestatus(sd,SP_CARTINFO);
  6352. }
  6353. clif_updatestatus(sd,SP_MAXWEIGHT);
  6354. clif_updatestatus(sd,SP_WEIGHT);
  6355. clif_updatestatus(sd,SP_STR);
  6356. clif_updatestatus(sd,SP_AGI);
  6357. clif_updatestatus(sd,SP_VIT);
  6358. clif_updatestatus(sd,SP_INT);
  6359. clif_updatestatus(sd,SP_DEX);
  6360. clif_updatestatus(sd,SP_LUK);
  6361. if (sd->spiritball)
  6362. clif_spiritball_single(sd->fd, sd);
  6363. if (sd->vd.cloth_color)
  6364. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6365. if(merc_is_hom_active(sd->hd))
  6366. clif_send_homdata(sd,0,0);
  6367. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6368. clif_weather_check(sd);
  6369. return 0;
  6370. }
  6371. // updates the object's (bl) name on client
  6372. int clif_charnameack (int fd, struct block_list *bl)
  6373. {
  6374. unsigned char buf[103];
  6375. int cmd = 0x95;
  6376. nullpo_retr(0, bl);
  6377. WBUFW(buf,0) = cmd;
  6378. WBUFL(buf,2) = bl->id;
  6379. switch(bl->type) {
  6380. case BL_PC:
  6381. {
  6382. struct map_session_data *ssd = (struct map_session_data *)bl;
  6383. struct party_data *p = NULL;
  6384. struct guild *g = NULL;
  6385. //Requesting your own "shadow" name. [Skotlex]
  6386. if (ssd->fd == fd && ssd->disguise)
  6387. WBUFL(buf,2) = -bl->id;
  6388. if (strlen(ssd->fakename)>1) {
  6389. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6390. break;
  6391. }
  6392. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6393. if (ssd->status.party_id > 0)
  6394. p = party_search(ssd->status.party_id);
  6395. if (ssd->status.guild_id > 0)
  6396. g = guild_search(ssd->status.guild_id);
  6397. if (p == NULL && g == NULL)
  6398. break;
  6399. WBUFW(buf, 0) = cmd = 0x195;
  6400. if (p)
  6401. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6402. else
  6403. WBUFB(buf,30) = 0;
  6404. if (g)
  6405. {
  6406. int i, ps = -1;
  6407. for(i = 0; i < g->max_member; i++) {
  6408. if (g->member[i].account_id == ssd->status.account_id &&
  6409. g->member[i].char_id == ssd->status.char_id )
  6410. {
  6411. ps = g->member[i].position;
  6412. break;
  6413. }
  6414. }
  6415. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6416. {
  6417. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6418. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6419. } else { //Assume no guild.
  6420. WBUFB(buf,54) = 0;
  6421. WBUFB(buf,78) = 0;
  6422. }
  6423. } else {
  6424. WBUFB(buf,54) = 0;
  6425. WBUFB(buf,78) = 0;
  6426. }
  6427. }
  6428. break;
  6429. //[blackhole89]
  6430. case BL_HOM:
  6431. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6432. break;
  6433. case BL_PET:
  6434. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6435. break;
  6436. case BL_NPC:
  6437. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6438. break;
  6439. case BL_MOB:
  6440. {
  6441. struct mob_data *md = (struct mob_data *)bl;
  6442. nullpo_retr(0, md);
  6443. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6444. if (md->guardian_data && md->guardian_data->guild_id) {
  6445. WBUFW(buf, 0) = cmd = 0x195;
  6446. WBUFB(buf,30) = 0;
  6447. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6448. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6449. } else if (battle_config.show_mob_info) {
  6450. char mobhp[50], *str_p = mobhp;
  6451. WBUFW(buf, 0) = cmd = 0x195;
  6452. if (battle_config.show_mob_info&4)
  6453. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6454. if (battle_config.show_mob_info&1)
  6455. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6456. if (battle_config.show_mob_info&2)
  6457. str_p += sprintf(str_p, "HP: %d%% | ",
  6458. md->status.max_hp > 10000?
  6459. md->status.hp/(md->status.max_hp/100):
  6460. 100*md->status.hp/md->status.max_hp);
  6461. //Even thought mobhp ain't a name, we send it as one so the client
  6462. //can parse it. [Skotlex]
  6463. if (str_p != mobhp) {
  6464. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6465. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6466. WBUFB(buf,54) = 0;
  6467. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6468. }
  6469. }
  6470. }
  6471. break;
  6472. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6473. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6474. // break;
  6475. return 0;
  6476. default:
  6477. if (battle_config.error_log)
  6478. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6479. return 0;
  6480. }
  6481. // if no receipient specified just update nearby clients
  6482. if (fd == 0)
  6483. clif_send(buf, packet_len(cmd), bl, AREA);
  6484. else {
  6485. WFIFOHEAD(fd, packet_len(cmd));
  6486. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6487. WFIFOSET(fd, packet_len(cmd));
  6488. }
  6489. return 0;
  6490. }
  6491. //Used to update when a char leaves a party/guild. [Skotlex]
  6492. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6493. int clif_charnameupdate (struct map_session_data *ssd)
  6494. {
  6495. unsigned char buf[103];
  6496. int cmd = 0x195;
  6497. struct party_data *p = NULL;
  6498. struct guild *g = NULL;
  6499. nullpo_retr(0, ssd);
  6500. if (strlen(ssd->fakename)>1)
  6501. return 0; //No need to update as the party/guild was not displayed anyway.
  6502. WBUFW(buf,0) = cmd;
  6503. WBUFL(buf,2) = ssd->bl.id;
  6504. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6505. if (ssd->status.party_id > 0)
  6506. p = party_search(ssd->status.party_id);
  6507. if (ssd->status.guild_id > 0)
  6508. g = guild_search(ssd->status.guild_id);
  6509. if (p)
  6510. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6511. else
  6512. WBUFB(buf,30) = 0;
  6513. if (g)
  6514. {
  6515. int i, ps = -1;
  6516. for(i = 0; i < g->max_member; i++) {
  6517. if (g->member[i].account_id == ssd->status.account_id &&
  6518. g->member[i].char_id == ssd->status.char_id )
  6519. {
  6520. ps = g->member[i].position;
  6521. break;
  6522. }
  6523. }
  6524. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6525. {
  6526. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6527. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6528. } else { //Assume no guild.
  6529. WBUFB(buf,54) = 0;
  6530. WBUFB(buf,78) = 0;
  6531. }
  6532. } else {
  6533. WBUFB(buf,54) = 0;
  6534. WBUFB(buf,78) = 0;
  6535. }
  6536. // Update nearby clients
  6537. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6538. return 0;
  6539. }
  6540. int clif_slide(struct block_list *bl, int x, int y){
  6541. unsigned char buf[10];
  6542. nullpo_retr(0, bl);
  6543. WBUFW(buf, 0) = 0x01ff;
  6544. WBUFL(buf, 2) = bl->id;
  6545. WBUFW(buf, 6) = x;
  6546. WBUFW(buf, 8) = y;
  6547. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6548. return 0;
  6549. }
  6550. /*------------------------------------------
  6551. * @me command by lordalfa, rewritten implementation by Skotlex
  6552. *------------------------------------------*/
  6553. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6554. {
  6555. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6556. int len_mes = strlen(mes)+1; //Account for \0
  6557. if (len_mes + 8 >= 256) {
  6558. if (battle_config.error_log)
  6559. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6560. len_mes = 247; //Trunk it to avoid problems.
  6561. }
  6562. // send message to others
  6563. WBUFW(buf,0) = 0x8d;
  6564. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6565. WBUFL(buf,4) = sd->bl.id;
  6566. memcpy(WBUFP(buf,8), mes, len_mes);
  6567. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6568. // send back message to the speaker
  6569. WBUFW(buf,0) = 0x8e;
  6570. WBUFW(buf, 2) = len_mes + 4;
  6571. memcpy(WBUFP(buf,4), mes, len_mes);
  6572. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6573. return 0;
  6574. }
  6575. /*==========================
  6576. * Minimap fix [Kevin]
  6577. * Remove dot from minimap
  6578. *--------------------------*/
  6579. int clif_party_xy_remove(struct map_session_data *sd)
  6580. {
  6581. unsigned char buf[16];
  6582. nullpo_retr(0, sd);
  6583. WBUFW(buf,0)=0x107;
  6584. WBUFL(buf,2)=sd->status.account_id;
  6585. WBUFW(buf,6)=-1;
  6586. WBUFW(buf,8)=-1;
  6587. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6588. return 0;
  6589. }
  6590. //Displays gospel-buff information (thanks to Rayce):
  6591. //Type determines message based on this table:
  6592. /*
  6593. 0x15 End all negative status
  6594. 0x16 Immunity to all status
  6595. 0x17 MaxHP +100%
  6596. 0x18 MaxSP +100%
  6597. 0x19 All stats +20
  6598. 0x1c Enchant weapon with Holy element
  6599. 0x1d Enchant armor with Holy element
  6600. 0x1e DEF +25%
  6601. 0x1f ATK +100%
  6602. 0x20 HIT/Flee +50
  6603. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6604. */
  6605. void clif_gospel_info(struct map_session_data *sd, int type)
  6606. {
  6607. int fd=sd->fd;
  6608. WFIFOHEAD(fd,packet_len(0x215));
  6609. WFIFOW(fd,0)=0x215;
  6610. WFIFOL(fd,2)=type;
  6611. WFIFOSET(fd, packet_len(0x215));
  6612. }
  6613. /*==========================================
  6614. * Info about Star Glaldiator save map [Komurka]
  6615. * type: 1: Information, 0: Map registered
  6616. *------------------------------------------*/
  6617. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6618. {
  6619. int fd=sd->fd;
  6620. WFIFOHEAD(fd,packet_len(0x20e));
  6621. WFIFOW(fd,0) = 0x20e;
  6622. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6623. WFIFOL(fd,26) = sd->bl.id;
  6624. WFIFOB(fd,30) = feel_level;
  6625. WFIFOB(fd,31) = type?1:0;
  6626. WFIFOSET(fd,packet_len(0x20e));
  6627. }
  6628. /*==========================================
  6629. * Info about Star Glaldiator hate mob [Komurka]
  6630. * type: 1: Register mob, 0: Information.
  6631. *------------------------------------------*/
  6632. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6633. {
  6634. int fd=sd->fd;
  6635. WFIFOHEAD(fd,packet_len(0x20e));
  6636. WFIFOW(fd,0)=0x20e;
  6637. if (pcdb_checkid(class_))
  6638. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6639. else if (mobdb_checkid(class_))
  6640. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6641. else //Really shouldn't happen...
  6642. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6643. WFIFOL(fd,26)=sd->bl.id;
  6644. WFIFOB(fd,30)=hate_level;
  6645. WFIFOB(fd,31)=type?10:11; //Register/Info
  6646. WFIFOSET(fd, packet_len(0x20e));
  6647. }
  6648. /*==========================================
  6649. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6650. *------------------------------------------*/
  6651. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6652. {
  6653. int fd=sd->fd;
  6654. WFIFOHEAD(fd,packet_len(0x20e));
  6655. WFIFOW(fd,0)=0x20e;
  6656. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6657. WFIFOL(fd,26)=mob_id;
  6658. WFIFOB(fd,30)=progress; //Message to display
  6659. WFIFOB(fd,31)=20;
  6660. WFIFOSET(fd, packet_len(0x20e));
  6661. }
  6662. /*==========================================
  6663. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6664. *------------------------------------------*/
  6665. void clif_feel_hate_reset(struct map_session_data *sd)
  6666. {
  6667. int fd=sd->fd;
  6668. WFIFOHEAD(fd,packet_len(0x20e));
  6669. WFIFOW(fd,0)=0x20e;
  6670. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6671. WFIFOL(fd,26)=sd->bl.id;
  6672. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6673. WFIFOB(fd,31)=30;
  6674. WFIFOSET(fd, packet_len(0x20e));
  6675. }
  6676. /// Validates one global/guild/party/whisper message packet to and tries to recognize its components.
  6677. /// Returns true if the packet was parsed successfully.
  6678. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6679. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6680. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6681. {
  6682. char *text, *name, *message;
  6683. unsigned int packetlen, textlen, namelen, messagelen;
  6684. int fd = sd->fd;
  6685. *name_ = NULL;
  6686. *namelen_ = 0;
  6687. *message_ = NULL;
  6688. *messagelen_ = 0;
  6689. packetlen = RFIFOW(fd,2);
  6690. // basic structure checks
  6691. if( packetlen > RFIFOREST(fd) )
  6692. { // there has to be enough data to read
  6693. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6694. return false;
  6695. }
  6696. if( packetlen < 4 + 1 )
  6697. { // 4-byte header and at least an empty string is expected
  6698. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6699. return false;
  6700. }
  6701. text = (char*)RFIFOP(fd,4);
  6702. textlen = packetlen - 4;
  6703. // process <name> part of the packet
  6704. if( format == 0 )
  6705. {// name and message are separated by ' : '
  6706. // validate name
  6707. name = text;
  6708. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6709. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6710. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6711. {
  6712. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6713. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6714. clif_setwaitclose(fd); // Just kick them out to correct it.
  6715. return false;
  6716. }
  6717. message = name + namelen + 3;
  6718. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6719. }
  6720. else
  6721. {// name has fixed width
  6722. if( textlen < NAME_LENGTH + 1 )
  6723. {
  6724. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6725. return false;
  6726. }
  6727. // validate name
  6728. name = text;
  6729. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6730. if( name[namelen] != '\0' )
  6731. { // only restriction is that the name must be zero-terminated
  6732. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6733. return false;
  6734. }
  6735. message = name + NAME_LENGTH;
  6736. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6737. }
  6738. if( messagelen != strnlen(message, messagelen)+1 )
  6739. { // the declared length must match real length
  6740. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6741. return false;
  6742. }
  6743. // verify <message> part of the packet
  6744. if( message[messagelen-1] != '\0' )
  6745. { // message must be zero-terminated
  6746. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6747. return false;
  6748. }
  6749. if( messagelen > CHAT_SIZE_MAX )
  6750. { // messages mustn't be too long
  6751. // Normally you can only enter CHATBOX_SIZE-1 chars into the chat box, but Frost Joke / Dazzler's text can be longer.
  6752. // Neither the official client nor server place any restriction on the length of the text in the packet,
  6753. // but we'll only allow reasonably long strings here. This also makes sure all strings fit into the `chatlog` table.
  6754. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX, message);
  6755. return false;
  6756. }
  6757. *name_ = name;
  6758. *namelen_ = namelen;
  6759. *message_ = message;
  6760. *messagelen_ = messagelen;
  6761. return true;
  6762. }
  6763. // ---------------------
  6764. // clif_guess_PacketVer
  6765. // ---------------------
  6766. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6767. // error codes:
  6768. // 0 - Success
  6769. // 1 - Unknown packet_ver
  6770. // 2 - Invalid account_id
  6771. // 3 - Invalid char_id
  6772. // 4 - Invalid login_id1 (reserved)
  6773. // 5 - Invalid client_tick (reserved)
  6774. // 6 - Invalid sex
  6775. // Only the first 'invalid' error that appears is used.
  6776. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6777. {
  6778. static int err = 1;
  6779. static int packet_ver = -1;
  6780. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6781. if (get_previous)
  6782. {//For quick reruns, since the normal code flow is to fetch this once to identify the packet version, then again in the wanttoconnect function. [Skotlex]
  6783. if( error )
  6784. *error = err;
  6785. return packet_ver;
  6786. }
  6787. //By default, start searching on the default one.
  6788. err = 1;
  6789. packet_ver = clif_config.packet_db_ver;
  6790. cmd = RFIFOW(fd,0);
  6791. packet_len = RFIFOREST(fd);
  6792. #define SET_ERROR(n) \
  6793. if( err == 1 )\
  6794. err = n;\
  6795. //define SET_ERROR
  6796. #define CHECK_PACKET_VER() \
  6797. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6798. ;/* not wanttoconnection or wrong length */\
  6799. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6800. { SET_ERROR(2); }/* invalid account_id */\
  6801. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6802. { SET_ERROR(3); }/* invalid char_id */\
  6803. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6804. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6805. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6806. { SET_ERROR(6); }/* invalid sex */\
  6807. else\
  6808. {\
  6809. err = 0;\
  6810. if( error )\
  6811. *error = 0;\
  6812. return packet_ver;\
  6813. }\
  6814. //define CHECK_PACKET_VER
  6815. CHECK_PACKET_VER();//Default packet version found.
  6816. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6817. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6818. CHECK_PACKET_VER();
  6819. }
  6820. if( error )
  6821. *error = err;
  6822. packet_ver = -1;
  6823. return -1;
  6824. #undef SET_ERROR
  6825. #undef CHECK_PACKET_VER
  6826. }
  6827. // ------------
  6828. // clif_parse_*
  6829. // ------------
  6830. // パケット読み取って色々操作
  6831. /*==========================================
  6832. *
  6833. *------------------------------------------*/
  6834. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6835. {
  6836. int cmd, account_id, char_id, login_id1, sex;
  6837. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6838. int packet_ver; // 5: old, 6: 7july04, 7: 13july04, 8: 26july04, 9: 9aug04/16aug04/17aug04, 10: 6sept04, 11: 21sept04, 12: 18oct04, 13: 25oct04 (by [Yor])
  6839. if (sd) {
  6840. if (battle_config.error_log)
  6841. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  6842. return;
  6843. }
  6844. // Only valid packet version get here
  6845. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6846. cmd = RFIFOW(fd,0);
  6847. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6848. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6849. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6850. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6851. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6852. if( packet_ver < 5 || // reject really old client versions
  6853. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6854. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6855. {// packet version rejected
  6856. ShowInfo("Rejected connection attempt, forbidden packet version (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"', Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%s"CL_RESET"').\n", account_id, char_id, packet_ver, ip2str(session[fd]->client_addr, NULL));
  6857. WFIFOHEAD(fd,packet_len(0x6a));
  6858. WFIFOW(fd,0) = 0x6a;
  6859. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6860. WFIFOSET(fd,packet_len(0x6a));
  6861. clif_setwaitclose(fd);
  6862. return;
  6863. } else
  6864. {// packet version accepted
  6865. struct block_list* bl;
  6866. if( (bl=map_id2bl(account_id)) != NULL && bl->type != BL_PC )
  6867. {// non-player object already has that id
  6868. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6869. WFIFOHEAD(fd,packet_len(0x6a));
  6870. WFIFOW(fd,0) = 0x6a;
  6871. WFIFOB(fd,2) = 3; // Rejected by server
  6872. WFIFOSET(fd,packet_len(0x6a));
  6873. clif_setwaitclose(fd);
  6874. return;
  6875. }
  6876. }
  6877. CREATE(sd, TBL_PC, 1);
  6878. sd->fd = fd;
  6879. sd->packet_ver = packet_ver;
  6880. session[fd]->session_data = sd;
  6881. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6882. WFIFOHEAD(fd,4);
  6883. WFIFOL(fd,0) = sd->bl.id;
  6884. WFIFOSET(fd,4);
  6885. chrif_authreq(sd);
  6886. return;
  6887. }
  6888. /*==========================================
  6889. * 007d クライアント側マップ読み込み完了
  6890. * map侵入時に必要なデータを全て送りつける
  6891. *------------------------------------------*/
  6892. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6893. {
  6894. if(sd->bl.prev != NULL)
  6895. return;
  6896. if (!sd->state.auth)
  6897. { //Character loading is not complete yet!
  6898. //Let pc_reg_received reinvoke this when ready.
  6899. sd->state.connect_new = 0;
  6900. return;
  6901. }
  6902. if (sd->state.rewarp)
  6903. { //Rewarp player.
  6904. sd->state.rewarp = 0;
  6905. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6906. return;
  6907. }
  6908. // look
  6909. #if PACKETVER < 4
  6910. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6911. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6912. #else
  6913. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6914. #endif
  6915. if(sd->vd.cloth_color)
  6916. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6917. // item
  6918. pc_checkitem(sd);
  6919. clif_inventorylist(sd);
  6920. // cart
  6921. if(pc_iscarton(sd)) {
  6922. clif_cartlist(sd);
  6923. clif_updatestatus(sd,SP_CARTINFO);
  6924. }
  6925. // weight max, now
  6926. clif_updatestatus(sd,SP_MAXWEIGHT);
  6927. clif_updatestatus(sd,SP_WEIGHT);
  6928. // guild
  6929. // (needs to go before clif_spawn() to show guild emblems correctly)
  6930. if(sd->status.guild_id)
  6931. guild_send_memberinfoshort(sd,1);
  6932. if(battle_config.pc_invincible_time > 0) {
  6933. if(map_flag_gvg(sd->bl.m))
  6934. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6935. else
  6936. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6937. }
  6938. map_addblock(&sd->bl);
  6939. clif_spawn(&sd->bl);
  6940. // Party
  6941. // (needs to go after clif_spawn() to show hp bars correctly)
  6942. if(sd->status.party_id) {
  6943. party_send_movemap(sd);
  6944. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6945. }
  6946. if(map[sd->bl.m].flag.pvp) {
  6947. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6948. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6949. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6950. sd->pvp_rank = 0;
  6951. sd->pvp_lastusers = 0;
  6952. sd->pvp_point = 5;
  6953. sd->pvp_won = 0;
  6954. sd->pvp_lost = 0;
  6955. }
  6956. clif_set0199(fd,1);
  6957. } else
  6958. // set flag, if it's a duel [LuzZza]
  6959. if(sd->duel_group)
  6960. clif_set0199(fd,1);
  6961. if (map[sd->bl.m].flag.gvg_dungeon)
  6962. {
  6963. clif_set0199(fd,1); //TODO: Figure out the real packet to send here.
  6964. if (!sd->pvp_point)
  6965. {
  6966. sd->pvp_point = 5; //Need to die twice to be warped out.
  6967. sd->pvp_won = 0;
  6968. sd->pvp_lost = 0;
  6969. }
  6970. }
  6971. if(map_flag_gvg(sd->bl.m))
  6972. clif_set0199(fd,3);
  6973. map_foreachinarea(clif_getareachar, sd->bl.m,
  6974. sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE,
  6975. BL_ALL, sd);
  6976. // pet
  6977. if(sd->pd) {
  6978. map_addblock(&sd->pd->bl);
  6979. clif_spawn(&sd->pd->bl);
  6980. clif_send_petdata(sd,sd->pd,0,0);
  6981. clif_send_petstatus(sd);
  6982. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6983. }
  6984. //homunculus [blackhole89]
  6985. if(merc_is_hom_active(sd->hd)) {
  6986. map_addblock(&sd->hd->bl);
  6987. clif_spawn(&sd->hd->bl);
  6988. clif_hominfo(sd,sd->hd,1);
  6989. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6990. clif_send_homdata(sd,0,0);
  6991. clif_homskillinfoblock(sd);
  6992. if (battle_config.hom_setting&0x8)
  6993. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6994. if (!(battle_config.hom_setting&0x2))
  6995. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6996. }
  6997. if(sd->state.connect_new) {
  6998. int lv;
  6999. sd->state.connect_new = 0;
  7000. clif_skillinfoblock(sd);
  7001. clif_hotkeys_send(sd);
  7002. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7003. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7004. clif_updatestatus(sd,SP_SKILLPOINT);
  7005. clif_initialstatus(sd);
  7006. if (sd->sc.option&OPTION_FALCON)
  7007. clif_status_load(&sd->bl, SI_FALCON, 1);
  7008. if (sd->sc.option&OPTION_RIDING)
  7009. clif_status_load(&sd->bl, SI_RIDING, 1);
  7010. if(sd->status.manner < 0)
  7011. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7012. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7013. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7014. if(sd->bl.m == sd->feel_map[0].m
  7015. || sd->bl.m == sd->feel_map[1].m
  7016. || sd->bl.m == sd->feel_map[2].m)
  7017. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7018. }
  7019. if(sd->pd && sd->pd->pet.intimate > 900)
  7020. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7021. if(merc_is_hom_active(sd->hd))
  7022. merc_hom_init_timers(sd->hd);
  7023. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7024. {
  7025. sd->state.night = 1;
  7026. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7027. }
  7028. // Notify everyone that this char logged in [Skotlex].
  7029. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7030. //Login Event
  7031. npc_script_event(sd, NPCE_LOGIN);
  7032. } else {
  7033. //For some reason the client "loses" these on map-change.
  7034. clif_updatestatus(sd,SP_STR);
  7035. clif_updatestatus(sd,SP_AGI);
  7036. clif_updatestatus(sd,SP_VIT);
  7037. clif_updatestatus(sd,SP_INT);
  7038. clif_updatestatus(sd,SP_DEX);
  7039. clif_updatestatus(sd,SP_LUK);
  7040. sd->state.using_fake_npc = 0;
  7041. //New 'night' effect by dynamix [Skotlex]
  7042. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7043. { //Display night.
  7044. if (!sd->state.night) {
  7045. sd->state.night = 1;
  7046. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7047. }
  7048. } else if (sd->state.night) { //Clear night display.
  7049. sd->state.night = 0;
  7050. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7051. }
  7052. if(sd->npc_id)
  7053. npc_event_dequeue(sd);
  7054. }
  7055. // Lance
  7056. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  7057. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  7058. npc_script_event(sd, NPCE_LOADMAP);
  7059. }
  7060. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7061. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7062. if (sd->sc.opt2) //Client loses these on warp.
  7063. clif_changeoption(&sd->bl);
  7064. clif_weather_check(sd);
  7065. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7066. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7067. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7068. else
  7069. sd->areanpc_id = 0;
  7070. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7071. if(pc_isdead(sd))
  7072. clif_clearunit_area(&sd->bl, 1);
  7073. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7074. // else
  7075. // clif_changed_dir(&sd->bl, SELF);
  7076. // Trigger skill effects if you appear standing on them
  7077. if(!battle_config.pc_invincible_time)
  7078. skill_unit_move(&sd->bl,gettick(),1);
  7079. }
  7080. /*==========================================
  7081. *
  7082. *------------------------------------------*/
  7083. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7084. {
  7085. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7086. WFIFOHEAD(fd, packet_len(0x7f));
  7087. WFIFOW(fd,0)=0x7f;
  7088. WFIFOL(fd,2)=gettick();
  7089. WFIFOSET(fd,packet_len(0x7f));
  7090. // removed until the socket problems are fixed. [FlavioJS]
  7091. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7092. return;
  7093. }
  7094. void clif_hotkeys_send(struct map_session_data *sd) {
  7095. #ifdef HOTKEY_SAVING
  7096. const int fd = sd->fd;
  7097. int i;
  7098. if (!fd) return;
  7099. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7100. WFIFOW(fd, 0) = 0x02b9;
  7101. for(i = 0; i < MAX_HOTKEYS; i++) {
  7102. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7103. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7104. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7105. }
  7106. WFIFOSET(fd, packet_len(0x02b9));
  7107. #endif
  7108. }
  7109. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7110. #ifdef HOTKEY_SAVING
  7111. unsigned short idx;
  7112. int cmd;
  7113. cmd = RFIFOW(fd, 0);
  7114. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7115. if (idx >= MAX_HOTKEYS) return;
  7116. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7117. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7118. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7119. return;
  7120. #endif
  7121. }
  7122. /*==========================================
  7123. *
  7124. *------------------------------------------*/
  7125. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7126. {
  7127. short x, y;
  7128. int cmd;
  7129. if (pc_isdead(sd)) {
  7130. clif_clearunit_area(&sd->bl, 1);
  7131. return;
  7132. }
  7133. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7134. ; //You CAN walk on this OPT1 value.
  7135. else if (pc_cant_act(sd))
  7136. return;
  7137. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7138. return;
  7139. pc_delinvincibletimer(sd);
  7140. cmd = RFIFOW(fd,0);
  7141. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7142. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7143. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7144. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7145. //Set last idle time... [Skotlex]
  7146. sd->idletime = last_tick;
  7147. unit_walktoxy(&sd->bl, x, y, 4);
  7148. }
  7149. /*==========================================
  7150. *
  7151. *------------------------------------------*/
  7152. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7153. {
  7154. WFIFOHEAD(fd,packet_len(0x18b));
  7155. WFIFOW(fd,0) = 0x18b;
  7156. /* Rovert's prevent logout option fixed [Valaris] */
  7157. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7158. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7159. ) {
  7160. clif_setwaitclose(fd);
  7161. WFIFOW(fd,2)=0;
  7162. } else {
  7163. WFIFOW(fd,2)=1;
  7164. }
  7165. WFIFOSET(fd,packet_len(0x18b));
  7166. }
  7167. /*==========================================
  7168. *
  7169. *------------------------------------------*/
  7170. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7171. {
  7172. int account_id;
  7173. struct block_list* bl;
  7174. struct status_change *sc;
  7175. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7176. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7177. account_id= sd->bl.id;
  7178. bl = map_id2bl(account_id);
  7179. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7180. if (!bl) return;
  7181. sc = status_get_sc(bl);
  7182. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7183. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7184. pc_isGM(sd) < battle_config.hack_info_GM_level
  7185. ) {
  7186. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7187. //Asked name of invisible player, this shouldn't be possible!
  7188. //Possible bot? Thanks to veider and qspirit
  7189. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7190. char gm_msg[256];
  7191. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target.", sd->status.name, sd->status.account_id);
  7192. ShowWarning(gm_msg);
  7193. // information is sended to all online GM
  7194. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7195. return;
  7196. }
  7197. clif_charnameack(fd, bl);
  7198. }
  7199. /*==========================================
  7200. * Validates and processes global messages
  7201. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7202. *------------------------------------------*/
  7203. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7204. {
  7205. const char* text = (char*)RFIFOP(fd,4);
  7206. int textlen = RFIFOW(fd,2) - 4;
  7207. char *name, *message;
  7208. int namelen, messagelen;
  7209. // validate packet and retrieve name and message
  7210. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7211. return;
  7212. if( is_atcommand(fd, sd, message) != AtCommand_None || is_charcommand(fd, sd, message) != CharCommand_None )
  7213. return;
  7214. if( sd->sc.data[SC_BERSERK].timer != -1 || (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT) )
  7215. return;
  7216. if( battle_config.min_chat_delay )
  7217. { //[Skotlex]
  7218. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7219. return;
  7220. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7221. }
  7222. // send message to others (using the send buffer for temp. storage)
  7223. WFIFOHEAD(fd, 8 + textlen);
  7224. WFIFOW(fd,0) = 0x8d;
  7225. WFIFOW(fd,2) = 8 + textlen;
  7226. WFIFOL(fd,4) = sd->bl.id;
  7227. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7228. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7229. // send back message to the speaker
  7230. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7231. WFIFOW(fd,0) = 0x8e;
  7232. WFIFOSET(fd, WFIFOW(fd,2));
  7233. #ifdef PCRE_SUPPORT
  7234. // trigger listening mobs/npcs
  7235. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7236. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, text, textlen, &sd->bl);
  7237. #endif
  7238. // check for special supernovice phrase
  7239. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7240. {
  7241. int next = pc_nextbaseexp(sd);
  7242. if( next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0 ) { // 0%, 10%, 20%, ...
  7243. switch (sd->state.snovice_call_flag) {
  7244. case 0:
  7245. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7246. sd->state.snovice_call_flag++;
  7247. break;
  7248. case 1: {
  7249. char buf[256];
  7250. sprintf(buf, msg_txt(505), sd->status.name);
  7251. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7252. sd->state.snovice_call_flag++;
  7253. }
  7254. break;
  7255. case 2:
  7256. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7257. sd->state.snovice_call_flag++;
  7258. break;
  7259. case 3:
  7260. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7261. break; //Do not override the noskill mapflag. [Skotlex]
  7262. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7263. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7264. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7265. sd->state.snovice_call_flag = 0;
  7266. break;
  7267. }
  7268. }
  7269. }
  7270. // Chat logging type 'O' / Global Chat
  7271. if( log_config.chat&1 || (log_config.chat&2 && !(agit_flag && log_config.chat&64)) )
  7272. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7273. return;
  7274. }
  7275. /*==========================================
  7276. * /mm /mapmove (as @rura GM command)
  7277. *------------------------------------------*/
  7278. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7279. {
  7280. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7281. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7282. char* map_name;
  7283. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7284. return;
  7285. if(pc_isGM(sd) < get_atcommand_level(AtCommand_MapMove))
  7286. return;
  7287. map_name = (char*)RFIFOP(fd,2);
  7288. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7289. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7290. atcommand_rura(fd, sd, "@rura", output);
  7291. if(log_config.gm && get_atcommand_level(AtCommand_MapMove) >= log_config.gm)
  7292. {
  7293. sprintf(message, "/mm %s", output);
  7294. log_atcommand(sd, message);
  7295. }
  7296. return;
  7297. }
  7298. /*==========================================
  7299. *
  7300. *------------------------------------------*/
  7301. void clif_changed_dir(struct block_list *bl, int type)
  7302. {
  7303. unsigned char buf[64];
  7304. WBUFW(buf,0) = 0x9c;
  7305. WBUFL(buf,2) = bl->id;
  7306. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7307. WBUFB(buf,8) = unit_getdir(bl);
  7308. clif_send(buf, packet_len(0x9c), bl, type);
  7309. if (disguised(bl)) {
  7310. WBUFL(buf,2) = -bl->id;
  7311. WBUFW(buf,6) = 0;
  7312. clif_send(buf, packet_len(0x9c), bl, SELF);
  7313. }
  7314. return;
  7315. }
  7316. /*==========================================
  7317. *
  7318. *------------------------------------------*/
  7319. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7320. {
  7321. unsigned char headdir, dir;
  7322. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7323. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7324. pc_setdir(sd, dir, headdir);
  7325. clif_changed_dir(&sd->bl, AREA_WOS);
  7326. return;
  7327. }
  7328. /*==========================================
  7329. *
  7330. *------------------------------------------*/
  7331. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7332. {
  7333. unsigned char buf[64];
  7334. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7335. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7336. clif_skill_fail(sd, 1, 0, 1);
  7337. return;
  7338. }
  7339. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7340. if (sd->emotionlasttime >= time(NULL)) {
  7341. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7342. clif_skill_fail(sd, 1, 0, 1);
  7343. return;
  7344. }
  7345. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7346. WBUFW(buf,0) = 0xc0;
  7347. WBUFL(buf,2) = sd->bl.id;
  7348. WBUFB(buf,6) = RFIFOB(fd,2);
  7349. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7350. } else
  7351. clif_skill_fail(sd, 1, 0, 1);
  7352. }
  7353. /*==========================================
  7354. *
  7355. *------------------------------------------*/
  7356. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7357. {
  7358. WFIFOHEAD(fd,packet_len(0xc2));
  7359. WFIFOW(fd,0) = 0xc2;
  7360. WFIFOL(fd,2) = map_getusers();
  7361. WFIFOSET(fd,packet_len(0xc2));
  7362. }
  7363. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7364. {
  7365. if (pc_isdead(sd)) {
  7366. clif_clearunit_area(&sd->bl, 1);
  7367. return;
  7368. }
  7369. if (sd->sc.count &&
  7370. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7371. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7372. sd->sc.data[SC_BLADESTOP].timer != -1))
  7373. return;
  7374. pc_stop_walking(sd, 1);
  7375. pc_stop_attack(sd);
  7376. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7377. target_id = sd->bl.id;
  7378. switch(action_type)
  7379. {
  7380. case 0x00: // once attack
  7381. case 0x07: // continuous attack
  7382. if (pc_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7383. return;
  7384. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7385. return;
  7386. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7387. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7388. clif_skill_fail(sd, 1, 4, 0);
  7389. return;
  7390. }
  7391. }
  7392. pc_delinvincibletimer(sd);
  7393. sd->idletime = last_tick;
  7394. unit_attack(&sd->bl, target_id, action_type != 0);
  7395. break;
  7396. case 0x02: // sitdown
  7397. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7398. clif_skill_fail(sd, 1, 0, 2);
  7399. break;
  7400. }
  7401. if(pc_issit(sd)) {
  7402. //Bugged client? Just refresh them.
  7403. clif_sitting(&sd->bl);
  7404. return;
  7405. }
  7406. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7407. break;
  7408. if (sd->sc.count && (
  7409. sd->sc.data[SC_DANCING].timer != -1 ||
  7410. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7411. )) //No sitting during these states either.
  7412. break;
  7413. pc_setsit(sd);
  7414. skill_sit(sd,1);
  7415. clif_sitting(&sd->bl);
  7416. break;
  7417. case 0x03: // standup
  7418. if (!pc_issit(sd)) {
  7419. //Bugged client? Just refresh them.
  7420. clif_standing(&sd->bl);
  7421. return;
  7422. }
  7423. pc_setstand(sd);
  7424. skill_sit(sd,0);
  7425. clif_standing(&sd->bl);
  7426. break;
  7427. }
  7428. }
  7429. /*==========================================
  7430. *
  7431. *------------------------------------------*/
  7432. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7433. {
  7434. clif_parse_ActionRequest_sub(sd,
  7435. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7436. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7437. gettick()
  7438. );
  7439. }
  7440. /*==========================================
  7441. *
  7442. *------------------------------------------*/
  7443. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7444. {
  7445. switch(RFIFOB(fd,2)) {
  7446. case 0x00:
  7447. if (!pc_isdead(sd))
  7448. break;
  7449. pc_setstand(sd);
  7450. pc_setrestartvalue(sd, 3);
  7451. if (pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2))
  7452. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  7453. break;
  7454. case 0x01:
  7455. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7456. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7457. { //Send to char-server for character selection.
  7458. chrif_charselectreq(sd, session[fd]->client_addr);
  7459. } else {
  7460. WFIFOHEAD(fd,packet_len(0x18b));
  7461. WFIFOW(fd,0)=0x18b;
  7462. WFIFOW(fd,2)=1;
  7463. WFIFOSET(fd,packet_len(0x018b));
  7464. }
  7465. break;
  7466. }
  7467. }
  7468. /*==========================================
  7469. * Validates and processes whispered messages
  7470. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7471. *------------------------------------------*/
  7472. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7473. {
  7474. struct map_session_data* dstsd;
  7475. int i;
  7476. char *target, *message;
  7477. int namelen, messagelen;
  7478. // validate packet and retrieve name and message
  7479. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7480. return;
  7481. if (is_atcommand(fd, sd, message) != AtCommand_None || is_charcommand(fd, sd, message) != CharCommand_None )
  7482. return;
  7483. if (sd->sc.data[SC_BERSERK].timer!=-1 || (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))
  7484. return;
  7485. if (battle_config.min_chat_delay)
  7486. { //[Skotlex]
  7487. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7488. return;
  7489. }
  7490. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7491. }
  7492. // Chat logging type 'W' / Whisper
  7493. if( log_config.chat&1 || (log_config.chat&4 && !(agit_flag && log_config.chat&64)) )
  7494. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7495. //-------------------------------------------------------//
  7496. // Lordalfa - Paperboy - To whisper NPC commands //
  7497. //-------------------------------------------------------//
  7498. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7499. {
  7500. char* str = target+4; //Skip the NPC: string part.
  7501. struct npc_data* npc;
  7502. if ((npc = npc_name2id(str)))
  7503. {
  7504. char split_data[10][50];
  7505. char *split;
  7506. char output[256];
  7507. str = message;
  7508. for( i = 0; i < 10; ++i )
  7509. {// Splits the message using '#' as separators
  7510. split = strchr(str,'#');
  7511. if( split == NULL )
  7512. { // use the remaining string
  7513. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7514. for( ++i; i < 10; ++i )
  7515. split_data[i][0] = '\0';
  7516. break;
  7517. }
  7518. *split = '\0';
  7519. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7520. str = split+1;
  7521. }
  7522. for( i = 0; i < 10; ++i )
  7523. {
  7524. sprintf(output, "@whispervar%d$", i);
  7525. set_var(sd,output,(char *) split_data[i]);
  7526. }
  7527. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7528. npc_event(sd,output,0); // Calls the NPC label
  7529. return;
  7530. }
  7531. }
  7532. // Main chat [LuzZza]
  7533. if(strcmpi(target, main_chat_nick) == 0)
  7534. {
  7535. if(!sd->state.mainchat)
  7536. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7537. else {
  7538. char output[256];
  7539. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7540. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7541. }
  7542. return;
  7543. }
  7544. // searching destination character
  7545. dstsd = map_nick2sd(target);
  7546. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7547. {
  7548. // player is not on this map-server
  7549. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7550. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7551. // and if we ask for 'Test', we must not contact 'test' player
  7552. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7553. intif_wis_message(sd, target, message, messagelen);
  7554. return;
  7555. }
  7556. // if player ignores everyone
  7557. if (dstsd->state.ignoreAll)
  7558. {
  7559. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7560. clif_wis_end(fd, 1); // 1: target character is not loged in
  7561. else
  7562. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7563. return;
  7564. }
  7565. // if player ignores the source character
  7566. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7567. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7568. { // source char present in ignore list
  7569. clif_wis_end(fd, 2); // 2: ignored by target
  7570. return;
  7571. }
  7572. // notify sender of success
  7573. clif_wis_end(fd, 0); // 0: success to send wisper
  7574. // if player has an auto-away message
  7575. if(dstsd->away_message[0] != '\0')
  7576. {
  7577. char output[256];
  7578. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7579. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7580. if(dstsd->state.autotrade)
  7581. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7582. else
  7583. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7584. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7585. return;
  7586. }
  7587. // Normal message
  7588. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7589. return;
  7590. }
  7591. /*==========================================
  7592. * /b /nb
  7593. * S 0099 <packet len>.w <text>.?B 00
  7594. *------------------------------------------*/
  7595. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7596. {
  7597. char* msg = (char*)RFIFOP(fd,4);
  7598. unsigned int len = RFIFOW(fd,2)-4;
  7599. int lv;
  7600. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7601. return;
  7602. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Broadcast)))
  7603. return;
  7604. // as the length varies depending on the command used, just block unreasonably long strings
  7605. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7606. intif_GMmessage(msg, len, 0);
  7607. if(log_config.gm && lv >= log_config.gm) {
  7608. char logmsg[CHAT_SIZE_MAX+4];
  7609. sprintf(logmsg, "/b %s", msg);
  7610. log_atcommand(sd, logmsg);
  7611. }
  7612. }
  7613. /*==========================================
  7614. *
  7615. *------------------------------------------*/
  7616. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7617. {
  7618. struct flooritem_data *fitem;
  7619. int map_object_id;
  7620. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7621. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7622. do {
  7623. if (pc_isdead(sd)) {
  7624. clif_clearunit_area(&sd->bl, 1);
  7625. break;
  7626. }
  7627. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7628. break;
  7629. if (pc_cant_act(sd))
  7630. break;
  7631. //Disable cloaking/chasewalking characters from looting [Skotlex]
  7632. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  7633. break;
  7634. if(sd->sc.count && (
  7635. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7636. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7637. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  7638. )
  7639. break;
  7640. if (!pc_takeitem(sd, fitem))
  7641. break;
  7642. return;
  7643. } while (0);
  7644. // Client REQUIRES a fail packet or you can no longer pick items.
  7645. clif_additem(sd,0,0,6);
  7646. }
  7647. /*==========================================
  7648. *
  7649. *------------------------------------------*/
  7650. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7651. {
  7652. int item_index, item_amount;
  7653. if (pc_isdead(sd)) {
  7654. clif_clearunit_area(&sd->bl, 1);
  7655. return;
  7656. }
  7657. if (pc_cant_act(sd))
  7658. return;
  7659. if (sd->sc.count && (
  7660. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7661. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7662. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  7663. ))
  7664. return;
  7665. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7666. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7667. if (!pc_dropitem(sd, item_index, item_amount))
  7668. //Because the client does not likes being ignored.
  7669. clif_delitem(sd, item_index,0);
  7670. }
  7671. /*==========================================
  7672. *
  7673. *------------------------------------------*/
  7674. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7675. {
  7676. int n;
  7677. if (pc_isdead(sd)) {
  7678. clif_clearunit_area(&sd->bl, 1);
  7679. return;
  7680. }
  7681. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7682. return;
  7683. //This flag enables you to use items while in an NPC. [Skotlex]
  7684. if (sd->npc_id) {
  7685. if (sd->npc_id != sd->npc_item_flag)
  7686. return;
  7687. } else
  7688. if (pc_istrading(sd))
  7689. return;
  7690. pc_delinvincibletimer(sd);
  7691. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7692. sd->idletime = last_tick;
  7693. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7694. if(n <0 || n >= MAX_INVENTORY)
  7695. return;
  7696. if (!pc_useitem(sd,n))
  7697. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7698. }
  7699. /*==========================================
  7700. *
  7701. *------------------------------------------*/
  7702. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7703. {
  7704. int index;
  7705. if(pc_isdead(sd)) {
  7706. clif_clearunit_area(&sd->bl,1);
  7707. return;
  7708. }
  7709. index = RFIFOW(fd,2)-2;
  7710. if (index < 0 || index >= MAX_INVENTORY)
  7711. return; //Out of bounds check.
  7712. if(sd->npc_id) {
  7713. if (sd->npc_id != sd->npc_item_flag)
  7714. return;
  7715. } else if (sd->state.storage_flag || sd->sc.opt1)
  7716. ; //You can equip/unequip stuff while storage is open/under status changes
  7717. else if (pc_cant_act(sd))
  7718. return;
  7719. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  7720. return;
  7721. if(!sd->status.inventory[index].identify) {
  7722. clif_equipitemack(sd,index,0,0); // fail
  7723. return;
  7724. }
  7725. if(!sd->inventory_data[index])
  7726. return;
  7727. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7728. pet_equipitem(sd,index);
  7729. return;
  7730. }
  7731. //Client doesn't send the position for ammo.
  7732. if(sd->inventory_data[index]->type == IT_AMMO)
  7733. pc_equipitem(sd,index,EQP_AMMO);
  7734. else
  7735. pc_equipitem(sd,index,RFIFOW(fd,4));
  7736. }
  7737. /*==========================================
  7738. *
  7739. *------------------------------------------*/
  7740. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7741. {
  7742. int index;
  7743. if(pc_isdead(sd)) {
  7744. clif_clearunit_area(&sd->bl,1);
  7745. return;
  7746. }
  7747. if (sd->state.storage_flag)
  7748. ; //You can equip/unequip stuff while storage is open.
  7749. else if (pc_cant_act(sd))
  7750. return;
  7751. index = RFIFOW(fd,2)-2;
  7752. pc_unequipitem(sd,index,1);
  7753. }
  7754. /*==========================================
  7755. *
  7756. *------------------------------------------*/
  7757. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7758. {
  7759. struct block_list *bl;
  7760. if(pc_isdead(sd)) {
  7761. clif_clearunit_area(&sd->bl,1);
  7762. return;
  7763. }
  7764. if (pc_cant_act(sd))
  7765. return;
  7766. bl = map_id2bl(RFIFOL(fd,2));
  7767. if (!bl) return;
  7768. switch (bl->type) {
  7769. case BL_MOB:
  7770. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  7771. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7772. break;
  7773. case BL_PC:
  7774. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7775. break;
  7776. case BL_NPC:
  7777. npc_click(sd,(TBL_NPC*)bl);
  7778. break;
  7779. }
  7780. return;
  7781. }
  7782. /*==========================================
  7783. *
  7784. *------------------------------------------*/
  7785. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7786. {
  7787. if (sd->state.trading)
  7788. return;
  7789. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7790. }
  7791. /*==========================================
  7792. *
  7793. *------------------------------------------*/
  7794. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  7795. {
  7796. int fail=0,n;
  7797. unsigned short *item_list;
  7798. n = (RFIFOW(fd,2)-4) /4;
  7799. item_list = (unsigned short*)RFIFOP(fd,4);
  7800. if (sd->state.trading|| !sd->npc_shopid)
  7801. fail = 1;
  7802. else
  7803. fail = npc_buylist(sd,n,item_list);
  7804. sd->npc_shopid = 0; //Clear shop data.
  7805. WFIFOHEAD(fd,packet_len(0xca));
  7806. WFIFOW(fd,0)=0xca;
  7807. WFIFOB(fd,2)=fail;
  7808. WFIFOSET(fd,packet_len(0xca));
  7809. }
  7810. /*==========================================
  7811. *
  7812. *------------------------------------------*/
  7813. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7814. {
  7815. int fail=0,n;
  7816. unsigned short *item_list;
  7817. n = (RFIFOW(fd,2)-4) /4;
  7818. item_list = (unsigned short*)RFIFOP(fd,4);
  7819. if (sd->state.trading || !sd->npc_shopid)
  7820. fail = 1;
  7821. else
  7822. fail = npc_selllist(sd,n,item_list);
  7823. sd->npc_shopid = 0; //Clear shop data.
  7824. WFIFOHEAD(fd,packet_len(0xcb));
  7825. WFIFOW(fd,0)=0xcb;
  7826. WFIFOB(fd,2)=fail;
  7827. WFIFOSET(fd,packet_len(0xcb));
  7828. }
  7829. /*==========================================
  7830. * Chatroom creation request
  7831. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7832. *------------------------------------------*/
  7833. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7834. {
  7835. int len = RFIFOW(fd,2)-15;
  7836. int limit = RFIFOW(fd,4);
  7837. bool pub = (RFIFOB(fd,6) != 0);
  7838. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7839. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7840. char s_title[CHATROOM_TITLE_SIZE];
  7841. char s_password[CHATROOM_PASS_SIZE];
  7842. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  7843. return;
  7844. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7845. clif_skill_fail(sd,1,0,3);
  7846. return;
  7847. }
  7848. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7849. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7850. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7851. }
  7852. /*==========================================
  7853. * Chatroom join request
  7854. * S 00d9 <chat ID>.l <passwd>.8B
  7855. *------------------------------------------*/
  7856. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7857. {
  7858. int chatid = RFIFOL(fd,2);
  7859. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7860. chat_joinchat(sd,chatid,password);
  7861. }
  7862. /*==========================================
  7863. * Chatroom properties adjustment request
  7864. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7865. *------------------------------------------*/
  7866. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7867. {
  7868. int len = RFIFOW(fd,2)-15;
  7869. int limit = RFIFOW(fd,4);
  7870. bool pub = (RFIFOB(fd,6) != 0);
  7871. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7872. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7873. char s_title[CHATROOM_TITLE_SIZE];
  7874. char s_password[CHATROOM_PASS_SIZE];
  7875. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7876. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7877. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7878. }
  7879. /*==========================================
  7880. * S 00e0 ?.l <nick>.24B
  7881. *------------------------------------------*/
  7882. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7883. {
  7884. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7885. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7886. }
  7887. /*==========================================
  7888. *
  7889. *------------------------------------------*/
  7890. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7891. {
  7892. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7893. }
  7894. /*==========================================
  7895. * Request to leave the current chatroom
  7896. * S 00e3
  7897. *------------------------------------------*/
  7898. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7899. {
  7900. chat_leavechat(sd,0);
  7901. }
  7902. //Handles notifying asker and rejecter of what has just ocurred.
  7903. //Type is used to determine the correct msg_txt to use:
  7904. //0:
  7905. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7906. {
  7907. char *msg, output[256];
  7908. // Your request has been rejected by autoreject option.
  7909. msg = msg_txt(392);
  7910. clif_disp_onlyself(src, msg, strlen(msg));
  7911. //Notice that a request was rejected.
  7912. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7913. clif_disp_onlyself(target, output, strlen(output));
  7914. }
  7915. /*==========================================
  7916. * 取引要請を相手に送る
  7917. *------------------------------------------*/
  7918. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7919. {
  7920. struct map_session_data *t_sd;
  7921. t_sd = map_id2sd(RFIFOL(fd,2));
  7922. if(!sd->chatID && pc_cant_act(sd))
  7923. return; //You can trade while in a chatroom.
  7924. // @noask [LuzZza]
  7925. if(t_sd && t_sd->state.noask) {
  7926. clif_noask_sub(sd, t_sd, 0);
  7927. return;
  7928. }
  7929. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  7930. trade_traderequest(sd,t_sd);
  7931. } else
  7932. clif_skill_fail(sd,1,0,0);
  7933. }
  7934. /*==========================================
  7935. * 取引要請
  7936. *------------------------------------------*/
  7937. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7938. {
  7939. trade_tradeack(sd,RFIFOB(fd,2));
  7940. }
  7941. /*==========================================
  7942. * アイテム追加
  7943. *------------------------------------------*/
  7944. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7945. {
  7946. short index = RFIFOW(fd,2);
  7947. int amount = RFIFOL(fd,4);
  7948. if( index == 0 )
  7949. trade_tradeaddzeny(sd, amount);
  7950. else
  7951. trade_tradeadditem(sd, index, (short)amount);
  7952. }
  7953. /*==========================================
  7954. * アイテム追加完了(ok押し)
  7955. *------------------------------------------*/
  7956. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7957. {
  7958. trade_tradeok(sd);
  7959. }
  7960. /*==========================================
  7961. * 取引キャンセル
  7962. *------------------------------------------*/
  7963. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7964. {
  7965. trade_tradecancel(sd);
  7966. }
  7967. /*==========================================
  7968. * 取引許諾(trade押し)
  7969. *------------------------------------------*/
  7970. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7971. {
  7972. trade_tradecommit(sd);
  7973. }
  7974. /*==========================================
  7975. *
  7976. *------------------------------------------*/
  7977. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7978. {
  7979. pc_stop_attack(sd);
  7980. }
  7981. /*==========================================
  7982. * カートへアイテムを移す
  7983. *------------------------------------------*/
  7984. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  7985. {
  7986. if (pc_istrading(sd))
  7987. return;
  7988. if (!pc_iscarton(sd))
  7989. return;
  7990. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7991. }
  7992. /*==========================================
  7993. * カートからアイテムを出す
  7994. *------------------------------------------*/
  7995. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  7996. {
  7997. if (!pc_iscarton(sd))
  7998. return;
  7999. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8000. }
  8001. /*==========================================
  8002. * 付属品(鷹,ペコ,カート)をはずす
  8003. *------------------------------------------*/
  8004. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8005. {
  8006. //Can only remove Cart/Riding/Falcon.
  8007. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8008. }
  8009. /*==========================================
  8010. * チェンジカート
  8011. *------------------------------------------*/
  8012. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8013. {
  8014. int type;
  8015. type = (int)RFIFOW(fd,2);
  8016. if( (type == 5 && sd->status.base_level <= 90) ||
  8017. (type == 4 && sd->status.base_level <= 80) ||
  8018. (type == 3 && sd->status.base_level <= 65) ||
  8019. (type == 2 && sd->status.base_level <= 40) ||
  8020. pc_setcart(sd,type) )
  8021. {
  8022. LOG_SUSPICIOUS(sd,"clif_parse_ChangeCart");
  8023. }
  8024. }
  8025. /*==========================================
  8026. * ステータスアップ
  8027. *------------------------------------------*/
  8028. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8029. {
  8030. pc_statusup(sd,RFIFOW(fd,2));
  8031. }
  8032. /*==========================================
  8033. * スキルレベルアップ
  8034. *------------------------------------------*/
  8035. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8036. {
  8037. pc_skillup(sd,RFIFOW(fd,2));
  8038. }
  8039. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8040. {
  8041. int lv;
  8042. if (!hd)
  8043. return;
  8044. if (skillnotok_hom(skillnum, hd)) //[orn]
  8045. return;
  8046. if (hd->bl.id != target_id &&
  8047. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8048. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8049. if (hd->ud.skilltimer != -1) {
  8050. if (skillnum != SA_CASTCANCEL)
  8051. return;
  8052. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8053. return;
  8054. lv = merc_hom_checkskill(hd, skillnum);
  8055. if (skilllv > lv)
  8056. skilllv = lv;
  8057. if (skilllv)
  8058. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8059. }
  8060. /*==========================================
  8061. * スキル使用(ID指定)
  8062. *------------------------------------------*/
  8063. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8064. {
  8065. short skillnum, skilllv;
  8066. int tmp, target_id;
  8067. unsigned int tick = gettick();
  8068. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8069. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8070. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8071. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8072. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8073. sd->idletime = last_tick;
  8074. tmp = skill_get_inf(skillnum);
  8075. if (tmp&INF_GROUND_SKILL || !tmp)
  8076. return; //Using a ground/passive skill on a target? WRONG.
  8077. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8078. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8079. return;
  8080. }
  8081. if (pc_cant_act(sd))
  8082. return;
  8083. if (pc_issit(sd))
  8084. return;
  8085. if (skillnotok(skillnum, sd))
  8086. return;
  8087. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8088. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8089. if (sd->ud.skilltimer != -1) {
  8090. if (skillnum != SA_CASTCANCEL)
  8091. return;
  8092. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8093. clif_skill_fail(sd, skillnum, 4, 0);
  8094. return;
  8095. }
  8096. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8097. return;
  8098. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8099. target_id = sd->bl.id;
  8100. if(sd->menuskill_id)
  8101. {
  8102. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8103. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8104. else
  8105. if (sd->menuskill_id != SA_AUTOSPELL)
  8106. return; //Can't use skills while a menu is open.
  8107. }
  8108. if (sd->skillitem == skillnum) {
  8109. if (skilllv != sd->skillitemlv)
  8110. skilllv = sd->skillitemlv;
  8111. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8112. return;
  8113. }
  8114. sd->skillitem = sd->skillitemlv = 0;
  8115. if (skillnum == MO_EXTREMITYFIST) {
  8116. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8117. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8118. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8119. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8120. if (!sd->state.skill_flag ) {
  8121. sd->state.skill_flag = 1;
  8122. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8123. return;
  8124. } else if (sd->bl.id == target_id) {
  8125. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8126. return;
  8127. }
  8128. }
  8129. }
  8130. if (skillnum == TK_JUMPKICK) {
  8131. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8132. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8133. if (!sd->state.skill_flag ) {
  8134. sd->state.skill_flag = 1;
  8135. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8136. return;
  8137. } else if (sd->bl.id == target_id) {
  8138. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8139. return;
  8140. }
  8141. }
  8142. }
  8143. if (skillnum >= GD_SKILLBASE) {
  8144. if (sd->state.gmaster_flag)
  8145. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8146. else
  8147. skilllv = 0;
  8148. } else {
  8149. tmp = pc_checkskill(sd, skillnum);
  8150. if (skilllv > tmp)
  8151. skilllv = tmp;
  8152. }
  8153. pc_delinvincibletimer(sd);
  8154. if (skilllv)
  8155. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8156. if (sd->state.skill_flag)
  8157. sd->state.skill_flag = 0;
  8158. }
  8159. /*==========================================
  8160. * スキル使用(場所指定)
  8161. *------------------------------------------*/
  8162. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8163. {
  8164. int lv;
  8165. unsigned int tick = gettick();
  8166. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8167. sd->idletime = last_tick;
  8168. if (skillnotok(skillnum, sd))
  8169. return;
  8170. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8171. return; //Using a target skill on the ground? WRONG.
  8172. if (skillmoreinfo != -1) {
  8173. if (pc_issit(sd)) {
  8174. clif_skill_fail(sd, skillnum, 0, 0);
  8175. return;
  8176. }
  8177. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8178. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8179. }
  8180. if (sd->ud.skilltimer != -1)
  8181. return;
  8182. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8183. {
  8184. clif_skill_fail(sd, skillnum, 4, 0);
  8185. return;
  8186. }
  8187. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8188. return;
  8189. if(sd->menuskill_id)
  8190. {
  8191. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8192. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8193. else
  8194. if (sd->menuskill_id != SA_AUTOSPELL)
  8195. return; //Can't use skills while a menu is open.
  8196. }
  8197. pc_delinvincibletimer(sd);
  8198. if (sd->skillitem == skillnum) {
  8199. if (skilllv != sd->skillitemlv)
  8200. skilllv = sd->skillitemlv;
  8201. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8202. } else {
  8203. sd->skillitem = sd->skillitemlv = 0;
  8204. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8205. if (skilllv > lv)
  8206. skilllv = lv;
  8207. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8208. }
  8209. }
  8210. }
  8211. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8212. {
  8213. if (pc_cant_act(sd))
  8214. return;
  8215. if (pc_issit(sd))
  8216. return;
  8217. clif_parse_UseSkillToPosSub(fd, sd,
  8218. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8219. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8220. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8221. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8222. -1 //Skill more info.
  8223. );
  8224. }
  8225. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8226. {
  8227. if (pc_cant_act(sd))
  8228. return;
  8229. if (pc_issit(sd))
  8230. return;
  8231. clif_parse_UseSkillToPosSub(fd, sd,
  8232. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8233. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8234. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8235. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8236. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8237. );
  8238. }
  8239. /*==========================================
  8240. * スキル使用(map指定)
  8241. *------------------------------------------*/
  8242. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8243. {
  8244. short skill_num = RFIFOW(fd,2);
  8245. char map_name[MAP_NAME_LENGTH];
  8246. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8247. if(skill_num != sd->menuskill_id)
  8248. return;
  8249. if (pc_cant_act(sd))
  8250. {
  8251. sd->menuskill_id = sd->menuskill_val = 0;
  8252. return;
  8253. }
  8254. pc_delinvincibletimer(sd);
  8255. skill_castend_map(sd,skill_num,map_name);
  8256. }
  8257. /*==========================================
  8258. * メモ要求
  8259. *------------------------------------------*/
  8260. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8261. {
  8262. if (!pc_isdead(sd))
  8263. pc_memo(sd,-1);
  8264. }
  8265. /*==========================================
  8266. * アイテム合成
  8267. *------------------------------------------*/
  8268. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8269. {
  8270. if (sd->menuskill_id != AM_PHARMACY)
  8271. return;
  8272. if (pc_istrading(sd)) {
  8273. //Make it fail to avoid shop exploits where you sell something different than you see.
  8274. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8275. sd->menuskill_val = sd->menuskill_id = 0;
  8276. return;
  8277. }
  8278. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8279. sd->menuskill_val = sd->menuskill_id = 0;
  8280. }
  8281. /*==========================================
  8282. * 武器修理
  8283. *------------------------------------------*/
  8284. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8285. {
  8286. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8287. return;
  8288. if (pc_istrading(sd)) {
  8289. //Make it fail to avoid shop exploits where you sell something different than you see.
  8290. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8291. sd->menuskill_val = sd->menuskill_id = 0;
  8292. return;
  8293. }
  8294. skill_repairweapon(sd,RFIFOW(fd,2));
  8295. sd->menuskill_val = sd->menuskill_id = 0;
  8296. }
  8297. /*==========================================
  8298. *
  8299. *------------------------------------------*/
  8300. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8301. {
  8302. int idx;
  8303. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8304. return;
  8305. if (pc_istrading(sd)) {
  8306. //Make it fail to avoid shop exploits where you sell something different than you see.
  8307. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8308. sd->menuskill_val = sd->menuskill_id = 0;
  8309. return;
  8310. }
  8311. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8312. skill_weaponrefine(sd, idx-2);
  8313. sd->menuskill_val = sd->menuskill_id = 0;
  8314. }
  8315. /*==========================================
  8316. *
  8317. *------------------------------------------*/
  8318. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8319. {
  8320. uint8 select;
  8321. select = RFIFOB(fd,6);
  8322. if((select > sd->npc_menu && select != 0xff) || !select){
  8323. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8324. clif_GM_kick(sd,sd,0);
  8325. } else {
  8326. sd->npc_menu=select;
  8327. npc_scriptcont(sd,RFIFOL(fd,2));
  8328. }
  8329. }
  8330. /*==========================================
  8331. *
  8332. *------------------------------------------*/
  8333. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8334. {
  8335. npc_scriptcont(sd,RFIFOL(fd,2));
  8336. }
  8337. /*==========================================
  8338. * Value entered into a NPC input box.
  8339. * S 0143 <npcID>.l <amount>.l
  8340. *------------------------------------------*/
  8341. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8342. {
  8343. int npcid = RFIFOL(fd,2);
  8344. int amount = (int)RFIFOL(fd,6);
  8345. sd->npc_amount = amount;
  8346. npc_scriptcont(sd, npcid);
  8347. }
  8348. /*==========================================
  8349. * Text entered into a NPC input box.
  8350. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8351. *------------------------------------------*/
  8352. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8353. {
  8354. int message_len = RFIFOW(fd,2)-8;
  8355. int npcid = RFIFOL(fd,4);
  8356. const char* message = (char*)RFIFOP(fd,8);
  8357. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8358. npc_scriptcont(sd, npcid);
  8359. }
  8360. /*==========================================
  8361. *
  8362. *------------------------------------------*/
  8363. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8364. {
  8365. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8366. return;
  8367. npc_scriptcont(sd,RFIFOL(fd,2));
  8368. }
  8369. /*==========================================
  8370. * アイテム鑑定
  8371. *------------------------------------------*/
  8372. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8373. {
  8374. if (sd->menuskill_id != MC_IDENTIFY)
  8375. return;
  8376. skill_identify(sd,RFIFOW(fd,2)-2);
  8377. sd->menuskill_val = sd->menuskill_id = 0;
  8378. }
  8379. /*==========================================
  8380. * 矢作成
  8381. *------------------------------------------*/
  8382. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8383. {
  8384. if (sd->menuskill_id != AC_MAKINGARROW)
  8385. return;
  8386. if (pc_istrading(sd)) {
  8387. //Make it fail to avoid shop exploits where you sell something different than you see.
  8388. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8389. sd->menuskill_val = sd->menuskill_id = 0;
  8390. return;
  8391. }
  8392. skill_arrow_create(sd,RFIFOW(fd,2));
  8393. sd->menuskill_val = sd->menuskill_id = 0;
  8394. }
  8395. /*==========================================
  8396. * オートスペル受信
  8397. *------------------------------------------*/
  8398. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8399. {
  8400. if (sd->menuskill_id != SA_AUTOSPELL)
  8401. return;
  8402. skill_autospell(sd,RFIFOW(fd,2));
  8403. sd->menuskill_val = sd->menuskill_id = 0;
  8404. }
  8405. /*==========================================
  8406. * カード使用
  8407. *------------------------------------------*/
  8408. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8409. {
  8410. if (sd->state.trading != 0)
  8411. return;
  8412. clif_use_card(sd,RFIFOW(fd,2)-2);
  8413. }
  8414. /*==========================================
  8415. * カード挿入装備選択
  8416. *------------------------------------------*/
  8417. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8418. {
  8419. if (sd->state.trading != 0)
  8420. return;
  8421. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8422. }
  8423. /*==========================================
  8424. * 0193 キャラID名前引き
  8425. *------------------------------------------*/
  8426. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8427. {
  8428. int charid;
  8429. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8430. map_reqnickdb(sd, charid);
  8431. }
  8432. /*==========================================
  8433. * 0197 /resetskill /resetstate
  8434. *------------------------------------------*/
  8435. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8436. {
  8437. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8438. return;
  8439. if (pc_isGM(sd) < get_atcommand_level(AtCommand_ResetState))
  8440. return;
  8441. if (RFIFOW(fd,2))
  8442. pc_resetskill(sd,1);
  8443. else
  8444. pc_resetstate(sd);
  8445. if(log_config.gm && get_atcommand_level(AtCommand_ResetState >= log_config.gm))
  8446. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8447. }
  8448. /*==========================================
  8449. * /lb /nlb
  8450. * S 019c <packet len>.w <text>.?B 00
  8451. *------------------------------------------*/
  8452. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8453. {
  8454. char* msg = (char*)RFIFOP(fd,4);
  8455. unsigned int len = RFIFOW(fd,2)-4;
  8456. int lv;
  8457. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8458. return;
  8459. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_LocalBroadcast)))
  8460. return;
  8461. // as the length varies depending on the command used, just block unreasonably long strings
  8462. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8463. clif_GMmessage(&sd->bl, msg, len, 1);
  8464. if(log_config.gm && lv >= log_config.gm) {
  8465. char logmsg[CHAT_SIZE_MAX+5];
  8466. sprintf(logmsg, "/lb %s", msg);
  8467. log_atcommand(sd, logmsg);
  8468. }
  8469. }
  8470. /*==========================================
  8471. * カプラ倉庫へ入れる
  8472. *------------------------------------------*/
  8473. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8474. {
  8475. int item_index, item_amount;
  8476. if (pc_istrading(sd))
  8477. return;
  8478. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8479. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8480. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8481. return;
  8482. if (sd->state.storage_flag == 1)
  8483. storage_storageadd(sd, item_index, item_amount);
  8484. else if (sd->state.storage_flag == 2)
  8485. storage_guild_storageadd(sd, item_index, item_amount);
  8486. }
  8487. /*==========================================
  8488. * カプラ倉庫から出す
  8489. *------------------------------------------*/
  8490. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8491. {
  8492. int item_index, item_amount;
  8493. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8494. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8495. if (sd->state.storage_flag == 1)
  8496. storage_storageget(sd, item_index, item_amount);
  8497. else if(sd->state.storage_flag == 2)
  8498. storage_guild_storageget(sd, item_index, item_amount);
  8499. }
  8500. /*==========================================
  8501. * カプラ倉庫へカートから入れる
  8502. *------------------------------------------*/
  8503. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8504. {
  8505. if(sd->vender_id)
  8506. return;
  8507. if (!pc_iscarton(sd))
  8508. return;
  8509. if (sd->state.storage_flag == 1)
  8510. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8511. else if (sd->state.storage_flag == 2)
  8512. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8513. }
  8514. /*==========================================
  8515. * カプラ倉庫から出す
  8516. *------------------------------------------*/
  8517. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8518. {
  8519. if (sd->vender_id)
  8520. return;
  8521. if (!pc_iscarton(sd))
  8522. return;
  8523. if (sd->state.storage_flag == 1)
  8524. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8525. else if (sd->state.storage_flag == 2)
  8526. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8527. }
  8528. /*==========================================
  8529. * カプラ倉庫を閉じる
  8530. *------------------------------------------*/
  8531. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8532. {
  8533. if (sd->state.storage_flag == 1)
  8534. storage_storageclose(sd);
  8535. else if (sd->state.storage_flag == 2)
  8536. storage_guild_storageclose(sd);
  8537. }
  8538. /*==========================================
  8539. * Kafra storage protection password system
  8540. *------------------------------------------*/
  8541. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8542. {
  8543. //TODO
  8544. }
  8545. /*==========================================
  8546. * パーティを作る
  8547. *------------------------------------------*/
  8548. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8549. {
  8550. if(map[sd->bl.m].flag.partylock)
  8551. { //Guild locked.
  8552. clif_displaymessage(fd, msg_txt(227));
  8553. return;
  8554. }
  8555. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8556. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8557. } else
  8558. clif_skill_fail(sd,1,0,4);
  8559. }
  8560. /*==========================================
  8561. * パーティを作る
  8562. *------------------------------------------*/
  8563. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8564. {
  8565. if(map[sd->bl.m].flag.partylock)
  8566. { //Guild locked.
  8567. clif_displaymessage(fd, msg_txt(227));
  8568. return;
  8569. }
  8570. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7)
  8571. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8572. else
  8573. clif_skill_fail(sd,1,0,4);
  8574. }
  8575. /*==========================================
  8576. * パーティに勧誘
  8577. *------------------------------------------*/
  8578. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8579. {
  8580. struct map_session_data *t_sd;
  8581. if(map[sd->bl.m].flag.partylock)
  8582. { //Guild locked.
  8583. clif_displaymessage(fd, msg_txt(227));
  8584. return;
  8585. }
  8586. t_sd = map_id2sd(RFIFOL(fd,2));
  8587. // @noask [LuzZza]
  8588. if(t_sd && t_sd->state.noask) {
  8589. clif_noask_sub(sd, t_sd, 1);
  8590. return;
  8591. }
  8592. party_invite(sd, t_sd);
  8593. }
  8594. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8595. {
  8596. struct map_session_data *t_sd;
  8597. char *name = (char*)RFIFOP(fd,2);
  8598. name[NAME_LENGTH]='\0';
  8599. if(map[sd->bl.m].flag.partylock)
  8600. { //Guild locked.
  8601. clif_displaymessage(fd, msg_txt(227));
  8602. return;
  8603. }
  8604. t_sd = map_nick2sd(name);
  8605. // @noask [LuzZza]
  8606. if(t_sd && t_sd->state.noask) {
  8607. clif_noask_sub(sd, t_sd, 1);
  8608. return;
  8609. }
  8610. party_invite(sd, t_sd);
  8611. }
  8612. /*==========================================
  8613. * パーティ勧誘返答
  8614. *------------------------------------------*/
  8615. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8616. {
  8617. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8618. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8619. } else {
  8620. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8621. clif_skill_fail(sd,1,0,4);
  8622. }
  8623. }
  8624. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8625. {
  8626. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8627. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8628. } else {
  8629. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8630. clif_skill_fail(sd,1,0,4);
  8631. }
  8632. }
  8633. /*==========================================
  8634. * パーティ脱退要求
  8635. *------------------------------------------*/
  8636. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8637. {
  8638. if(map[sd->bl.m].flag.partylock)
  8639. { //Guild locked.
  8640. clif_displaymessage(fd, msg_txt(227));
  8641. return;
  8642. }
  8643. party_leave(sd);
  8644. }
  8645. /*==========================================
  8646. * パーティ除名要求
  8647. *------------------------------------------*/
  8648. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8649. {
  8650. if(map[sd->bl.m].flag.partylock)
  8651. { //Guild locked.
  8652. clif_displaymessage(fd, msg_txt(227));
  8653. return;
  8654. }
  8655. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8656. }
  8657. /*==========================================
  8658. * パーティ設定変更要求
  8659. *------------------------------------------*/
  8660. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8661. {
  8662. struct party_data *p;
  8663. if(!sd->status.party_id)
  8664. return;
  8665. p = party_search(sd->status.party_id);
  8666. if (!p) return;
  8667. //The client no longer can change the item-field, therefore it always
  8668. //comes as zero. Here, resend the item data as it is.
  8669. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8670. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8671. }
  8672. /*==========================================
  8673. * Validates and processes party messages
  8674. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8675. *------------------------------------------*/
  8676. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8677. {
  8678. const char* text = (char*)RFIFOP(fd,4);
  8679. int textlen = RFIFOW(fd,2) - 4;
  8680. char *name, *message;
  8681. int namelen, messagelen;
  8682. // validate packet and retrieve name and message
  8683. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8684. return;
  8685. if (is_charcommand(fd, sd, message) != CharCommand_None || is_atcommand(fd, sd, message) != AtCommand_None)
  8686. return;
  8687. if (sd->sc.data[SC_BERSERK].timer!=-1 || (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))
  8688. return;
  8689. if (battle_config.min_chat_delay)
  8690. { //[Skotlex]
  8691. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8692. return;
  8693. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8694. }
  8695. party_send_message(sd, text, textlen);
  8696. }
  8697. /*==========================================
  8698. * 露店閉鎖
  8699. *------------------------------------------*/
  8700. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8701. {
  8702. vending_closevending(sd);
  8703. }
  8704. /*==========================================
  8705. * 露店アイテムリスト要求
  8706. *------------------------------------------*/
  8707. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8708. {
  8709. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8710. if( sd->npc_id )
  8711. npc_event_dequeue(sd);
  8712. }
  8713. /*==========================================
  8714. * Shop item(s) purchase request
  8715. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8716. *------------------------------------------*/
  8717. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8718. {
  8719. int len = (int)RFIFOW(fd,2) - 8;
  8720. int id = (int)RFIFOL(fd,4);
  8721. const uint8* data = (uint8*)RFIFOP(fd,8);
  8722. vending_purchasereq(sd, id, data, len/4);
  8723. }
  8724. /*==========================================
  8725. * Confirm or cancel the shop preparation window
  8726. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8727. * flag: 0=cancel, 1=confirm
  8728. *------------------------------------------*/
  8729. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8730. {
  8731. short len = (short)RFIFOW(fd,2) - 85;
  8732. const char* message = (char*)RFIFOP(fd,4);
  8733. bool flag = (bool)RFIFOB(fd,84);
  8734. const uint8* data = (uint8*)RFIFOP(fd,85);
  8735. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8736. return;
  8737. if (map[sd->bl.m].flag.novending) {
  8738. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open shop on this map"
  8739. return;
  8740. }
  8741. if( message[0] == '\0' ) // invalid input
  8742. return;
  8743. vending_openvending(sd, message, flag, data, len/8);
  8744. }
  8745. /*==========================================
  8746. * ギルドを作る
  8747. *------------------------------------------*/
  8748. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8749. {
  8750. if(map[sd->bl.m].flag.guildlock)
  8751. { //Guild locked.
  8752. clif_displaymessage(fd, msg_txt(228));
  8753. return;
  8754. }
  8755. guild_create(sd, (char*)RFIFOP(fd,6));
  8756. }
  8757. /*==========================================
  8758. * ギルドマスターかどうか確認
  8759. *------------------------------------------*/
  8760. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8761. {
  8762. clif_guild_masterormember(sd);
  8763. }
  8764. /*==========================================
  8765. * ギルド情報要求
  8766. *------------------------------------------*/
  8767. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8768. {
  8769. if (!sd->status.guild_id)
  8770. return;
  8771. switch(RFIFOL(fd,2)){
  8772. case 0: // ギルド基本情報、同盟敵対情報
  8773. clif_guild_basicinfo(sd);
  8774. clif_guild_allianceinfo(sd);
  8775. break;
  8776. case 1: // メンバーリスト、役職名リスト
  8777. clif_guild_positionnamelist(sd);
  8778. clif_guild_memberlist(sd);
  8779. break;
  8780. case 2: // 役職名リスト、役職情報リスト
  8781. clif_guild_positionnamelist(sd);
  8782. clif_guild_positioninfolist(sd);
  8783. break;
  8784. case 3: // スキルリスト
  8785. clif_guild_skillinfo(sd);
  8786. break;
  8787. case 4: // 追放リスト
  8788. clif_guild_expulsionlist(sd);
  8789. break;
  8790. default:
  8791. if (battle_config.error_log)
  8792. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8793. break;
  8794. }
  8795. }
  8796. /*==========================================
  8797. * ギルド役職変更
  8798. *------------------------------------------*/
  8799. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8800. {
  8801. int i;
  8802. if(!sd->state.gmaster_flag)
  8803. return;
  8804. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8805. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8806. }
  8807. }
  8808. /*==========================================
  8809. * ギルドメンバ役職変更
  8810. *------------------------------------------*/
  8811. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8812. {
  8813. int i;
  8814. if(!sd->state.gmaster_flag)
  8815. return;
  8816. for(i=4;i<RFIFOW(fd,2);i+=12){
  8817. guild_change_memberposition(sd->status.guild_id,
  8818. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8819. }
  8820. }
  8821. /*==========================================
  8822. * ギルドエンブレム要求
  8823. *------------------------------------------*/
  8824. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8825. {
  8826. struct guild* g = guild_search(RFIFOL(fd,2));
  8827. if(g!=NULL)
  8828. clif_guild_emblem(sd,g);
  8829. }
  8830. /*==========================================
  8831. * ギルドエンブレム変更
  8832. *------------------------------------------*/
  8833. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8834. {
  8835. if(!sd->state.gmaster_flag)
  8836. return;
  8837. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8838. }
  8839. /*==========================================
  8840. * Guild notice update request
  8841. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8842. *------------------------------------------*/
  8843. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8844. {
  8845. int guild_id = RFIFOL(fd,2);
  8846. char* msg1 = (char*)RFIFOP(fd,6);
  8847. char* msg2 = (char*)RFIFOP(fd,66);
  8848. if(!sd->state.gmaster_flag)
  8849. return;
  8850. // compensate for some client defects when using multilanguage mode
  8851. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8852. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8853. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8854. guild_change_notice(sd, guild_id, msg1, msg2);
  8855. }
  8856. /*==========================================
  8857. * ギルド勧誘
  8858. *------------------------------------------*/
  8859. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8860. {
  8861. struct map_session_data *t_sd;
  8862. if(map[sd->bl.m].flag.guildlock)
  8863. { //Guild locked.
  8864. clif_displaymessage(fd, msg_txt(228));
  8865. return;
  8866. }
  8867. t_sd = map_id2sd(RFIFOL(fd,2));
  8868. // @noask [LuzZza]
  8869. if(t_sd && t_sd->state.noask) {
  8870. clif_noask_sub(sd, t_sd, 2);
  8871. return;
  8872. }
  8873. guild_invite(sd,t_sd);
  8874. }
  8875. /*==========================================
  8876. * ギルド勧誘返信
  8877. *------------------------------------------*/
  8878. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8879. {
  8880. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8881. }
  8882. /*==========================================
  8883. * ギルド脱退
  8884. *------------------------------------------*/
  8885. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8886. {
  8887. if(map[sd->bl.m].flag.guildlock)
  8888. { //Guild locked.
  8889. clif_displaymessage(fd, msg_txt(228));
  8890. return;
  8891. }
  8892. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8893. }
  8894. /*==========================================
  8895. * ギルド追放
  8896. *------------------------------------------*/
  8897. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8898. {
  8899. if(map[sd->bl.m].flag.guildlock)
  8900. { //Guild locked.
  8901. clif_displaymessage(fd, msg_txt(228));
  8902. return;
  8903. }
  8904. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8905. }
  8906. /*==========================================
  8907. * Validates and processes guild messages
  8908. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  8909. *------------------------------------------*/
  8910. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  8911. {
  8912. const char* text = (char*)RFIFOP(fd,4);
  8913. int textlen = RFIFOW(fd,2) - 4;
  8914. char *name, *message;
  8915. int namelen, messagelen;
  8916. // validate packet and retrieve name and message
  8917. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8918. return;
  8919. if (is_charcommand(fd, sd, message) != CharCommand_None || is_atcommand(fd, sd, message) != AtCommand_None)
  8920. return;
  8921. if (sd->sc.data[SC_BERSERK].timer!=-1 || (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))
  8922. return;
  8923. if (battle_config.min_chat_delay)
  8924. { //[Skotlex]
  8925. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8926. return;
  8927. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8928. }
  8929. guild_send_message(sd, text, textlen);
  8930. }
  8931. /*==========================================
  8932. * ギルド同盟要求
  8933. *------------------------------------------*/
  8934. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  8935. {
  8936. struct map_session_data *t_sd;
  8937. if(!sd->state.gmaster_flag)
  8938. return;
  8939. if(map[sd->bl.m].flag.guildlock)
  8940. { //Guild locked.
  8941. clif_displaymessage(fd, msg_txt(228));
  8942. return;
  8943. }
  8944. t_sd = map_id2sd(RFIFOL(fd,2));
  8945. // @noask [LuzZza]
  8946. if(t_sd && t_sd->state.noask) {
  8947. clif_noask_sub(sd, t_sd, 3);
  8948. return;
  8949. }
  8950. guild_reqalliance(sd,t_sd);
  8951. }
  8952. /*==========================================
  8953. * ギルド同盟要求返信
  8954. *------------------------------------------*/
  8955. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  8956. {
  8957. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8958. }
  8959. /*==========================================
  8960. * ギルド関係解消
  8961. *------------------------------------------*/
  8962. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  8963. {
  8964. if(!sd->state.gmaster_flag)
  8965. return;
  8966. if(map[sd->bl.m].flag.guildlock)
  8967. { //Guild locked.
  8968. clif_displaymessage(fd, msg_txt(228));
  8969. return;
  8970. }
  8971. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8972. }
  8973. /*==========================================
  8974. * ギルド敵対
  8975. *------------------------------------------*/
  8976. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  8977. {
  8978. struct map_session_data *t_sd;
  8979. if(!sd->state.gmaster_flag)
  8980. return;
  8981. if(map[sd->bl.m].flag.guildlock)
  8982. { //Guild locked.
  8983. clif_displaymessage(fd, msg_txt(228));
  8984. return;
  8985. }
  8986. t_sd = map_id2sd(RFIFOL(fd,2));
  8987. // @noask [LuzZza]
  8988. if(t_sd && t_sd->state.noask) {
  8989. clif_noask_sub(sd, t_sd, 4);
  8990. return;
  8991. }
  8992. guild_opposition(sd,t_sd);
  8993. }
  8994. /*==========================================
  8995. * ギルド解散
  8996. *------------------------------------------*/
  8997. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  8998. {
  8999. if(map[sd->bl.m].flag.guildlock)
  9000. { //Guild locked.
  9001. clif_displaymessage(fd, msg_txt(228));
  9002. return;
  9003. }
  9004. guild_break(sd,(char*)RFIFOP(fd,2));
  9005. }
  9006. // pet
  9007. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9008. {
  9009. pet_menu(sd,RFIFOB(fd,2));
  9010. }
  9011. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9012. {
  9013. pet_catch_process2(sd,RFIFOL(fd,2));
  9014. }
  9015. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9016. {
  9017. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9018. return;
  9019. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9020. sd->menuskill_val = sd->menuskill_id = 0;
  9021. }
  9022. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9023. {
  9024. if(sd->pd)
  9025. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9026. }
  9027. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9028. {
  9029. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9030. }
  9031. // Kick (right click menu for GM "(name) force to quit")
  9032. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9033. {
  9034. struct block_list *target;
  9035. int tid,lv;
  9036. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9037. return;
  9038. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Kick)))
  9039. return;
  9040. tid = RFIFOL(fd,2);
  9041. target = map_id2bl(tid);
  9042. if (!target) {
  9043. clif_GM_kickack(sd, 0);
  9044. return;
  9045. }
  9046. switch (target->type) {
  9047. case BL_PC:
  9048. {
  9049. struct map_session_data *tsd = (struct map_session_data *)target;
  9050. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9051. clif_GM_kickack(sd, 0);
  9052. return;
  9053. }
  9054. clif_GM_kick(sd, tsd, 1);
  9055. if(log_config.gm && lv >= log_config.gm) {
  9056. char message[NAME_LENGTH+6];
  9057. sprintf(message, "/kick %d", tsd->status.char_id);
  9058. log_atcommand(sd, message);
  9059. }
  9060. break;
  9061. }
  9062. case BL_MOB:
  9063. status_percent_damage(&sd->bl, target, 100, 0);
  9064. if(log_config.gm && lv >= log_config.gm) {
  9065. char message[NAME_LENGTH+16];
  9066. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9067. log_atcommand(sd, message);
  9068. }
  9069. break;
  9070. default:
  9071. clif_GM_kickack(sd, 0);
  9072. }
  9073. }
  9074. /*==========================================
  9075. * /shift
  9076. *------------------------------------------*/
  9077. void clif_parse_Shift(int fd, struct map_session_data *sd)
  9078. {
  9079. char *player_name;
  9080. int lv;
  9081. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9082. return;
  9083. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_JumpTo)))
  9084. return;
  9085. player_name = (char*)RFIFOP(fd,2);
  9086. player_name[NAME_LENGTH-1] = '\0';
  9087. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9088. if(log_config.gm && lv >= log_config.gm) {
  9089. char message[NAME_LENGTH+7];
  9090. sprintf(message, "/shift %s", player_name);
  9091. log_atcommand(sd, message);
  9092. }
  9093. return;
  9094. }
  9095. /*==========================================
  9096. * /recall
  9097. *------------------------------------------*/
  9098. void clif_parse_Recall(int fd, struct map_session_data *sd)
  9099. {
  9100. char *player_name;
  9101. int lv;
  9102. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9103. return;
  9104. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Recall)))
  9105. return;
  9106. player_name = (char*)RFIFOP(fd,2);
  9107. player_name[NAME_LENGTH-1] = '\0';
  9108. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9109. if(log_config.gm && lv >= log_config.gm) {
  9110. char message[NAME_LENGTH+8];
  9111. sprintf(message, "/recall %s", player_name);
  9112. log_atcommand(sd, message);
  9113. }
  9114. return;
  9115. }
  9116. /*==========================================
  9117. * /monster /item
  9118. *------------------------------------------*/
  9119. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9120. {
  9121. char *monster_item_name;
  9122. char message[NAME_LENGTH+10]; //For logging.
  9123. int level;
  9124. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9125. return;
  9126. monster_item_name = (char*)RFIFOP(fd,2);
  9127. monster_item_name[NAME_LENGTH-1] = '\0';
  9128. if (mobdb_searchname(monster_item_name)) {
  9129. if (pc_isGM(sd) < (level=get_atcommand_level(AtCommand_Spawn)))
  9130. return;
  9131. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9132. if(log_config.gm && level >= log_config.gm)
  9133. { //Log action. [Skotlex]
  9134. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9135. log_atcommand(sd, message);
  9136. }
  9137. return;
  9138. }
  9139. if (itemdb_searchname(monster_item_name) == NULL)
  9140. return;
  9141. if (pc_isGM(sd) < (level = get_atcommand_level(AtCommand_Item)))
  9142. return;
  9143. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9144. if(log_config.gm && level >= log_config.gm)
  9145. { //Log action. [Skotlex]
  9146. sprintf(message, "@item %s", monster_item_name);
  9147. log_atcommand(sd, message);
  9148. }
  9149. }
  9150. /*==========================================
  9151. * /hide
  9152. *------------------------------------------*/
  9153. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9154. {
  9155. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9156. return;
  9157. if (pc_isGM(sd) < get_atcommand_level(AtCommand_Hide))
  9158. return;
  9159. if (sd->sc.option & OPTION_INVISIBLE) {
  9160. sd->sc.option &= ~OPTION_INVISIBLE;
  9161. if (sd->disguise)
  9162. status_set_viewdata(&sd->bl, sd->disguise);
  9163. else
  9164. status_set_viewdata(&sd->bl, sd->status.class_);
  9165. clif_displaymessage(fd, "Invisible: Off.");
  9166. } else {
  9167. sd->sc.option |= OPTION_INVISIBLE;
  9168. sd->vd.class_ = INVISIBLE_CLASS;
  9169. clif_displaymessage(fd, "Invisible: On.");
  9170. if(log_config.gm && get_atcommand_level(AtCommand_Hide) >= log_config.gm)
  9171. log_atcommand(sd, "/hide");
  9172. }
  9173. clif_changeoption(&sd->bl);
  9174. }
  9175. /*==========================================
  9176. * GMによるチャット禁止時間付与
  9177. *------------------------------------------*/
  9178. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9179. {
  9180. int type, limit, level;
  9181. struct block_list *bl;
  9182. struct map_session_data *dstsd;
  9183. bl = map_id2bl(RFIFOL(fd,2));
  9184. if (!bl || bl->type != BL_PC)
  9185. return;
  9186. dstsd =(struct map_session_data *)bl;
  9187. type = RFIFOB(fd,6);
  9188. limit = RFIFOW(fd,7);
  9189. if (type == 0)
  9190. limit = 0 - limit;
  9191. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9192. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9193. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9194. return;
  9195. if (
  9196. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9197. || (type == 2 && !level))
  9198. {
  9199. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9200. dstsd->status.manner -= limit;
  9201. if(dstsd->status.manner < 0)
  9202. sc_start(bl,SC_NOCHAT,100,0,0);
  9203. else
  9204. {
  9205. dstsd->status.manner = 0;
  9206. status_change_end(bl,SC_NOCHAT,-1);
  9207. }
  9208. }
  9209. return;
  9210. }
  9211. /*==========================================
  9212. * GMによるチャット禁止時間参照(?)
  9213. *------------------------------------------*/
  9214. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9215. {
  9216. int tid;
  9217. tid = RFIFOL(fd,2);
  9218. WFIFOHEAD(fd,packet_len(0x1e0));
  9219. WFIFOW(fd,0) = 0x1e0;
  9220. WFIFOL(fd,2) = tid;
  9221. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9222. WFIFOSET(fd, packet_len(0x1e0));
  9223. return;
  9224. }
  9225. static int pstrcmp(const void *a, const void *b)
  9226. {
  9227. char *name1 = (char *)a;
  9228. char *name2 = (char *)b;
  9229. if (name1[0] && name2[0])
  9230. return strcmp(name1, name2);
  9231. //Since names are sorted in ascending order, send blank entries to the bottom.
  9232. if (name1[0])
  9233. return -1;
  9234. if (name2[0])
  9235. return 1;
  9236. return 0;
  9237. }
  9238. void clif_parse_PMIgnore(int fd, struct map_session_data *sd)
  9239. {
  9240. char output[512];
  9241. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9242. int i;
  9243. memset(output, '\0', sizeof(output));
  9244. nick = (char*)RFIFOP(fd,2); // speed up
  9245. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9246. WFIFOHEAD(fd,packet_len(0xd1));
  9247. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <result>.B: type: 0: deny, 1: allow, result: 0: success, 1: fail 2: list full
  9248. WFIFOB(fd,2) = RFIFOB(fd,26);
  9249. if (RFIFOB(fd,26) == 0)
  9250. { // Add name to ignore list (block)
  9251. // Bot-check...
  9252. if (strcmp(wisp_server_name, nick) == 0)
  9253. { // to find possible bot users who automaticaly ignore people
  9254. sprintf(output, "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  9255. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9256. WFIFOB(fd,3) = 1; // fail
  9257. WFIFOSET(fd, packet_len(0x0d1));
  9258. return;
  9259. }
  9260. // try to find a free spot, while checking for duplicates at the same time
  9261. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0' && strcmp(sd->ignore[i].name, nick) != 0; i++);
  9262. if (i == MAX_IGNORE_LIST) { // no space for new entry
  9263. WFIFOB(fd,3) = 2; // fail
  9264. WFIFOSET(fd, packet_len(0x0d1));
  9265. return;
  9266. }
  9267. if(sd->ignore[i].name[0] != '\0') { // name already exists
  9268. WFIFOB(fd,3) = 0; // Aegis reports success.
  9269. WFIFOSET(fd, packet_len(0x0d1));
  9270. return;
  9271. }
  9272. //Insert in position i
  9273. memcpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9274. WFIFOB(fd,3) = 0; // success
  9275. WFIFOSET(fd, packet_len(0x0d1));
  9276. //Sort the ignore list.
  9277. //FIXME: why not just use a simple shift-and-insert scheme instead? [ultramage]
  9278. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9279. }
  9280. else
  9281. { // Remove name from ignore list (unblock)
  9282. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0' && strcmp(sd->ignore[i].name, nick) != 0; i++);
  9283. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0') { //Not found
  9284. WFIFOB(fd,3) = 1; // fail
  9285. WFIFOSET(fd, packet_len(0x0d1));
  9286. return;
  9287. }
  9288. //Move everything one place down to overwrite removed entry.
  9289. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9290. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9291. WFIFOB(fd,3) = 0; // success
  9292. WFIFOSET(fd, packet_len(0x0d1));
  9293. }
  9294. //for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9295. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9296. return;
  9297. }
  9298. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9299. {
  9300. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9301. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9302. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9303. WFIFOHEAD(fd,packet_len(0xd2));
  9304. WFIFOW(fd,0) = 0x0d2;
  9305. WFIFOB(fd,2) = RFIFOB(fd,2);
  9306. if (RFIFOB(fd,2) == 0) { //Deny all
  9307. if (sd->state.ignoreAll) {
  9308. WFIFOB(fd,3) = 1; // fail
  9309. WFIFOSET(fd, packet_len(0x0d2));
  9310. return;
  9311. }
  9312. sd->state.ignoreAll = 1;
  9313. WFIFOB(fd,3) = 0; // success
  9314. WFIFOSET(fd, packet_len(0x0d2));
  9315. return;
  9316. }
  9317. //Unblock everyone
  9318. if (!sd->state.ignoreAll) {
  9319. if (sd->ignore[0].name[0] != '\0')
  9320. { //Wipe the ignore list.
  9321. memset(sd->ignore, 0, sizeof(sd->ignore));
  9322. WFIFOB(fd,3) = 0;
  9323. WFIFOSET(fd, packet_len(0x0d2));
  9324. return;
  9325. }
  9326. WFIFOB(fd,3) = 1; // fail
  9327. WFIFOSET(fd, packet_len(0x0d2));
  9328. return;
  9329. }
  9330. sd->state.ignoreAll = 0;
  9331. WFIFOB(fd,3) = 0; // success
  9332. WFIFOSET(fd, packet_len(0x0d2));
  9333. return;
  9334. }
  9335. /*==========================================
  9336. * Wis拒否リスト
  9337. *------------------------------------------*/
  9338. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9339. {
  9340. int i;
  9341. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9342. WFIFOW(fd,0) = 0xd4;
  9343. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9344. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9345. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9346. WFIFOSET(fd, WFIFOW(fd,2));
  9347. return;
  9348. }
  9349. /*==========================================
  9350. * スパノビの/doridoriによるSPR2倍
  9351. *------------------------------------------*/
  9352. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9353. {
  9354. if (sd->state.doridori) return;
  9355. switch (sd->class_&MAPID_UPPERMASK)
  9356. {
  9357. case MAPID_SOUL_LINKER:
  9358. case MAPID_STAR_GLADIATOR:
  9359. case MAPID_TAEKWON:
  9360. if (!sd->state.rest)
  9361. break;
  9362. case MAPID_SUPER_NOVICE:
  9363. sd->state.doridori=1;
  9364. break;
  9365. }
  9366. return;
  9367. }
  9368. /*==========================================
  9369. * スパノビの爆裂波動
  9370. *------------------------------------------*/
  9371. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9372. {
  9373. if(sd){
  9374. int nextbaseexp=pc_nextbaseexp(sd);
  9375. if (battle_config.etc_log){
  9376. if(nextbaseexp != 0)
  9377. ShowInfo("SuperNovice explosionspirits!! %d %d %d %d\n",sd->bl.id,sd->status.class_,sd->status.base_exp,(int)((double)1000*sd->status.base_exp/nextbaseexp));
  9378. else
  9379. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9380. }
  9381. if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_exp > 0 && nextbaseexp > 0 && (int)((double)1000*sd->status.base_exp/nextbaseexp)%100==0){
  9382. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9383. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9384. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9385. }
  9386. }
  9387. return;
  9388. }
  9389. // random notes:
  9390. // 0x214: monster/player info ?
  9391. /*==========================================
  9392. * Friends List
  9393. *------------------------------------------*/
  9394. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9395. { //Toggles a single friend online/offline [Skotlex]
  9396. int i, fd = sd->fd;
  9397. //Seek friend.
  9398. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9399. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9400. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9401. return; //Not found
  9402. WFIFOHEAD(fd,packet_len(0x206));
  9403. WFIFOW(fd, 0) = 0x206;
  9404. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9405. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9406. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9407. WFIFOSET(fd, packet_len(0x206));
  9408. }
  9409. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9410. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9411. {
  9412. int account_id, char_id, online;
  9413. account_id = va_arg(ap, int);
  9414. char_id = va_arg(ap, int);
  9415. online = va_arg(ap, int);
  9416. clif_friendslist_toggle(sd, account_id, char_id, online);
  9417. return 0;
  9418. }
  9419. //For sending the whole friends list.
  9420. void clif_friendslist_send(struct map_session_data *sd)
  9421. {
  9422. int i = 0, n, fd = sd->fd;
  9423. // Send friends list
  9424. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9425. WFIFOW(fd, 0) = 0x201;
  9426. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9427. {
  9428. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9429. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9430. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9431. }
  9432. if (i) {
  9433. WFIFOW(fd,2) = 4 + 32 * i;
  9434. WFIFOSET(fd, WFIFOW(fd,2));
  9435. }
  9436. for (n = 0; n < i; n++)
  9437. { //Sending the online players
  9438. if (map_charid2sd(sd->status.friends[n].char_id))
  9439. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9440. }
  9441. }
  9442. /// Reply for add friend request: (success => type 0)
  9443. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9444. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9445. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9446. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9447. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9448. {
  9449. int fd;
  9450. nullpo_retv(sd);
  9451. fd = sd->fd;
  9452. WFIFOHEAD(fd,packet_len(0x209));
  9453. WFIFOW(fd,0) = 0x209;
  9454. WFIFOW(fd,2) = type;
  9455. if (f_sd)
  9456. {
  9457. WFIFOW(fd,4) = f_sd->status.account_id;
  9458. WFIFOW(fd,8) = f_sd->status.char_id;
  9459. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9460. }
  9461. WFIFOSET(fd, packet_len(0x209));
  9462. }
  9463. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9464. {
  9465. struct map_session_data *f_sd;
  9466. int i, f_fd;
  9467. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9468. // Friend doesn't exist (no player with this name)
  9469. if (f_sd == NULL) {
  9470. clif_displaymessage(fd, msg_txt(3));
  9471. return;
  9472. }
  9473. // @noask [LuzZza]
  9474. if(f_sd->state.noask) {
  9475. clif_noask_sub(sd, f_sd, 5);
  9476. return;
  9477. }
  9478. // Friend already exists
  9479. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9480. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9481. clif_displaymessage(fd, "Friend already exists.");
  9482. return;
  9483. }
  9484. }
  9485. if (i == MAX_FRIENDS) {
  9486. //No space, list full.
  9487. clif_friendslist_reqack(sd, f_sd, 2);
  9488. return;
  9489. }
  9490. f_fd = f_sd->fd;
  9491. WFIFOHEAD(f_fd,packet_len(0x207));
  9492. WFIFOW(f_fd,0) = 0x207;
  9493. WFIFOL(f_fd,2) = sd->status.account_id;
  9494. WFIFOL(f_fd,6) = sd->status.char_id;
  9495. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9496. WFIFOSET(f_fd, packet_len(0x207));
  9497. return;
  9498. }
  9499. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9500. {
  9501. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9502. struct map_session_data *f_sd;
  9503. int char_id, account_id;
  9504. char reply;
  9505. account_id = RFIFOL(fd,2);
  9506. char_id = RFIFOL(fd,6);
  9507. reply = RFIFOB(fd,10);
  9508. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9509. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9510. if (f_sd == NULL)
  9511. return;
  9512. if (reply == 0)
  9513. clif_friendslist_reqack(f_sd, sd, 1);
  9514. else {
  9515. int i;
  9516. // Find an empty slot
  9517. for (i = 0; i < MAX_FRIENDS; i++)
  9518. if (f_sd->status.friends[i].char_id == 0)
  9519. break;
  9520. if (i == MAX_FRIENDS) {
  9521. clif_friendslist_reqack(f_sd, sd, 2);
  9522. return;
  9523. }
  9524. f_sd->status.friends[i].account_id = sd->status.account_id;
  9525. f_sd->status.friends[i].char_id = sd->status.char_id;
  9526. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9527. clif_friendslist_reqack(f_sd, sd, 0);
  9528. if (battle_config.friend_auto_add) {
  9529. // Also add f_sd to sd's friendlist.
  9530. for (i = 0; i < MAX_FRIENDS; i++) {
  9531. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9532. return; //No need to add anything.
  9533. if (sd->status.friends[i].char_id == 0)
  9534. break;
  9535. }
  9536. if (i == MAX_FRIENDS) {
  9537. clif_friendslist_reqack(sd, f_sd, 2);
  9538. return;
  9539. }
  9540. sd->status.friends[i].account_id = f_sd->status.account_id;
  9541. sd->status.friends[i].char_id = f_sd->status.char_id;
  9542. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9543. clif_friendslist_reqack(sd, f_sd, 0);
  9544. }
  9545. }
  9546. return;
  9547. }
  9548. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9549. {
  9550. // 0x203 </o> <ID to be removed W 4B>
  9551. int account_id, char_id;
  9552. int i, j;
  9553. account_id = RFIFOL(fd,2);
  9554. char_id = RFIFOL(fd,6);
  9555. // Search friend
  9556. for (i = 0; i < MAX_FRIENDS &&
  9557. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9558. if (i == MAX_FRIENDS) {
  9559. clif_displaymessage(fd, "Name not found in list.");
  9560. return;
  9561. }
  9562. // move all chars down
  9563. for(j = i + 1; j < MAX_FRIENDS; j++)
  9564. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9565. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9566. clif_displaymessage(fd, "Friend removed");
  9567. WFIFOHEAD(fd,packet_len(0x20a));
  9568. WFIFOW(fd,0) = 0x20a;
  9569. WFIFOL(fd,2) = account_id;
  9570. WFIFOL(fd,6) = char_id;
  9571. WFIFOSET(fd, packet_len(0x20a));
  9572. // clif_friendslist_send(sd); //This is not needed anymore.
  9573. return;
  9574. }
  9575. /*==========================================
  9576. * /killall
  9577. *------------------------------------------*/
  9578. void clif_parse_GMKillAll(int fd, struct map_session_data* sd)
  9579. {
  9580. is_atcommand(fd, sd, "@kickall");
  9581. }
  9582. /*==========================================
  9583. * /pvpinfo
  9584. *------------------------------------------*/
  9585. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9586. {
  9587. WFIFOHEAD(fd,packet_len(0x210));
  9588. WFIFOW(fd,0) = 0x210;
  9589. //WFIFOL(fd,2) = 0; // not sure what for yet
  9590. //WFIFOL(fd,6) = 0;
  9591. WFIFOL(fd,10) = sd->pvp_won; // times won
  9592. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9593. WFIFOL(fd,18) = sd->pvp_point;
  9594. WFIFOSET(fd, packet_len(0x210));
  9595. return;
  9596. }
  9597. /*==========================================
  9598. * /blacksmith
  9599. *------------------------------------------*/
  9600. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9601. {
  9602. int i;
  9603. const char* name;
  9604. WFIFOHEAD(fd,packet_len(0x219));
  9605. WFIFOW(fd,0) = 0x219;
  9606. //Packet size limits this list to 10 elements. [Skotlex]
  9607. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9608. if (smith_fame_list[i].id > 0) {
  9609. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9610. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9611. {
  9612. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9613. } else
  9614. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9615. } else
  9616. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9617. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9618. }
  9619. for(;i < 10; i++) { //In case the MAX is less than 10.
  9620. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9621. WFIFOL(fd, 242 + i * 4) = 0;
  9622. }
  9623. WFIFOSET(fd, packet_len(0x219));
  9624. }
  9625. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9626. {
  9627. int fd = sd->fd;
  9628. WFIFOHEAD(fd,packet_len(0x21b));
  9629. WFIFOW(fd,0) = 0x21b;
  9630. WFIFOL(fd,2) = points;
  9631. WFIFOL(fd,6) = sd->status.fame;
  9632. WFIFOSET(fd, packet_len(0x21b));
  9633. return 0;
  9634. }
  9635. /*==========================================
  9636. * /alchemist
  9637. *------------------------------------------*/
  9638. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9639. {
  9640. int i;
  9641. const char* name;
  9642. WFIFOHEAD(fd,packet_len(0x21a));
  9643. WFIFOW(fd,0) = 0x21a;
  9644. //Packet size limits this list to 10 elements. [Skotlex]
  9645. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9646. if (chemist_fame_list[i].id > 0) {
  9647. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9648. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9649. {
  9650. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9651. } else
  9652. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9653. } else
  9654. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9655. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9656. }
  9657. for(;i < 10; i++) { //In case the MAX is less than 10.
  9658. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9659. WFIFOL(fd, 242 + i * 4) = 0;
  9660. }
  9661. WFIFOSET(fd, packet_len(0x21a));
  9662. }
  9663. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9664. {
  9665. int fd = sd->fd;
  9666. WFIFOHEAD(fd,packet_len(0x21c));
  9667. WFIFOW(fd,0) = 0x21c;
  9668. WFIFOL(fd,2) = points;
  9669. WFIFOL(fd,6) = sd->status.fame;
  9670. WFIFOSET(fd, packet_len(0x21c));
  9671. return 0;
  9672. }
  9673. /*==========================================
  9674. * /taekwon
  9675. *------------------------------------------*/
  9676. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9677. {
  9678. int i;
  9679. const char* name;
  9680. WFIFOHEAD(fd,packet_len(0x226));
  9681. WFIFOW(fd,0) = 0x226;
  9682. //Packet size limits this list to 10 elements. [Skotlex]
  9683. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9684. if (taekwon_fame_list[i].id > 0) {
  9685. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9686. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9687. {
  9688. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9689. } else
  9690. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9691. } else
  9692. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9693. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9694. }
  9695. for(;i < 10; i++) { //In case the MAX is less than 10.
  9696. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9697. WFIFOL(fd, 242 + i * 4) = 0;
  9698. }
  9699. WFIFOSET(fd, packet_len(0x226));
  9700. }
  9701. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9702. {
  9703. int fd = sd->fd;
  9704. WFIFOHEAD(fd,packet_len(0x224));
  9705. WFIFOW(fd,0) = 0x224;
  9706. WFIFOL(fd,2) = points;
  9707. WFIFOL(fd,6) = sd->status.fame;
  9708. WFIFOSET(fd, packet_len(0x224));
  9709. return 0;
  9710. }
  9711. /*==========================================
  9712. * PK Ranking table?
  9713. *------------------------------------------*/
  9714. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9715. {
  9716. int i;
  9717. WFIFOHEAD(fd,packet_len(0x238));
  9718. WFIFOW(fd,0) = 0x238;
  9719. for(i=0;i<10;i++){
  9720. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9721. WFIFOL(fd,i*4+242) = 0;
  9722. }
  9723. WFIFOSET(fd, packet_len(0x238));
  9724. return;
  9725. }
  9726. /*==========================================
  9727. * SG Feel save OK [Komurka]
  9728. *------------------------------------------*/
  9729. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9730. {
  9731. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  9732. int i;
  9733. if (sd->menuskill_id != SG_FEEL)
  9734. return;
  9735. i = sd->menuskill_val-1;
  9736. if (i<0 || i > 2) return; //Bug?
  9737. sd->feel_map[i].index = map[sd->bl.m].index;
  9738. sd->feel_map[i].m = sd->bl.m;
  9739. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  9740. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9741. // clif_misceffect2(&sd->bl, 0x1b0);
  9742. // clif_misceffect2(&sd->bl, 0x21f);
  9743. clif_feel_info(sd, i, 0);
  9744. sd->menuskill_val = sd->menuskill_id = 0;
  9745. }
  9746. /*==========================================
  9747. * Question about Star Glaldiator save map [Komurka]
  9748. *------------------------------------------*/
  9749. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9750. {
  9751. WFIFOHEAD(fd,packet_len(0x253));
  9752. WFIFOW(fd,0)=0x253;
  9753. WFIFOSET(fd, packet_len(0x253));
  9754. sd->menuskill_id = SG_FEEL;
  9755. sd->menuskill_val = skilllv;
  9756. }
  9757. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd)
  9758. {
  9759. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  9760. //Missing packets are the client's reply packets to the adopt request one.
  9761. //[Skotlex]
  9762. int account_id;
  9763. struct map_session_data *sd2;
  9764. account_id = RFIFOL(fd,2);
  9765. sd2 = map_id2sd(account_id);
  9766. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  9767. fd = sd2->fd;
  9768. WFIFOHEAD(fd,packet_len(0x1f9));
  9769. WFIFOW(fd,0)=0x1f9;
  9770. WFIFOSET(fd, packet_len(0x1f9));
  9771. }
  9772. }
  9773. /*==========================================
  9774. * Homunculus packets
  9775. *------------------------------------------*/
  9776. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9777. {
  9778. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9779. }
  9780. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9781. { //[orn]
  9782. nullpo_retv(sd);
  9783. if(!merc_is_hom_active(sd->hd))
  9784. return;
  9785. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  9786. }
  9787. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd)
  9788. { //[orn]
  9789. short x,y,cmd;
  9790. nullpo_retv(sd);
  9791. if(!merc_is_hom_active(sd->hd))
  9792. return;
  9793. cmd = RFIFOW(fd,0);
  9794. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  9795. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9796. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  9797. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9798. unit_walktoxy(&(sd->hd->bl),x,y,4);
  9799. }
  9800. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9801. { //[orn]
  9802. if(!merc_is_hom_active(sd->hd))
  9803. return;
  9804. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  9805. }
  9806. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9807. { //[orn]
  9808. int cmd;
  9809. cmd = RFIFOW(fd,0);
  9810. if(!merc_is_hom_active(sd->hd))
  9811. return;
  9812. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9813. }
  9814. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9815. {
  9816. int item_position;
  9817. nullpo_retv(sd);
  9818. item_position = pc_search_inventory(sd, 7621);
  9819. if (item_position < 0)
  9820. return;
  9821. if (!status_revive(&sd->bl, 100, 100))
  9822. return;
  9823. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9824. pc_delitem(sd, item_position, 1, 0);
  9825. }
  9826. #ifndef TXT_ONLY
  9827. /*==========================================
  9828. * MAIL SYSTEM
  9829. * By Zephyrus
  9830. *------------------------------------------
  9831. * Opens Mail Window on Client
  9832. *------------------------------------------*/
  9833. void clif_Mail_openmail(int fd)
  9834. {
  9835. WFIFOHEAD(fd,packet_len(0x260));
  9836. WFIFOW(fd,0) = 0x260;
  9837. WFIFOL(fd,2) = 0;
  9838. WFIFOSET(fd,packet_len(0x260));
  9839. }
  9840. /*------------------------------------------
  9841. * Send Inbox Data to Client
  9842. *------------------------------------------*/
  9843. void clif_Mail_refreshinbox(struct map_session_data *sd)
  9844. {
  9845. int fd = sd->fd;
  9846. struct mail_data *md = &sd->mail.inbox;
  9847. struct mail_message *msg;
  9848. int len, i, j;
  9849. len = 8 + (73 * md->amount);
  9850. WFIFOHEAD(fd,len);
  9851. WFIFOW(fd,0) = 0x240;
  9852. WFIFOW(fd,2) = len;
  9853. WFIFOL(fd,4) = md->amount;
  9854. for( i = j = 0; i < MAX_MAIL_INBOX && j < md->amount; i++ )
  9855. {
  9856. msg = &md->msg[i];
  9857. if (msg->id < 1)
  9858. continue; // Deleted Message
  9859. WFIFOL(fd,8+73*j) = msg->id;
  9860. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  9861. WFIFOB(fd,52+73*j) = msg->read;
  9862. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  9863. WFIFOL(fd,77+73*j) = msg->timestamp;
  9864. j++;
  9865. }
  9866. WFIFOSET(fd,len);
  9867. }
  9868. /*------------------------------------------
  9869. * Client Request Inbox List
  9870. *------------------------------------------*/
  9871. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  9872. {
  9873. struct mail_data *md;
  9874. nullpo_retv(sd);
  9875. md = &sd->mail.inbox;
  9876. if( md->amount < MAX_MAIL_INBOX && (md->satured || md->changed) )
  9877. intif_Mail_requestinbox(sd->status.char_id, 1);
  9878. else
  9879. clif_Mail_refreshinbox(sd);
  9880. mail_removeitem(sd, 0);
  9881. mail_removezeny(sd, 0);
  9882. }
  9883. /*------------------------------------------
  9884. * Read Message
  9885. *------------------------------------------*/
  9886. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  9887. {
  9888. int i, fd = sd->fd;
  9889. ARR_FIND(0, MAX_MAIL_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9890. if (i < MAX_MAIL_INBOX)
  9891. {
  9892. struct mail_message *msg = &sd->mail.inbox.msg[i];
  9893. struct item *item = &msg->item;
  9894. struct item_data *data;
  9895. int msg_len = strlen(msg->body), len;
  9896. if( msg_len == 0 ) {
  9897. strcpy(msg->body, "(no message)");
  9898. msg_len = strlen(msg->body);
  9899. }
  9900. len = 101 + msg_len;
  9901. WFIFOHEAD(fd,len);
  9902. WFIFOW(fd,0) = 0x242;
  9903. WFIFOW(fd,2) = len;
  9904. WFIFOL(fd,4) = msg->id;
  9905. memcpy(WFIFOP(fd, 8), msg->title, MAIL_TITLE_LENGTH);
  9906. memcpy(WFIFOP(fd,48), msg->send_name, NAME_LENGTH);
  9907. WFIFOL(fd,72) = 0;
  9908. WFIFOL(fd,76) = msg->zeny;
  9909. if (item->nameid)
  9910. {
  9911. WFIFOL(fd,80) = item->amount;
  9912. if ((data = itemdb_search(item->nameid)) != NULL)
  9913. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  9914. else
  9915. ShowWarning("clif_parse_Mail_read: Invalid attachment on message %d.\n", msg->id);
  9916. WFIFOW(fd,86) = data->type;
  9917. }
  9918. else
  9919. {
  9920. WFIFOL(fd,80) = 0;
  9921. WFIFOW(fd,84) = 0;
  9922. WFIFOW(fd,86) = 0;
  9923. }
  9924. WFIFOB(fd,88) = item->identify;
  9925. WFIFOB(fd,89) = item->attribute;
  9926. WFIFOB(fd,90) = item->refine;
  9927. WFIFOW(fd,91) = item->card[0];
  9928. WFIFOW(fd,93) = item->card[1];
  9929. WFIFOW(fd,95) = item->card[2];
  9930. WFIFOW(fd,97) = item->card[3];
  9931. WFIFOB(fd,99) = (unsigned char)msg_len;
  9932. memcpy(WFIFOP(fd,100), msg->body, msg_len);
  9933. WFIFOB(fd,len - 1) = 0x00;
  9934. WFIFOSET(fd,len);
  9935. if (!msg->read) {
  9936. msg->read = 1;
  9937. intif_Mail_read(mail_id);
  9938. clif_parse_Mail_refreshinbox(fd, sd);
  9939. }
  9940. }
  9941. else
  9942. ShowWarning("clif_parse_Mail_read: account %d trying to read a message not the inbox.\n", sd->status.account_id);
  9943. }
  9944. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  9945. {
  9946. nullpo_retv(sd);
  9947. clif_Mail_read(sd, RFIFOL(fd,2));
  9948. }
  9949. /*------------------------------------------
  9950. * Get Attachment from Message
  9951. *------------------------------------------*/
  9952. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  9953. {
  9954. int i, mail_id = RFIFOL(fd,2);
  9955. nullpo_retv(sd);
  9956. ARR_FIND(0, MAX_MAIL_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9957. if (i < MAX_MAIL_INBOX)
  9958. {
  9959. if (sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1))
  9960. return;
  9961. if (sd->mail.inbox.msg[i].item.nameid > 0)
  9962. {
  9963. struct item_data *data;
  9964. unsigned int weight;
  9965. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  9966. return;
  9967. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  9968. if (weight > sd->max_weight - sd->weight)
  9969. {
  9970. clif_displaymessage(fd, "Attachment to heavy for you...");
  9971. return;
  9972. }
  9973. }
  9974. sd->mail.inbox.msg[i].zeny = 0;
  9975. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  9976. clif_Mail_read(sd, mail_id);
  9977. // Send the request for Char Server to delete the attachment
  9978. // If it is done, the client will receive it.
  9979. intif_Mail_getattach(sd->status.char_id, mail_id);
  9980. }
  9981. }
  9982. /*------------------------------------------
  9983. * Delete Message
  9984. *------------------------------------------*/
  9985. void clif_Mail_delete(struct map_session_data *sd, int mail_id, short flag)
  9986. {
  9987. int fd = sd->fd;
  9988. if (!flag)
  9989. {
  9990. int i;
  9991. ARR_FIND(0, MAX_MAIL_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9992. if( i < MAX_MAIL_INBOX )
  9993. {
  9994. memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
  9995. sd->mail.inbox.amount--;
  9996. }
  9997. }
  9998. WFIFOHEAD(fd, packet_len(0x257));
  9999. WFIFOW(fd,0) = 0x257;
  10000. WFIFOL(fd,2) = mail_id;
  10001. WFIFOW(fd,6) = flag;
  10002. WFIFOSET(fd, packet_len(0x257));
  10003. if( !flag && sd->mail.inbox.satured )
  10004. intif_Mail_requestinbox(sd->status.char_id, 1); // Reload the Mail Inbox
  10005. }
  10006. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  10007. {
  10008. int i, mail_id = RFIFOL(fd,2);
  10009. nullpo_retv(sd);
  10010. ARR_FIND(0, MAX_MAIL_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10011. if (i < MAX_MAIL_INBOX)
  10012. {
  10013. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10014. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  10015. {
  10016. clif_Mail_delete(sd, mail_id, 1);
  10017. return;
  10018. }
  10019. intif_Mail_delete(sd->status.char_id, mail_id);
  10020. }
  10021. }
  10022. /*------------------------------------------
  10023. * You have Mail Message
  10024. *------------------------------------------*/
  10025. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  10026. {
  10027. WFIFOHEAD(fd,packet_len(0x24a));
  10028. WFIFOW(fd,0) = 0x24a;
  10029. WFIFOL(fd,2) = mail_id;
  10030. memcpy(WFIFOP(fd,6), sender, NAME_LENGTH);
  10031. memcpy(WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  10032. WFIFOSET(fd,packet_len(0x24a));
  10033. }
  10034. /*------------------------------------------
  10035. * Return Mail Message
  10036. *------------------------------------------*/
  10037. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  10038. {
  10039. int i, mail_id = RFIFOL(fd,2);
  10040. nullpo_retv(sd);
  10041. ARR_FIND(0, MAX_MAIL_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10042. if (i < MAX_MAIL_INBOX)
  10043. intif_Mail_return(sd->status.char_id, mail_id);
  10044. }
  10045. void clif_Mail_return(struct map_session_data *sd, int mail_id, int new_mail)
  10046. {
  10047. int fd = sd->fd;
  10048. if (new_mail > 0)
  10049. {
  10050. int i;
  10051. ARR_FIND(0, MAX_MAIL_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10052. if (i < MAX_MAIL_INBOX)
  10053. {
  10054. struct map_session_data *rd = map_charid2sd(sd->mail.inbox.msg[i].send_id);
  10055. if (rd)
  10056. {
  10057. char title[MAIL_TITLE_LENGTH];
  10058. snprintf(title, MAIL_TITLE_LENGTH, "RE:%s", sd->mail.inbox.msg[i].title);
  10059. rd->mail.inbox.changed = 1;
  10060. clif_Mail_new(rd->fd, new_mail, sd->status.name, title);
  10061. }
  10062. memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
  10063. sd->mail.inbox.amount--;
  10064. }
  10065. }
  10066. WFIFOHEAD(fd,packet_len(0x274));
  10067. WFIFOW(fd,0) = 0x274;
  10068. WFIFOL(fd,2) = mail_id;
  10069. WFIFOW(fd,6) = (new_mail > 0)?0:1;
  10070. WFIFOSET(fd,packet_len(0x274));
  10071. }
  10072. /*------------------------------------------
  10073. * Set Attachment
  10074. *------------------------------------------*/
  10075. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  10076. {
  10077. int idx = RFIFOW(fd,2), amount = RFIFOL(fd,4);
  10078. char flag;
  10079. nullpo_retv(sd);
  10080. if (idx < 0 || amount < 0)
  10081. return;
  10082. flag = mail_setitem(sd, idx, amount);
  10083. if (flag > -1)
  10084. {
  10085. WFIFOHEAD(fd,packet_len(0x245));
  10086. WFIFOW(fd,0) = 0x245;
  10087. WFIFOB(fd,2) = flag;
  10088. WFIFOSET(fd,packet_len(0x245));
  10089. }
  10090. }
  10091. /*------------------------------------------
  10092. * Mail Window Operation
  10093. *------------------------------------------*/
  10094. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  10095. {
  10096. int flag = RFIFOW(fd,2);
  10097. nullpo_retv(sd);
  10098. if (!flag || flag == 1)
  10099. mail_removeitem(sd, 0);
  10100. if (!flag || flag == 2)
  10101. mail_removezeny(sd, 0);
  10102. }
  10103. /*------------------------------------------
  10104. * Send Mail
  10105. *------------------------------------------*/
  10106. void clif_Mail_send(int fd, unsigned char flag)
  10107. {
  10108. WFIFOHEAD(fd,packet_len(0x249));
  10109. WFIFOW(fd,0) = 0x249;
  10110. WFIFOB(fd,2) = flag;
  10111. WFIFOSET(fd,packet_len(0x249));
  10112. }
  10113. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  10114. {
  10115. struct map_session_data *rd;
  10116. struct mail_message *msg;
  10117. int body_len;
  10118. nullpo_retv(sd);
  10119. if( RFIFOW(fd,2) < 69 ) {
  10120. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  10121. return;
  10122. }
  10123. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  10124. {
  10125. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  10126. clif_Mail_send(fd, 1);
  10127. return;
  10128. }
  10129. body_len = RFIFOB(fd,68);
  10130. rd = map_nick2sd_nocase(RFIFOP(fd,4));
  10131. if (rd && rd == sd) {
  10132. clif_Mail_send(fd, 1);
  10133. mail_removeitem(sd,0);
  10134. mail_removezeny(sd,0);
  10135. return;
  10136. }
  10137. if (body_len > MAIL_BODY_LENGTH)
  10138. body_len = MAIL_BODY_LENGTH;
  10139. msg = (struct mail_message*)aCalloc(sizeof(struct mail_message), 1);
  10140. if (mail_getattach(sd, msg))
  10141. {
  10142. msg->send_id = sd->status.char_id;
  10143. safestrncpy(msg->send_name, sd->status.name, NAME_LENGTH);
  10144. if (rd) {
  10145. msg->dest_id = rd->status.char_id;
  10146. safestrncpy(msg->dest_name, rd->status.name, NAME_LENGTH);
  10147. } else {
  10148. msg->dest_id = 0;
  10149. safestrncpy(msg->dest_name, RFIFOP(fd,4), NAME_LENGTH);
  10150. }
  10151. memcpy(msg->title, RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  10152. if (body_len)
  10153. memcpy(msg->body, RFIFOP(fd,69), body_len);
  10154. else
  10155. memset(msg->body, 0x00, MAIL_BODY_LENGTH);
  10156. msg->timestamp = (int)mail_calctimes();
  10157. intif_Mail_send(sd->status.account_id, msg);
  10158. sd->cansendmail_tick = gettick() + 1000; // 5 Seconds flood Protection
  10159. }
  10160. else
  10161. {
  10162. mail_removeitem(sd,0);
  10163. mail_removezeny(sd,0);
  10164. clif_Mail_send(sd->fd, 1); // Fail
  10165. }
  10166. aFree(msg);
  10167. }
  10168. #endif
  10169. /*==========================================
  10170. * パケットデバッグ
  10171. *------------------------------------------*/
  10172. void clif_parse_debug(int fd,struct map_session_data *sd)
  10173. {
  10174. int i, cmd, len;
  10175. cmd = RFIFOW(fd,0);
  10176. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10177. ShowDebug("packet debug 0x%4X\n",cmd);
  10178. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10179. for(i=0;i<len;i++){
  10180. if((i&15)==0)
  10181. printf("\n%04X ",i);
  10182. printf("%02X ",RFIFOB(fd,i));
  10183. }
  10184. printf("\n");
  10185. }
  10186. /*==========================================
  10187. * Main client packet processing function
  10188. *------------------------------------------*/
  10189. int clif_parse(int fd)
  10190. {
  10191. int cmd, packet_ver, packet_len, err;
  10192. TBL_PC* sd;
  10193. int pnum;
  10194. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  10195. // Note: "click masters" can do 80+ clicks in 10 seconds
  10196. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  10197. { // begin main client packet processing loop
  10198. sd = (TBL_PC *)session[fd]->session_data;
  10199. if (session[fd]->eof) {
  10200. if (sd) {
  10201. if (sd->state.autotrade) {
  10202. //Disassociate character from the socket connection.
  10203. session[fd]->session_data = NULL;
  10204. sd->fd = 0;
  10205. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10206. } else
  10207. if (sd->state.auth) {
  10208. // Player logout display [Valaris]
  10209. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10210. clif_quitsave(fd, sd);
  10211. } else {
  10212. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n", sd->bl.id, sd->status.char_id);
  10213. map_quit(sd);
  10214. }
  10215. } else {
  10216. uint32 ip = session[fd]->client_addr;
  10217. ShowInfo("Closed connection from '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", CONVIP(ip));
  10218. }
  10219. do_close(fd);
  10220. return 0;
  10221. }
  10222. if (RFIFOREST(fd) < 2)
  10223. return 0;
  10224. cmd = RFIFOW(fd,0);
  10225. // identify client's packet version
  10226. if (sd) {
  10227. packet_ver = sd->packet_ver;
  10228. } else {
  10229. // check authentification packet to know packet version
  10230. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10231. if( err )
  10232. {// failed to identify packet version
  10233. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10234. err == 1 ? "" :
  10235. err == 2 ? ", possibly for having an invalid account_id" :
  10236. err == 3 ? ", possibly for having an invalid char_id." :
  10237. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10238. err == 4 ? ", possibly for having an invalid login_id1." :
  10239. err == 5 ? ", possibly for having an invalid client_tick." :
  10240. */
  10241. err == 6 ? ", possibly for having an invalid sex." :
  10242. ". ERROR invalid error code"));
  10243. WFIFOHEAD(fd,packet_len(0x6a));
  10244. WFIFOW(fd,0) = 0x6a;
  10245. WFIFOB(fd,2) = 3; // Rejected from Server
  10246. WFIFOSET(fd,packet_len(0x6a));
  10247. RFIFOSKIP(fd, RFIFOREST(fd));
  10248. clif_setwaitclose(fd);
  10249. return 0;
  10250. }
  10251. }
  10252. // filter out invalid / unsupported packets
  10253. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  10254. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10255. set_eof(fd);
  10256. return 0;
  10257. }
  10258. // determine real packet length
  10259. packet_len = packet_db[packet_ver][cmd].len;
  10260. if (packet_len == -1) { // variable-length packet
  10261. if (RFIFOREST(fd) < 4)
  10262. return 0;
  10263. packet_len = RFIFOW(fd,2);
  10264. if (packet_len < 4 || packet_len > 32768) {
  10265. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10266. set_eof(fd);
  10267. return 0;
  10268. }
  10269. }
  10270. if ((int)RFIFOREST(fd) < packet_len)
  10271. return 0; // not enough data received to form the packet
  10272. if (sd && sd->state.waitingdisconnect == 1) {
  10273. // 切断待ちの場合パケットを処理しない
  10274. } else if (packet_db[packet_ver][cmd].func) {
  10275. if (sd && sd->bl.prev == NULL &&
  10276. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10277. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10278. else
  10279. if (sd
  10280. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10281. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10282. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10283. packet_db[packet_ver][cmd].func(fd, sd);
  10284. }
  10285. #if DUMP_UNKNOWN_PACKET
  10286. else if (battle_config.error_log)
  10287. {
  10288. int i;
  10289. FILE *fp;
  10290. char packet_txt[256] = "save/packet.txt";
  10291. time_t now;
  10292. dump = 1;
  10293. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10294. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10295. return 1;
  10296. } else {
  10297. time(&now);
  10298. if (sd && sd->state.auth) {
  10299. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10300. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10301. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10302. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10303. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10304. for(i = 0; i < packet_len; i++) {
  10305. if ((i & 15) == 0)
  10306. fprintf(fp, "\n\t%04X ", i);
  10307. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10308. }
  10309. fprintf(fp, "\n\n");
  10310. fclose(fp);
  10311. }
  10312. }
  10313. #endif
  10314. /* TODO: use utils.c :: dump()
  10315. if (dump) {
  10316. int i;
  10317. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10318. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10319. for(i = 0; i < packet_len; i++) {
  10320. if ((i & 15) == 0)
  10321. printf("\n%04X ",i);
  10322. printf("%02X ", RFIFOB(fd,i));
  10323. }
  10324. printf("\n");
  10325. if (sd && sd->state.auth) {
  10326. if (sd->status.name != NULL)
  10327. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10328. sd->status.account_id, sd->status.char_id, sd->status.name);
  10329. else
  10330. printf("\nAccount ID %d.\n", sd->bl.id);
  10331. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10332. printf("\nAccount ID %d.\n", sd->bl.id);
  10333. }*/
  10334. RFIFOSKIP(fd, packet_len);
  10335. }; // main loop end
  10336. return 0;
  10337. }
  10338. /*==========================================
  10339. * パケットデータベース読み込み
  10340. *------------------------------------------*/
  10341. static int packetdb_readdb(void)
  10342. {
  10343. FILE *fp;
  10344. char line[1024];
  10345. int ln=0;
  10346. int cmd,i,j,packet_ver;
  10347. int max_cmd=-1;
  10348. int skip_ver = 0;
  10349. int warned = 0;
  10350. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10351. int packet_len_table[MAX_PACKET_DB] = {
  10352. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10356. //#0x0040
  10357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10359. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10360. #if PACKETVER < 2
  10361. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10362. #else // 78-7b 亀島以降 lv99エフェクト用
  10363. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10364. #endif
  10365. //#0x0080
  10366. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10367. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10368. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10369. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10370. //#0x00C0
  10371. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10372. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10373. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10374. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10375. //#0x0100
  10376. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10377. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10378. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10379. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10380. //#0x0140
  10381. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10382. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10383. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10384. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10385. //#0x0180
  10386. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10387. #if PACKETVER < 1
  10388. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10389. #else // 196 comodo以降 状態表示アイコン用
  10390. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10391. #endif
  10392. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10393. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10394. //#0x01C0, Set 0x1d5=-1
  10395. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10396. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10397. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10398. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10399. //#0x0200
  10400. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10401. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  10402. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10403. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  10404. //#0x0240
  10405. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  10406. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  10407. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10408. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10409. //#0x0280
  10410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  10411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10413. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  10414. //#0x02C0
  10415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10419. };
  10420. struct {
  10421. void (*func)(int, struct map_session_data *);
  10422. char *name;
  10423. } clif_parse_func[]={
  10424. {clif_parse_WantToConnection,"wanttoconnection"},
  10425. {clif_parse_LoadEndAck,"loadendack"},
  10426. {clif_parse_TickSend,"ticksend"},
  10427. {clif_parse_WalkToXY,"walktoxy"},
  10428. {clif_parse_QuitGame,"quitgame"},
  10429. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10430. {clif_parse_GlobalMessage,"globalmessage"},
  10431. {clif_parse_MapMove,"mapmove"},
  10432. {clif_parse_ChangeDir,"changedir"},
  10433. {clif_parse_Emotion,"emotion"},
  10434. {clif_parse_HowManyConnections,"howmanyconnections"},
  10435. {clif_parse_ActionRequest,"actionrequest"},
  10436. {clif_parse_Restart,"restart"},
  10437. {clif_parse_WisMessage,"wis"},
  10438. {clif_parse_GMmessage,"gmmessage"},
  10439. {clif_parse_TakeItem,"takeitem"},
  10440. {clif_parse_DropItem,"dropitem"},
  10441. {clif_parse_UseItem,"useitem"},
  10442. {clif_parse_EquipItem,"equipitem"},
  10443. {clif_parse_UnequipItem,"unequipitem"},
  10444. {clif_parse_NpcClicked,"npcclicked"},
  10445. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10446. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10447. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10448. {clif_parse_CreateChatRoom,"createchatroom"},
  10449. {clif_parse_ChatAddMember,"chataddmember"},
  10450. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10451. {clif_parse_ChangeChatOwner,"changechatowner"},
  10452. {clif_parse_KickFromChat,"kickfromchat"},
  10453. {clif_parse_ChatLeave,"chatleave"},
  10454. {clif_parse_TradeRequest,"traderequest"},
  10455. {clif_parse_TradeAck,"tradeack"},
  10456. {clif_parse_TradeAddItem,"tradeadditem"},
  10457. {clif_parse_TradeOk,"tradeok"},
  10458. {clif_parse_TradeCancel,"tradecancel"},
  10459. {clif_parse_TradeCommit,"tradecommit"},
  10460. {clif_parse_StopAttack,"stopattack"},
  10461. {clif_parse_PutItemToCart,"putitemtocart"},
  10462. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10463. {clif_parse_RemoveOption,"removeoption"},
  10464. {clif_parse_ChangeCart,"changecart"},
  10465. {clif_parse_StatusUp,"statusup"},
  10466. {clif_parse_SkillUp,"skillup"},
  10467. {clif_parse_UseSkillToId,"useskilltoid"},
  10468. {clif_parse_UseSkillToPos,"useskilltopos"},
  10469. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10470. {clif_parse_UseSkillMap,"useskillmap"},
  10471. {clif_parse_RequestMemo,"requestmemo"},
  10472. {clif_parse_ProduceMix,"producemix"},
  10473. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10474. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10475. {clif_parse_NpcAmountInput,"npcamountinput"},
  10476. {clif_parse_NpcStringInput,"npcstringinput"},
  10477. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10478. {clif_parse_ItemIdentify,"itemidentify"},
  10479. {clif_parse_SelectArrow,"selectarrow"},
  10480. {clif_parse_AutoSpell,"autospell"},
  10481. {clif_parse_UseCard,"usecard"},
  10482. {clif_parse_InsertCard,"insertcard"},
  10483. {clif_parse_RepairItem,"repairitem"},
  10484. {clif_parse_WeaponRefine,"weaponrefine"},
  10485. {clif_parse_SolveCharName,"solvecharname"},
  10486. {clif_parse_ResetChar,"resetchar"},
  10487. {clif_parse_LGMmessage,"lgmmessage"},
  10488. {clif_parse_MoveToKafra,"movetokafra"},
  10489. {clif_parse_MoveFromKafra,"movefromkafra"},
  10490. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10491. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10492. {clif_parse_CloseKafra,"closekafra"},
  10493. {clif_parse_CreateParty,"createparty"},
  10494. {clif_parse_CreateParty2,"createparty2"},
  10495. {clif_parse_PartyInvite,"partyinvite"},
  10496. {clif_parse_PartyInvite2,"partyinvite2"},
  10497. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10498. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  10499. {clif_parse_LeaveParty,"leaveparty"},
  10500. {clif_parse_RemovePartyMember,"removepartymember"},
  10501. {clif_parse_PartyChangeOption,"partychangeoption"},
  10502. {clif_parse_PartyMessage,"partymessage"},
  10503. {clif_parse_CloseVending,"closevending"},
  10504. {clif_parse_VendingListReq,"vendinglistreq"},
  10505. {clif_parse_PurchaseReq,"purchasereq"},
  10506. {clif_parse_OpenVending,"openvending"},
  10507. {clif_parse_CreateGuild,"createguild"},
  10508. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10509. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10510. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10511. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10512. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10513. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10514. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10515. {clif_parse_GuildInvite,"guildinvite"},
  10516. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10517. {clif_parse_GuildLeave,"guildleave"},
  10518. {clif_parse_GuildExpulsion,"guildexplusion"},
  10519. {clif_parse_GuildMessage,"guildmessage"},
  10520. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10521. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10522. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10523. {clif_parse_GuildOpposition,"guildopposition"},
  10524. {clif_parse_GuildBreak,"guildbreak"},
  10525. {clif_parse_PetMenu,"petmenu"},
  10526. {clif_parse_CatchPet,"catchpet"},
  10527. {clif_parse_SelectEgg,"selectegg"},
  10528. {clif_parse_SendEmotion,"sendemotion"},
  10529. {clif_parse_ChangePetName,"changepetname"},
  10530. {clif_parse_GMKick,"gmkick"},
  10531. {clif_parse_GMHide,"gmhide"},
  10532. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10533. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10534. {clif_parse_NoviceDoriDori,"sndoridori"},
  10535. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10536. {clif_parse_PMIgnore,"wisexin"},
  10537. {clif_parse_PMIgnoreList,"wisexlist"},
  10538. {clif_parse_PMIgnoreAll,"wisall"},
  10539. {clif_parse_FriendsListAdd,"friendslistadd"},
  10540. {clif_parse_FriendsListRemove,"friendslistremove"},
  10541. {clif_parse_FriendsListReply,"friendslistreply"},
  10542. {clif_parse_GMKillAll,"killall"},
  10543. {clif_parse_Recall,"summon"},
  10544. {clif_parse_GM_Monster_Item,"itemmonster"},
  10545. {clif_parse_Shift,"shift"},
  10546. {clif_parse_Blacksmith,"blacksmith"},
  10547. {clif_parse_Alchemist,"alchemist"},
  10548. {clif_parse_Taekwon,"taekwon"},
  10549. {clif_parse_RankingPk,"rankingpk"},
  10550. {clif_parse_FeelSaveOk,"feelsaveok"},
  10551. {clif_parse_AdoptRequest,"adopt"},
  10552. {clif_parse_debug,"debug"},
  10553. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10554. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10555. {clif_parse_HomMoveTo,"hommoveto"},
  10556. {clif_parse_HomAttack,"homattack"},
  10557. {clif_parse_HomMenu,"hommenu"},
  10558. {clif_parse_StoragePassword,"storagepassword"},
  10559. {clif_parse_Hotkey,"hotkey"},
  10560. {clif_parse_AutoRevive,"autorevive"},
  10561. #ifndef TXT_ONLY
  10562. // MAIL SYSTEM
  10563. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  10564. {clif_parse_Mail_read,"mailread"},
  10565. {clif_parse_Mail_getattach,"mailgetattach"},
  10566. {clif_parse_Mail_delete,"maildelete"},
  10567. {clif_parse_Mail_return,"mailreturn"},
  10568. {clif_parse_Mail_setattach,"mailsetattach"},
  10569. {clif_parse_Mail_winopen,"mailwinopen"},
  10570. {clif_parse_Mail_send,"mailsend"},
  10571. #endif
  10572. {NULL,NULL}
  10573. };
  10574. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  10575. memset(packet_db,0,sizeof(packet_db));
  10576. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  10577. packet_len(i) = packet_len_table[i];
  10578. sprintf(line, "%s/packet_db.txt", db_path);
  10579. if( (fp=fopen(line,"r"))==NULL ){
  10580. ShowFatalError("can't read %s\n", line);
  10581. exit(EXIT_FAILURE);
  10582. }
  10583. clif_config.packet_db_ver = MAX_PACKET_VER;
  10584. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10585. while( fgets(line, sizeof(line), fp) )
  10586. {
  10587. ln++;
  10588. if(line[0]=='/' && line[1]=='/')
  10589. continue;
  10590. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  10591. {
  10592. if(strcmpi(w1,"packet_ver")==0) {
  10593. int prev_ver = packet_ver;
  10594. skip_ver = 0;
  10595. packet_ver = atoi(w2);
  10596. if ( packet_ver > MAX_PACKET_VER )
  10597. { //Check to avoid overflowing. [Skotlex]
  10598. if( (warned&1) == 0 )
  10599. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10600. warned &= 1;
  10601. skip_ver = 1;
  10602. }
  10603. else if( packet_ver < 0 )
  10604. {
  10605. if( (warned&2) == 0 )
  10606. ShowWarning("Negative packet versions are not supported.\n");
  10607. warned &= 2;
  10608. skip_ver = 1;
  10609. }
  10610. else if( packet_ver == SERVER )
  10611. {
  10612. if( (warned&4) == 0 )
  10613. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10614. warned &= 4;
  10615. skip_ver = 1;
  10616. }
  10617. if( skip_ver )
  10618. {
  10619. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10620. packet_ver = prev_ver;
  10621. continue;
  10622. }
  10623. // copy from previous version into new version and continue
  10624. // - indicating all following packets should be read into the newer version
  10625. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10626. continue;
  10627. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10628. if(strcmpi(w2,"default")==0) //This is the preferred version.
  10629. clif_config.packet_db_ver = MAX_PACKET_VER;
  10630. else // to manually set the packet DB version
  10631. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  10632. continue;
  10633. }
  10634. }
  10635. if( skip_ver != 0 )
  10636. continue; // Skipping current packet version
  10637. memset(str,0,sizeof(str));
  10638. for(j=0,p=line;j<4 && p; ++j)
  10639. {
  10640. str[j]=p;
  10641. p=strchr(p,',');
  10642. if(p) *p++=0;
  10643. }
  10644. if(str[0]==NULL)
  10645. continue;
  10646. cmd=strtol(str[0],(char **)NULL,0);
  10647. if(max_cmd < cmd)
  10648. max_cmd = cmd;
  10649. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  10650. continue;
  10651. if(str[1]==NULL){
  10652. ShowError("packet_db: packet len error\n");
  10653. continue;
  10654. }
  10655. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  10656. if(str[2]==NULL){
  10657. packet_db[packet_ver][cmd].func = NULL;
  10658. ln++;
  10659. continue;
  10660. }
  10661. for(j=0;j<ARRAYLENGTH(clif_parse_func);j++){
  10662. if(clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0)
  10663. {
  10664. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10665. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10666. for(i=0;i<=MAX_PACKET_DB;i++){
  10667. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10668. {
  10669. memset(&packet_db[packet_ver][i], 0, sizeof(struct s_packet_db));
  10670. break;
  10671. }
  10672. }
  10673. }
  10674. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10675. break;
  10676. }
  10677. }
  10678. // set the identifying cmd for the packet_db version
  10679. if (strcmp(str[2],"wanttoconnection")==0)
  10680. clif_config.connect_cmd[packet_ver] = cmd;
  10681. if(str[3]==NULL){
  10682. ShowError("packet_db: packet error\n");
  10683. exit(EXIT_FAILURE);
  10684. }
  10685. for(j=0,p2=str[3];p2;j++){
  10686. short k;
  10687. str2[j]=p2;
  10688. p2=strchr(p2,':');
  10689. if(p2) *p2++=0;
  10690. k = atoi(str2[j]);
  10691. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10692. packet_db[packet_ver][cmd].pos[j] = k;
  10693. }
  10694. }
  10695. fclose(fp);
  10696. if(max_cmd > MAX_PACKET_DB)
  10697. {
  10698. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10699. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10700. }
  10701. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10702. { //Locate the nearest version that we still support. [Skotlex]
  10703. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10704. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10705. }
  10706. ShowStatus("Done reading packet database from '"CL_WHITE"%s"CL_RESET"'. Using default packet version: "CL_WHITE"%d"CL_RESET".\n", "packet_db.txt", clif_config.packet_db_ver);
  10707. return 0;
  10708. }
  10709. /*==========================================
  10710. *
  10711. *------------------------------------------*/
  10712. int do_init_clif(void)
  10713. {
  10714. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10715. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10716. memset(packet_db,0,sizeof(packet_db));
  10717. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10718. packetdb_readdb();
  10719. set_defaultparse(clif_parse);
  10720. if (!make_listen_bind(bind_ip,map_port)) {
  10721. ShowFatalError("can't bind game port\n");
  10722. exit(EXIT_FAILURE);
  10723. }
  10724. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10725. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  10726. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10727. return 0;
  10728. }