clif.c 319 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #define DUMP_UNKNOWN_PACKET 0
  4. #define DUMP_ALL_PACKETS 0
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdarg.h>
  10. #include <time.h>
  11. #include "../common/cbasetypes.h"
  12. #include "../common/socket.h"
  13. #include "../common/timer.h"
  14. #include "../common/malloc.h"
  15. #include "../common/version.h"
  16. #include "../common/nullpo.h"
  17. #include "../common/showmsg.h"
  18. #include "map.h"
  19. #include "chrif.h"
  20. #include "clif.h"
  21. #include "pc.h"
  22. #include "status.h"
  23. #include "npc.h"
  24. #include "itemdb.h"
  25. #include "chat.h"
  26. #include "trade.h"
  27. #include "storage.h"
  28. #include "script.h"
  29. #include "skill.h"
  30. #include "atcommand.h"
  31. #include "charcommand.h"
  32. #include "intif.h"
  33. #include "battle.h"
  34. #include "mob.h"
  35. #include "party.h"
  36. #include "unit.h"
  37. #include "guild.h"
  38. #include "vending.h"
  39. #include "pet.h"
  40. #include "mercenary.h" //[orn]
  41. #include "log.h"
  42. #include "irc.h"
  43. struct Clif_Config {
  44. int packet_db_ver; //Preferred packet version.
  45. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  46. } clif_config;
  47. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
  48. //Converts item type in case of pet eggs.
  49. #define itemtype(a) (a == 7)?4:a
  50. #define WBUFPOS(p,pos,x,y,dir) \
  51. do { \
  52. uint8 *__p = (p); \
  53. __p+=(pos); \
  54. __p[0] = (uint8)((x)>>2); \
  55. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  56. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  57. } while(0)
  58. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  59. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  60. do { \
  61. uint8 *__p = (p); \
  62. __p+=(pos); \
  63. __p[0]=(uint8)((x0)>>2); \
  64. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  65. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  66. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  67. __p[4]=(uint8)(y1); \
  68. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  69. } while(0)
  70. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  71. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  72. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  73. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  74. //Removed sd->npc_shopid because there is no packet sent from the client when you cancel a buy!
  75. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  76. #define clif_cant_act(sd) (sd->npc_id || sd->vender_id || sd->chatID || sd->sc.opt1 || sd->state.trading || sd->state.storage_flag)
  77. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  78. #define clif_trading(sd) (sd->npc_id || sd->vender_id || sd->state.trading )
  79. //To idenfity disguised characters.
  80. #define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
  81. static char map_ip_str[128];
  82. static in_addr_t map_ip;
  83. static in_addr_t bind_ip = INADDR_ANY;
  84. static int map_port = 5121;
  85. int map_fd;
  86. char talkie_mes[MESSAGE_SIZE];
  87. //These two will be used to verify the incoming player's validity.
  88. //It helps identify their client packet version correctly. [Skotlex]
  89. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  90. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  91. int clif_parse (int fd);
  92. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  93. /*==========================================
  94. * map鯖のip設定
  95. *------------------------------------------
  96. */
  97. int clif_setip(char *ip)
  98. {
  99. char ip_str[16];
  100. map_ip = resolve_hostbyname(ip,NULL,ip_str);
  101. if (!map_ip) {
  102. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  103. return 0;
  104. }
  105. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  106. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str);
  107. return 1;
  108. }
  109. void clif_setbindip(char *ip)
  110. {
  111. unsigned char ip_str[4];
  112. bind_ip = resolve_hostbyname(ip,ip_str,NULL);
  113. if (bind_ip) {
  114. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip, ip_str[0], ip_str[1], ip_str[2], ip_str[3]);
  115. } else {
  116. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  117. }
  118. }
  119. /*==========================================
  120. * map鯖のport設定
  121. *------------------------------------------
  122. */
  123. void clif_setport(int port)
  124. {
  125. map_port = port;
  126. }
  127. /*==========================================
  128. * map鯖のip読み出し
  129. *------------------------------------------
  130. */
  131. in_addr_t clif_getip(void)
  132. {
  133. return map_ip;
  134. }
  135. //Returns the ip casted as a basic type, to avoid needing to include the socket/net related libs by calling modules.
  136. unsigned long clif_getip_long(void)
  137. {
  138. return (unsigned long)map_ip;
  139. }
  140. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it
  141. //returns 0.
  142. unsigned long clif_refresh_ip(void) {
  143. in_addr_t new_ip;
  144. new_ip = resolve_hostbyname(map_ip_str, NULL, NULL);
  145. if (new_ip && new_ip != map_ip) {
  146. map_ip = new_ip;
  147. ShowInfo("Updating IP resolution of [%s].\n",map_ip_str);
  148. return (unsigned long)map_ip;
  149. }
  150. return 0;
  151. }
  152. /*==========================================
  153. * map鯖のport読み出し
  154. *------------------------------------------
  155. */
  156. int clif_getport(void)
  157. {
  158. return map_port;
  159. }
  160. /*==========================================
  161. * Counts connected players.
  162. *------------------------------------------
  163. */
  164. int clif_countusers(void)
  165. {
  166. int users = 0, i;
  167. struct map_session_data *sd;
  168. for(i = 0; i < fd_max; i++) {
  169. if (session[i] && session[i]->func_parse == clif_parse &&
  170. (sd = (struct map_session_data*)session[i]->session_data) &&
  171. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  172. users++;
  173. }
  174. return users;
  175. }
  176. /*==========================================
  177. * 全てのclientに対してfunc()実行
  178. *------------------------------------------
  179. */
  180. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  181. {
  182. int i;
  183. va_list ap;
  184. struct map_session_data *sd;
  185. va_start(ap,func);
  186. for(i = 0; i < fd_max; i++) {
  187. if ( session[i] && session[i]->func_parse == clif_parse) {
  188. sd = (struct map_session_data*)session[i]->session_data;
  189. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  190. func(sd, ap);
  191. }
  192. }
  193. va_end(ap);
  194. return 0;
  195. }
  196. /*==========================================
  197. * clif_sendでAREA*指定時用
  198. *------------------------------------------
  199. */
  200. int clif_send_sub(struct block_list *bl, va_list ap)
  201. {
  202. struct block_list *src_bl;
  203. struct map_session_data *sd;
  204. unsigned char *buf;
  205. int len, type, fd;
  206. nullpo_retr(0, bl);
  207. nullpo_retr(0, ap);
  208. nullpo_retr(0, sd = (struct map_session_data *)bl);
  209. fd = sd->fd;
  210. if (!fd) //Don't send to disconnected clients.
  211. return 0;
  212. buf = va_arg(ap,unsigned char*);
  213. len = va_arg(ap,int);
  214. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  215. type = va_arg(ap,int);
  216. switch(type) {
  217. case AREA_WOS:
  218. if (bl == src_bl)
  219. return 0;
  220. break;
  221. case AREA_WOC:
  222. if (sd->chatID || bl == src_bl)
  223. return 0;
  224. break;
  225. case AREA_WOSC:
  226. {
  227. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  228. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  229. return 0;
  230. }
  231. break;
  232. }
  233. if (session[fd] != NULL) {
  234. WFIFOHEAD(fd, len);
  235. if (WFIFOP(fd,0) == buf) {
  236. printf("WARNING: Invalid use of clif_send function\n");
  237. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  238. printf(" Please correct your code.\n");
  239. // don't send to not move the pointer of the packet for next sessions in the loop
  240. WFIFOSET(fd,0);//## TODO is this ok?
  241. } else {
  242. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  243. memcpy(WFIFOP(fd,0), buf, len);
  244. WFIFOSET(fd,len);
  245. }
  246. }
  247. }
  248. return 0;
  249. }
  250. /*==========================================
  251. *
  252. *------------------------------------------
  253. */
  254. int clif_send (unsigned char *buf, int len, struct block_list *bl, int type) {
  255. int i;
  256. struct map_session_data *sd = NULL;
  257. struct party_data *p = NULL;
  258. struct guild *g = NULL;
  259. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  260. if (type != ALL_CLIENT &&
  261. type != CHAT_MAINCHAT) {
  262. nullpo_retr(0, bl);
  263. if (bl->type == BL_PC) {
  264. sd = (struct map_session_data *)bl;
  265. }
  266. }
  267. switch(type) {
  268. case ALL_CLIENT: //All player clients.
  269. for (i = 0; i < fd_max; i++) {
  270. if (session[i] && session[i]->func_parse == clif_parse &&
  271. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  272. sd->state.auth) {
  273. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  274. WFIFOHEAD(i, len);
  275. memcpy(WFIFOP(i,0), buf, len);
  276. WFIFOSET(i,len);
  277. }
  278. }
  279. }
  280. break;
  281. case ALL_SAMEMAP: //All players on the same map
  282. for(i = 0; i < fd_max; i++) {
  283. if (session[i] && session[i]->func_parse == clif_parse &&
  284. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  285. sd->state.auth && sd->bl.m == bl->m) {
  286. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  287. WFIFOHEAD(i,len);
  288. memcpy(WFIFOP(i,0), buf, len);
  289. WFIFOSET(i,len);
  290. }
  291. }
  292. }
  293. break;
  294. case AREA:
  295. case AREA_WOSC:
  296. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  297. clif_send (buf, len, bl, SELF);
  298. case AREA_WOC:
  299. case AREA_WOS:
  300. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  301. BL_PC, buf, len, bl, type);
  302. break;
  303. case AREA_CHAT_WOC:
  304. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  305. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  306. break;
  307. case CHAT:
  308. case CHAT_WOS:
  309. {
  310. struct chat_data *cd;
  311. if (sd) {
  312. cd = (struct chat_data*)map_id2bl(sd->chatID);
  313. } else if (bl->type == BL_CHAT) {
  314. cd = (struct chat_data*)bl;
  315. } else break;
  316. if (cd == NULL)
  317. break;
  318. for(i = 0; i < cd->users; i++) {
  319. if (type == CHAT_WOS && cd->usersd[i] == sd)
  320. continue;
  321. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  322. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  323. {
  324. WFIFOHEAD(fd,len);
  325. memcpy(WFIFOP(fd,0), buf, len);
  326. WFIFOSET(fd,len);
  327. }
  328. }
  329. }
  330. }
  331. break;
  332. case CHAT_MAINCHAT: //[LuzZza]
  333. for(i=1; i<fd_max; i++) {
  334. if (session[i] && session[i]->func_parse == clif_parse &&
  335. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  336. sd->state.mainchat && (fd=sd->fd))
  337. {
  338. WFIFOHEAD(fd,len);
  339. memcpy(WFIFOP(fd,0), buf, len);
  340. WFIFOSET(fd, len);
  341. }
  342. }
  343. break;
  344. case PARTY_AREA:
  345. case PARTY_AREA_WOS:
  346. x0 = bl->x - AREA_SIZE;
  347. y0 = bl->y - AREA_SIZE;
  348. x1 = bl->x + AREA_SIZE;
  349. y1 = bl->y + AREA_SIZE;
  350. case PARTY:
  351. case PARTY_WOS:
  352. case PARTY_SAMEMAP:
  353. case PARTY_SAMEMAP_WOS:
  354. if (sd && sd->status.party_id)
  355. p = party_search(sd->status.party_id);
  356. if (p) {
  357. for(i=0;i<MAX_PARTY;i++){
  358. if ((sd = p->data[i].sd) == NULL)
  359. continue;
  360. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  361. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  362. continue;
  363. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  364. continue;
  365. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  366. continue;
  367. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  368. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  369. continue;
  370. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  371. WFIFOHEAD(fd,len);
  372. memcpy(WFIFOP(fd,0), buf, len);
  373. WFIFOSET(fd,len);
  374. }
  375. }
  376. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  377. break;
  378. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  379. if (session[i] && session[i]->func_parse == clif_parse &&
  380. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  381. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  382. {
  383. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  384. WFIFOHEAD(fd,len);
  385. memcpy(WFIFOP(fd,0), buf, len);
  386. WFIFOSET(fd,len);
  387. }
  388. }
  389. }
  390. }
  391. break;
  392. case DUEL:
  393. case DUEL_WOS:
  394. if (!sd || !sd->duel_group) break; //Invalid usage.
  395. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  396. for (i = 0; i < fd_max; i++) {
  397. if (session[i] && session[i]->func_parse == clif_parse &&
  398. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  399. sd->state.auth && sd->duel_group == x0) {
  400. if (type == DUEL_WOS && bl->id == sd->bl.id)
  401. continue;
  402. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  403. WFIFOHEAD(i, len);
  404. memcpy(WFIFOP(i,0), buf, len);
  405. WFIFOSET(i,len);
  406. }
  407. }
  408. }
  409. break;
  410. case SELF:
  411. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  412. WFIFOHEAD(fd,len);
  413. memcpy(WFIFOP(fd,0), buf, len);
  414. WFIFOSET(fd,len);
  415. }
  416. break;
  417. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  418. case GUILD_AREA:
  419. case GUILD_AREA_WOS:
  420. x0 = bl->x - AREA_SIZE;
  421. y0 = bl->y - AREA_SIZE;
  422. x1 = bl->x + AREA_SIZE;
  423. y1 = bl->y + AREA_SIZE;
  424. case GUILD_SAMEMAP:
  425. case GUILD_SAMEMAP_WOS:
  426. case GUILD:
  427. case GUILD_WOS:
  428. if (sd && sd->status.guild_id)
  429. g = guild_search(sd->status.guild_id);
  430. if (g) {
  431. for(i = 0; i < g->max_member; i++) {
  432. if ((sd = g->member[i].sd) != NULL) {
  433. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  434. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  435. continue;
  436. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  437. continue;
  438. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  439. continue;
  440. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  441. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  442. continue;
  443. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  444. WFIFOHEAD(fd,len);
  445. memcpy(WFIFOP(fd,0), buf, len);
  446. WFIFOSET(fd,len);
  447. }
  448. }
  449. }
  450. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  451. break;
  452. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  453. if (session[i] && session[i]->func_parse == clif_parse &&
  454. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  455. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  456. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  457. WFIFOHEAD(fd,len);
  458. memcpy(WFIFOP(fd,0), buf, len);
  459. WFIFOSET(fd,len);
  460. }
  461. }
  462. }
  463. }
  464. break;
  465. /* End [Valaris] */
  466. default:
  467. if (battle_config.error_log)
  468. ShowError("clif_send: Unrecognized type %d\n",type);
  469. return -1;
  470. }
  471. return 0;
  472. }
  473. //
  474. // パケット作って送信
  475. //
  476. /*==========================================
  477. *
  478. *------------------------------------------
  479. */
  480. int clif_authok(struct map_session_data *sd) {
  481. int fd;
  482. if (!sd->fd)
  483. return 0;
  484. fd = sd->fd;
  485. WFIFOHEAD(fd, packet_len(0x73));
  486. WFIFOW(fd, 0) = 0x73;
  487. WFIFOL(fd, 2) = gettick();
  488. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  489. WFIFOB(fd, 9) = 5; // ignored
  490. WFIFOB(fd,10) = 5; // ignored
  491. WFIFOSET(fd,packet_len(0x73));
  492. return 0;
  493. }
  494. /*==========================================
  495. * Authentication failed/disconnect client.
  496. *------------------------------------------
  497. * The client closes it's socket and displays a message according to type:
  498. * 1 - server closed -> MsgStringTable[4]
  499. * 2 - ID already logged in -> MsgStringTable[5]
  500. * 3 - timeout/too much lag -> MsgStringTable[241]
  501. * 4 - server full -> MsgStringTable[264]
  502. * 5 - underaged -> MsgStringTable[305]
  503. * 9 - too many connections from this ip -> MsgStringTable[529]
  504. * 10 - payed time has ended -> MsgStringTable[530]
  505. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  506. * other - disconnected -> MsgStringTable[3]
  507. */
  508. int clif_authfail_fd(int fd, int type) {
  509. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  510. return 0;
  511. WFIFOHEAD(fd, packet_len(0x81));
  512. WFIFOW(fd,0) = 0x81;
  513. WFIFOB(fd,2) = type;
  514. WFIFOSET(fd,packet_len(0x81));
  515. clif_setwaitclose(fd);
  516. return 0;
  517. }
  518. /*==========================================
  519. * Used to know which is the max valid account/char id [Skotlex]
  520. *------------------------------------------
  521. */
  522. void clif_updatemaxid(int account_id, int char_id)
  523. {
  524. max_account_id = account_id;
  525. max_char_id = char_id;
  526. }
  527. /*==========================================
  528. *
  529. *------------------------------------------
  530. */
  531. int clif_charselectok(int id) {
  532. struct map_session_data *sd;
  533. int fd;
  534. if ((sd = map_id2sd(id)) == NULL)
  535. return 1;
  536. if (!sd->fd)
  537. return 1;
  538. fd = sd->fd;
  539. WFIFOHEAD(fd, packet_len(0xb3));
  540. WFIFOW(fd,0) = 0xb3;
  541. WFIFOB(fd,2) = 1;
  542. WFIFOSET(fd,packet_len(0xb3));
  543. return 0;
  544. }
  545. /*==========================================
  546. *
  547. *------------------------------------------
  548. */
  549. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  550. int view;
  551. nullpo_retr(0, fitem);
  552. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  553. WBUFW(buf, 0) = 0x9e;
  554. WBUFL(buf, 2) = fitem->bl.id;
  555. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  556. WBUFW(buf, 6) = view;
  557. else
  558. WBUFW(buf, 6) = fitem->item_data.nameid;
  559. WBUFB(buf, 8) = fitem->item_data.identify;
  560. WBUFW(buf, 9) = fitem->bl.x;
  561. WBUFW(buf,11) = fitem->bl.y;
  562. WBUFB(buf,13) = fitem->subx;
  563. WBUFB(buf,14) = fitem->suby;
  564. WBUFW(buf,15) = fitem->item_data.amount;
  565. return packet_len(0x9e);
  566. }
  567. /*==========================================
  568. *
  569. *------------------------------------------
  570. */
  571. int clif_dropflooritem(struct flooritem_data *fitem) {
  572. unsigned char buf[64];
  573. nullpo_retr(0, fitem);
  574. if (fitem->item_data.nameid <= 0)
  575. return 0;
  576. clif_set009e(fitem, buf);
  577. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  578. return 0;
  579. }
  580. /*==========================================
  581. *
  582. *------------------------------------------
  583. */
  584. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  585. unsigned char buf[16];
  586. nullpo_retr(0, fitem);
  587. WBUFW(buf,0) = 0xa1;
  588. WBUFL(buf,2) = fitem->bl.id;
  589. if (fd == 0) {
  590. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  591. } else {
  592. WFIFOHEAD(fd,packet_len(0xa1));
  593. memcpy(WFIFOP(fd,0), buf, 6);
  594. WFIFOSET(fd,packet_len(0xa1));
  595. }
  596. return 0;
  597. }
  598. /*==========================================
  599. *
  600. *------------------------------------------
  601. */
  602. int clif_clearchar(struct block_list *bl, int type) {
  603. unsigned char buf[16];
  604. nullpo_retr(0, bl);
  605. WBUFW(buf,0) = 0x80;
  606. WBUFL(buf,2) = bl->id;
  607. WBUFB(buf,6) = type;
  608. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  609. if(disguised(bl)) {
  610. WBUFL(buf,2) = -bl->id;
  611. clif_send(buf, packet_len(0x80), bl, SELF);
  612. }
  613. return 0;
  614. }
  615. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  616. struct block_list *bl = (struct block_list *)id;
  617. clif_clearchar(bl,data);
  618. aFree(bl);
  619. return 0;
  620. }
  621. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  622. struct block_list *tbl;
  623. tbl = aMalloc(sizeof (struct block_list));
  624. memcpy (tbl, bl, sizeof (struct block_list));
  625. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  626. return 0;
  627. }
  628. /*==========================================
  629. *
  630. *------------------------------------------
  631. */
  632. int clif_clearchar_id(int id, int type, int fd) {
  633. WFIFOHEAD(fd, packet_len(0x80));
  634. WFIFOW(fd,0) = 0x80;
  635. WFIFOL(fd,2) = id;
  636. WFIFOB(fd,6) = (char)type; // Why use int for a char in the first place?
  637. WFIFOSET(fd, packet_len(0x80));
  638. return 0;
  639. }
  640. void clif_get_weapon_view(TBL_PC* sd, unsigned short *rhand, unsigned short *lhand)
  641. {
  642. #if PACKETVER > 3
  643. struct item_data *id;
  644. #endif
  645. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  646. {
  647. *rhand = *lhand = 0;
  648. return;
  649. }
  650. #if PACKETVER < 4
  651. *rhand = sd->status.weapon;
  652. *lhand = sd->status.shield;
  653. #else
  654. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  655. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  656. {
  657. id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  658. if (id->view_id > 0)
  659. *rhand = id->view_id;
  660. else
  661. *rhand = id->nameid;
  662. } else
  663. *rhand = 0;
  664. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  665. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  666. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  667. {
  668. id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  669. if (id->view_id > 0)
  670. *lhand = id->view_id;
  671. else
  672. *lhand = id->nameid;
  673. } else
  674. *lhand = 0;
  675. #endif
  676. }
  677. static void clif_get_guild_data(struct block_list *bl, long *guild_id, short *emblem_id)
  678. {
  679. //TODO: There has to be a way to clean this up.
  680. switch (bl->type) {
  681. case BL_PC:
  682. *guild_id = ((TBL_PC*)bl)->status.guild_id;
  683. *emblem_id = ((TBL_PC*)bl)->guild_emblem_id;
  684. break;
  685. case BL_MOB:
  686. if (((TBL_MOB*)bl)->guardian_data) {
  687. *guild_id =((TBL_MOB*)bl)->guardian_data->guild_id;
  688. *emblem_id =((TBL_MOB*)bl)->guardian_data->emblem_id;
  689. }
  690. break;
  691. case BL_NPC:
  692. if (bl->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) {
  693. struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id);
  694. if (g) {
  695. *guild_id =g->guild_id;
  696. *emblem_id =g->emblem_id;
  697. }
  698. }
  699. break;
  700. default:
  701. *guild_id = status_get_guild_id(bl);
  702. }
  703. return;
  704. }
  705. /*==========================================
  706. *
  707. *------------------------------------------
  708. */
  709. static int clif_set0078(struct block_list *bl, struct view_data *vd, unsigned char *buf) {
  710. struct status_change *sc;
  711. struct map_session_data *sd;
  712. long guild_id=0;
  713. unsigned short emblem_id=0, lv;
  714. unsigned short dir;
  715. nullpo_retr(0, bl);
  716. BL_CAST(BL_PC, bl, sd);
  717. sc = status_get_sc(bl);
  718. clif_get_guild_data(bl, &guild_id, &emblem_id);
  719. dir = unit_getdir(bl);
  720. lv = status_get_lv(bl);
  721. if(pcdb_checkid(vd->class_)) {
  722. #if PACKETVER > 6
  723. memset(buf,0,packet_len(0x22a));
  724. WBUFW(buf,0)=0x22a;
  725. WBUFL(buf,2)=bl->id;
  726. WBUFW(buf,6)=status_get_speed(bl);
  727. if (sc) {
  728. WBUFW(buf,8)=sc->opt1;
  729. WBUFW(buf,10)=sc->opt2;
  730. WBUFL(buf,12)=sc->option;
  731. WBUFL(buf,44)=sc->opt3;
  732. }
  733. WBUFW(buf,16)=vd->class_;
  734. WBUFW(buf,18)=vd->hair_style;
  735. WBUFW(buf,20)=vd->weapon;
  736. WBUFW(buf,22)=vd->shield;
  737. WBUFW(buf,24)=vd->head_bottom;
  738. WBUFW(buf,26)=vd->head_top;
  739. WBUFW(buf,28)=vd->head_mid;
  740. WBUFW(buf,30)=vd->hair_color;
  741. WBUFW(buf,32)=vd->cloth_color;
  742. WBUFW(buf,34)=sd?sd->head_dir:0;
  743. WBUFL(buf,36)=guild_id;
  744. WBUFW(buf,40)=emblem_id;
  745. if (sd) {
  746. WBUFW(buf,42)=sd->status.manner;
  747. WBUFB(buf,48)=sd->status.karma;
  748. }
  749. WBUFB(buf,49)=vd->sex;
  750. WBUFPOS(buf,50,bl->x,bl->y,dir);
  751. WBUFB(buf,53)=5;
  752. WBUFB(buf,54)=5;
  753. WBUFB(buf,55)=vd->dead_sit;
  754. WBUFW(buf,56)=clif_setlevel(lv);
  755. return packet_len(0x22a);
  756. #elif PACKETVER > 3
  757. memset(buf,0,packet_len(0x1d8));
  758. WBUFW(buf,0)=0x1d8;
  759. WBUFL(buf,2)=bl->id;
  760. WBUFW(buf,6)=status_get_speed(bl);
  761. if (sc) {
  762. WBUFW(buf,8)=sc->opt1;
  763. WBUFW(buf,10)=sc->opt2;
  764. WBUFW(buf,12)=sc->option;
  765. WBUFW(buf,42)=sc->opt3;
  766. }
  767. WBUFW(buf,14)=vd->class_;
  768. WBUFW(buf,16)=vd->hair_style;
  769. WBUFW(buf,18)=vd->weapon;
  770. WBUFW(buf,20)=vd->shield;
  771. WBUFW(buf,22)=vd->head_bottom;
  772. WBUFW(buf,24)=vd->head_top;
  773. WBUFW(buf,26)=vd->head_mid;
  774. WBUFW(buf,28)=vd->hair_color;
  775. WBUFW(buf,30)=vd->cloth_color;
  776. WBUFW(buf,32)=sd?sd->head_dir:0;
  777. WBUFL(buf,34)=guild_id;
  778. WBUFW(buf,38)=emblem_id;
  779. if (sd) {
  780. WBUFW(buf,40)=sd->status.manner;
  781. WBUFB(buf,44)=sd->status.karma;
  782. }
  783. WBUFB(buf,45)=vd->sex;
  784. WBUFPOS(buf,46,bl->x,bl->y,dir);
  785. WBUFB(buf,49)=5;
  786. WBUFB(buf,50)=5;
  787. WBUFB(buf,51)=vd->dead_sit;
  788. WBUFW(buf,52)=clif_setlevel(lv);
  789. return packet_len(0x1d8);
  790. #else
  791. memset(buf,0,packet_len(0x78));
  792. WBUFW(buf,0)=0x78;
  793. WBUFL(buf,2)=bl->id;
  794. WBUFW(buf,6)=status_get_speed(bl);
  795. if (sc) {
  796. WBUFW(buf,8)=sc->opt1;
  797. WBUFW(buf,10)=sc->opt2;
  798. WBUFW(buf,12)=sc->option;
  799. WBUFW(buf,42)=sc->opt3;
  800. }
  801. WBUFW(buf,14)=vd->class_;
  802. WBUFW(buf,16)=vd->hair_style;
  803. WBUFW(buf,18)=vd->weapon;
  804. WBUFW(buf,20)=vd->head_bottom;
  805. WBUFW(buf,22)=vd->shield;
  806. WBUFW(buf,24)=vd->head_top;
  807. WBUFW(buf,26)=vd->head_mid;
  808. WBUFW(buf,28)=vd->hair_color;
  809. WBUFW(buf,30)=vd->cloth_color;
  810. WBUFW(buf,32)=sd?sd->head_dir:0;
  811. WBUFL(buf,34)=guild_id;
  812. WBUFL(buf,38)=emblem_id;
  813. if (sd)
  814. WBUFB(buf,44)=sd->status.karma;
  815. WBUFB(buf,45)=vd->sex;
  816. WBUFPOS(buf,46,bl->x,bl->y,dir);
  817. WBUFB(buf,49)=5;
  818. WBUFB(buf,50)=5;
  819. WBUFB(buf,51)=vd->dead_sit;
  820. WBUFW(buf,52)=clif_setlevel(lv);
  821. return packet_len(0x78);
  822. #endif
  823. }
  824. //Non-player sprites need just a few fields filled.
  825. memset(buf,0,packet_len(0x78));
  826. WBUFW(buf,0)=0x78;
  827. WBUFL(buf,2)=bl->id;
  828. WBUFW(buf,6)=status_get_speed(bl);
  829. if (sc) {
  830. WBUFW(buf,8)=sc->opt1;
  831. WBUFW(buf,10)=sc->opt2;
  832. WBUFW(buf,12)=sc->option;
  833. WBUFW(buf,42)=sc->opt3;
  834. }
  835. WBUFW(buf,14)=vd->class_;
  836. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  837. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  838. if (bl->type == BL_NPC && vd->class_ == 722)
  839. { //The hell, why flags work like this?
  840. WBUFL(buf,22)=emblem_id;
  841. WBUFL(buf,26)=guild_id;
  842. }
  843. WBUFW(buf,32)=dir;
  844. WBUFL(buf,34)=guild_id;
  845. WBUFL(buf,38)=emblem_id;
  846. WBUFPOS(buf,46,bl->x,bl->y,dir);
  847. WBUFB(buf,49)=5;
  848. WBUFB(buf,50)=5;
  849. WBUFW(buf,52)=clif_setlevel(lv);
  850. return packet_len(0x78);
  851. }
  852. /*==========================================
  853. *
  854. *------------------------------------------
  855. */
  856. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf) {
  857. struct status_change *sc;
  858. struct map_session_data *sd;
  859. long guild_id=0;
  860. unsigned short emblem_id=0, lv;
  861. nullpo_retr(0, bl);
  862. BL_CAST(BL_PC, bl, sd);
  863. sc = status_get_sc(bl);
  864. clif_get_guild_data(bl, &guild_id, &emblem_id);
  865. lv = status_get_lv(bl);
  866. if(pcdb_checkid(vd->class_)) {
  867. #if PACKETVER > 6
  868. memset(buf,0,packet_len(0x22c));
  869. WBUFW(buf,0)=0x22c;
  870. WBUFL(buf,2)=bl->id;
  871. WBUFW(buf,6)=status_get_speed(bl);
  872. if (sc) {
  873. WBUFW(buf,8)= sc->opt1;
  874. WBUFW(buf,10)= sc->opt2;
  875. WBUFL(buf,12)= sc->option;
  876. WBUFL(buf,48)= sc->opt3;
  877. }
  878. WBUFW(buf,16)=vd->class_;
  879. WBUFW(buf,18)=vd->hair_style;
  880. WBUFW(buf,20)=vd->weapon;
  881. WBUFW(buf,22)=vd->shield;
  882. WBUFW(buf,24)=vd->head_bottom;
  883. WBUFL(buf,26)=gettick();
  884. WBUFW(buf,30)=vd->head_top;
  885. WBUFW(buf,32)=vd->head_mid;
  886. WBUFW(buf,34)=vd->hair_color;
  887. WBUFW(buf,36)=vd->cloth_color;
  888. WBUFW(buf,38)=sd?sd->head_dir:0;
  889. WBUFL(buf,40)=guild_id;
  890. WBUFW(buf,44)=emblem_id;
  891. if (sd) {
  892. WBUFW(buf,46)=sd->status.manner;
  893. WBUFB(buf,52)=sd->status.karma;
  894. }
  895. WBUFB(buf,53)=vd->sex;
  896. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  897. WBUFB(buf,60)=0;
  898. WBUFB(buf,61)=0;
  899. WBUFW(buf,62)=clif_setlevel(lv);
  900. return packet_len(0x22c);
  901. #elif PACKETVER > 3
  902. memset(buf,0,packet_len(0x1da));
  903. WBUFW(buf,0)=0x1da;
  904. WBUFL(buf,2)=bl->id;
  905. WBUFW(buf,6)=status_get_speed(bl);
  906. if (sc) {
  907. WBUFW(buf,8)=sc->opt1;
  908. WBUFW(buf,10)=sc->opt2;
  909. WBUFW(buf,12)=sc->option;
  910. WBUFW(buf,46)=sc->opt3;
  911. }
  912. WBUFW(buf,14)=vd->class_;
  913. WBUFW(buf,16)=vd->hair_style;
  914. WBUFW(buf,18)=vd->weapon;
  915. WBUFW(buf,20)=vd->shield;
  916. WBUFW(buf,22)=vd->head_bottom;
  917. WBUFL(buf,24)=gettick();
  918. WBUFW(buf,28)=vd->head_top;
  919. WBUFW(buf,30)=vd->head_mid;
  920. WBUFW(buf,32)=vd->hair_color;
  921. WBUFW(buf,34)=vd->cloth_color;
  922. WBUFW(buf,36)=sd?sd->head_dir:0;
  923. WBUFL(buf,38)=guild_id;
  924. WBUFW(buf,42)=emblem_id;
  925. if (sd) {
  926. WBUFW(buf,44)=sd->status.manner;
  927. WBUFB(buf,48)=sd->status.karma;
  928. }
  929. WBUFB(buf,49)=vd->sex;
  930. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  931. WBUFB(buf,56)=5;
  932. WBUFB(buf,57)=5;
  933. WBUFW(buf,58)=clif_setlevel(lv);
  934. return packet_len(0x1da);
  935. #else
  936. memset(buf,0,packet_len(0x7b));
  937. WBUFW(buf,0)=0x7b;
  938. WBUFL(buf,2)=bl->id;
  939. WBUFW(buf,6)=status_get_speed(bl);
  940. if (sc) {
  941. WBUFW(buf,8)=sc->opt1;
  942. WBUFW(buf,10)=sc->opt2;
  943. WBUFW(buf,12)=sc->option;
  944. WBUFW(buf,46)=sc->opt3;
  945. }
  946. WBUFW(buf,14)=vd->class_;
  947. WBUFW(buf,16)=vd->hair_style;
  948. WBUFW(buf,18)=vd->weapon;
  949. WBUFW(buf,20)=vd->head_bottom;
  950. WBUFL(buf,22)=gettick();
  951. WBUFW(buf,26)=vd->shield;
  952. WBUFW(buf,28)=vd->head_top;
  953. WBUFW(buf,30)=vd->head_mid;
  954. WBUFW(buf,32)=vd->hair_color;
  955. WBUFW(buf,34)=vd->cloth_color;
  956. WBUFW(buf,36)=sd?sd->head_dir:0;
  957. WBUFL(buf,38)=guild_id;
  958. WBUFL(buf,42)=emblem_id;
  959. if (sd)
  960. WBUFB(buf,48)=sd->status.karma;
  961. WBUFB(buf,49)=vd->sex;
  962. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  963. WBUFB(buf,56)=5;
  964. WBUFB(buf,57)=5;
  965. WBUFW(buf,58)=clif_setlevel(lv);
  966. return packet_len(0x7b);
  967. #endif
  968. }
  969. //Non-player sprites only require a few fields.
  970. #if PACKETVER > 6
  971. memset(buf,0,packet_len(0x22c));
  972. WBUFW(buf,0)=0x22c;
  973. WBUFL(buf,2)=bl->id;
  974. WBUFW(buf,6)=status_get_speed(bl);
  975. if (sc) {
  976. WBUFW(buf,8)=sc->opt1;
  977. WBUFW(buf,10)=sc->opt2;
  978. WBUFL(buf,12)=sc->option;
  979. WBUFL(buf,48)=sc->opt3;
  980. }
  981. WBUFW(buf,16)=vd->class_;
  982. WBUFW(buf,18)=vd->hair_style; //For pets
  983. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  984. WBUFL(buf,26)=gettick();
  985. WBUFW(buf,38)=unit_getdir(bl);
  986. WBUFL(buf,40)=guild_id;
  987. WBUFL(buf,44)=emblem_id;
  988. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  989. WBUFB(buf,60)=0;
  990. WBUFB(buf,61)=0;
  991. WBUFW(buf,62)=clif_setlevel(lv);
  992. return packet_len(0x22c);
  993. #else
  994. memset(buf,0,packet_len(0x7b));
  995. WBUFW(buf,0)=0x7b;
  996. WBUFL(buf,2)=bl->id;
  997. WBUFW(buf,6)=status_get_speed(bl);
  998. if (sc) {
  999. WBUFW(buf,8)=sc->opt1;
  1000. WBUFW(buf,10)=sc->opt2;
  1001. WBUFW(buf,12)=sc->option;
  1002. WBUFW(buf,46)=sc->opt3;
  1003. }
  1004. WBUFW(buf,14)=vd->class_;
  1005. WBUFW(buf,16)=vd->hair_style; //For pets
  1006. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  1007. WBUFL(buf,22)=gettick();
  1008. WBUFW(buf,36)=unit_getdir(bl);
  1009. WBUFL(buf,38)=guild_id;
  1010. WBUFL(buf,42)=emblem_id;
  1011. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1012. WBUFB(buf,56)=5;
  1013. WBUFB(buf,57)=5;
  1014. WBUFW(buf,58)=clif_setlevel(lv);
  1015. return packet_len(0x7b);
  1016. #endif
  1017. }
  1018. //Modifies the buffer for disguise characters and sends it to self.
  1019. //Flag = 0: change id to negative, buf will have disguise data.
  1020. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1021. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1022. //But no longer holds true for those packet of PACKETVER 7.
  1023. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag) {
  1024. if (flag) {
  1025. #if PACKETVER > 6
  1026. switch (WBUFW(buf,0)) {
  1027. case 0x22c:
  1028. case 0x22b:
  1029. case 0x22a:
  1030. WBUFL(buf,12)=OPTION_INVISIBLE;
  1031. WBUFW(buf,16)=sd->status.class_;
  1032. break;
  1033. default:
  1034. #endif
  1035. WBUFL(buf,2)=sd->bl.id;
  1036. WBUFW(buf,12)=OPTION_INVISIBLE;
  1037. WBUFW(buf,14)=sd->status.class_;
  1038. #if PACKETVER > 6
  1039. break;
  1040. }
  1041. #endif
  1042. } else {
  1043. WBUFL(buf,2)=-sd->bl.id;
  1044. }
  1045. clif_send(buf, len, &sd->bl, SELF);
  1046. }
  1047. /*==========================================
  1048. * クラスチェンジ typeはMobの場合は1で他は0?
  1049. *------------------------------------------
  1050. */
  1051. int clif_class_change(struct block_list *bl,int class_,int type)
  1052. {
  1053. unsigned char buf[16];
  1054. nullpo_retr(0, bl);
  1055. if(!pcdb_checkid(class_)) {
  1056. WBUFW(buf,0)=0x1b0;
  1057. WBUFL(buf,2)=bl->id;
  1058. WBUFB(buf,6)=type;
  1059. WBUFL(buf,7)=class_;
  1060. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1061. }
  1062. return 0;
  1063. }
  1064. /*==========================================
  1065. *
  1066. *------------------------------------------
  1067. */
  1068. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1069. {
  1070. WFIFOHEAD(fd, packet_len(0x1e1));
  1071. WFIFOW(fd,0)=0x1e1;
  1072. WFIFOL(fd,2)=sd->bl.id;
  1073. WFIFOW(fd,6)=sd->spiritball;
  1074. WFIFOSET(fd, packet_len(0x1e1));
  1075. }
  1076. /*==========================================
  1077. *
  1078. *------------------------------------------
  1079. */
  1080. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1081. WFIFOHEAD(fd, packet_len(0x192));
  1082. WFIFOW(fd,0) = 0x192;
  1083. WFIFOW(fd,2) = x;
  1084. WFIFOW(fd,4) = y;
  1085. WFIFOW(fd,6) = type;
  1086. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1087. WFIFOSET(fd,packet_len(0x192));
  1088. return 0;
  1089. }
  1090. // new and improved weather display [Valaris]
  1091. static void clif_weather_sub(int fd, int id, int type) {
  1092. WFIFOHEAD(fd, packet_len(0x1f3));
  1093. WFIFOW(fd,0) = 0x1f3;
  1094. WFIFOL(fd,2) = id;
  1095. WFIFOL(fd,6) = type;
  1096. WFIFOSET(fd,packet_len(0x1f3));
  1097. }
  1098. /*==========================================
  1099. *
  1100. *------------------------------------------
  1101. */
  1102. static void clif_weather_check(struct map_session_data *sd) {
  1103. int m = sd->bl.m, fd = sd->fd;
  1104. if (map[m].flag.snow
  1105. || map[m].flag.clouds
  1106. || map[m].flag.fog
  1107. || map[m].flag.fireworks
  1108. || map[m].flag.sakura
  1109. || map[m].flag.leaves
  1110. || map[m].flag.rain
  1111. || map[m].flag.clouds2)
  1112. {
  1113. if (map[m].flag.snow)
  1114. clif_weather_sub(fd, sd->bl.id, 162);
  1115. if (map[m].flag.clouds)
  1116. clif_weather_sub(fd, sd->bl.id, 233);
  1117. if (map[m].flag.clouds2)
  1118. clif_weather_sub(fd, sd->bl.id, 516);
  1119. if (map[m].flag.fog)
  1120. clif_weather_sub(fd, sd->bl.id, 515);
  1121. if (map[m].flag.fireworks) {
  1122. clif_weather_sub(fd, sd->bl.id, 297);
  1123. clif_weather_sub(fd, sd->bl.id, 299);
  1124. clif_weather_sub(fd, sd->bl.id, 301);
  1125. }
  1126. if (map[m].flag.sakura)
  1127. clif_weather_sub(fd, sd->bl.id, 163);
  1128. if (map[m].flag.leaves)
  1129. clif_weather_sub(fd, sd->bl.id, 333);
  1130. if (map[m].flag.rain)
  1131. clif_weather_sub(fd, sd->bl.id, 161);
  1132. }
  1133. }
  1134. int clif_weather(int m) {
  1135. int i;
  1136. struct map_session_data *sd=NULL;
  1137. for(i = 0; i < fd_max; i++) {
  1138. if (session[i] && session[i]->func_parse == clif_parse &&
  1139. (sd = session[i]->session_data) != NULL &&
  1140. sd->state.auth && sd->bl.m == m) {
  1141. clif_weather_check(sd);
  1142. }
  1143. }
  1144. return 0;
  1145. }
  1146. int clif_spawn(struct block_list *bl)
  1147. {
  1148. unsigned char buf[128];
  1149. struct view_data *vd;
  1150. nullpo_retr(0, bl);
  1151. vd = status_get_viewdata(bl);
  1152. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1153. return 0;
  1154. if (pcdb_checkid(vd->class_))
  1155. { //Player spawn packet.
  1156. clif_set0078(bl, vd, buf);
  1157. switch(WBUFW(buf,0)) {
  1158. case 0x78: //Convert to 0x79
  1159. WBUFW(buf, 0) = 0x79;
  1160. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1161. clif_send(buf, packet_len(0x79), bl, AREA_WOS);
  1162. if (disguised(bl))
  1163. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x79), 0);
  1164. break;
  1165. #if PACKETVER > 3
  1166. case 0x1d8: //Convert to 0x1d9
  1167. WBUFW(buf, 0) = 0x1d9;
  1168. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1169. clif_send(buf, packet_len(0x1d9), bl, AREA_WOS);
  1170. if (disguised(bl))
  1171. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x1d9), 0);
  1172. break;
  1173. #endif
  1174. #if PACKETVER > 6
  1175. case 0x22a: //Convert to 0x22b
  1176. WBUFW(buf, 0) = 0x22b;
  1177. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1178. clif_send(buf, packet_len(0x22b), bl, AREA_WOS);
  1179. if (disguised(bl))
  1180. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x22b), 0);
  1181. break;
  1182. #endif
  1183. }
  1184. } else { //Mob spawn packet.
  1185. struct status_change *sc = status_get_sc(bl);
  1186. memset(buf,0,sizeof(buf));
  1187. WBUFW(buf,0)=0x7c;
  1188. WBUFL(buf,2)=bl->id;
  1189. WBUFW(buf,6)=status_get_speed(bl);
  1190. if (sc) {
  1191. WBUFW(buf,8)=sc->opt1;
  1192. WBUFW(buf,10)=sc->opt2;
  1193. WBUFW(buf,12)=sc->option;
  1194. }
  1195. WBUFW(buf,20)=vd->class_;
  1196. WBUFW(buf,22)=vd->hair_style; //Required for pets.
  1197. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  1198. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1199. clif_send(buf,packet_len(0x7c),bl,AREA_WOS);
  1200. if (disguised(bl)) {
  1201. WBUFL(buf,2)=-bl->id;
  1202. clif_send(buf,packet_len(0x7c),bl,SELF);
  1203. }
  1204. }
  1205. if (vd->cloth_color)
  1206. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1207. switch (bl->type)
  1208. {
  1209. case BL_PC:
  1210. {
  1211. TBL_PC *sd = ((TBL_PC*)bl);
  1212. if (sd->spiritball > 0)
  1213. clif_spiritball(sd);
  1214. if(sd->state.size==2) // tiny/big players [Valaris]
  1215. clif_specialeffect(bl,423,AREA);
  1216. else if(sd->state.size==1)
  1217. clif_specialeffect(bl,421,AREA);
  1218. }
  1219. break;
  1220. case BL_MOB:
  1221. {
  1222. TBL_MOB *md = ((TBL_MOB*)bl);
  1223. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1224. clif_specialeffect(&md->bl,423,AREA);
  1225. else if(md->special_state.size==1)
  1226. clif_specialeffect(&md->bl,421,AREA);
  1227. }
  1228. break;
  1229. }
  1230. return 0;
  1231. }
  1232. //[orn]
  1233. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1234. {
  1235. struct status_data *status;
  1236. unsigned char buf[128];
  1237. nullpo_retr(0, hd);
  1238. status = &hd->battle_status;
  1239. memset(buf,0,packet_len(0x22e));
  1240. WBUFW(buf,0)=0x22e;
  1241. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1242. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1243. WBUFB(buf,26)=hd->homunculus.rename_flag | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1244. WBUFW(buf,27)=hd->homunculus.level;
  1245. WBUFW(buf,29)=hd->homunculus.hunger;
  1246. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1247. WBUFW(buf,33)=0; // equip id
  1248. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1249. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1250. WBUFW(buf,39)=status->hit;
  1251. if (battle_config.hom_setting&0x10)
  1252. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1253. else
  1254. WBUFW(buf,41)=status->cri/10;
  1255. WBUFW(buf,43)=status->def + status->vit ;
  1256. WBUFW(buf,45)=status->mdef;
  1257. WBUFW(buf,47)=status->flee;
  1258. WBUFW(buf,49)=(flag)?0:status->amotion;
  1259. if (status->max_hp > SHRT_MAX) {
  1260. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1261. WBUFW(buf,53) = 100;
  1262. } else {
  1263. WBUFW(buf,51)=status->hp;
  1264. WBUFW(buf,53)=status->max_hp;
  1265. }
  1266. if (status->max_sp > SHRT_MAX) {
  1267. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1268. WBUFW(buf,57) = 100;
  1269. } else {
  1270. WBUFW(buf,55)=status->sp;
  1271. WBUFW(buf,57)=status->max_sp;
  1272. }
  1273. WBUFL(buf,59)=hd->homunculus.exp;
  1274. WBUFL(buf,63)=hd->exp_next;
  1275. WBUFW(buf,67)=hd->homunculus.skillpts;
  1276. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1277. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1278. return 0;
  1279. }
  1280. void clif_send_homdata(struct map_session_data *sd, int type, int param) { //[orn]
  1281. int fd = sd->fd;
  1282. WFIFOHEAD(fd, packet_len(0x230));
  1283. nullpo_retv(sd->hd);
  1284. WFIFOW(fd,0)=0x230;
  1285. WFIFOW(fd,2)=type;
  1286. WFIFOL(fd,4)=sd->hd->bl.id;
  1287. WFIFOL(fd,8)=param;
  1288. WFIFOSET(fd,packet_len(0x230));
  1289. return;
  1290. }
  1291. int clif_homskillinfoblock(struct map_session_data *sd) { //[orn]
  1292. struct homun_data *hd;
  1293. int fd = sd->fd;
  1294. int i,j,len=4,id;
  1295. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1296. hd = sd->hd;
  1297. if ( !hd )
  1298. return 0 ;
  1299. WFIFOW(fd,0)=0x235;
  1300. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1301. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1302. j = id - HM_SKILLBASE - 1 ;
  1303. WFIFOW(fd,len ) = id ;
  1304. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1305. WFIFOW(fd,len+4) = 0 ;
  1306. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1307. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1308. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1309. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1310. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1311. len+=37;
  1312. }
  1313. }
  1314. WFIFOW(fd,2)=len;
  1315. WFIFOSET(fd,len);
  1316. return 0;
  1317. }
  1318. void clif_homskillup(struct map_session_data *sd, int skill_num) { //[orn]
  1319. struct homun_data *hd;
  1320. int fd=sd->fd, skillid;
  1321. WFIFOHEAD(fd, packet_len(0x239));
  1322. nullpo_retv(sd);
  1323. skillid = skill_num - HM_SKILLBASE - 1;
  1324. hd=sd->hd;
  1325. WFIFOW(fd,0) = 0x239;
  1326. WFIFOW(fd,2) = skill_num;
  1327. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1328. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1329. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1330. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1331. WFIFOSET(fd,packet_len(0x239));
  1332. return;
  1333. }
  1334. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd) { //[orn]
  1335. struct homun_data *hd;
  1336. RFIFOHEAD(fd);
  1337. nullpo_retv(sd);
  1338. if((hd=sd->hd) == NULL)
  1339. return;
  1340. memcpy(hd->homunculus.name,RFIFOP(fd,2),24);
  1341. hd->homunculus.rename_flag = 1;
  1342. clif_hominfo(sd,hd,0);
  1343. clif_charnameack(sd->fd,&hd->bl);
  1344. }
  1345. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd) { //[orn]
  1346. nullpo_retv(sd);
  1347. if(!merc_is_hom_active(sd->hd))
  1348. return;
  1349. if (!unit_can_move(&sd->hd->bl))
  1350. return;
  1351. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 0);
  1352. }
  1353. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd) { //[orn]
  1354. int x,y,cmd;
  1355. RFIFOHEAD(fd);
  1356. nullpo_retv(sd);
  1357. if(!merc_is_hom_active(sd->hd))
  1358. return;
  1359. cmd = RFIFOW(fd,0);
  1360. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  1361. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  1362. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  1363. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  1364. if (!unit_can_move(&sd->hd->bl))
  1365. return;
  1366. unit_walktoxy(&(sd->hd->bl),x,y,0);
  1367. }
  1368. void clif_parse_HomAttack(int fd,struct map_session_data *sd) { //[orn]
  1369. struct block_list *target;
  1370. RFIFOHEAD(fd);
  1371. nullpo_retv(sd);
  1372. if(!merc_is_hom_active(sd->hd))
  1373. return;
  1374. if ((target = map_id2bl(RFIFOL(fd,6))) == NULL || status_isdead(target))
  1375. return;
  1376. merc_stop_walking(sd->hd, 1);
  1377. merc_stop_attack(sd->hd);
  1378. unit_attack(&sd->hd->bl,RFIFOL(fd,6),1) ;
  1379. }
  1380. void clif_parse_HomMenu(int fd, struct map_session_data *sd) { //[orn]
  1381. int cmd;
  1382. RFIFOHEAD(fd);
  1383. cmd = RFIFOW(fd,0);
  1384. if(!merc_is_hom_active(sd->hd))
  1385. return;
  1386. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  1387. }
  1388. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1389. {
  1390. int fd=sd->fd;
  1391. WFIFOHEAD(fd,packet_len(0x22f));
  1392. WFIFOW(fd,0)=0x22f;
  1393. WFIFOB(fd,2)=fail;
  1394. WFIFOW(fd,3)=foodid;
  1395. WFIFOSET(fd,packet_len(0x22f));
  1396. return 0;
  1397. }
  1398. /*==========================================
  1399. *
  1400. *------------------------------------------
  1401. */
  1402. int clif_walkok(struct map_session_data *sd)
  1403. {
  1404. int fd=sd->fd;
  1405. WFIFOHEAD(fd, packet_len(0x87));
  1406. WFIFOW(fd,0)=0x87;
  1407. WFIFOL(fd,2)=gettick();
  1408. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1409. WFIFOSET(fd,packet_len(0x87));
  1410. return 0;
  1411. }
  1412. /*==========================================
  1413. *
  1414. *------------------------------------------
  1415. */
  1416. int clif_movepc(struct map_session_data *sd) {
  1417. unsigned char buf[256];
  1418. nullpo_retr(0, sd);
  1419. if (map[sd->bl.m].flag.snow
  1420. || map[sd->bl.m].flag.clouds
  1421. || map[sd->bl.m].flag.fog
  1422. || map[sd->bl.m].flag.fireworks
  1423. || map[sd->bl.m].flag.sakura
  1424. || map[sd->bl.m].flag.leaves
  1425. || map[sd->bl.m].flag.rain
  1426. || map[sd->bl.m].flag.clouds2
  1427. ) {
  1428. memset(buf,0,packet_len(0x7b));
  1429. WBUFW(buf,0)=0x7b;
  1430. WBUFL(buf,2)=-10;
  1431. WBUFW(buf,6)=sd->battle_status.speed;
  1432. WBUFW(buf,8)=0;
  1433. WBUFW(buf,10)=0;
  1434. WBUFW(buf,12)=OPTION_INVISIBLE;
  1435. WBUFW(buf,14)=100;
  1436. WBUFL(buf,22)=gettick();
  1437. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1438. WBUFB(buf,56)=5;
  1439. WBUFB(buf,57)=5;
  1440. clif_send(buf, packet_len(0x7b), &sd->bl, SELF);
  1441. }
  1442. return 0;
  1443. }
  1444. /*==========================================
  1445. *
  1446. *------------------------------------------
  1447. */
  1448. int clif_move(struct block_list *bl) {
  1449. struct view_data *vd;
  1450. struct unit_data *ud;
  1451. unsigned char buf[256];
  1452. int len;
  1453. nullpo_retr(0, bl);
  1454. vd = status_get_viewdata(bl);
  1455. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1456. return 0;
  1457. ud = unit_bl2ud(bl);
  1458. nullpo_retr(0, ud);
  1459. len = clif_set007b(bl,vd,ud,buf);
  1460. clif_send(buf,len,bl,AREA_WOS);
  1461. if (disguised(bl))
  1462. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1463. //Stupid client that needs this resent every time someone walks :X
  1464. if(vd->cloth_color)
  1465. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1466. switch(bl->type)
  1467. {
  1468. case BL_PC:
  1469. {
  1470. TBL_PC *sd = ((TBL_PC*)bl);
  1471. // clif_movepc(sd);
  1472. if(sd->state.size==2) // tiny/big players [Valaris]
  1473. clif_specialeffect(&sd->bl,423,AREA);
  1474. else if(sd->state.size==1)
  1475. clif_specialeffect(&sd->bl,421,AREA);
  1476. }
  1477. break;
  1478. case BL_MOB:
  1479. {
  1480. TBL_MOB *md = ((TBL_MOB*)bl);
  1481. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1482. clif_specialeffect(&md->bl,423,AREA);
  1483. else if(md->special_state.size==1)
  1484. clif_specialeffect(&md->bl,421,AREA);
  1485. }
  1486. break;
  1487. }
  1488. return 0;
  1489. }
  1490. /*==========================================
  1491. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1492. *------------------------------------------
  1493. */
  1494. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1495. struct map_session_data *sd = NULL;
  1496. //Remove player from map server
  1497. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1498. map_quit(sd);
  1499. return 0;
  1500. }
  1501. /*==========================================
  1502. *
  1503. *------------------------------------------
  1504. */
  1505. void clif_quitsave(int fd,struct map_session_data *sd)
  1506. {
  1507. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1508. !battle_config.prevent_logout ||
  1509. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1510. map_quit(sd);
  1511. else if (sd->fd)
  1512. { //Disassociate session from player (session is deleted after this function was called)
  1513. //And set a timer to make him quit later.
  1514. session[sd->fd]->session_data = NULL;
  1515. sd->fd = 0;
  1516. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1517. }
  1518. }
  1519. /*==========================================
  1520. *
  1521. *------------------------------------------
  1522. */
  1523. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1524. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1525. session[id]->eof = 1;
  1526. return 0;
  1527. }
  1528. /*==========================================
  1529. *
  1530. *------------------------------------------
  1531. */
  1532. void clif_setwaitclose(int fd) {
  1533. struct map_session_data *sd;
  1534. // if player is not already in the game (double connection probably)
  1535. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1536. // limited timer, just to send information.
  1537. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1538. } else
  1539. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1540. }
  1541. /*==========================================
  1542. *
  1543. *------------------------------------------
  1544. */
  1545. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1546. int fd;
  1547. nullpo_retr(0, sd);
  1548. fd = sd->fd;
  1549. WFIFOHEAD(fd, packet_len(0x91));
  1550. WFIFOW(fd,0) = 0x91;
  1551. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1552. WFIFOW(fd,18) = x;
  1553. WFIFOW(fd,20) = y;
  1554. WFIFOSET(fd, packet_len(0x91));
  1555. return 0;
  1556. }
  1557. /*==========================================
  1558. *
  1559. *------------------------------------------
  1560. */
  1561. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1562. int fd;
  1563. nullpo_retr(0, sd);
  1564. fd = sd->fd;
  1565. WFIFOHEAD(fd, packet_len(0x92));
  1566. WFIFOW(fd,0) = 0x92;
  1567. //Better not trust the null-terminator is there. [Skotlex]
  1568. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1569. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1570. WFIFOW(fd,18) = x;
  1571. WFIFOW(fd,20) = y;
  1572. WFIFOL(fd,22) = ip;
  1573. WFIFOW(fd,26) = port;
  1574. WFIFOSET(fd, packet_len(0x92));
  1575. return 0;
  1576. }
  1577. int clif_blown(struct block_list *bl) {
  1578. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1579. // return clif_fixpos(bl);
  1580. return clif_slide(bl, bl->x, bl->y);
  1581. }
  1582. /*==========================================
  1583. *
  1584. *------------------------------------------
  1585. */
  1586. int clif_fixpos(struct block_list *bl) {
  1587. unsigned char buf[16];
  1588. nullpo_retr(0, bl);
  1589. WBUFW(buf,0)=0x88;
  1590. WBUFL(buf,2)=bl->id;
  1591. WBUFW(buf,6)=bl->x;
  1592. WBUFW(buf,8)=bl->y;
  1593. clif_send(buf, packet_len(0x88), bl, AREA);
  1594. if (disguised(bl)) {
  1595. WBUFL(buf,2)=-bl->id;
  1596. clif_send(buf, packet_len(0x88), bl, SELF);
  1597. }
  1598. return 0;
  1599. }
  1600. /*==========================================
  1601. *
  1602. *------------------------------------------
  1603. */
  1604. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1605. int fd;
  1606. nullpo_retr(0, sd);
  1607. fd=sd->fd;
  1608. WFIFOHEAD(fd, packet_len(0xc4));
  1609. WFIFOW(fd,0)=0xc4;
  1610. WFIFOL(fd,2)=id;
  1611. WFIFOSET(fd,packet_len(0xc4));
  1612. return 0;
  1613. }
  1614. /*==========================================
  1615. *
  1616. *------------------------------------------
  1617. */
  1618. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1619. struct item_data *id;
  1620. int fd,i,val;
  1621. nullpo_retr(0, sd);
  1622. nullpo_retr(0, nd);
  1623. fd=sd->fd;
  1624. WFIFOHEAD(fd, 200 * 11 + 4);
  1625. WFIFOW(fd,0)=0xc6;
  1626. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1627. id = itemdb_search(nd->u.shop_item[i].nameid);
  1628. val=nd->u.shop_item[i].value;
  1629. WFIFOL(fd,4+i*11)=val;
  1630. if (!id->flag.value_notdc)
  1631. val=pc_modifybuyvalue(sd,val);
  1632. WFIFOL(fd,8+i*11)=val;
  1633. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1634. if (id->view_id > 0)
  1635. WFIFOW(fd,13+i*11)=id->view_id;
  1636. else
  1637. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1638. }
  1639. WFIFOW(fd,2)=i*11+4;
  1640. WFIFOSET(fd,WFIFOW(fd,2));
  1641. return 0;
  1642. }
  1643. /*==========================================
  1644. *
  1645. *------------------------------------------
  1646. */
  1647. int clif_selllist(struct map_session_data *sd) {
  1648. int fd,i,c=0,val;
  1649. nullpo_retr(0, sd);
  1650. fd=sd->fd;
  1651. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1652. WFIFOW(fd,0)=0xc7;
  1653. for(i=0;i<MAX_INVENTORY;i++) {
  1654. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1655. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1656. continue;
  1657. val=sd->inventory_data[i]->value_sell;
  1658. if (val < 0)
  1659. continue;
  1660. WFIFOW(fd,4+c*10)=i+2;
  1661. WFIFOL(fd,6+c*10)=val;
  1662. if (!sd->inventory_data[i]->flag.value_notoc)
  1663. val=pc_modifysellvalue(sd,val);
  1664. WFIFOL(fd,10+c*10)=val;
  1665. c++;
  1666. }
  1667. }
  1668. WFIFOW(fd,2)=c*10+4;
  1669. WFIFOSET(fd,WFIFOW(fd,2));
  1670. return 0;
  1671. }
  1672. /*==========================================
  1673. *
  1674. *------------------------------------------
  1675. */
  1676. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  1677. int fd = sd->fd;
  1678. int slen = strlen(mes) + 9;
  1679. WFIFOHEAD(fd, slen);
  1680. WFIFOW(fd,0)=0xb4;
  1681. WFIFOW(fd,2)=slen;
  1682. WFIFOL(fd,4)=npcid;
  1683. strcpy((char*)WFIFOP(fd,8),mes);
  1684. WFIFOSET(fd,WFIFOW(fd,2));
  1685. return 0;
  1686. }
  1687. /*==========================================
  1688. *
  1689. *------------------------------------------
  1690. */
  1691. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  1692. int fd;
  1693. nullpo_retr(0, sd);
  1694. fd=sd->fd;
  1695. WFIFOHEAD(fd, packet_len(0xb5));
  1696. WFIFOW(fd,0)=0xb5;
  1697. WFIFOL(fd,2)=npcid;
  1698. WFIFOSET(fd,packet_len(0xb5));
  1699. return 0;
  1700. }
  1701. /*==========================================
  1702. *
  1703. *------------------------------------------
  1704. */
  1705. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  1706. int fd;
  1707. nullpo_retr(0, sd);
  1708. fd=sd->fd;
  1709. WFIFOHEAD(fd, packet_len(0xb6));
  1710. WFIFOW(fd,0)=0xb6;
  1711. WFIFOL(fd,2)=npcid;
  1712. WFIFOSET(fd,packet_len(0xb6));
  1713. return 0;
  1714. }
  1715. /*==========================================
  1716. *
  1717. *------------------------------------------
  1718. */
  1719. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1720. int fd = sd->fd;
  1721. WFIFOHEAD(fd, packet_len(0x78));
  1722. sd->state.using_fake_npc = 1;
  1723. memset(WFIFOP(fd,0), 0, packet_len(0x78));
  1724. WFIFOW(fd,0)=0x78;
  1725. WFIFOL(fd,2)=npcid;
  1726. WFIFOW(fd,14)=111;
  1727. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1728. WFIFOB(fd,49)=5;
  1729. WFIFOB(fd,50)=5;
  1730. WFIFOSET(fd, packet_len(0x78));
  1731. return;
  1732. }
  1733. /*==========================================
  1734. *
  1735. *------------------------------------------
  1736. */
  1737. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  1738. int fd = sd->fd;
  1739. int slen = strlen(mes) + 8;
  1740. struct block_list *bl = NULL;
  1741. WFIFOHEAD(fd, slen);
  1742. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1743. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1744. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1745. clif_sendfakenpc(sd, npcid);
  1746. WFIFOW(fd,0)=0xb7;
  1747. WFIFOW(fd,2)=slen;
  1748. WFIFOL(fd,4)=npcid;
  1749. strcpy((char*)WFIFOP(fd,8),mes);
  1750. WFIFOSET(fd,WFIFOW(fd,2));
  1751. return 0;
  1752. }
  1753. /*==========================================
  1754. *
  1755. *------------------------------------------
  1756. */
  1757. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  1758. int fd;
  1759. struct block_list *bl = NULL;
  1760. nullpo_retr(0, sd);
  1761. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1762. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1763. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1764. clif_sendfakenpc(sd, npcid);
  1765. fd=sd->fd;
  1766. WFIFOHEAD(fd, packet_len(0x142));
  1767. WFIFOW(fd,0)=0x142;
  1768. WFIFOL(fd,2)=npcid;
  1769. WFIFOSET(fd,packet_len(0x142));
  1770. return 0;
  1771. }
  1772. /*==========================================
  1773. *
  1774. *------------------------------------------
  1775. */
  1776. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1777. int fd;
  1778. struct block_list *bl = NULL;
  1779. nullpo_retr(0, sd);
  1780. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1781. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1782. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1783. clif_sendfakenpc(sd, npcid);
  1784. fd=sd->fd;
  1785. WFIFOHEAD(fd, packet_len(0x1d4));
  1786. WFIFOW(fd,0)=0x1d4;
  1787. WFIFOL(fd,2)=npcid;
  1788. WFIFOSET(fd,packet_len(0x1d4));
  1789. return 0;
  1790. }
  1791. /*==========================================
  1792. *
  1793. *------------------------------------------
  1794. */
  1795. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  1796. int fd;
  1797. nullpo_retr(0, sd);
  1798. fd=sd->fd;
  1799. WFIFOHEAD(fd, packet_len(0x144));
  1800. WFIFOW(fd,0)=0x144;
  1801. WFIFOL(fd,2)=npc_id;
  1802. WFIFOL(fd,6)=type;
  1803. WFIFOL(fd,10)=x;
  1804. WFIFOL(fd,14)=y;
  1805. WFIFOB(fd,18)=id;
  1806. WFIFOL(fd,19)=color;
  1807. WFIFOSET(fd,packet_len(0x144));
  1808. return 0;
  1809. }
  1810. /*==========================================
  1811. *
  1812. *------------------------------------------
  1813. */
  1814. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  1815. int fd;
  1816. nullpo_retr(0, sd);
  1817. fd=sd->fd;
  1818. WFIFOHEAD(fd, packet_len(0x1b3));
  1819. WFIFOW(fd,0)=0x1b3;
  1820. strncpy((char*)WFIFOP(fd,2),image,64);
  1821. WFIFOB(fd,66)=type;
  1822. WFIFOSET(fd,packet_len(0x1b3));
  1823. return 0;
  1824. }
  1825. /*==========================================
  1826. * Fills in card data from the given item and into the buffer. [Skotlex]
  1827. *------------------------------------------
  1828. */
  1829. static void clif_addcards(unsigned char* buf, struct item* item)
  1830. {
  1831. int i=0,j;
  1832. if (item == NULL) { //Blank data
  1833. WBUFW(buf,0)=0;
  1834. WBUFW(buf,2)=0;
  1835. WBUFW(buf,4)=0;
  1836. WBUFW(buf,6)=0;
  1837. return;
  1838. }
  1839. if(item->card[0]==CARD0_PET) { //pet eggs
  1840. WBUFW(buf,0)=0;
  1841. WBUFW(buf,2)=0;
  1842. WBUFW(buf,4)=0;
  1843. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1844. return;
  1845. }
  1846. if(item->card[0]==CARD0_FORGE || item->card[0]==CARD0_CREATE) { //Forged/created items
  1847. WBUFW(buf,0)=item->card[0];
  1848. WBUFW(buf,2)=item->card[1];
  1849. WBUFW(buf,4)=item->card[2];
  1850. WBUFW(buf,6)=item->card[3];
  1851. return;
  1852. }
  1853. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1854. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1855. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1856. //Normal items.
  1857. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1858. WBUFW(buf,0)=j;
  1859. else
  1860. WBUFW(buf,0)= item->card[i];
  1861. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1862. WBUFW(buf,2)=j;
  1863. else
  1864. WBUFW(buf,2)=item->card[i];
  1865. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1866. WBUFW(buf,4)=j;
  1867. else
  1868. WBUFW(buf,4)=item->card[i];
  1869. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1870. WBUFW(buf,6)=j;
  1871. else
  1872. WBUFW(buf,6)=item->card[i];
  1873. }
  1874. /*==========================================
  1875. *
  1876. *------------------------------------------
  1877. */
  1878. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  1879. int fd;
  1880. unsigned char *buf;
  1881. nullpo_retr(0, sd);
  1882. fd = sd->fd;
  1883. if (!session_isActive(fd)) //Sasuke-
  1884. return 0;
  1885. WFIFOHEAD(fd,packet_len(0xa0));
  1886. buf = WFIFOP(fd,0);
  1887. if(fail) {
  1888. WBUFW(buf,0)=0xa0;
  1889. WBUFW(buf,2)=n+2;
  1890. WBUFW(buf,4)=amount;
  1891. WBUFW(buf,6)=0;
  1892. WBUFB(buf,8)=0;
  1893. WBUFB(buf,9)=0;
  1894. WBUFB(buf,10)=0;
  1895. WBUFW(buf,11)=0;
  1896. WBUFW(buf,13)=0;
  1897. WBUFW(buf,15)=0;
  1898. WBUFW(buf,17)=0;
  1899. WBUFW(buf,19)=0;
  1900. WBUFB(buf,21)=0;
  1901. WBUFB(buf,22)=fail;
  1902. } else {
  1903. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1904. return 1;
  1905. WBUFW(buf,0)=0xa0;
  1906. WBUFW(buf,2)=n+2;
  1907. WBUFW(buf,4)=amount;
  1908. if (sd->inventory_data[n]->view_id > 0)
  1909. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  1910. else
  1911. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  1912. WBUFB(buf,8)=sd->status.inventory[n].identify;
  1913. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  1914. WBUFB(buf,10)=sd->status.inventory[n].refine;
  1915. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  1916. WBUFW(buf,19)=pc_equippoint(sd,n);
  1917. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  1918. WBUFB(buf,22)=fail;
  1919. }
  1920. WFIFOSET(fd,packet_len(0xa0));
  1921. return 0;
  1922. }
  1923. /*==========================================
  1924. *
  1925. *------------------------------------------
  1926. */
  1927. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1928. {
  1929. int fd;
  1930. nullpo_retr(0, sd);
  1931. fd=sd->fd;
  1932. WFIFOHEAD(fd, packet_len(0xaf));
  1933. WFIFOW(fd,0)=0xaf;
  1934. WFIFOW(fd,2)=n+2;
  1935. WFIFOW(fd,4)=amount;
  1936. WFIFOSET(fd,packet_len(0xaf));
  1937. return 0;
  1938. }
  1939. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1940. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1941. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1942. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1943. {
  1944. if (id->view_id > 0)
  1945. WBUFW(buf,n)=id->view_id;
  1946. else
  1947. WBUFW(buf,n)=i->nameid;
  1948. WBUFB(buf,n+2)=itemtype(id->type);
  1949. WBUFB(buf,n+3)=i->identify;
  1950. if (equip >= 0) { //Equippable item
  1951. WBUFW(buf,n+4)=equip;
  1952. WBUFW(buf,n+6)=i->equip;
  1953. WBUFB(buf,n+8)=i->attribute;
  1954. WBUFB(buf,n+9)=i->refine;
  1955. } else { //Stackable item.
  1956. WBUFW(buf,n+4)=i->amount;
  1957. if (equip == -2 && id->equip == EQP_AMMO)
  1958. WBUFW(buf,n+6)=EQP_AMMO;
  1959. else
  1960. WBUFW(buf,n+6)=0;
  1961. }
  1962. }
  1963. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1964. void clif_inventorylist(struct map_session_data *sd)
  1965. {
  1966. int i,n,ne,fd = sd->fd,arrow=-1;
  1967. unsigned char *buf;
  1968. unsigned char bufe[MAX_INVENTORY*20+4];
  1969. #if PACKETVER < 5
  1970. const int s = 10; //Entry size.
  1971. #else
  1972. const int s = 18;
  1973. #endif
  1974. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1975. buf = WFIFOP(fd,0);
  1976. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1977. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1978. continue;
  1979. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1980. { //Non-stackable (Equippable)
  1981. WBUFW(bufe,ne*20+4)=i+2;
  1982. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1983. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1984. ne++;
  1985. } else { //Stackable.
  1986. WBUFW(buf,n*s+4)=i+2;
  1987. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1988. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1989. sd->status.inventory[i].equip)
  1990. arrow=i;
  1991. #if PACKETVER >= 5
  1992. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1993. #endif
  1994. n++;
  1995. }
  1996. }
  1997. if (n) {
  1998. #if PACKETVER < 5
  1999. WBUFW(buf,0)=0xa3;
  2000. #else
  2001. WBUFW(buf,0)=0x1ee;
  2002. #endif
  2003. WBUFW(buf,2)=4+n*s;
  2004. WFIFOSET(fd,WFIFOW(fd,2));
  2005. }
  2006. if(arrow >= 0)
  2007. clif_arrowequip(sd,arrow);
  2008. if(ne){
  2009. WBUFW(bufe,0)=0xa4;
  2010. WBUFW(bufe,2)=4+ne*20;
  2011. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2012. }
  2013. }
  2014. //Required when items break/get-repaired. Only sends equippable item list.
  2015. void clif_equiplist(struct map_session_data *sd)
  2016. {
  2017. int i,n,fd = sd->fd;
  2018. unsigned char *buf;
  2019. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  2020. buf = WFIFOP(fd,0);
  2021. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2022. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2023. continue;
  2024. if(itemdb_isstackable2(sd->inventory_data[i]))
  2025. continue;
  2026. //Equippable
  2027. WBUFW(buf,n*20+4)=i+2;
  2028. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2029. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  2030. n++;
  2031. }
  2032. if (n) {
  2033. WBUFW(buf,0)=0xa4;
  2034. WBUFW(buf,2)=4+n*20;
  2035. WFIFOSET(fd,WFIFOW(fd,2));
  2036. }
  2037. }
  2038. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2039. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  2040. {
  2041. struct item_data *id;
  2042. int i,n,ne,fd=sd->fd;
  2043. unsigned char *buf;
  2044. unsigned char bufe[MAX_STORAGE*20+4];
  2045. #if PACKETVER < 5
  2046. const int s = 10; //Entry size.
  2047. #else
  2048. const int s = 18;
  2049. #endif
  2050. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  2051. buf = WFIFOP(fd,0);
  2052. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  2053. if(stor->storage_[i].nameid<=0)
  2054. continue;
  2055. id = itemdb_search(stor->storage_[i].nameid);
  2056. if(!itemdb_isstackable2(id))
  2057. { //Equippable
  2058. WBUFW(bufe,ne*20+4)=i+1;
  2059. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2060. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2061. ne++;
  2062. } else { //Stackable
  2063. WBUFW(buf,n*s+4)=i+1;
  2064. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2065. #if PACKETVER >= 5
  2066. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2067. #endif
  2068. n++;
  2069. }
  2070. }
  2071. if(n){
  2072. #if PACKETVER < 5
  2073. WBUFW(buf,0)=0xa5;
  2074. #else
  2075. WBUFW(buf,0)=0x1f0;
  2076. #endif
  2077. WBUFW(buf,2)=4+n*s;
  2078. WFIFOSET(fd,WFIFOW(fd,2));
  2079. }
  2080. if(ne){
  2081. WBUFW(bufe,0)=0xa6;
  2082. WBUFW(bufe,2)=4+ne*20;
  2083. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2084. }
  2085. }
  2086. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2087. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  2088. {
  2089. struct item_data *id;
  2090. int i,n,ne,fd=sd->fd;
  2091. unsigned char *buf;
  2092. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  2093. #if PACKETVER < 5
  2094. const int s = 10; //Entry size.
  2095. #else
  2096. const int s = 18;
  2097. #endif
  2098. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  2099. buf = WFIFOP(fd,0);
  2100. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  2101. if(stor->storage_[i].nameid<=0)
  2102. continue;
  2103. id = itemdb_search(stor->storage_[i].nameid);
  2104. if(!itemdb_isstackable2(id))
  2105. { //Equippable
  2106. WBUFW(bufe,ne*20+4)=i+1;
  2107. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2108. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2109. ne++;
  2110. } else { //Stackable
  2111. WBUFW(buf,n*s+4)=i+1;
  2112. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2113. #if PACKETVER >= 5
  2114. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2115. #endif
  2116. n++;
  2117. }
  2118. }
  2119. if(n){
  2120. #if PACKETVER < 5
  2121. WBUFW(buf,0)=0xa5;
  2122. #else
  2123. WBUFW(buf,0)=0x1f0;
  2124. #endif
  2125. WBUFW(buf,2)=4+n*s;
  2126. WFIFOSET(fd,WFIFOW(fd,2));
  2127. }
  2128. if(ne){
  2129. WBUFW(bufe,0)=0xa6;
  2130. WBUFW(bufe,2)=4+ne*20;
  2131. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2132. }
  2133. }
  2134. void clif_cartlist(struct map_session_data *sd)
  2135. {
  2136. struct item_data *id;
  2137. int i,n,ne,fd=sd->fd;
  2138. unsigned char *buf;
  2139. unsigned char bufe[MAX_CART*20+4];
  2140. #if PACKETVER < 5
  2141. const int s = 10; //Entry size.
  2142. #else
  2143. const int s = 18;
  2144. #endif
  2145. WFIFOHEAD(fd, MAX_CART * s + 4);
  2146. buf = WFIFOP(fd,0);
  2147. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2148. if(sd->status.cart[i].nameid<=0)
  2149. continue;
  2150. id = itemdb_search(sd->status.cart[i].nameid);
  2151. if(!itemdb_isstackable2(id))
  2152. { //Equippable
  2153. WBUFW(bufe,ne*20+4)=i+2;
  2154. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2155. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2156. ne++;
  2157. } else { //Stackable
  2158. WBUFW(buf,n*s+4)=i+2;
  2159. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2160. #if PACKETVER >= 5
  2161. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2162. #endif
  2163. n++;
  2164. }
  2165. }
  2166. if(n){
  2167. #if PACKETVER < 5
  2168. WBUFW(buf,0)=0x123;
  2169. #else
  2170. WBUFW(buf,0)=0x1ef;
  2171. #endif
  2172. WBUFW(buf,2)=4+n*s;
  2173. WFIFOSET(fd,WFIFOW(fd,2));
  2174. }
  2175. if(ne){
  2176. WBUFW(bufe,0)=0x122;
  2177. WBUFW(bufe,2)=4+ne*20;
  2178. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2179. }
  2180. return;
  2181. }
  2182. // Guild XY locators [Valaris]
  2183. int clif_guild_xy(struct map_session_data *sd)
  2184. {
  2185. unsigned char buf[10];
  2186. nullpo_retr(0, sd);
  2187. WBUFW(buf,0)=0x1eb;
  2188. WBUFL(buf,2)=sd->status.account_id;
  2189. WBUFW(buf,6)=sd->bl.x;
  2190. WBUFW(buf,8)=sd->bl.y;
  2191. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2192. return 0;
  2193. }
  2194. /*==========================================
  2195. * Sends x/y dot to a single fd. [Skotlex]
  2196. *------------------------------------------
  2197. */
  2198. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2199. {
  2200. WFIFOHEAD(fd,packet_len(0x1eb));
  2201. WFIFOW(fd,0)=0x1eb;
  2202. WFIFOL(fd,2)=sd->status.account_id;
  2203. WFIFOW(fd,6)=sd->bl.x;
  2204. WFIFOW(fd,8)=sd->bl.y;
  2205. WFIFOSET(fd,packet_len(0x1eb));
  2206. return 0;
  2207. }
  2208. // Guild XY locators [Valaris]
  2209. int clif_guild_xy_remove(struct map_session_data *sd)
  2210. {
  2211. unsigned char buf[10];
  2212. nullpo_retr(0, sd);
  2213. WBUFW(buf,0)=0x1eb;
  2214. WBUFL(buf,2)=sd->status.account_id;
  2215. WBUFW(buf,6)=-1;
  2216. WBUFW(buf,8)=-1;
  2217. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2218. return 0;
  2219. }
  2220. /*==========================================
  2221. * ステータスを送りつける
  2222. * 表示専用数字はこの中で計算して送る
  2223. *------------------------------------------
  2224. */
  2225. int clif_updatestatus(struct map_session_data *sd,int type)
  2226. {
  2227. int fd,len=8;
  2228. nullpo_retr(0, sd);
  2229. fd=sd->fd;
  2230. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2231. return 0;
  2232. WFIFOHEAD(fd, 14);
  2233. WFIFOW(fd,0)=0xb0;
  2234. WFIFOW(fd,2)=type;
  2235. switch(type){
  2236. // 00b0
  2237. case SP_WEIGHT:
  2238. pc_updateweightstatus(sd);
  2239. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2240. WFIFOW(fd,2)=type;
  2241. WFIFOL(fd,4)=sd->weight;
  2242. break;
  2243. case SP_MAXWEIGHT:
  2244. WFIFOL(fd,4)=sd->max_weight;
  2245. break;
  2246. case SP_SPEED:
  2247. WFIFOL(fd,4)=sd->battle_status.speed;
  2248. break;
  2249. case SP_BASELEVEL:
  2250. WFIFOL(fd,4)=sd->status.base_level;
  2251. break;
  2252. case SP_JOBLEVEL:
  2253. WFIFOL(fd,4)=sd->status.job_level;
  2254. break;
  2255. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2256. WFIFOL(fd,4)=sd->status.karma;
  2257. break;
  2258. case SP_MANNER:
  2259. WFIFOL(fd,4)=sd->status.manner;
  2260. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2261. break;
  2262. case SP_STATUSPOINT:
  2263. WFIFOL(fd,4)=sd->status.status_point;
  2264. break;
  2265. case SP_SKILLPOINT:
  2266. WFIFOL(fd,4)=sd->status.skill_point;
  2267. break;
  2268. case SP_HIT:
  2269. WFIFOL(fd,4)=sd->battle_status.hit;
  2270. break;
  2271. case SP_FLEE1:
  2272. WFIFOL(fd,4)=sd->battle_status.flee;
  2273. break;
  2274. case SP_FLEE2:
  2275. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2276. break;
  2277. case SP_MAXHP:
  2278. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2279. break;
  2280. case SP_MAXSP:
  2281. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2282. break;
  2283. case SP_HP:
  2284. WFIFOL(fd,4)=sd->battle_status.hp;
  2285. if (battle_config.disp_hpmeter)
  2286. clif_hpmeter(sd);
  2287. if (!battle_config.party_hp_mode && sd->status.party_id)
  2288. clif_party_hp(sd);
  2289. break;
  2290. case SP_SP:
  2291. WFIFOL(fd,4)=sd->battle_status.sp;
  2292. break;
  2293. case SP_ASPD:
  2294. WFIFOL(fd,4)=sd->battle_status.amotion;
  2295. break;
  2296. case SP_ATK1:
  2297. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2298. break;
  2299. case SP_DEF1:
  2300. WFIFOL(fd,4)=sd->battle_status.def;
  2301. break;
  2302. case SP_MDEF1:
  2303. WFIFOL(fd,4)=sd->battle_status.mdef;
  2304. break;
  2305. case SP_ATK2:
  2306. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2307. break;
  2308. case SP_DEF2:
  2309. WFIFOL(fd,4)=sd->battle_status.def2;
  2310. break;
  2311. case SP_MDEF2:
  2312. //negative check (in case you have something like Berserk active)
  2313. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2314. if (len < 0) len = 0;
  2315. WFIFOL(fd,4)= len;
  2316. len = 8;
  2317. break;
  2318. case SP_CRITICAL:
  2319. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2320. break;
  2321. case SP_MATK1:
  2322. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2323. break;
  2324. case SP_MATK2:
  2325. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2326. break;
  2327. case SP_ZENY:
  2328. WFIFOW(fd,0)=0xb1;
  2329. WFIFOL(fd,4)=sd->status.zeny;
  2330. break;
  2331. case SP_BASEEXP:
  2332. WFIFOW(fd,0)=0xb1;
  2333. WFIFOL(fd,4)=sd->status.base_exp;
  2334. break;
  2335. case SP_JOBEXP:
  2336. WFIFOW(fd,0)=0xb1;
  2337. WFIFOL(fd,4)=sd->status.job_exp;
  2338. break;
  2339. case SP_NEXTBASEEXP:
  2340. WFIFOW(fd,0)=0xb1;
  2341. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2342. break;
  2343. case SP_NEXTJOBEXP:
  2344. WFIFOW(fd,0)=0xb1;
  2345. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2346. break;
  2347. // 00be 終了
  2348. case SP_USTR:
  2349. case SP_UAGI:
  2350. case SP_UVIT:
  2351. case SP_UINT:
  2352. case SP_UDEX:
  2353. case SP_ULUK:
  2354. WFIFOW(fd,0)=0xbe;
  2355. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2356. len=5;
  2357. break;
  2358. // 013a 終了
  2359. case SP_ATTACKRANGE:
  2360. WFIFOW(fd,0)=0x13a;
  2361. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2362. len=4;
  2363. break;
  2364. // 0141 終了
  2365. case SP_STR:
  2366. WFIFOW(fd,0)=0x141;
  2367. WFIFOL(fd,2)=type;
  2368. WFIFOL(fd,6)=sd->status.str;
  2369. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2370. len=14;
  2371. break;
  2372. case SP_AGI:
  2373. WFIFOW(fd,0)=0x141;
  2374. WFIFOL(fd,2)=type;
  2375. WFIFOL(fd,6)=sd->status.agi;
  2376. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2377. len=14;
  2378. break;
  2379. case SP_VIT:
  2380. WFIFOW(fd,0)=0x141;
  2381. WFIFOL(fd,2)=type;
  2382. WFIFOL(fd,6)=sd->status.vit;
  2383. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2384. len=14;
  2385. break;
  2386. case SP_INT:
  2387. WFIFOW(fd,0)=0x141;
  2388. WFIFOL(fd,2)=type;
  2389. WFIFOL(fd,6)=sd->status.int_;
  2390. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2391. len=14;
  2392. break;
  2393. case SP_DEX:
  2394. WFIFOW(fd,0)=0x141;
  2395. WFIFOL(fd,2)=type;
  2396. WFIFOL(fd,6)=sd->status.dex;
  2397. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2398. len=14;
  2399. break;
  2400. case SP_LUK:
  2401. WFIFOW(fd,0)=0x141;
  2402. WFIFOL(fd,2)=type;
  2403. WFIFOL(fd,6)=sd->status.luk;
  2404. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2405. len=14;
  2406. break;
  2407. case SP_CARTINFO:
  2408. WFIFOW(fd,0)=0x121;
  2409. WFIFOW(fd,2)=sd->cart_num;
  2410. WFIFOW(fd,4)=sd->cart_max_num;
  2411. WFIFOL(fd,6)=sd->cart_weight;
  2412. WFIFOL(fd,10)=sd->cart_max_weight;
  2413. len=14;
  2414. break;
  2415. default:
  2416. if(battle_config.error_log)
  2417. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2418. return 1;
  2419. }
  2420. WFIFOSET(fd,len);
  2421. return 0;
  2422. }
  2423. int clif_changestatus(struct block_list *bl,int type,int val)
  2424. {
  2425. unsigned char buf[12];
  2426. struct map_session_data *sd = NULL;
  2427. nullpo_retr(0, bl);
  2428. if(bl->type == BL_PC)
  2429. sd = (struct map_session_data *)bl;
  2430. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2431. if(sd){
  2432. WBUFW(buf,0)=0x1ab;
  2433. WBUFL(buf,2)=bl->id;
  2434. WBUFW(buf,6)=type;
  2435. switch(type){
  2436. case SP_MANNER:
  2437. WBUFL(buf,8)=val;
  2438. break;
  2439. default:
  2440. if(battle_config.error_log)
  2441. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2442. return 1;
  2443. }
  2444. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2445. }
  2446. return 0;
  2447. }
  2448. /*==========================================
  2449. *
  2450. *------------------------------------------
  2451. */
  2452. int clif_changelook(struct block_list *bl,int type,int val)
  2453. {
  2454. unsigned char buf[32];
  2455. struct map_session_data *sd = NULL;
  2456. struct view_data *vd;
  2457. vd = status_get_viewdata(bl);
  2458. nullpo_retr(0, vd);
  2459. BL_CAST(BL_PC, bl, sd);
  2460. switch(type) {
  2461. case LOOK_WEAPON:
  2462. if (sd)
  2463. {
  2464. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2465. val = vd->weapon;
  2466. }
  2467. else vd->weapon = val;
  2468. break;
  2469. case LOOK_SHIELD:
  2470. if (sd)
  2471. {
  2472. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2473. val = vd->shield;
  2474. }
  2475. else vd->shield = val;
  2476. break;
  2477. case LOOK_BASE:
  2478. vd->class_ = val;
  2479. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2480. vd->weapon = vd->shield = 0;
  2481. if (vd->cloth_color && (
  2482. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2483. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2484. ))
  2485. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2486. break;
  2487. case LOOK_HAIR:
  2488. vd->hair_style = val;
  2489. break;
  2490. case LOOK_HEAD_BOTTOM:
  2491. vd->head_bottom = val;
  2492. break;
  2493. case LOOK_HEAD_TOP:
  2494. vd->head_top = val;
  2495. break;
  2496. case LOOK_HEAD_MID:
  2497. vd->head_mid = val;
  2498. break;
  2499. case LOOK_HAIR_COLOR:
  2500. vd->hair_color = val;
  2501. break;
  2502. case LOOK_CLOTHES_COLOR:
  2503. if (val && (
  2504. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2505. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2506. ))
  2507. val = 0;
  2508. vd->cloth_color = val;
  2509. break;
  2510. case LOOK_SHOES:
  2511. #if PACKETVER > 3
  2512. if (sd) {
  2513. int n;
  2514. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2515. if(sd->inventory_data[n]->view_id > 0)
  2516. val = sd->inventory_data[n]->view_id;
  2517. else
  2518. val = sd->status.inventory[n].nameid;
  2519. }
  2520. val = 0;
  2521. }
  2522. #endif
  2523. //Shoes? No packet uses this....
  2524. break;
  2525. }
  2526. #if PACKETVER < 4
  2527. WBUFW(buf,0)=0xc3;
  2528. WBUFL(buf,2)=bl->id;
  2529. WBUFB(buf,6)=type;
  2530. WBUFB(buf,7)=val;
  2531. clif_send(buf,packet_len(0xc3),bl,AREA);
  2532. #else
  2533. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2534. WBUFW(buf,0)=0x1d7;
  2535. WBUFL(buf,2)=bl->id;
  2536. WBUFB(buf,6)=LOOK_WEAPON;
  2537. WBUFW(buf,7)=vd->weapon;
  2538. WBUFW(buf,9)=vd->shield;
  2539. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2540. }
  2541. else
  2542. {
  2543. WBUFW(buf,0)=0x1d7;
  2544. WBUFL(buf,2)=bl->id;
  2545. WBUFB(buf,6)=type;
  2546. WBUFW(buf,7)=val;
  2547. WBUFW(buf,9)=0;
  2548. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2549. }
  2550. #endif
  2551. return 0;
  2552. }
  2553. //Sends a change-base-look packet required for traps as they are triggered.
  2554. void clif_changetraplook(struct block_list *bl,int val)
  2555. {
  2556. unsigned char buf[32];
  2557. #if PACKETVER < 4
  2558. WBUFW(buf,0)=0xc3;
  2559. WBUFL(buf,2)=bl->id;
  2560. WBUFB(buf,6)=LOOK_BASE;
  2561. WBUFB(buf,7)=val;
  2562. clif_send(buf,packet_len(0xc3),bl,AREA);
  2563. #else
  2564. WBUFW(buf,0)=0x1d7;
  2565. WBUFL(buf,2)=bl->id;
  2566. WBUFB(buf,6)=LOOK_BASE;
  2567. WBUFW(buf,7)=val;
  2568. WBUFW(buf,9)=0;
  2569. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2570. #endif
  2571. }
  2572. //For the stupid cloth-dye bug. Resends the given view data
  2573. //to the area specified by bl.
  2574. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2575. {
  2576. unsigned char buf[32];
  2577. #if PACKETVER < 4
  2578. WBUFW(buf,0)=0xc3;
  2579. WBUFL(buf,2)=id;
  2580. WBUFB(buf,6)=type;
  2581. WBUFB(buf,7)=val;
  2582. clif_send(buf,packet_len(0xc3),bl,area);
  2583. #else
  2584. WBUFW(buf,0)=0x1d7;
  2585. WBUFL(buf,2)=id;
  2586. WBUFB(buf,6)=type;
  2587. WBUFW(buf,7)=val;
  2588. WBUFW(buf,9)=0;
  2589. clif_send(buf,packet_len(0x1d7),bl,area);
  2590. #endif
  2591. return;
  2592. }
  2593. /*==========================================
  2594. *
  2595. *------------------------------------------
  2596. */
  2597. int clif_initialstatus(struct map_session_data *sd)
  2598. {
  2599. int fd;
  2600. unsigned char *buf;
  2601. nullpo_retr(0, sd);
  2602. fd=sd->fd;
  2603. WFIFOHEAD(fd,packet_len(0xbd));
  2604. buf=WFIFOP(fd,0);
  2605. WBUFW(buf,0)=0xbd;
  2606. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2607. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2608. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2609. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2610. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2611. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2612. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2613. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2614. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2615. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2616. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2617. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2618. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2619. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2620. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2621. WBUFW(buf,20) = sd->battle_status.matk_max;
  2622. WBUFW(buf,22) = sd->battle_status.matk_min;
  2623. WBUFW(buf,24) = sd->battle_status.def; // def
  2624. WBUFW(buf,26) = sd->battle_status.def2;
  2625. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2626. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2627. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2628. WBUFW(buf,30) = fd;
  2629. fd = sd->fd;
  2630. WBUFW(buf,32) = sd->battle_status.hit;
  2631. WBUFW(buf,34) = sd->battle_status.flee;
  2632. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2633. WBUFW(buf,38) = sd->battle_status.cri/10;
  2634. WBUFW(buf,40) = sd->status.karma;
  2635. WBUFW(buf,42) = sd->status.manner;
  2636. WFIFOSET(fd,packet_len(0xbd));
  2637. clif_updatestatus(sd,SP_STR);
  2638. clif_updatestatus(sd,SP_AGI);
  2639. clif_updatestatus(sd,SP_VIT);
  2640. clif_updatestatus(sd,SP_INT);
  2641. clif_updatestatus(sd,SP_DEX);
  2642. clif_updatestatus(sd,SP_LUK);
  2643. clif_updatestatus(sd,SP_ATTACKRANGE);
  2644. clif_updatestatus(sd,SP_ASPD);
  2645. return 0;
  2646. }
  2647. /*==========================================
  2648. *矢装備
  2649. *------------------------------------------
  2650. */
  2651. int clif_arrowequip(struct map_session_data *sd,int val)
  2652. {
  2653. int fd;
  2654. nullpo_retr(0, sd);
  2655. pc_stop_attack(sd); // [Valaris]
  2656. fd=sd->fd;
  2657. WFIFOHEAD(fd, packet_len(0x013c));
  2658. WFIFOW(fd,0)=0x013c;
  2659. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2660. WFIFOSET(fd,packet_len(0x013c));
  2661. return 0;
  2662. }
  2663. /*==========================================
  2664. *
  2665. *------------------------------------------
  2666. */
  2667. int clif_arrow_fail(struct map_session_data *sd,int type)
  2668. {
  2669. int fd;
  2670. nullpo_retr(0, sd);
  2671. fd=sd->fd;
  2672. WFIFOHEAD(fd, packet_len(0x013b));
  2673. WFIFOW(fd,0)=0x013b;
  2674. WFIFOW(fd,2)=type;
  2675. WFIFOSET(fd,packet_len(0x013b));
  2676. return 0;
  2677. }
  2678. /*==========================================
  2679. * 作成可能 矢リスト送信
  2680. *------------------------------------------
  2681. */
  2682. int clif_arrow_create_list(struct map_session_data *sd)
  2683. {
  2684. int i, c, j;
  2685. int fd;
  2686. nullpo_retr(0, sd);
  2687. fd = sd->fd;
  2688. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2689. WFIFOW(fd,0) = 0x1ad;
  2690. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2691. if (skill_arrow_db[i].nameid > 0 &&
  2692. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2693. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2694. {
  2695. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2696. WFIFOW(fd,c*2+4) = j;
  2697. else
  2698. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2699. c++;
  2700. }
  2701. }
  2702. WFIFOW(fd,2) = c*2+4;
  2703. WFIFOSET(fd, WFIFOW(fd,2));
  2704. if (c > 0) {
  2705. sd->menuskill_id = AC_MAKINGARROW;
  2706. sd->menuskill_lv = c;
  2707. }
  2708. return 0;
  2709. }
  2710. /*==========================================
  2711. *
  2712. *------------------------------------------
  2713. */
  2714. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2715. {
  2716. int fd;
  2717. nullpo_retr(0, sd);
  2718. fd=sd->fd;
  2719. WFIFOHEAD(fd,packet_len(0xbc));
  2720. WFIFOW(fd,0)=0xbc;
  2721. WFIFOW(fd,2)=type;
  2722. WFIFOB(fd,4)=ok;
  2723. WFIFOB(fd,5)=val;
  2724. WFIFOSET(fd,packet_len(0xbc));
  2725. return 0;
  2726. }
  2727. /*==========================================
  2728. *
  2729. *------------------------------------------
  2730. */
  2731. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2732. {
  2733. int fd;
  2734. nullpo_retr(0, sd);
  2735. fd=sd->fd;
  2736. WFIFOHEAD(fd,packet_len(0xaa));
  2737. WFIFOW(fd,0)=0xaa;
  2738. WFIFOW(fd,2)=n+2;
  2739. WFIFOW(fd,4)=pos;
  2740. WFIFOB(fd,6)=ok;
  2741. WFIFOSET(fd,packet_len(0xaa));
  2742. return 0;
  2743. }
  2744. /*==========================================
  2745. *
  2746. *------------------------------------------
  2747. */
  2748. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2749. {
  2750. int fd;
  2751. nullpo_retr(0, sd);
  2752. fd=sd->fd;
  2753. WFIFOHEAD(fd,packet_len(0xac));
  2754. WFIFOW(fd,0)=0xac;
  2755. WFIFOW(fd,2)=n+2;
  2756. WFIFOW(fd,4)=pos;
  2757. WFIFOB(fd,6)=ok;
  2758. WFIFOSET(fd,packet_len(0xac));
  2759. return 0;
  2760. }
  2761. /*==========================================
  2762. *
  2763. *------------------------------------------
  2764. */
  2765. int clif_misceffect(struct block_list* bl,int type)
  2766. {
  2767. unsigned char buf[32];
  2768. nullpo_retr(0, bl);
  2769. WBUFW(buf,0) = 0x19b;
  2770. WBUFL(buf,2) = bl->id;
  2771. WBUFL(buf,6) = type;
  2772. clif_send(buf,packet_len(0x19b),bl,AREA);
  2773. return 0;
  2774. }
  2775. int clif_misceffect2(struct block_list *bl, int type) {
  2776. unsigned char buf[24];
  2777. nullpo_retr(0, bl);
  2778. memset(buf, 0, packet_len(0x1f3));
  2779. WBUFW(buf,0) = 0x1f3;
  2780. WBUFL(buf,2) = bl->id;
  2781. WBUFL(buf,6) = type;
  2782. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2783. return 0;
  2784. }
  2785. /*==========================================
  2786. * 表示オプション変更
  2787. *------------------------------------------
  2788. */
  2789. int clif_changeoption(struct block_list* bl)
  2790. {
  2791. unsigned char buf[32];
  2792. struct status_change *sc;
  2793. nullpo_retr(0, bl);
  2794. sc = status_get_sc(bl);
  2795. if (!sc) return 0; //How can an option change if there's no sc?
  2796. #if PACKETVER > 6
  2797. WBUFW(buf,0) = 0x229;
  2798. WBUFL(buf,2) = bl->id;
  2799. WBUFW(buf,6) = sc->opt1;
  2800. WBUFW(buf,8) = sc->opt2;
  2801. WBUFL(buf,10) = sc->option;
  2802. WBUFB(buf,14) = 0; // PK???
  2803. if(disguised(bl)) {
  2804. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2805. WBUFL(buf,2) = -bl->id;
  2806. clif_send(buf,packet_len(0x229),bl,SELF);
  2807. WBUFL(buf,2) = bl->id;
  2808. WBUFL(buf,10) = OPTION_INVISIBLE;
  2809. clif_send(buf,packet_len(0x229),bl,SELF);
  2810. } else
  2811. clif_send(buf,packet_len(0x229),bl,AREA);
  2812. #else
  2813. WBUFW(buf,0) = 0x119;
  2814. WBUFL(buf,2) = bl->id;
  2815. WBUFW(buf,6) = sc->opt1;
  2816. WBUFW(buf,8) = sc->opt2;
  2817. WBUFW(buf,10) = sc->option;
  2818. WBUFB(buf,12) = 0; // ??
  2819. if(disguised(bl)) {
  2820. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2821. WBUFL(buf,2) = -bl->id;
  2822. clif_send(buf,packet_len(0x119),bl,SELF);
  2823. WBUFL(buf,2) = bl->id;
  2824. WBUFW(buf,10) = OPTION_INVISIBLE;
  2825. clif_send(buf,packet_len(0x119),bl,SELF);
  2826. } else
  2827. clif_send(buf,packet_len(0x119),bl,AREA);
  2828. #endif
  2829. return 0;
  2830. }
  2831. /*==========================================
  2832. *
  2833. *------------------------------------------
  2834. */
  2835. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2836. {
  2837. nullpo_retr(0, sd);
  2838. if(!ok) {
  2839. int fd=sd->fd;
  2840. WFIFOHEAD(fd,packet_len(0xa8));
  2841. WFIFOW(fd,0)=0xa8;
  2842. WFIFOW(fd,2)=index+2;
  2843. WFIFOW(fd,4)=amount;
  2844. WFIFOB(fd,6)=ok;
  2845. WFIFOSET(fd,packet_len(0xa8));
  2846. }
  2847. else {
  2848. #if PACKETVER < 3
  2849. int fd=sd->fd;
  2850. WFIFOHEAD(fd,packet_len(0xa8));
  2851. WFIFOW(fd,0)=0xa8;
  2852. WFIFOW(fd,2)=index+2;
  2853. WFIFOW(fd,4)=amount;
  2854. WFIFOB(fd,6)=ok;
  2855. WFIFOSET(fd,packet_len(0xa8));
  2856. #else
  2857. unsigned char buf[32];
  2858. WBUFW(buf,0)=0x1c8;
  2859. WBUFW(buf,2)=index+2;
  2860. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2861. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2862. else
  2863. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2864. WBUFL(buf,6)=sd->bl.id;
  2865. WBUFW(buf,10)=amount;
  2866. WBUFB(buf,12)=ok;
  2867. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2868. #endif
  2869. }
  2870. return 0;
  2871. }
  2872. /*==========================================
  2873. *
  2874. *------------------------------------------
  2875. */
  2876. int clif_createchat(struct map_session_data *sd,int fail)
  2877. {
  2878. int fd;
  2879. nullpo_retr(0, sd);
  2880. fd=sd->fd;
  2881. WFIFOHEAD(fd,packet_len(0xd6));
  2882. WFIFOW(fd,0)=0xd6;
  2883. WFIFOB(fd,2)=fail;
  2884. WFIFOSET(fd,packet_len(0xd6));
  2885. return 0;
  2886. }
  2887. /*==========================================
  2888. *
  2889. *------------------------------------------
  2890. */
  2891. int clif_dispchat(struct chat_data *cd,int fd)
  2892. {
  2893. unsigned char buf[128]; // 最大title(60バイト)+17
  2894. if(cd==NULL || *cd->owner==NULL)
  2895. return 1;
  2896. WBUFW(buf,0)=0xd7;
  2897. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  2898. WBUFL(buf,4)=(*cd->owner)->id;
  2899. WBUFL(buf,8)=cd->bl.id;
  2900. WBUFW(buf,12)=cd->limit;
  2901. WBUFW(buf,14)=cd->users;
  2902. WBUFB(buf,16)=cd->pub;
  2903. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2904. if(fd){
  2905. WFIFOHEAD(fd, WBUFW(buf,2));
  2906. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2907. WFIFOSET(fd,WBUFW(buf,2));
  2908. } else {
  2909. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  2910. }
  2911. return 0;
  2912. }
  2913. /*==========================================
  2914. * chatの状態変更成功
  2915. * 外部の人用と命令コード(d7->df)が違うだけ
  2916. *------------------------------------------
  2917. */
  2918. int clif_changechatstatus(struct chat_data *cd)
  2919. {
  2920. unsigned char buf[128]; // 最大title(60バイト)+17
  2921. if(cd==NULL || cd->usersd[0]==NULL)
  2922. return 1;
  2923. WBUFW(buf,0)=0xdf;
  2924. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  2925. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  2926. WBUFL(buf,8)=cd->bl.id;
  2927. WBUFW(buf,12)=cd->limit;
  2928. WBUFW(buf,14)=cd->users;
  2929. WBUFB(buf,16)=cd->pub;
  2930. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2931. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2932. return 0;
  2933. }
  2934. /*==========================================
  2935. *
  2936. *------------------------------------------
  2937. */
  2938. int clif_clearchat(struct chat_data *cd,int fd)
  2939. {
  2940. unsigned char buf[32];
  2941. nullpo_retr(0, cd);
  2942. WBUFW(buf,0)=0xd8;
  2943. WBUFL(buf,2)=cd->bl.id;
  2944. if(fd){
  2945. WFIFOHEAD(fd,packet_len(0xd8));
  2946. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2947. WFIFOSET(fd,packet_len(0xd8));
  2948. } else {
  2949. clif_send(buf,packet_len(0xd8),*cd->owner,AREA_WOSC);
  2950. }
  2951. return 0;
  2952. }
  2953. /*==========================================
  2954. *
  2955. *------------------------------------------
  2956. */
  2957. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2958. {
  2959. int fd;
  2960. nullpo_retr(0, sd);
  2961. fd=sd->fd;
  2962. WFIFOHEAD(fd,packet_len(0xda));
  2963. WFIFOW(fd,0)=0xda;
  2964. WFIFOB(fd,2)=fail;
  2965. WFIFOSET(fd,packet_len(0xda));
  2966. return 0;
  2967. }
  2968. /*==========================================
  2969. *
  2970. *------------------------------------------
  2971. */
  2972. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2973. {
  2974. int fd;
  2975. int i;
  2976. nullpo_retr(0, sd);
  2977. nullpo_retr(0, cd);
  2978. fd = sd->fd;
  2979. if (!session_isActive(fd))
  2980. return 0;
  2981. WFIFOHEAD(fd, 8 + (28*cd->users));
  2982. WFIFOW(fd, 0) = 0xdb;
  2983. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2984. WFIFOL(fd, 4) = cd->bl.id;
  2985. for (i = 0; i < cd->users; i++) {
  2986. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  2987. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2988. }
  2989. WFIFOSET(fd, WFIFOW(fd, 2));
  2990. return 0;
  2991. }
  2992. /*==========================================
  2993. *
  2994. *------------------------------------------
  2995. */
  2996. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2997. {
  2998. unsigned char buf[32];
  2999. nullpo_retr(0, sd);
  3000. nullpo_retr(0, cd);
  3001. WBUFW(buf, 0) = 0x0dc;
  3002. WBUFW(buf, 2) = cd->users;
  3003. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3004. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3005. return 0;
  3006. }
  3007. /*==========================================
  3008. *
  3009. *------------------------------------------
  3010. */
  3011. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  3012. {
  3013. unsigned char buf[64];
  3014. nullpo_retr(0, sd);
  3015. nullpo_retr(0, cd);
  3016. WBUFW(buf, 0) = 0xe1;
  3017. WBUFL(buf, 2) = 1;
  3018. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3019. WBUFW(buf,30) = 0xe1;
  3020. WBUFL(buf,32) = 0;
  3021. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3022. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3023. return 0;
  3024. }
  3025. /*==========================================
  3026. *
  3027. *------------------------------------------
  3028. */
  3029. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  3030. {
  3031. unsigned char buf[32];
  3032. nullpo_retr(0, sd);
  3033. nullpo_retr(0, cd);
  3034. WBUFW(buf, 0) = 0xdd;
  3035. WBUFW(buf, 2) = cd->users-1;
  3036. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3037. WBUFB(buf,28) = 0;
  3038. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3039. return 0;
  3040. }
  3041. /*==========================================
  3042. * 取り引き要請受け
  3043. *------------------------------------------
  3044. */
  3045. int clif_traderequest(struct map_session_data *sd,char *name)
  3046. {
  3047. int fd;
  3048. nullpo_retr(0, sd);
  3049. fd=sd->fd;
  3050. WFIFOHEAD(fd,packet_len(0xe5));
  3051. WFIFOW(fd,0)=0xe5;
  3052. strcpy((char*)WFIFOP(fd,2),name);
  3053. WFIFOSET(fd,packet_len(0xe5));
  3054. return 0;
  3055. }
  3056. /*==========================================
  3057. * 取り引き要求応答
  3058. *------------------------------------------
  3059. */
  3060. int clif_tradestart(struct map_session_data *sd,int type)
  3061. {
  3062. int fd;
  3063. nullpo_retr(0, sd);
  3064. fd=sd->fd;
  3065. WFIFOHEAD(fd,packet_len(0xe7));
  3066. WFIFOW(fd,0)=0xe7;
  3067. WFIFOB(fd,2)=type;
  3068. WFIFOSET(fd,packet_len(0xe7));
  3069. return 0;
  3070. }
  3071. /*==========================================
  3072. * 相手方からのアイテム追加
  3073. *------------------------------------------
  3074. */
  3075. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  3076. {
  3077. int fd;
  3078. nullpo_retr(0, sd);
  3079. nullpo_retr(0, tsd);
  3080. fd=tsd->fd;
  3081. WFIFOHEAD(fd,packet_len(0xe9));
  3082. WFIFOW(fd,0)=0xe9;
  3083. WFIFOL(fd,2)=amount;
  3084. if(index==0){
  3085. WFIFOW(fd,6) = 0; // type id
  3086. WFIFOB(fd,8) = 0; //identify flag
  3087. WFIFOB(fd,9) = 0; // attribute
  3088. WFIFOB(fd,10)= 0; //refine
  3089. WFIFOW(fd,11)= 0; //card (4w)
  3090. WFIFOW(fd,13)= 0; //card (4w)
  3091. WFIFOW(fd,15)= 0; //card (4w)
  3092. WFIFOW(fd,17)= 0; //card (4w)
  3093. }
  3094. else{
  3095. index-=2; //index fix
  3096. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3097. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3098. else
  3099. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3100. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3101. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3102. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3103. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3104. }
  3105. WFIFOSET(fd,packet_len(0xe9));
  3106. return 0;
  3107. }
  3108. /*==========================================
  3109. * アイテム追加成功/失敗
  3110. *------------------------------------------
  3111. */
  3112. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3113. {
  3114. int fd;
  3115. nullpo_retr(0, sd);
  3116. fd=sd->fd;
  3117. WFIFOHEAD(fd,packet_len(0xea));
  3118. WFIFOW(fd,0)=0xea;
  3119. WFIFOW(fd,2)=index;
  3120. WFIFOB(fd,4)=fail;
  3121. WFIFOSET(fd,packet_len(0xea));
  3122. return 0;
  3123. }
  3124. /*==========================================
  3125. * 取り引きok押し
  3126. *------------------------------------------
  3127. */
  3128. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3129. {
  3130. int fd;
  3131. nullpo_retr(0, sd);
  3132. fd=sd->fd;
  3133. WFIFOHEAD(fd,packet_len(0xec));
  3134. WFIFOW(fd,0)=0xec;
  3135. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3136. WFIFOSET(fd,packet_len(0xec));
  3137. return 0;
  3138. }
  3139. /*==========================================
  3140. * 取り引きがキャンセルされました
  3141. *------------------------------------------
  3142. */
  3143. int clif_tradecancelled(struct map_session_data *sd)
  3144. {
  3145. int fd;
  3146. nullpo_retr(0, sd);
  3147. fd=sd->fd;
  3148. WFIFOHEAD(fd,packet_len(0xee));
  3149. WFIFOW(fd,0)=0xee;
  3150. WFIFOSET(fd,packet_len(0xee));
  3151. return 0;
  3152. }
  3153. /*==========================================
  3154. * 取り引き完了
  3155. *------------------------------------------
  3156. */
  3157. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3158. {
  3159. int fd;
  3160. nullpo_retr(0, sd);
  3161. fd=sd->fd;
  3162. WFIFOHEAD(fd,packet_len(0xf0));
  3163. WFIFOW(fd,0)=0xf0;
  3164. WFIFOB(fd,2)=fail;
  3165. WFIFOSET(fd,packet_len(0xf0));
  3166. return 0;
  3167. }
  3168. /*==========================================
  3169. * カプラ倉庫のアイテム数を更新
  3170. *------------------------------------------
  3171. */
  3172. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3173. {
  3174. int fd;
  3175. nullpo_retr(0, sd);
  3176. nullpo_retr(0, stor);
  3177. fd=sd->fd;
  3178. WFIFOHEAD(fd,packet_len(0xf2));
  3179. WFIFOW(fd,0) = 0xf2; // update storage amount
  3180. WFIFOW(fd,2) = stor->storage_amount; //items
  3181. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3182. WFIFOSET(fd,packet_len(0xf2));
  3183. return 0;
  3184. }
  3185. /*==========================================
  3186. * カプラ倉庫にアイテムを追加する
  3187. *------------------------------------------
  3188. */
  3189. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3190. {
  3191. int view,fd;
  3192. nullpo_retr(0, sd);
  3193. nullpo_retr(0, stor);
  3194. fd=sd->fd;
  3195. WFIFOHEAD(fd,packet_len(0xf4));
  3196. WFIFOW(fd,0) =0xf4; // Storage item added
  3197. WFIFOW(fd,2) =index+1; // index
  3198. WFIFOL(fd,4) =amount; // amount
  3199. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3200. WFIFOW(fd,8) =view;
  3201. else
  3202. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3203. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3204. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3205. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3206. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3207. WFIFOSET(fd,packet_len(0xf4));
  3208. return 0;
  3209. }
  3210. /*==========================================
  3211. *
  3212. *------------------------------------------
  3213. */
  3214. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3215. {
  3216. int fd;
  3217. nullpo_retr(0, sd);
  3218. nullpo_retr(0, stor);
  3219. fd=sd->fd;
  3220. WFIFOHEAD(fd,packet_len(0xf2));
  3221. WFIFOW(fd,0) = 0xf2; // update storage amount
  3222. WFIFOW(fd,2) = stor->storage_amount; //items
  3223. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3224. WFIFOSET(fd,packet_len(0xf2));
  3225. return 0;
  3226. }
  3227. /*==========================================
  3228. *
  3229. *------------------------------------------
  3230. */
  3231. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3232. {
  3233. int view,fd;
  3234. nullpo_retr(0, sd);
  3235. nullpo_retr(0, stor);
  3236. fd=sd->fd;
  3237. WFIFOHEAD(fd,packet_len(0xf4));
  3238. WFIFOW(fd,0) =0xf4; // Storage item added
  3239. WFIFOW(fd,2) =index+1; // index
  3240. WFIFOL(fd,4) =amount; // amount
  3241. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3242. WFIFOW(fd,8) =view;
  3243. else
  3244. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3245. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3246. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3247. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3248. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3249. WFIFOSET(fd,packet_len(0xf4));
  3250. return 0;
  3251. }
  3252. /*==========================================
  3253. * カプラ倉庫からアイテムを取り去る
  3254. *------------------------------------------
  3255. */
  3256. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3257. {
  3258. int fd;
  3259. nullpo_retr(0, sd);
  3260. fd=sd->fd;
  3261. WFIFOHEAD(fd,packet_len(0xf6));
  3262. WFIFOW(fd,0)=0xf6; // Storage item removed
  3263. WFIFOW(fd,2)=index+1;
  3264. WFIFOL(fd,4)=amount;
  3265. WFIFOSET(fd,packet_len(0xf6));
  3266. return 0;
  3267. }
  3268. /*==========================================
  3269. * カプラ倉庫を閉じる
  3270. *------------------------------------------
  3271. */
  3272. int clif_storageclose(struct map_session_data *sd)
  3273. {
  3274. int fd;
  3275. nullpo_retr(0, sd);
  3276. fd=sd->fd;
  3277. WFIFOHEAD(fd,packet_len(0xf8));
  3278. WFIFOW(fd,0)=0xf8; // Storage Closed
  3279. WFIFOSET(fd,packet_len(0xf8));
  3280. return 0;
  3281. }
  3282. //
  3283. // callback系 ?
  3284. //
  3285. /*==========================================
  3286. * PC表示
  3287. *------------------------------------------
  3288. */
  3289. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3290. {
  3291. int len;
  3292. if(dstsd->chatID){
  3293. struct chat_data *cd;
  3294. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3295. if(cd && cd->usersd[0]==dstsd)
  3296. clif_dispchat(cd,sd->fd);
  3297. }
  3298. if(dstsd->vender_id)
  3299. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3300. if(dstsd->spiritball > 0)
  3301. clif_spiritball_single(sd->fd, dstsd);
  3302. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3303. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3304. )
  3305. clif_hpmeter_single(sd->fd, dstsd);
  3306. if(dstsd->status.manner < 0)
  3307. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3308. // pvp circle for duel [LuzZza]
  3309. /*
  3310. if(dstsd->duel_group)
  3311. clif_specialeffect(&dstsd->bl, 159, 4);
  3312. */
  3313. }
  3314. void clif_getareachar_char(struct map_session_data* sd,struct block_list *bl)
  3315. {
  3316. struct unit_data *ud;
  3317. struct view_data *vd;
  3318. int len, fd = sd->fd;
  3319. vd = status_get_viewdata(bl);
  3320. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3321. return;
  3322. ud = unit_bl2ud(bl);
  3323. if (ud && ud->walktimer != -1)
  3324. {
  3325. #if PACKETVER > 6
  3326. WFIFOHEAD(fd, packet_len(0x22c));
  3327. #elif PACKETVER > 3
  3328. WFIFOHEAD(fd, packet_len(0x1da));
  3329. #else
  3330. WFIFOHEAD(fd, packet_len(0x7b));
  3331. #endif
  3332. len = clif_set007b(bl,vd,ud,WFIFOP(fd,0));
  3333. WFIFOSET(fd,len);
  3334. } else {
  3335. #if PACKETVER > 6
  3336. WFIFOHEAD(fd,packet_len(0x22a));
  3337. #elif PACKETVER > 3
  3338. WFIFOHEAD(fd,packet_len(0x1d8));
  3339. #else
  3340. WFIFOHEAD(fd,packet_len(0x78));
  3341. #endif
  3342. len = clif_set0078(bl,vd,WFIFOP(fd,0));
  3343. WFIFOSET(fd,len);
  3344. }
  3345. if (vd->cloth_color)
  3346. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3347. switch (bl->type)
  3348. {
  3349. case BL_PC:
  3350. {
  3351. TBL_PC* tsd = (TBL_PC*)bl;
  3352. clif_getareachar_pc(sd, tsd);
  3353. if(tsd->state.size==2) // tiny/big players [Valaris]
  3354. clif_specialeffect(bl,423,AREA);
  3355. else if(tsd->state.size==1)
  3356. clif_specialeffect(bl,421,AREA);
  3357. }
  3358. break;
  3359. case BL_NPC:
  3360. {
  3361. if(((TBL_NPC*)bl)->chat_id)
  3362. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3363. }
  3364. break;
  3365. case BL_MOB:
  3366. {
  3367. TBL_MOB* md = (TBL_MOB*)bl;
  3368. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3369. clif_specialeffect(bl,423,AREA);
  3370. else if(md->special_state.size==1)
  3371. clif_specialeffect(bl,421,AREA);
  3372. }
  3373. break;
  3374. }
  3375. }
  3376. /*==========================================
  3377. * Older fix pos packet.
  3378. *------------------------------------------
  3379. */
  3380. int clif_fixpos2(struct block_list* bl)
  3381. {
  3382. struct unit_data *ud;
  3383. struct view_data *vd;
  3384. unsigned char buf[256];
  3385. int len;
  3386. nullpo_retr(0, bl);
  3387. ud = unit_bl2ud(bl);
  3388. vd = status_get_viewdata(bl);
  3389. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3390. return 0;
  3391. if(ud && ud->walktimer != -1)
  3392. len = clif_set007b(bl,vd,ud,buf);
  3393. else
  3394. len = clif_set0078(bl,vd,buf);
  3395. if (disguised(bl)) {
  3396. clif_send(buf,len,bl,AREA_WOS);
  3397. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  3398. clif_setdisguise((TBL_PC*)bl, buf, len, 1);
  3399. } else
  3400. clif_send(buf,len,bl,AREA);
  3401. return 0;
  3402. }
  3403. //Modifies the type of damage according to status changes [Skotlex]
  3404. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3405. /*==========================================
  3406. * Estimates walk delay based on the damage criteria. [Skotlex]
  3407. *------------------------------------------
  3408. */
  3409. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3410. if (type == 4 || type == 9 || damage <=0)
  3411. return 0;
  3412. if (bl->type == BL_PC) {
  3413. if (battle_config.pc_walk_delay_rate != 100)
  3414. delay = delay*battle_config.pc_walk_delay_rate/100;
  3415. } else
  3416. if (battle_config.walk_delay_rate != 100)
  3417. delay = delay*battle_config.walk_delay_rate/100;
  3418. if (div_ > 1) //Multi-hit skills mean higher delays.
  3419. delay += battle_config.multihit_delay*(div_-1);
  3420. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3421. }
  3422. /*==========================================
  3423. * 通常攻撃エフェクト&ダメージ
  3424. *------------------------------------------
  3425. */
  3426. 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)
  3427. {
  3428. unsigned char buf[256];
  3429. struct status_change *sc;
  3430. nullpo_retr(0, src);
  3431. nullpo_retr(0, dst);
  3432. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3433. sc = status_get_sc(dst);
  3434. if(sc && sc->count) {
  3435. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3436. if(damage > 0)
  3437. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3438. if(damage2 > 0)
  3439. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3440. }
  3441. }
  3442. WBUFW(buf,0)=0x8a;
  3443. WBUFL(buf,2)=src->id;
  3444. WBUFL(buf,6)=dst->id;
  3445. WBUFL(buf,10)=tick;
  3446. WBUFL(buf,14)=sdelay;
  3447. WBUFL(buf,18)=ddelay;
  3448. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3449. WBUFW(buf,22)=damage?div:0;
  3450. WBUFW(buf,27)=damage2?div:0;
  3451. } else {
  3452. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3453. WBUFW(buf,27)=damage2;
  3454. }
  3455. WBUFW(buf,24)=div;
  3456. WBUFB(buf,26)=type;
  3457. clif_send(buf,packet_len(0x8a),src,AREA);
  3458. if(disguised(src)) {
  3459. WBUFL(buf,2)=-src->id;
  3460. if(damage > 0)
  3461. WBUFW(buf,22)=-1;
  3462. if(damage2 > 0)
  3463. WBUFW(buf,27)=-1;
  3464. clif_send(buf,packet_len(0x8a),src,SELF);
  3465. }
  3466. if (disguised(dst)) {
  3467. WBUFL(buf,6)=-dst->id;
  3468. if (disguised(src))
  3469. WBUFL(buf,2)=src->id;
  3470. else {
  3471. if(damage > 0)
  3472. WBUFW(buf,22)=-1;
  3473. if(damage2 > 0)
  3474. WBUFW(buf,27)=-1;
  3475. }
  3476. clif_send(buf,packet_len(0x8a),dst,SELF);
  3477. }
  3478. //Return adjusted can't walk delay for further processing.
  3479. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3480. }
  3481. /*==========================================
  3482. *
  3483. *------------------------------------------
  3484. */
  3485. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3486. {
  3487. int view,fd;
  3488. fd=sd->fd;
  3489. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3490. WFIFOHEAD(fd,packet_len(0x9d));
  3491. WFIFOW(fd,0)=0x9d;
  3492. WFIFOL(fd,2)=fitem->bl.id;
  3493. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3494. WFIFOW(fd,6)=view;
  3495. else
  3496. WFIFOW(fd,6)=fitem->item_data.nameid;
  3497. WFIFOB(fd,8)=fitem->item_data.identify;
  3498. WFIFOW(fd,9)=fitem->bl.x;
  3499. WFIFOW(fd,11)=fitem->bl.y;
  3500. WFIFOW(fd,13)=fitem->item_data.amount;
  3501. WFIFOB(fd,15)=fitem->subx;
  3502. WFIFOB(fd,16)=fitem->suby;
  3503. WFIFOSET(fd,packet_len(0x9d));
  3504. }
  3505. /*==========================================
  3506. * 場所スキルエフェクトが視界に入る
  3507. *------------------------------------------
  3508. */
  3509. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3510. {
  3511. int fd;
  3512. struct block_list *bl;
  3513. fd=sd->fd;
  3514. bl=map_id2bl(unit->group->src_id);
  3515. #if PACKETVER >= 3
  3516. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3517. WFIFOHEAD(fd,packet_len(0x1c9));
  3518. memset(WFIFOP(fd,0),0,packet_len(0x1c9));
  3519. WFIFOW(fd, 0)=0x1c9;
  3520. WFIFOL(fd, 2)=unit->bl.id;
  3521. WFIFOL(fd, 6)=unit->group->src_id;
  3522. WFIFOW(fd,10)=unit->bl.x;
  3523. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3524. WFIFOB(fd,14)=unit->group->unit_id;
  3525. WFIFOB(fd,15)=1;
  3526. WFIFOB(fd,16)=1;
  3527. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3528. WFIFOSET(fd,packet_len(0x1c9));
  3529. return 0;
  3530. }
  3531. #endif
  3532. WFIFOHEAD(fd,packet_len(0x11f));
  3533. memset(WFIFOP(fd,0),0,packet_len(0x11f));
  3534. WFIFOW(fd, 0)=0x11f;
  3535. WFIFOL(fd, 2)=unit->bl.id;
  3536. WFIFOL(fd, 6)=unit->group->src_id;
  3537. WFIFOW(fd,10)=unit->bl.x;
  3538. WFIFOW(fd,12)=unit->bl.y;
  3539. //Use invisible unit id for traps.
  3540. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3541. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3542. else
  3543. WFIFOB(fd,14)=unit->group->unit_id;
  3544. WFIFOB(fd,15)=0;
  3545. WFIFOSET(fd,packet_len(0x11f));
  3546. if(unit->group->skill_id == WZ_ICEWALL)
  3547. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3548. return 0;
  3549. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3550. WFIFOHEAD(fd,packet_len(0x1c9));
  3551. memset(WFIFOP(fd,0),0,packet_len(0x1c9));
  3552. WFIFOW(fd, 0)=0x1c9;
  3553. WFIFOL(fd, 2)=unit->bl.id;
  3554. WFIFOL(fd, 6)=unit->group->src_id;
  3555. WFIFOW(fd,10)=unit->bl.x;
  3556. WFIFOW(fd,12)=unit->bl.y;
  3557. WFIFOB(fd,14)=unit->group->unit_id;
  3558. WFIFOB(fd,15)=1;
  3559. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3560. WFIFOB(fd,16)=1;
  3561. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3562. } else {
  3563. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3564. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3565. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3566. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3567. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3568. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3569. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3570. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3571. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3572. //37-39
  3573. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3574. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3575. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3576. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3577. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3578. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3579. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3580. //65-68
  3581. //69-72
  3582. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3583. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3584. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3585. }
  3586. WFIFOSET(fd,packet_len(0x1c9));
  3587. #endif
  3588. if(unit->group->skill_id == WZ_ICEWALL)
  3589. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3590. return 0;
  3591. */
  3592. }
  3593. /*==========================================
  3594. * 場所スキルエフェクトが視界から消える
  3595. *------------------------------------------
  3596. */
  3597. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3598. {
  3599. nullpo_retr(0, unit);
  3600. WFIFOHEAD(fd,packet_len(0x120));
  3601. WFIFOW(fd, 0)=0x120;
  3602. WFIFOL(fd, 2)=unit->bl.id;
  3603. WFIFOSET(fd,packet_len(0x120));
  3604. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3605. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3606. return 0;
  3607. }
  3608. /*==========================================
  3609. * Unknown... trap related?
  3610. * Only affects units with class [139,153] client-side
  3611. *------------------------------------------
  3612. */
  3613. int clif_01ac(struct block_list *bl)
  3614. {
  3615. unsigned char buf[32];
  3616. nullpo_retr(0, bl);
  3617. WBUFW(buf, 0) = 0x1ac;
  3618. WBUFL(buf, 2) = bl->id;
  3619. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3620. return 0;
  3621. }
  3622. /*==========================================
  3623. *
  3624. *------------------------------------------
  3625. */
  3626. int clif_getareachar(struct block_list* bl,va_list ap)
  3627. {
  3628. struct map_session_data *sd;
  3629. nullpo_retr(0, bl);
  3630. nullpo_retr(0, ap);
  3631. sd=va_arg(ap,struct map_session_data*);
  3632. if (sd == NULL || !sd->fd || session[sd->fd] == NULL)
  3633. return 0;
  3634. switch(bl->type){
  3635. case BL_ITEM:
  3636. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3637. break;
  3638. case BL_SKILL:
  3639. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3640. break;
  3641. default:
  3642. if(&sd->bl == bl)
  3643. break;
  3644. clif_getareachar_char(sd,bl);
  3645. break;
  3646. }
  3647. return 0;
  3648. }
  3649. /*==========================================
  3650. * tbl has gone out of view-size of bl
  3651. *------------------------------------------
  3652. */
  3653. int clif_outsight(struct block_list *bl,va_list ap)
  3654. {
  3655. struct block_list *tbl;
  3656. struct view_data *vd;
  3657. TBL_PC *sd, *tsd;
  3658. tbl=va_arg(ap,struct block_list*);
  3659. if(bl == tbl) return 0;
  3660. BL_CAST(BL_PC, bl, sd);
  3661. BL_CAST(BL_PC, tbl, tsd);
  3662. if (tsd && tsd->fd)
  3663. { //tsd has lost sight of the bl object.
  3664. switch(bl->type){
  3665. case BL_PC:
  3666. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3667. clif_clearchar_id(bl->id,0,tsd->fd);
  3668. if(sd->chatID){
  3669. struct chat_data *cd;
  3670. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3671. if(cd->usersd[0]==sd)
  3672. clif_dispchat(cd,tsd->fd);
  3673. }
  3674. if(sd->vender_id)
  3675. clif_closevendingboard(bl,tsd->fd);
  3676. break;
  3677. case BL_ITEM:
  3678. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3679. break;
  3680. case BL_SKILL:
  3681. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3682. break;
  3683. default:
  3684. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3685. clif_clearchar_id(bl->id,0,tsd->fd);
  3686. break;
  3687. }
  3688. }
  3689. if (sd && sd->fd)
  3690. { //sd is watching tbl go out of view.
  3691. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3692. clif_clearchar_id(tbl->id,0,sd->fd);
  3693. }
  3694. return 0;
  3695. }
  3696. /*==========================================
  3697. * tbl has come into view of bl
  3698. *------------------------------------------
  3699. */
  3700. int clif_insight(struct block_list *bl,va_list ap)
  3701. {
  3702. struct block_list *tbl;
  3703. TBL_PC *sd, *tsd;
  3704. tbl=va_arg(ap,struct block_list*);
  3705. if (bl == tbl) return 0;
  3706. BL_CAST(BL_PC, bl, sd);
  3707. BL_CAST(BL_PC, tbl, tsd);
  3708. if (tsd && tsd->fd)
  3709. { //Tell tsd that bl entered into his view
  3710. switch(bl->type){
  3711. case BL_ITEM:
  3712. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3713. break;
  3714. case BL_SKILL:
  3715. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3716. break;
  3717. default:
  3718. clif_getareachar_char(tsd,bl);
  3719. break;
  3720. }
  3721. }
  3722. if (sd && sd->fd)
  3723. { //Tell sd that tbl walked into his view
  3724. clif_getareachar_char(sd,tbl);
  3725. }
  3726. return 0;
  3727. }
  3728. /*==========================================
  3729. *
  3730. *------------------------------------------
  3731. */
  3732. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3733. {
  3734. int fd,id;
  3735. nullpo_retr(0, sd);
  3736. fd=sd->fd;
  3737. if( (id=sd->status.skill[skillid].id) <= 0 )
  3738. return 0;
  3739. WFIFOHEAD(fd,packet_len(0x147));
  3740. WFIFOW(fd,0)=0x147;
  3741. WFIFOW(fd,2) = id;
  3742. if(type < 0)
  3743. WFIFOW(fd,4) = skill_get_inf(id);
  3744. else
  3745. WFIFOW(fd,4) = type;
  3746. WFIFOW(fd,6) = 0;
  3747. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3748. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3749. if(range < 0)
  3750. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3751. WFIFOW(fd,12)= range;
  3752. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3753. if(sd->status.skill[skillid].flag ==0)
  3754. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3755. else
  3756. WFIFOB(fd,38) = 0;
  3757. WFIFOSET(fd,packet_len(0x147));
  3758. return 0;
  3759. }
  3760. /*==========================================
  3761. * スキルリストを送信する
  3762. *------------------------------------------
  3763. */
  3764. int clif_skillinfoblock(struct map_session_data *sd)
  3765. {
  3766. int fd;
  3767. int i,c,len=4,id;
  3768. nullpo_retr(0, sd);
  3769. fd=sd->fd;
  3770. if (!fd) return 0;
  3771. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3772. WFIFOW(fd,0)=0x10f;
  3773. for ( i = c = 0; i < MAX_SKILL; i++){
  3774. if( (id=sd->status.skill[i].id)!=0 ){
  3775. WFIFOW(fd,len ) = id;
  3776. WFIFOW(fd,len+2) = skill_get_inf(id);
  3777. WFIFOW(fd,len+4) = 0;
  3778. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3779. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3780. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3781. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3782. if(sd->status.skill[i].flag ==0)
  3783. WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3784. else
  3785. WFIFOB(fd,len+36) = 0;
  3786. len+=37;
  3787. c++;
  3788. }
  3789. }
  3790. WFIFOW(fd,2)=len;
  3791. WFIFOSET(fd,len);
  3792. return 1;
  3793. }
  3794. /*==========================================
  3795. * スキル割り振り通知
  3796. *------------------------------------------
  3797. */
  3798. int clif_skillup(struct map_session_data *sd,int skill_num)
  3799. {
  3800. int fd;
  3801. nullpo_retr(0, sd);
  3802. fd=sd->fd;
  3803. WFIFOHEAD(fd,packet_len(0x10e));
  3804. WFIFOW(fd,0) = 0x10e;
  3805. WFIFOW(fd,2) = skill_num;
  3806. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3807. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3808. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3809. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3810. WFIFOSET(fd,packet_len(0x10e));
  3811. return 0;
  3812. }
  3813. /*==========================================
  3814. * スキル詠唱エフェクトを送信する
  3815. *------------------------------------------
  3816. */
  3817. int clif_skillcasting(struct block_list* bl,
  3818. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  3819. {
  3820. int pl = skill_get_pl(skill_num);
  3821. unsigned char buf[32];
  3822. WBUFW(buf,0) = 0x13e;
  3823. WBUFL(buf,2) = src_id;
  3824. WBUFL(buf,6) = dst_id;
  3825. WBUFW(buf,10) = dst_x;
  3826. WBUFW(buf,12) = dst_y;
  3827. WBUFW(buf,14) = skill_num;
  3828. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3829. WBUFL(buf,20) = casttime;
  3830. clif_send(buf,packet_len(0x13e), bl, AREA);
  3831. if (disguised(bl)) {
  3832. WBUFL(buf,2) = -src_id;
  3833. WBUFL(buf,20) = 0;
  3834. clif_send(buf,packet_len(0x13e), bl, SELF);
  3835. }
  3836. return 0;
  3837. }
  3838. /*==========================================
  3839. *
  3840. *------------------------------------------
  3841. */
  3842. int clif_skillcastcancel(struct block_list* bl)
  3843. {
  3844. unsigned char buf[16];
  3845. nullpo_retr(0, bl);
  3846. WBUFW(buf,0) = 0x1b9;
  3847. WBUFL(buf,2) = bl->id;
  3848. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3849. return 0;
  3850. }
  3851. /*==========================================
  3852. * スキル詠唱失敗
  3853. *------------------------------------------
  3854. */
  3855. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3856. {
  3857. int fd;
  3858. if (!sd) { //Since this is the most common nullpo....
  3859. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3860. return 0;
  3861. }
  3862. fd=sd->fd;
  3863. if(battle_config.display_skill_fail&1)
  3864. return 0; //Disable all skill failed messages
  3865. if(type==0x4 && !sd->state.showdelay)
  3866. return 0; //Disable delay failed messages
  3867. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3868. return 0;
  3869. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3870. return 0;
  3871. WFIFOHEAD(fd,packet_len(0x110));
  3872. WFIFOW(fd,0) = 0x110;
  3873. WFIFOW(fd,2) = skill_id;
  3874. WFIFOW(fd,4) = btype;
  3875. WFIFOW(fd,6) = 0;
  3876. WFIFOB(fd,8) = 0;
  3877. WFIFOB(fd,9) = type;
  3878. WFIFOSET(fd,packet_len(0x110));
  3879. return 1;
  3880. }
  3881. /*==========================================
  3882. * スキル攻撃エフェクト&ダメージ
  3883. *------------------------------------------
  3884. */
  3885. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  3886. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3887. {
  3888. unsigned char buf[64];
  3889. struct status_change *sc;
  3890. nullpo_retr(0, src);
  3891. nullpo_retr(0, dst);
  3892. type = (type>0)?type:skill_get_hit(skill_id);
  3893. type = clif_calc_delay(type, ddelay);
  3894. sc = status_get_sc(dst);
  3895. if(sc && sc->count) {
  3896. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3897. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3898. }
  3899. #if PACKETVER < 3
  3900. WBUFW(buf,0)=0x114;
  3901. WBUFW(buf,2)=skill_id;
  3902. WBUFL(buf,4)=src->id;
  3903. WBUFL(buf,8)=dst->id;
  3904. WBUFL(buf,12)=tick;
  3905. WBUFL(buf,16)=sdelay;
  3906. WBUFL(buf,20)=ddelay;
  3907. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3908. WBUFW(buf,24)=damage?div:0;
  3909. } else {
  3910. WBUFW(buf,24)=damage;
  3911. }
  3912. WBUFW(buf,26)=skill_lv;
  3913. WBUFW(buf,28)=div;
  3914. WBUFB(buf,30)=type;
  3915. clif_send(buf,packet_len(0x114),src,AREA);
  3916. if(disguised(src)) {
  3917. WBUFL(buf,4)=-src->id;
  3918. if(damage > 0)
  3919. WBUFW(buf,24)=-1;
  3920. clif_send(buf,packet_len(0x114),src,SELF);
  3921. }
  3922. if (disguised(dst)) {
  3923. WBUFL(buf,8)=-dst->id;
  3924. if (disguised(src))
  3925. WBUFL(buf,4)=src->id;
  3926. else if(damage > 0)
  3927. WBUFW(buf,24)=-1;
  3928. clif_send(buf,packet_len(0x114),dst,SELF);
  3929. }
  3930. #else
  3931. WBUFW(buf,0)=0x1de;
  3932. WBUFW(buf,2)=skill_id;
  3933. WBUFL(buf,4)=src->id;
  3934. WBUFL(buf,8)=dst->id;
  3935. WBUFL(buf,12)=tick;
  3936. WBUFL(buf,16)=sdelay;
  3937. WBUFL(buf,20)=ddelay;
  3938. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3939. WBUFL(buf,24)=damage?div:0;
  3940. } else {
  3941. WBUFL(buf,24)=damage;
  3942. }
  3943. WBUFW(buf,28)=skill_lv;
  3944. WBUFW(buf,30)=div;
  3945. WBUFB(buf,32)=type;
  3946. clif_send(buf,packet_len(0x1de),src,AREA);
  3947. if(disguised(src)) {
  3948. WBUFL(buf,4)=-src->id;
  3949. if(damage > 0)
  3950. WBUFL(buf,24)=-1;
  3951. clif_send(buf,packet_len(0x1de),src,SELF);
  3952. }
  3953. if (disguised(dst)) {
  3954. WBUFL(buf,8)=-dst->id;
  3955. if (disguised(src))
  3956. WBUFL(buf,4)=src->id;
  3957. else if(damage > 0)
  3958. WBUFL(buf,24)=-1;
  3959. clif_send(buf,packet_len(0x1de),dst,SELF);
  3960. }
  3961. #endif
  3962. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3963. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3964. }
  3965. /*==========================================
  3966. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3967. *------------------------------------------
  3968. */
  3969. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  3970. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3971. {
  3972. unsigned char buf[64];
  3973. struct status_change *sc;
  3974. nullpo_retr(0, src);
  3975. nullpo_retr(0, dst);
  3976. type = (type>0)?type:skill_get_hit(skill_id);
  3977. type = clif_calc_delay(type, ddelay);
  3978. sc = status_get_sc(dst);
  3979. if(sc && sc->count) {
  3980. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3981. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3982. }
  3983. WBUFW(buf,0)=0x115;
  3984. WBUFW(buf,2)=skill_id;
  3985. WBUFL(buf,4)=src->id;
  3986. WBUFL(buf,8)=dst->id;
  3987. WBUFL(buf,12)=tick;
  3988. WBUFL(buf,16)=sdelay;
  3989. WBUFL(buf,20)=ddelay;
  3990. WBUFW(buf,24)=dst->x;
  3991. WBUFW(buf,26)=dst->y;
  3992. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3993. WBUFW(buf,28)=damage?div:0;
  3994. } else {
  3995. WBUFW(buf,28)=damage;
  3996. }
  3997. WBUFW(buf,30)=skill_lv;
  3998. WBUFW(buf,32)=div;
  3999. WBUFB(buf,34)=type;
  4000. clif_send(buf,packet_len(0x115),src,AREA);
  4001. if(disguised(src)) {
  4002. WBUFL(buf,4)=-src->id;
  4003. if(damage > 0)
  4004. WBUFW(buf,28)=-1;
  4005. clif_send(buf,packet_len(0x115),src,SELF);
  4006. }
  4007. if (disguised(dst)) {
  4008. WBUFL(buf,8)=-dst->id;
  4009. if (disguised(src))
  4010. WBUFL(buf,4)=src->id;
  4011. else if(damage > 0)
  4012. WBUFW(buf,28)=-1;
  4013. clif_send(buf,packet_len(0x115),dst,SELF);
  4014. }
  4015. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4016. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4017. }
  4018. /*==========================================
  4019. * 支援/回復スキルエフェクト
  4020. *------------------------------------------
  4021. */
  4022. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  4023. int skill_id,int heal,int fail)
  4024. {
  4025. unsigned char buf[32];
  4026. nullpo_retr(0, dst);
  4027. WBUFW(buf,0)=0x11a;
  4028. WBUFW(buf,2)=skill_id;
  4029. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  4030. WBUFL(buf,6)=dst->id;
  4031. WBUFL(buf,10)=src?src->id:0;
  4032. WBUFB(buf,14)=fail;
  4033. clif_send(buf,packet_len(0x11a),dst,AREA);
  4034. if (disguised(dst)) {
  4035. WBUFL(buf,6)=-dst->id;
  4036. clif_send(buf,packet_len(0x115),dst,SELF);
  4037. }
  4038. if(src && disguised(src)) {
  4039. WBUFL(buf,10)=-src->id;
  4040. if (disguised(dst))
  4041. WBUFL(buf,6)=dst->id;
  4042. clif_send(buf,packet_len(0x115),src,SELF);
  4043. }
  4044. return fail;
  4045. }
  4046. /*==========================================
  4047. * 場所スキルエフェクト
  4048. *------------------------------------------
  4049. */
  4050. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4051. {
  4052. unsigned char buf[32];
  4053. nullpo_retr(0, src);
  4054. WBUFW(buf,0)=0x117;
  4055. WBUFW(buf,2)=skill_id;
  4056. WBUFL(buf,4)=src->id;
  4057. WBUFW(buf,8)=val;
  4058. WBUFW(buf,10)=x;
  4059. WBUFW(buf,12)=y;
  4060. WBUFL(buf,14)=tick;
  4061. clif_send(buf,packet_len(0x117),src,AREA);
  4062. if(disguised(src)) {
  4063. WBUFL(buf,4)=-src->id;
  4064. clif_send(buf,packet_len(0x117),src,SELF);
  4065. }
  4066. return 0;
  4067. }
  4068. /*==========================================
  4069. * 場所スキルエフェクト表示
  4070. *------------------------------------------
  4071. */
  4072. int clif_skill_setunit(struct skill_unit *unit)
  4073. {
  4074. unsigned char buf[128];
  4075. struct block_list *bl;
  4076. nullpo_retr(0, unit);
  4077. bl=map_id2bl(unit->group->src_id);
  4078. // These are invisible client-side, but are necessary because
  4079. // otherwise the client will not know who caused the attack.
  4080. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  4081. // return 0;
  4082. #if PACKETVER >= 3
  4083. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4084. memset(WBUFP(buf, 0),0,packet_len(0x1c9));
  4085. WBUFW(buf, 0)=0x1c9;
  4086. WBUFL(buf, 2)=unit->bl.id;
  4087. WBUFL(buf, 6)=unit->group->src_id;
  4088. WBUFW(buf,10)=unit->bl.x;
  4089. WBUFW(buf,12)=unit->bl.y;
  4090. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4091. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4092. } else {
  4093. WBUFB(buf,14)=unit->group->unit_id;
  4094. }
  4095. WBUFB(buf,15)=1;
  4096. WBUFB(buf,16)=1;
  4097. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4098. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4099. return 0;
  4100. }
  4101. #endif
  4102. memset(WBUFP(buf, 0),0,packet_len(0x11f));
  4103. WBUFW(buf, 0)=0x11f;
  4104. WBUFL(buf, 2)=unit->bl.id;
  4105. WBUFL(buf, 6)=unit->group->src_id;
  4106. WBUFW(buf,10)=unit->bl.x;
  4107. WBUFW(buf,12)=unit->bl.y;
  4108. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4109. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4110. } else {
  4111. WBUFB(buf,14)=unit->group->unit_id;
  4112. }
  4113. WBUFB(buf,15)=0;
  4114. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4115. return 0;
  4116. /* Previous mysterious implementation noone really understands. [Skotlex]
  4117. memset(WBUFP(buf, 0),0,packet_len(0x1c9));
  4118. WBUFW(buf, 0)=0x1c9;
  4119. WBUFL(buf, 2)=unit->bl.id;
  4120. WBUFL(buf, 6)=unit->group->src_id;
  4121. WBUFW(buf,10)=unit->bl.x;
  4122. WBUFW(buf,12)=unit->bl.y;
  4123. WBUFB(buf,14)=unit->group->unit_id;
  4124. WBUFB(buf,15)=1;
  4125. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4126. WBUFB(buf,16)=1;
  4127. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4128. } else {
  4129. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4130. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4131. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4132. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4133. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4134. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4135. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4136. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4137. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4138. //37-39
  4139. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4140. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4141. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4142. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4143. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4144. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4145. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4146. //65-68
  4147. //69-72
  4148. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4149. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4150. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4151. }
  4152. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4153. #endif
  4154. return 0;
  4155. */
  4156. }
  4157. /*==========================================
  4158. * 場所スキルエフェクト削除
  4159. *------------------------------------------
  4160. */
  4161. int clif_skill_delunit(struct skill_unit *unit)
  4162. {
  4163. unsigned char buf[16];
  4164. nullpo_retr(0, unit);
  4165. WBUFW(buf, 0)=0x120;
  4166. WBUFL(buf, 2)=unit->bl.id;
  4167. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4168. return 0;
  4169. }
  4170. /*==========================================
  4171. * ワープ場所選択
  4172. *------------------------------------------
  4173. */
  4174. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4175. const char *map1,const char *map2,const char *map3,const char *map4)
  4176. {
  4177. int fd;
  4178. nullpo_retr(0, sd);
  4179. fd=sd->fd;
  4180. WFIFOHEAD(fd,packet_len(0x11c));
  4181. WFIFOW(fd,0)=0x11c;
  4182. WFIFOW(fd,2)=skill_num;
  4183. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4184. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4185. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4186. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4187. WFIFOSET(fd,packet_len(0x11c));
  4188. sd->menuskill_id = skill_num;
  4189. if (skill_num == AL_WARP)
  4190. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4191. else
  4192. sd->menuskill_lv = skill_lv;
  4193. return 0;
  4194. }
  4195. /*==========================================
  4196. * メモ応答
  4197. *------------------------------------------
  4198. */
  4199. int clif_skill_memo(struct map_session_data *sd,int flag)
  4200. {
  4201. int fd;
  4202. nullpo_retr(0, sd);
  4203. fd=sd->fd;
  4204. WFIFOHEAD(fd,packet_len(0x11e));
  4205. WFIFOW(fd,0)=0x11e;
  4206. WFIFOB(fd,2)=flag;
  4207. WFIFOSET(fd,packet_len(0x11e));
  4208. return 0;
  4209. }
  4210. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4211. {
  4212. int fd;
  4213. nullpo_retr(0, sd);
  4214. fd=sd->fd;
  4215. WFIFOHEAD(fd,packet_len(0x189));
  4216. WFIFOW(fd,0)=0x189;
  4217. WFIFOW(fd,2)=flag;
  4218. WFIFOSET(fd,packet_len(0x189));
  4219. return 0;
  4220. }
  4221. /*==========================================
  4222. * モンスター情報
  4223. *------------------------------------------
  4224. */
  4225. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4226. {
  4227. struct status_data *status;
  4228. unsigned char buf[64];
  4229. int i;//, fix;
  4230. nullpo_retr(0, sd);
  4231. nullpo_retr(0, dst);
  4232. if(dst->type!=BL_MOB )
  4233. return 0;
  4234. status = status_get_status_data(dst);
  4235. WBUFW(buf, 0)=0x18c;
  4236. WBUFW(buf, 2)=status_get_class(dst);
  4237. WBUFW(buf, 4)=status_get_lv(dst);
  4238. WBUFW(buf, 6)=status->size;
  4239. WBUFL(buf, 8)=status->hp;
  4240. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4241. +(battle_config.estimation_type&2?status->def2:0);
  4242. WBUFW(buf,14)=status->race;
  4243. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4244. +(battle_config.estimation_type&2?status->mdef2:0);
  4245. WBUFW(buf,18)= status->def_ele;
  4246. for(i=0;i<9;i++)
  4247. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4248. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4249. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4250. clif_send(buf,packet_len(0x18c),&sd->bl,
  4251. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4252. return 0;
  4253. }
  4254. /*==========================================
  4255. * アイテム合成可能リスト
  4256. *------------------------------------------
  4257. */
  4258. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4259. {
  4260. int i,c,view,fd;
  4261. nullpo_retr(0, sd);
  4262. if(sd->menuskill_id == AM_PHARMACY)
  4263. return 0; //Avoid resending the menu twice or more times...
  4264. fd=sd->fd;
  4265. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4266. WFIFOW(fd, 0)=0x18d;
  4267. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4268. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4269. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4270. WFIFOW(fd,c*8+ 4)= view;
  4271. else
  4272. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4273. WFIFOW(fd,c*8+ 6)= 0x0012;
  4274. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4275. c++;
  4276. }
  4277. }
  4278. WFIFOW(fd, 2)=c*8+8;
  4279. WFIFOSET(fd,WFIFOW(fd,2));
  4280. if(c > 0) {
  4281. sd->menuskill_id = AM_PHARMACY;
  4282. sd->menuskill_lv = trigger;
  4283. return 1;
  4284. }
  4285. return 0;
  4286. }
  4287. /*==========================================
  4288. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4289. *------------------------------------------
  4290. */
  4291. int clif_status_load(struct block_list *bl,int type, int flag)
  4292. {
  4293. int fd;
  4294. if (type == SI_BLANK) //It shows nothing on the client...
  4295. return 0;
  4296. if (bl->type != BL_PC)
  4297. return 0;
  4298. fd = ((struct map_session_data*)bl)->fd;
  4299. WFIFOHEAD(fd,packet_len(0x196));
  4300. WFIFOW(fd,0)=0x0196;
  4301. WFIFOW(fd,2)=type;
  4302. WFIFOL(fd,4)=bl->id;
  4303. WFIFOB(fd,8)=flag; //Status start
  4304. WFIFOSET(fd, packet_len(0x196));
  4305. return 0;
  4306. }
  4307. /*==========================================
  4308. * 状態異常アイコン/メッセージ表示
  4309. *------------------------------------------
  4310. */
  4311. int clif_status_change(struct block_list *bl,int type,int flag)
  4312. {
  4313. unsigned char buf[16];
  4314. if (type == SI_BLANK) //It shows nothing on the client...
  4315. return 0;
  4316. nullpo_retr(0, bl);
  4317. WBUFW(buf,0)=0x0196;
  4318. WBUFW(buf,2)=type;
  4319. WBUFL(buf,4)=bl->id;
  4320. WBUFB(buf,8)=flag;
  4321. clif_send(buf,packet_len(0x196),bl,AREA);
  4322. return 0;
  4323. }
  4324. /*==========================================
  4325. * Send message (modified by [Yor])
  4326. *------------------------------------------
  4327. */
  4328. int clif_displaymessage(const int fd, char* mes)
  4329. {
  4330. // invalid pointer?
  4331. nullpo_retr(-1, mes);
  4332. //Console [Wizputer] //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4333. if (fd == 0)
  4334. return 0;
  4335. else {
  4336. int len_mes = strlen(mes);
  4337. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4338. WFIFOHEAD(fd, 5 + len_mes);
  4339. WFIFOW(fd,0) = 0x8e;
  4340. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4341. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4342. WFIFOSET(fd, 5 + len_mes);
  4343. }
  4344. }
  4345. return 0;
  4346. }
  4347. /*==========================================
  4348. * 天の声を送信する
  4349. *------------------------------------------
  4350. */
  4351. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4352. {
  4353. unsigned char *buf;
  4354. int lp;
  4355. lp = (flag & 0x10) ? 8 : 4;
  4356. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4357. WBUFW(buf,0) = 0x9a;
  4358. WBUFW(buf,2) = len + lp;
  4359. WBUFL(buf,4) = 0x65756c62; //"blue":
  4360. memcpy(WBUFP(buf,lp), mes, len);
  4361. flag &= 0x07;
  4362. clif_send(buf, WBUFW(buf,2), bl,
  4363. (flag == 1) ? ALL_SAMEMAP :
  4364. (flag == 2) ? AREA :
  4365. (flag == 3) ? SELF :
  4366. ALL_CLIENT);
  4367. if(buf) aFree(buf);
  4368. if(use_irc && irc_announce_flag && !flag)
  4369. irc_announce(mes);
  4370. return 0;
  4371. }
  4372. /*==========================================
  4373. * グローバルメッセージ
  4374. *------------------------------------------
  4375. */
  4376. void clif_GlobalMessage(struct block_list *bl,char *message)
  4377. {
  4378. char buf[100];
  4379. int len;
  4380. nullpo_retv(bl);
  4381. if(!message)
  4382. return;
  4383. len = strlen(message)+1;
  4384. WBUFW(buf,0)=0x8d;
  4385. WBUFW(buf,2)=len+8;
  4386. WBUFL(buf,4)=bl->id;
  4387. strncpy((char *) WBUFP(buf,8),message,len);
  4388. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4389. }
  4390. /*==========================================
  4391. * Send main chat message [LuzZza]
  4392. *------------------------------------------
  4393. */
  4394. void clif_MainChatMessage(char* message) {
  4395. char buf[200];
  4396. int len;
  4397. if(!message)
  4398. return;
  4399. len = strlen(message)+1;
  4400. if (len+8 > sizeof(buf)) {
  4401. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4402. len = sizeof(buf)-8;
  4403. }
  4404. WBUFW(buf,0)=0x8d;
  4405. WBUFW(buf,2)=len+8;
  4406. WBUFL(buf,4)=0;
  4407. strncpy((char *) WBUFP(buf,8),message,len);
  4408. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4409. }
  4410. /*==========================================
  4411. * Does an announce message in the given color.
  4412. *------------------------------------------
  4413. */
  4414. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4415. {
  4416. unsigned char *buf;
  4417. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4418. WBUFW(buf,0) = 0x1c3;
  4419. WBUFW(buf,2) = len + 16;
  4420. WBUFL(buf,4) = color;
  4421. WBUFW(buf,8) = 0x190; //Font style? Type?
  4422. WBUFW(buf,10) = 0x0c; //12? Font size?
  4423. WBUFL(buf,12) = 0; //Unknown!
  4424. memcpy(WBUFP(buf,16), mes, len);
  4425. flag &= 0x07;
  4426. clif_send(buf, WBUFW(buf,2), bl,
  4427. (flag == 1) ? ALL_SAMEMAP :
  4428. (flag == 2) ? AREA :
  4429. (flag == 3) ? SELF :
  4430. ALL_CLIENT);
  4431. if(buf) aFree(buf);
  4432. return 0;
  4433. }
  4434. /*==========================================
  4435. * HPSP回復エフェクトを送信する
  4436. *------------------------------------------
  4437. */
  4438. int clif_heal(int fd,int type,int val)
  4439. {
  4440. WFIFOHEAD(fd,packet_len(0x13d));
  4441. WFIFOW(fd,0)=0x13d;
  4442. WFIFOW(fd,2)=type;
  4443. WFIFOW(fd,4)=val;
  4444. WFIFOSET(fd,packet_len(0x13d));
  4445. return 0;
  4446. }
  4447. /*==========================================
  4448. * 復活する
  4449. *------------------------------------------
  4450. */
  4451. int clif_resurrection(struct block_list *bl,int type)
  4452. {
  4453. unsigned char buf[16];
  4454. nullpo_retr(0, bl);
  4455. WBUFW(buf,0)=0x148;
  4456. WBUFL(buf,2)=bl->id;
  4457. WBUFW(buf,6)=type;
  4458. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4459. if (disguised(bl))
  4460. clif_spawn(bl);
  4461. return 0;
  4462. }
  4463. /*==========================================
  4464. * PVP実装?(仮)
  4465. *------------------------------------------
  4466. */
  4467. int clif_set0199(int fd,int type)
  4468. {
  4469. WFIFOHEAD(fd,packet_len(0x199));
  4470. WFIFOW(fd,0)=0x199;
  4471. WFIFOW(fd,2)=type;
  4472. WFIFOSET(fd,packet_len(0x199));
  4473. return 0;
  4474. }
  4475. /*==========================================
  4476. * PVP実装?(仮)
  4477. *------------------------------------------
  4478. */
  4479. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4480. {
  4481. int fd = sd->fd;
  4482. if(type == 2) {
  4483. WFIFOHEAD(fd,packet_len(0x19a));
  4484. WFIFOW(fd,0) = 0x19a;
  4485. WFIFOL(fd,2) = sd->bl.id;
  4486. WFIFOL(fd,6) = pvprank;
  4487. WFIFOL(fd,10) = pvpnum;
  4488. WFIFOSET(fd,packet_len(0x19a));
  4489. } else {
  4490. unsigned char buf[32];
  4491. WBUFW(buf,0) = 0x19a;
  4492. WBUFL(buf,2) = sd->bl.id;
  4493. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4494. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4495. else
  4496. WBUFL(buf,6) = pvprank;
  4497. WBUFL(buf,10) = pvpnum;
  4498. if(sd->sc.option&OPTION_INVISIBLE)
  4499. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4500. else if(!type)
  4501. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4502. else
  4503. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4504. }
  4505. return 0;
  4506. }
  4507. /*==========================================
  4508. *
  4509. *------------------------------------------
  4510. */
  4511. int clif_send0199(int map,int type)
  4512. {
  4513. struct block_list bl;
  4514. unsigned char buf[16];
  4515. bl.id = 0;
  4516. bl.type = BL_NUL;
  4517. bl.m = map;
  4518. WBUFW(buf,0)=0x199;
  4519. WBUFW(buf,2)=type;
  4520. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4521. return 0;
  4522. }
  4523. /*==========================================
  4524. * 精錬エフェクトを送信する
  4525. *------------------------------------------
  4526. */
  4527. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  4528. {
  4529. WFIFOHEAD(fd,packet_len(0x188));
  4530. WFIFOW(fd,0)=0x188;
  4531. WFIFOW(fd,2)=fail;
  4532. WFIFOW(fd,4)=index+2;
  4533. WFIFOW(fd,6)=val;
  4534. WFIFOSET(fd,packet_len(0x188));
  4535. return 0;
  4536. }
  4537. /*==========================================
  4538. * Wisp/page is transmitted to the destination player
  4539. *------------------------------------------
  4540. */
  4541. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4542. {
  4543. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4544. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4545. WFIFOW(fd,0) = 0x97;
  4546. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4547. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4548. memcpy(WFIFOP(fd,28), mes, mes_len);
  4549. WFIFOSET(fd,WFIFOW(fd,2));
  4550. return 0;
  4551. }
  4552. /*==========================================
  4553. * The transmission result of Wisp/page is transmitted to the source player
  4554. *------------------------------------------
  4555. */
  4556. int clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper, 1: target character is not loged in, 2: ignored by target, 3: everyone ignored by target
  4557. {
  4558. WFIFOHEAD(fd,packet_len(0x98));
  4559. WFIFOW(fd,0) = 0x98;
  4560. WFIFOW(fd,2) = flag;
  4561. WFIFOSET(fd,packet_len(0x98));
  4562. return 0;
  4563. }
  4564. /*==========================================
  4565. * キャラID名前引き結果を送信する
  4566. *------------------------------------------
  4567. */
  4568. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4569. {
  4570. char *p= map_charid2nick(char_id);
  4571. int fd;
  4572. nullpo_retr(0, sd);
  4573. fd=sd->fd;
  4574. if(p!=NULL){
  4575. WFIFOHEAD(fd,packet_len(0x194));
  4576. WFIFOW(fd,0)=0x194;
  4577. WFIFOL(fd,2)=char_id;
  4578. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4579. WFIFOSET(fd,packet_len(0x194));
  4580. }else{
  4581. map_reqchariddb(sd,char_id);
  4582. chrif_searchcharid(char_id);
  4583. }
  4584. return 0;
  4585. }
  4586. /*==========================================
  4587. * カードの挿入可能リストを返す
  4588. *------------------------------------------
  4589. */
  4590. int clif_use_card(struct map_session_data *sd,int idx)
  4591. {
  4592. int i,c,ep;
  4593. int fd=sd->fd;
  4594. nullpo_retr(0, sd);
  4595. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4596. return 0;
  4597. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4598. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4599. ep=sd->inventory_data[idx]->equip;
  4600. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4601. WFIFOW(fd,0)=0x017b;
  4602. for(i=c=0;i<MAX_INVENTORY;i++){
  4603. int j;
  4604. if(sd->inventory_data[i] == NULL)
  4605. continue;
  4606. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4607. continue;
  4608. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4609. continue;
  4610. if(sd->status.inventory[i].identify==0 ) //Not identified
  4611. continue;
  4612. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4613. continue;
  4614. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4615. continue;
  4616. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4617. if( sd->status.inventory[i].card[j]==0 )
  4618. break;
  4619. }
  4620. if(j==sd->inventory_data[i]->slot) // No room
  4621. continue;
  4622. WFIFOW(fd,4+c*2)=i+2;
  4623. c++;
  4624. }
  4625. WFIFOW(fd,2)=4+c*2;
  4626. WFIFOSET(fd,WFIFOW(fd,2));
  4627. return 0;
  4628. }
  4629. /*==========================================
  4630. * カードの挿入終了
  4631. *------------------------------------------
  4632. */
  4633. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4634. {
  4635. int fd;
  4636. nullpo_retr(0, sd);
  4637. fd=sd->fd;
  4638. WFIFOHEAD(fd,packet_len(0x17d));
  4639. WFIFOW(fd,0)=0x17d;
  4640. WFIFOW(fd,2)=idx_equip+2;
  4641. WFIFOW(fd,4)=idx_card+2;
  4642. WFIFOB(fd,6)=flag;
  4643. WFIFOSET(fd,packet_len(0x17d));
  4644. return 0;
  4645. }
  4646. /*==========================================
  4647. * 鑑定可能アイテムリスト送信
  4648. *------------------------------------------
  4649. */
  4650. int clif_item_identify_list(struct map_session_data *sd)
  4651. {
  4652. int i,c;
  4653. int fd;
  4654. nullpo_retr(0, sd);
  4655. fd=sd->fd;
  4656. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4657. WFIFOW(fd,0)=0x177;
  4658. for(i=c=0;i<MAX_INVENTORY;i++){
  4659. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4660. WFIFOW(fd,c*2+4)=i+2;
  4661. c++;
  4662. }
  4663. }
  4664. if(c > 0) {
  4665. WFIFOW(fd,2)=c*2+4;
  4666. WFIFOSET(fd,WFIFOW(fd,2));
  4667. sd->menuskill_id = MC_IDENTIFY;
  4668. sd->menuskill_lv = c;
  4669. }
  4670. return 0;
  4671. }
  4672. /*==========================================
  4673. * 鑑定結果
  4674. *------------------------------------------
  4675. */
  4676. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4677. {
  4678. int fd;
  4679. nullpo_retr(0, sd);
  4680. fd=sd->fd;
  4681. WFIFOHEAD(fd,packet_len(0x179));
  4682. WFIFOW(fd, 0)=0x179;
  4683. WFIFOW(fd, 2)=idx+2;
  4684. WFIFOB(fd, 4)=flag;
  4685. WFIFOSET(fd,packet_len(0x179));
  4686. return 0;
  4687. }
  4688. /*==========================================
  4689. * 修理可能アイテムリスト送信
  4690. *------------------------------------------
  4691. */
  4692. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4693. {
  4694. int i,c;
  4695. int fd;
  4696. int nameid;
  4697. nullpo_retr(0, sd);
  4698. nullpo_retr(0, dstsd);
  4699. fd=sd->fd;
  4700. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4701. WFIFOW(fd,0)=0x1fc;
  4702. for(i=c=0;i<MAX_INVENTORY;i++){
  4703. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4704. WFIFOW(fd,c*13+4) = i;
  4705. WFIFOW(fd,c*13+6) = nameid;
  4706. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4707. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4708. WFIFOB(fd,c*13+16)= c;
  4709. c++;
  4710. }
  4711. }
  4712. if(c > 0) {
  4713. WFIFOW(fd,2)=c*13+4;
  4714. WFIFOSET(fd,WFIFOW(fd,2));
  4715. sd->menuskill_id = BS_REPAIRWEAPON;
  4716. sd->menuskill_lv = dstsd->bl.id;
  4717. }else
  4718. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4719. return 0;
  4720. }
  4721. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4722. {
  4723. int view,fd;
  4724. nullpo_retr(0, sd);
  4725. fd=sd->fd;
  4726. WFIFOHEAD(fd,packet_len(0x1fe));
  4727. WFIFOW(fd, 0)=0x1fe;
  4728. if((view = itemdb_viewid(nameid)) > 0)
  4729. WFIFOW(fd, 2)=view;
  4730. else
  4731. WFIFOW(fd, 2)=nameid;
  4732. WFIFOB(fd, 4)=flag;
  4733. WFIFOSET(fd,packet_len(0x1fe));
  4734. return 0;
  4735. }
  4736. /*==========================================
  4737. * Weapon Refining - Taken from jAthena
  4738. *------------------------------------------
  4739. */
  4740. int clif_item_refine_list(struct map_session_data *sd)
  4741. {
  4742. int i,c;
  4743. int fd;
  4744. int skilllv;
  4745. int wlv;
  4746. int refine_item[5];
  4747. nullpo_retr(0, sd);
  4748. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4749. fd=sd->fd;
  4750. refine_item[0] = -1;
  4751. refine_item[1] = pc_search_inventory(sd,1010);
  4752. refine_item[2] = pc_search_inventory(sd,1011);
  4753. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4754. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4755. WFIFOW(fd,0)=0x221;
  4756. for(i=c=0;i<MAX_INVENTORY;i++){
  4757. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4758. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4759. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4760. WFIFOW(fd,c*13+ 4)=i+2;
  4761. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4762. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4763. WFIFOW(fd,c*13+10)=0;
  4764. WFIFOB(fd,c*13+12)=c;
  4765. c++;
  4766. }
  4767. }
  4768. WFIFOW(fd,2)=c*13+4;
  4769. WFIFOSET(fd,WFIFOW(fd,2));
  4770. sd->menuskill_id = WS_WEAPONREFINE;
  4771. sd->menuskill_lv = skilllv;
  4772. return 0;
  4773. }
  4774. /*==========================================
  4775. * アイテムによる一時的なスキル効果
  4776. *------------------------------------------
  4777. */
  4778. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  4779. {
  4780. int fd;
  4781. nullpo_retr(0, sd);
  4782. fd=sd->fd;
  4783. WFIFOHEAD(fd,packet_len(0x147));
  4784. WFIFOW(fd, 0)=0x147;
  4785. WFIFOW(fd, 2)=skillid;
  4786. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4787. WFIFOW(fd, 6)=0;
  4788. WFIFOW(fd, 8)=skilllv;
  4789. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4790. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4791. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  4792. WFIFOB(fd,38)=0;
  4793. WFIFOSET(fd,packet_len(0x147));
  4794. return 0;
  4795. }
  4796. /*==========================================
  4797. * カートにアイテム追加
  4798. *------------------------------------------
  4799. */
  4800. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4801. {
  4802. int view,fd;
  4803. unsigned char *buf;
  4804. nullpo_retr(0, sd);
  4805. fd=sd->fd;
  4806. WFIFOHEAD(fd,packet_len(0x124));
  4807. buf=WFIFOP(fd,0);
  4808. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4809. return 1;
  4810. WBUFW(buf,0)=0x124;
  4811. WBUFW(buf,2)=n+2;
  4812. WBUFL(buf,4)=amount;
  4813. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4814. WBUFW(buf,8)=view;
  4815. else
  4816. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4817. WBUFB(buf,10)=sd->status.cart[n].identify;
  4818. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4819. WBUFB(buf,12)=sd->status.cart[n].refine;
  4820. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4821. WFIFOSET(fd,packet_len(0x124));
  4822. return 0;
  4823. }
  4824. /*==========================================
  4825. * カートからアイテム削除
  4826. *------------------------------------------
  4827. */
  4828. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4829. {
  4830. int fd;
  4831. nullpo_retr(0, sd);
  4832. fd=sd->fd;
  4833. WFIFOHEAD(fd,packet_len(0x125));
  4834. WFIFOW(fd,0)=0x125;
  4835. WFIFOW(fd,2)=n+2;
  4836. WFIFOL(fd,4)=amount;
  4837. WFIFOSET(fd,packet_len(0x125));
  4838. return 0;
  4839. }
  4840. /*==========================================
  4841. * 露店開設
  4842. *------------------------------------------
  4843. */
  4844. int clif_openvendingreq(struct map_session_data *sd,int num)
  4845. {
  4846. int fd;
  4847. nullpo_retr(0, sd);
  4848. fd=sd->fd;
  4849. WFIFOHEAD(fd,packet_len(0x12d));
  4850. WFIFOW(fd,0)=0x12d;
  4851. WFIFOW(fd,2)=num;
  4852. WFIFOSET(fd,packet_len(0x12d));
  4853. return 0;
  4854. }
  4855. /*==========================================
  4856. * 露店看板表示
  4857. *------------------------------------------
  4858. */
  4859. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  4860. {
  4861. unsigned char buf[128];
  4862. nullpo_retr(0, bl);
  4863. WBUFW(buf,0)=0x131;
  4864. WBUFL(buf,2)=bl->id;
  4865. strncpy((char*)WBUFP(buf,6),message,80);
  4866. if(fd){
  4867. WFIFOHEAD(fd,packet_len(0x131));
  4868. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4869. WFIFOSET(fd,packet_len(0x131));
  4870. }else{
  4871. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4872. }
  4873. return 0;
  4874. }
  4875. /*==========================================
  4876. * 露店看板消去
  4877. *------------------------------------------
  4878. */
  4879. int clif_closevendingboard(struct block_list* bl,int fd)
  4880. {
  4881. unsigned char buf[16];
  4882. nullpo_retr(0, bl);
  4883. WBUFW(buf,0)=0x132;
  4884. WBUFL(buf,2)=bl->id;
  4885. if(fd){
  4886. WFIFOHEAD(fd,packet_len(0x132));
  4887. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4888. WFIFOSET(fd,packet_len(0x132));
  4889. }else{
  4890. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4891. }
  4892. return 0;
  4893. }
  4894. /*==========================================
  4895. * 露店アイテムリスト
  4896. *------------------------------------------
  4897. */
  4898. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  4899. {
  4900. struct item_data *data;
  4901. int i,n,index,fd;
  4902. struct map_session_data *vsd;
  4903. unsigned char *buf;
  4904. nullpo_retr(0, sd);
  4905. nullpo_retr(0, vending);
  4906. nullpo_retr(0, vsd=map_id2sd(id));
  4907. fd=sd->fd;
  4908. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  4909. buf = WFIFOP(fd,0);
  4910. for(i=0,n=0;i<vsd->vend_num;i++){
  4911. if(vending[i].amount<=0)
  4912. continue;
  4913. WBUFL(buf,8+n*22)=vending[i].value;
  4914. WBUFW(buf,12+n*22)=vending[i].amount;
  4915. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  4916. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  4917. continue;
  4918. data = itemdb_search(vsd->status.cart[index].nameid);
  4919. WBUFB(buf,16+n*22)=itemtype(data->type);
  4920. if(data->view_id > 0)
  4921. WBUFW(buf,17+n*22)=data->view_id;
  4922. else
  4923. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  4924. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  4925. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  4926. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  4927. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  4928. n++;
  4929. }
  4930. if(n > 0){
  4931. WBUFW(buf,0)=0x133;
  4932. WBUFW(buf,2)=8+n*22;
  4933. WBUFL(buf,4)=id;
  4934. WFIFOSET(fd,WFIFOW(fd,2));
  4935. }
  4936. return 0;
  4937. }
  4938. /*==========================================
  4939. * 露店アイテム購入失敗
  4940. *------------------------------------------
  4941. */
  4942. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  4943. {
  4944. int fd;
  4945. nullpo_retr(0, sd);
  4946. fd=sd->fd;
  4947. WFIFOHEAD(fd,packet_len(0x135));
  4948. WFIFOW(fd,0)=0x135;
  4949. WFIFOW(fd,2)=index+2;
  4950. WFIFOW(fd,4)=amount;
  4951. WFIFOB(fd,6)=fail;
  4952. WFIFOSET(fd,packet_len(0x135));
  4953. return 0;
  4954. }
  4955. /*==========================================
  4956. * 露店開設成功
  4957. *------------------------------------------
  4958. */
  4959. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  4960. {
  4961. struct item_data *data;
  4962. int i,n,index,fd;
  4963. unsigned char *buf;
  4964. nullpo_retr(0, sd);
  4965. fd=sd->fd;
  4966. WFIFOHEAD(fd, 8+sd->vend_num*22);
  4967. buf = WFIFOP(fd,0);
  4968. for(i=0,n=0;i<sd->vend_num;i++){
  4969. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  4970. WBUFL(buf,8+n*22)=vending[i].value;
  4971. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  4972. WBUFW(buf,14+n*22)=vending[i].amount;
  4973. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || !sd->status.cart[index].identify ||
  4974. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  4975. continue;
  4976. data = itemdb_search(sd->status.cart[index].nameid);
  4977. WBUFB(buf,16+n*22)=itemtype(data->type);
  4978. if(data->view_id > 0)
  4979. WBUFW(buf,17+n*22)=data->view_id;
  4980. else
  4981. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  4982. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  4983. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  4984. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  4985. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  4986. n++;
  4987. }
  4988. if(n > 0){
  4989. WBUFW(buf,0)=0x136;
  4990. WBUFW(buf,2)=8+n*22;
  4991. WBUFL(buf,4)=id;
  4992. WFIFOSET(fd,WFIFOW(fd,2));
  4993. }
  4994. return n;
  4995. }
  4996. /*==========================================
  4997. * 露店アイテム販売報告
  4998. *------------------------------------------
  4999. */
  5000. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  5001. {
  5002. int fd;
  5003. nullpo_retr(0, sd);
  5004. fd=sd->fd;
  5005. WFIFOHEAD(fd,packet_len(0x137));
  5006. WFIFOW(fd,0)=0x137;
  5007. WFIFOW(fd,2)=index+2;
  5008. WFIFOW(fd,4)=amount;
  5009. WFIFOSET(fd,packet_len(0x137));
  5010. return 0;
  5011. }
  5012. /*==========================================
  5013. * パーティ作成完了
  5014. *------------------------------------------
  5015. */
  5016. int clif_party_created(struct map_session_data *sd,int flag)
  5017. {
  5018. int fd;
  5019. nullpo_retr(0, sd);
  5020. fd=sd->fd;
  5021. WFIFOHEAD(fd,packet_len(0xfa));
  5022. WFIFOW(fd,0)=0xfa;
  5023. WFIFOB(fd,2)=flag;
  5024. WFIFOSET(fd,packet_len(0xfa));
  5025. return 0;
  5026. }
  5027. int clif_party_main_info(struct party_data *p, int fd)
  5028. {
  5029. struct map_session_data *sd;
  5030. int i;
  5031. unsigned char buf[96];
  5032. for (i=0; i<MAX_PARTY && !p->party.member[i].leader; i++);
  5033. if (i >= MAX_PARTY) return 0; //Should never happen...
  5034. sd = p->data[i].sd;
  5035. WBUFW(buf,0)=0x1e9;
  5036. WBUFL(buf,2)= p->party.member[i].account_id;
  5037. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  5038. WBUFW(buf,10)=sd?sd->bl.x:0;
  5039. WBUFW(buf,12)=sd?sd->bl.y:0;
  5040. WBUFB(buf,14)=(p->party.member[i].online)?0:1; //This byte is also unconfirmed...
  5041. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5042. memcpy(WBUFP(buf,39), p->party.member[i].name, NAME_LENGTH);
  5043. memcpy(WBUFP(buf,63), mapindex_id2name(p->party.member[i].map), MAP_NAME_LENGTH);
  5044. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5045. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5046. if(fd>=0){
  5047. WFIFOHEAD(fd,packet_len(0x1e9));
  5048. memcpy(WFIFOP(fd,0),buf,packet_len(0x1e9));
  5049. WFIFOSET(fd,packet_len(0x1e9));
  5050. return 1;
  5051. }
  5052. if (!sd) {
  5053. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++)
  5054. if (i >= MAX_PARTY) return 0; //Should never happen...
  5055. sd=p->data[i].sd;
  5056. }
  5057. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5058. return 1;
  5059. }
  5060. int clif_party_join_info(struct party *p, struct map_session_data *sd)
  5061. {
  5062. unsigned char buf[96];
  5063. WBUFW(buf,0)=0x1e9;
  5064. WBUFL(buf,2)= sd->status.account_id;
  5065. WBUFL(buf,6)= 0; //Apparently setting this to 1 makes you adoptable.
  5066. WBUFW(buf,10)=sd->bl.x;
  5067. WBUFW(buf,12)=sd->bl.y;
  5068. WBUFB(buf,14)=0; //Unconfirmed byte.
  5069. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5070. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5071. memcpy(WBUFP(buf,63), mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  5072. WBUFB(buf,79) = (p->item&1)?1:0;
  5073. WBUFB(buf,80) = (p->item&2)?1:0;
  5074. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY_WOS);
  5075. return 1;
  5076. }
  5077. /*==========================================
  5078. * パーティ情報送信
  5079. *------------------------------------------
  5080. */
  5081. int clif_party_info(struct party_data *p,int fd)
  5082. {
  5083. unsigned char buf[1024];
  5084. int i,c;
  5085. struct map_session_data *sd=NULL;
  5086. nullpo_retr(0, p);
  5087. WBUFW(buf,0)=0xfb;
  5088. memcpy(WBUFP(buf,4),p->party.name,NAME_LENGTH);
  5089. for(i=c=0;i<MAX_PARTY;i++){
  5090. struct party_member *m=&p->party.member[i];
  5091. if(!m->account_id)
  5092. continue;
  5093. if(sd==NULL) sd=p->data[i].sd;
  5094. WBUFL(buf,28+c*46)=m->account_id;
  5095. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5096. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5097. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5098. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5099. c++;
  5100. }
  5101. WBUFW(buf,2)=28+c*46;
  5102. if(fd>=0){ // fdが設定されてるならそれに送る
  5103. WFIFOHEAD(fd, 28+c*46);
  5104. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5105. WFIFOSET(fd,WFIFOW(fd,2));
  5106. return 9;
  5107. }
  5108. if(sd!=NULL)
  5109. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5110. return 0;
  5111. }
  5112. /*==========================================
  5113. * パーティ勧誘
  5114. *------------------------------------------
  5115. */
  5116. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5117. {
  5118. int fd;
  5119. struct party_data *p;
  5120. nullpo_retr(0, sd);
  5121. nullpo_retr(0, tsd);
  5122. fd=tsd->fd;
  5123. if( (p=party_search(sd->status.party_id))==NULL )
  5124. return 0;
  5125. WFIFOHEAD(fd,packet_len(0xfe));
  5126. WFIFOW(fd,0)=0xfe;
  5127. WFIFOL(fd,2)=sd->status.account_id;
  5128. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5129. WFIFOSET(fd,packet_len(0xfe));
  5130. return 0;
  5131. }
  5132. /*==========================================
  5133. * Party invitation result. Flag values are:
  5134. * 0 -> char is already in a party
  5135. * 1 -> party invite was rejected
  5136. * 2 -> party invite was accepted
  5137. * 3 -> party is full
  5138. * 4 -> char of the same account already joined the party
  5139. *------------------------------------------
  5140. */
  5141. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5142. {
  5143. int fd;
  5144. nullpo_retr(0, sd);
  5145. fd=sd->fd;
  5146. WFIFOHEAD(fd,packet_len(0xfd));
  5147. WFIFOW(fd,0)=0xfd;
  5148. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5149. WFIFOB(fd,26)=flag;
  5150. WFIFOSET(fd,packet_len(0xfd));
  5151. return 0;
  5152. }
  5153. /*==========================================
  5154. * パーティ設定送信
  5155. * flag & 0x001=exp変更ミス
  5156. * 0x010=item変更ミス
  5157. * 0x100=一人にのみ送信
  5158. *------------------------------------------
  5159. */
  5160. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5161. {
  5162. unsigned char buf[16];
  5163. nullpo_retr(0, p);
  5164. if(!sd && flag==0){
  5165. int i;
  5166. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5167. if (i < MAX_PARTY)
  5168. sd = p->data[i].sd;
  5169. }
  5170. if(!sd) return 0;
  5171. WBUFW(buf,0)=0x101;
  5172. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  5173. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5174. WBUFW(buf,4)=0;
  5175. if(flag==0)
  5176. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  5177. else
  5178. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  5179. return 0;
  5180. }
  5181. /*==========================================
  5182. * パーティ脱退(脱退前に呼ぶこと)
  5183. *------------------------------------------
  5184. */
  5185. int clif_party_leaved(struct party_data *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5186. {
  5187. unsigned char buf[64];
  5188. int i;
  5189. nullpo_retr(0, p);
  5190. if(!sd && (flag&0xf0)==0)
  5191. {
  5192. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5193. if (i < MAX_PARTY)
  5194. sd = p->data[i].sd;
  5195. }
  5196. if(!sd) return 0;
  5197. WBUFW(buf,0)=0x105;
  5198. WBUFL(buf,2)=account_id;
  5199. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5200. WBUFB(buf,30)=flag&0x0f;
  5201. if((flag&0xf0)==0)
  5202. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5203. else
  5204. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5205. return 0;
  5206. }
  5207. /*==========================================
  5208. * パーティメッセージ送信
  5209. *------------------------------------------
  5210. */
  5211. int clif_party_message(struct party_data *p,int account_id,char *mes,int len)
  5212. {
  5213. struct map_session_data *sd;
  5214. int i;
  5215. nullpo_retr(0, p);
  5216. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5217. if(i < MAX_PARTY){
  5218. unsigned char buf[1024];
  5219. sd = p->data[i].sd;
  5220. WBUFW(buf,0)=0x109;
  5221. WBUFW(buf,2)=len+8;
  5222. WBUFL(buf,4)=account_id;
  5223. memcpy(WBUFP(buf,8),mes,len);
  5224. clif_send(buf,len+8,&sd->bl,PARTY);
  5225. }
  5226. return 0;
  5227. }
  5228. /*==========================================
  5229. * パーティ座標通知
  5230. *------------------------------------------
  5231. */
  5232. int clif_party_xy(struct map_session_data *sd)
  5233. {
  5234. unsigned char buf[16];
  5235. nullpo_retr(0, sd);
  5236. WBUFW(buf,0)=0x107;
  5237. WBUFL(buf,2)=sd->status.account_id;
  5238. WBUFW(buf,6)=sd->bl.x;
  5239. WBUFW(buf,8)=sd->bl.y;
  5240. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5241. return 0;
  5242. }
  5243. /*==========================================
  5244. * Sends x/y dot to a single fd. [Skotlex]
  5245. *------------------------------------------
  5246. */
  5247. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5248. {
  5249. WFIFOHEAD(fd,packet_len(0x107));
  5250. WFIFOW(fd,0)=0x107;
  5251. WFIFOL(fd,2)=sd->status.account_id;
  5252. WFIFOW(fd,6)=sd->bl.x;
  5253. WFIFOW(fd,8)=sd->bl.y;
  5254. WFIFOSET(fd,packet_len(0x107));
  5255. return 0;
  5256. }
  5257. /*==========================================
  5258. * パーティHP通知
  5259. *------------------------------------------
  5260. */
  5261. int clif_party_hp(struct map_session_data *sd)
  5262. {
  5263. unsigned char buf[16];
  5264. nullpo_retr(0, sd);
  5265. WBUFW(buf,0)=0x106;
  5266. WBUFL(buf,2)=sd->status.account_id;
  5267. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5268. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5269. WBUFW(buf,8) = 100;
  5270. } else {
  5271. WBUFW(buf,6) = sd->battle_status.hp;
  5272. WBUFW(buf,8) = sd->battle_status.max_hp;
  5273. }
  5274. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  5275. return 0;
  5276. }
  5277. /*==========================================
  5278. * Sends HP bar to a single fd. [Skotlex]
  5279. *------------------------------------------
  5280. */
  5281. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5282. {
  5283. WFIFOHEAD(fd,packet_len(0x106));
  5284. WFIFOW(fd,0) = 0x106;
  5285. WFIFOL(fd,2) = sd->status.account_id;
  5286. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5287. WFIFOW(fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5288. WFIFOW(fd,8) = 100;
  5289. } else {
  5290. WFIFOW(fd,6) = sd->battle_status.hp;
  5291. WFIFOW(fd,8) = sd->battle_status.max_hp;
  5292. }
  5293. WFIFOSET (fd, packet_len(0x106));
  5294. }
  5295. /*==========================================
  5296. * GMへ場所とHP通知
  5297. *------------------------------------------
  5298. */
  5299. int clif_hpmeter(struct map_session_data *sd)
  5300. {
  5301. struct map_session_data *sd2;
  5302. unsigned char buf[16];
  5303. int i, x0, y0, x1, y1;
  5304. int level;
  5305. nullpo_retr(0, sd);
  5306. x0 = sd->bl.x - AREA_SIZE;
  5307. y0 = sd->bl.y - AREA_SIZE;
  5308. x1 = sd->bl.x + AREA_SIZE;
  5309. y1 = sd->bl.y + AREA_SIZE;
  5310. WBUFW(buf,0) = 0x106;
  5311. WBUFL(buf,2) = sd->status.account_id;
  5312. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5313. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5314. WBUFW(buf,8) = 100;
  5315. } else {
  5316. WBUFW(buf,6) = sd->battle_status.hp;
  5317. WBUFW(buf,8) = sd->battle_status.max_hp;
  5318. }
  5319. for (i = 0; i < fd_max; i++) {
  5320. if (session[i] && session[i]->func_parse == clif_parse &&
  5321. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5322. sd != sd2 && sd2->state.auth) {
  5323. if (sd2->bl.m != sd->bl.m ||
  5324. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5325. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5326. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5327. level < pc_isGM(sd))
  5328. continue;
  5329. WFIFOHEAD (i, packet_len(0x106));
  5330. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  5331. WFIFOSET (i, packet_len(0x106));
  5332. }
  5333. }
  5334. return 0;
  5335. }
  5336. /*==========================================
  5337. * パーティ場所移動(未使用)
  5338. *------------------------------------------
  5339. */
  5340. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5341. {
  5342. unsigned char buf[128];
  5343. nullpo_retr(0, sd);
  5344. nullpo_retr(0, p);
  5345. WBUFW(buf, 0)=0x104;
  5346. WBUFL(buf, 2)=sd->status.account_id;
  5347. WBUFL(buf, 6)=0;
  5348. WBUFW(buf,10)=sd->bl.x;
  5349. WBUFW(buf,12)=sd->bl.y;
  5350. WBUFB(buf,14)=!online;
  5351. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5352. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5353. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5354. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5355. return 0;
  5356. }
  5357. /*==========================================
  5358. * 攻撃するために移動が必要
  5359. *------------------------------------------
  5360. */
  5361. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5362. {
  5363. int fd;
  5364. nullpo_retr(0, sd);
  5365. nullpo_retr(0, bl);
  5366. fd=sd->fd;
  5367. WFIFOHEAD(fd,packet_len(0x139));
  5368. WFIFOW(fd, 0)=0x139;
  5369. WFIFOL(fd, 2)=bl->id;
  5370. WFIFOW(fd, 6)=bl->x;
  5371. WFIFOW(fd, 8)=bl->y;
  5372. WFIFOW(fd,10)=sd->bl.x;
  5373. WFIFOW(fd,12)=sd->bl.y;
  5374. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5375. WFIFOSET(fd,packet_len(0x139));
  5376. return 0;
  5377. }
  5378. /*==========================================
  5379. * 製造エフェクト
  5380. *------------------------------------------
  5381. */
  5382. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5383. {
  5384. int view,fd;
  5385. nullpo_retr(0, sd);
  5386. fd=sd->fd;
  5387. // 名前の登録と送信を先にしておく
  5388. if( map_charid2nick(sd->status.char_id)==NULL )
  5389. map_addchariddb(sd->status.char_id,sd->status.name);
  5390. clif_solved_charname(sd,sd->status.char_id);
  5391. WFIFOHEAD(fd,packet_len(0x18f));
  5392. WFIFOW(fd, 0)=0x18f;
  5393. WFIFOW(fd, 2)=flag;
  5394. if((view = itemdb_viewid(nameid)) > 0)
  5395. WFIFOW(fd, 4)=view;
  5396. else
  5397. WFIFOW(fd, 4)=nameid;
  5398. WFIFOSET(fd,packet_len(0x18f));
  5399. return 0;
  5400. }
  5401. // pet
  5402. int clif_catch_process(struct map_session_data *sd)
  5403. {
  5404. int fd;
  5405. nullpo_retr(0, sd);
  5406. fd=sd->fd;
  5407. WFIFOHEAD(fd,packet_len(0x19e));
  5408. WFIFOW(fd,0)=0x19e;
  5409. WFIFOSET(fd,packet_len(0x19e));
  5410. sd->menuskill_id = SA_TAMINGMONSTER;
  5411. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5412. sd->menuskill_lv = 0; //Free catch
  5413. else
  5414. sd->menuskill_lv = sd->itemid; //Consume catch
  5415. return 0;
  5416. }
  5417. int clif_pet_rulet(struct map_session_data *sd,int data)
  5418. {
  5419. int fd;
  5420. nullpo_retr(0, sd);
  5421. fd=sd->fd;
  5422. WFIFOHEAD(fd,packet_len(0x1a0));
  5423. WFIFOW(fd,0)=0x1a0;
  5424. WFIFOB(fd,2)=data;
  5425. WFIFOSET(fd,packet_len(0x1a0));
  5426. return 0;
  5427. }
  5428. /*==========================================
  5429. * pet卵リスト作成
  5430. *------------------------------------------
  5431. */
  5432. int clif_sendegg(struct map_session_data *sd)
  5433. {
  5434. //R 01a6 <len>.w <index>.w*
  5435. int i,n=0,fd;
  5436. nullpo_retr(0, sd);
  5437. fd=sd->fd;
  5438. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5439. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5440. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5441. return 0;
  5442. }
  5443. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5444. WFIFOW(fd,0)=0x1a6;
  5445. if(sd->status.pet_id <= 0) {
  5446. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5447. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5448. sd->inventory_data[i]->type!=IT_PETEGG ||
  5449. sd->status.inventory[i].amount<=0)
  5450. continue;
  5451. WFIFOW(fd,n*2+4)=i+2;
  5452. n++;
  5453. }
  5454. }
  5455. WFIFOW(fd,2)=4+n*2;
  5456. WFIFOSET(fd,WFIFOW(fd,2));
  5457. sd->menuskill_id = SA_TAMINGMONSTER;
  5458. sd->menuskill_lv = -1;
  5459. return 0;
  5460. }
  5461. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5462. {
  5463. int fd;
  5464. nullpo_retr(0, sd);
  5465. nullpo_retr(0, sd->pd);
  5466. fd=sd->fd;
  5467. WFIFOHEAD(fd,packet_len(0x1a4));
  5468. WFIFOW(fd,0)=0x1a4;
  5469. WFIFOB(fd,2)=type;
  5470. WFIFOL(fd,3)=sd->pd->bl.id;
  5471. WFIFOL(fd,7)=param;
  5472. WFIFOSET(fd,packet_len(0x1a4));
  5473. return 0;
  5474. }
  5475. int clif_send_petstatus(struct map_session_data *sd)
  5476. {
  5477. int fd;
  5478. struct s_pet *pet;
  5479. nullpo_retr(0, sd);
  5480. nullpo_retr(0, sd->pd);
  5481. fd=sd->fd;
  5482. pet = &sd->pd->pet;
  5483. WFIFOHEAD(fd,packet_len(0x1a2));
  5484. WFIFOW(fd,0)=0x1a2;
  5485. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5486. WFIFOB(fd,26)=(battle_config.pet_rename == 1)? 0:pet->rename_flag;
  5487. WFIFOW(fd,27)=pet->level;
  5488. WFIFOW(fd,29)=pet->hungry;
  5489. WFIFOW(fd,31)=pet->intimate;
  5490. WFIFOW(fd,33)=pet->equip;
  5491. WFIFOSET(fd,packet_len(0x1a2));
  5492. return 0;
  5493. }
  5494. /*==========================================
  5495. *
  5496. *------------------------------------------
  5497. */
  5498. int clif_pet_emotion(struct pet_data *pd,int param)
  5499. {
  5500. unsigned char buf[16];
  5501. nullpo_retr(0, pd);
  5502. memset(buf,0,packet_len(0x1aa));
  5503. WBUFW(buf,0)=0x1aa;
  5504. WBUFL(buf,2)=pd->bl.id;
  5505. if(param >= 100 && pd->petDB->talk_convert_class) {
  5506. if(pd->petDB->talk_convert_class < 0)
  5507. return 0;
  5508. else if(pd->petDB->talk_convert_class > 0) {
  5509. param -= (pd->pet.class_ - 100)*100;
  5510. param += (pd->petDB->talk_convert_class - 100)*100;
  5511. }
  5512. }
  5513. WBUFL(buf,6)=param;
  5514. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5515. return 0;
  5516. }
  5517. int clif_pet_performance(struct block_list *bl,int param)
  5518. {
  5519. unsigned char buf[16];
  5520. nullpo_retr(0, bl);
  5521. memset(buf,0,packet_len(0x1a4));
  5522. WBUFW(buf,0)=0x1a4;
  5523. WBUFB(buf,2)=4;
  5524. WBUFL(buf,3)=bl->id;
  5525. WBUFL(buf,7)=param;
  5526. clif_send(buf,packet_len(0x1a4),bl,AREA);
  5527. return 0;
  5528. }
  5529. int clif_pet_equip(struct pet_data *pd)
  5530. {
  5531. unsigned char buf[16];
  5532. nullpo_retr(0, pd);
  5533. memset(buf,0,packet_len(0x1a4));
  5534. WBUFW(buf,0)=0x1a4;
  5535. WBUFB(buf,2)=3;
  5536. WBUFL(buf,3)=pd->bl.id;
  5537. WBUFL(buf,7)=pd->vd.shield;
  5538. clif_send(buf,packet_len(0x1a4),&pd->bl,AREA);
  5539. return 0;
  5540. }
  5541. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5542. {
  5543. int fd;
  5544. nullpo_retr(0, sd);
  5545. fd=sd->fd;
  5546. WFIFOHEAD(fd,packet_len(0x1a3));
  5547. WFIFOW(fd,0)=0x1a3;
  5548. WFIFOB(fd,2)=fail;
  5549. WFIFOW(fd,3)=foodid;
  5550. WFIFOSET(fd,packet_len(0x1a3));
  5551. return 0;
  5552. }
  5553. /*==========================================
  5554. * オートスペル リスト送信
  5555. *------------------------------------------
  5556. */
  5557. int clif_autospell(struct map_session_data *sd,int skilllv)
  5558. {
  5559. int fd;
  5560. nullpo_retr(0, sd);
  5561. fd=sd->fd;
  5562. WFIFOHEAD(fd,packet_len(0x1cd));
  5563. WFIFOW(fd, 0)=0x1cd;
  5564. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5565. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5566. else
  5567. WFIFOL(fd,2)= 0x00000000;
  5568. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5569. WFIFOL(fd,6)= MG_COLDBOLT;
  5570. else
  5571. WFIFOL(fd,6)= 0x00000000;
  5572. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5573. WFIFOL(fd,10)= MG_FIREBOLT;
  5574. else
  5575. WFIFOL(fd,10)= 0x00000000;
  5576. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5577. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5578. else
  5579. WFIFOL(fd,14)= 0x00000000;
  5580. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5581. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5582. else
  5583. WFIFOL(fd,18)= 0x00000000;
  5584. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5585. WFIFOL(fd,22)= MG_FIREBALL;
  5586. else
  5587. WFIFOL(fd,22)= 0x00000000;
  5588. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5589. WFIFOL(fd,26)= MG_FROSTDIVER;
  5590. else
  5591. WFIFOL(fd,26)= 0x00000000;
  5592. WFIFOSET(fd,packet_len(0x1cd));
  5593. sd->menuskill_id = SA_AUTOSPELL;
  5594. sd->menuskill_lv = skilllv;
  5595. return 0;
  5596. }
  5597. /*==========================================
  5598. * ディボーションの青い糸
  5599. *------------------------------------------
  5600. */
  5601. int clif_devotion(struct map_session_data *sd)
  5602. {
  5603. unsigned char buf[56];
  5604. int i,n;
  5605. nullpo_retr(0, sd);
  5606. WBUFW(buf,0)=0x1cf;
  5607. WBUFL(buf,2)=sd->bl.id;
  5608. for(i=0,n=0;i<5;i++) {
  5609. if (!sd->devotion[i])
  5610. continue;
  5611. WBUFL(buf,6+4*n)=sd->devotion[i];
  5612. n++;
  5613. }
  5614. for(;n<5;n++)
  5615. WBUFL(buf,6+4*n)=0;
  5616. WBUFB(buf,26)=8;
  5617. WBUFB(buf,27)=0;
  5618. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5619. return 0;
  5620. }
  5621. int clif_marionette(struct block_list *src, struct block_list *target)
  5622. {
  5623. unsigned char buf[56];
  5624. int n;
  5625. WBUFW(buf,0)=0x1cf;
  5626. WBUFL(buf,2)=src->id;
  5627. for(n=0;n<5;n++)
  5628. WBUFL(buf,6+4*n)=0;
  5629. if (target) //The target goes on the second slot.
  5630. WBUFL(buf,6+4) = target->id;
  5631. WBUFB(buf,26)=8;
  5632. WBUFB(buf,27)=0;
  5633. clif_send(buf,packet_len(0x1cf),src,AREA);
  5634. return 0;
  5635. }
  5636. /*==========================================
  5637. * 氣球
  5638. *------------------------------------------
  5639. */
  5640. int clif_spiritball(struct map_session_data *sd)
  5641. {
  5642. unsigned char buf[16];
  5643. nullpo_retr(0, sd);
  5644. WBUFW(buf,0)=0x1d0;
  5645. WBUFL(buf,2)=sd->bl.id;
  5646. WBUFW(buf,6)=sd->spiritball;
  5647. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5648. return 0;
  5649. }
  5650. /*==========================================
  5651. *
  5652. *------------------------------------------
  5653. */
  5654. int clif_combo_delay(struct block_list *bl,int wait)
  5655. {
  5656. unsigned char buf[32];
  5657. nullpo_retr(0, bl);
  5658. WBUFW(buf,0)=0x1d2;
  5659. WBUFL(buf,2)=bl->id;
  5660. WBUFL(buf,6)=wait;
  5661. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5662. return 0;
  5663. }
  5664. /*==========================================
  5665. *白刃取り
  5666. *------------------------------------------
  5667. */
  5668. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5669. int _bool)
  5670. {
  5671. unsigned char buf[32];
  5672. nullpo_retr(0, src);
  5673. nullpo_retr(0, dst);
  5674. WBUFW(buf,0)=0x1d1;
  5675. WBUFL(buf,2)=src->id;
  5676. WBUFL(buf,6)=dst->id;
  5677. WBUFL(buf,10)=_bool;
  5678. clif_send(buf,packet_len(0x1d1),src,AREA);
  5679. return 0;
  5680. }
  5681. /*==========================================
  5682. *
  5683. *------------------------------------------
  5684. */
  5685. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5686. {
  5687. struct block_list bl;
  5688. unsigned char buf[32];
  5689. bl.type = BL_NUL;
  5690. bl.m = m;
  5691. bl.x = x;
  5692. bl.y = y;
  5693. WBUFW(buf,0) = 0x192;
  5694. WBUFW(buf,2) = x;
  5695. WBUFW(buf,4) = y;
  5696. WBUFW(buf,6) = cell_type;
  5697. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  5698. if(!type)
  5699. clif_send(buf,packet_len(0x192),&bl,AREA);
  5700. else
  5701. clif_send(buf,packet_len(0x192),&bl,ALL_SAMEMAP);
  5702. return 0;
  5703. }
  5704. /*==========================================
  5705. * MVPエフェクト
  5706. *------------------------------------------
  5707. */
  5708. int clif_mvp_effect(struct map_session_data *sd)
  5709. {
  5710. unsigned char buf[16];
  5711. nullpo_retr(0, sd);
  5712. WBUFW(buf,0)=0x10c;
  5713. WBUFL(buf,2)=sd->bl.id;
  5714. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5715. return 0;
  5716. }
  5717. /*==========================================
  5718. * MVPアイテム所得
  5719. *------------------------------------------
  5720. */
  5721. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5722. {
  5723. int view,fd;
  5724. nullpo_retr(0, sd);
  5725. fd=sd->fd;
  5726. WFIFOHEAD(fd,packet_len(0x10a));
  5727. WFIFOW(fd,0)=0x10a;
  5728. if((view = itemdb_viewid(nameid)) > 0)
  5729. WFIFOW(fd,2)=view;
  5730. else
  5731. WFIFOW(fd,2)=nameid;
  5732. WFIFOSET(fd,packet_len(0x10a));
  5733. return 0;
  5734. }
  5735. /*==========================================
  5736. * MVP経験値所得
  5737. *------------------------------------------
  5738. */
  5739. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5740. {
  5741. int fd;
  5742. nullpo_retr(0, sd);
  5743. fd=sd->fd;
  5744. WFIFOHEAD(fd,packet_len(0x10b));
  5745. WFIFOW(fd,0)=0x10b;
  5746. WFIFOL(fd,2)=exp;
  5747. WFIFOSET(fd,packet_len(0x10b));
  5748. return 0;
  5749. }
  5750. /*==========================================
  5751. * ギルド作成可否通知
  5752. *------------------------------------------
  5753. */
  5754. int clif_guild_created(struct map_session_data *sd,int flag)
  5755. {
  5756. int fd;
  5757. nullpo_retr(0, sd);
  5758. fd=sd->fd;
  5759. WFIFOHEAD(fd,packet_len(0x167));
  5760. WFIFOW(fd,0)=0x167;
  5761. WFIFOB(fd,2)=flag;
  5762. WFIFOSET(fd,packet_len(0x167));
  5763. return 0;
  5764. }
  5765. /*==========================================
  5766. * ギルド所属通知
  5767. *------------------------------------------
  5768. */
  5769. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5770. {
  5771. int ps,fd;
  5772. nullpo_retr(0, sd);
  5773. nullpo_retr(0, g);
  5774. fd=sd->fd;
  5775. ps=guild_getposition(sd,g);
  5776. WFIFOHEAD(fd,packet_len(0x16c));
  5777. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5778. WFIFOW(fd,0)=0x16c;
  5779. WFIFOL(fd,2)=g->guild_id;
  5780. WFIFOL(fd,6)=g->emblem_id;
  5781. WFIFOL(fd,10)=g->position[ps].mode;
  5782. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5783. WFIFOSET(fd,packet_len(0x16c));
  5784. return 0;
  5785. }
  5786. /*==========================================
  5787. * ギルドメンバログイン通知
  5788. *------------------------------------------
  5789. */
  5790. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5791. {
  5792. unsigned char buf[64];
  5793. nullpo_retr(0, g);
  5794. WBUFW(buf, 0)=0x16d;
  5795. WBUFL(buf, 2)=g->member[idx].account_id;
  5796. WBUFL(buf, 6)=g->member[idx].char_id;
  5797. WBUFL(buf,10)=flag;
  5798. if(g->member[idx].sd==NULL){
  5799. struct map_session_data *sd=guild_getavailablesd(g);
  5800. if(sd!=NULL)
  5801. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5802. }else
  5803. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5804. return 0;
  5805. }
  5806. // Function `clif_guild_memberlogin_notice` sends info about
  5807. // logins and logouts of a guild member to the rest members.
  5808. // But at the 1st time (after a player login or map changing)
  5809. // the client won't show the message.
  5810. // So I suggest use this function for sending "first-time-info"
  5811. // to some player on entering the game or changing location.
  5812. // At next time the client would always show the message.
  5813. // The function sends all the statuses in the single packet
  5814. // to economize traffic. [LuzZza]
  5815. int clif_guild_send_onlineinfo(struct map_session_data *sd) {
  5816. struct guild *g;
  5817. char buf[14*128];
  5818. int i, count=0, p_len;
  5819. nullpo_retr(0, sd);
  5820. p_len = packet_len(0x16d);
  5821. if(!(g = guild_search(sd->status.guild_id)))
  5822. return 0;
  5823. for(i=0; i<g->max_member; i++) {
  5824. if(g->member[i].account_id > 0 &&
  5825. g->member[i].account_id != sd->status.account_id) {
  5826. WBUFW(buf,count*p_len) = 0x16d;
  5827. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5828. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5829. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5830. count++;
  5831. }
  5832. }
  5833. clif_send(buf,p_len*count,&sd->bl,SELF);
  5834. return 0;
  5835. }
  5836. /*==========================================
  5837. * ギルドマスター通知(14dへの応答)
  5838. *------------------------------------------
  5839. */
  5840. int clif_guild_masterormember(struct map_session_data *sd)
  5841. {
  5842. int type=0x57,fd;
  5843. nullpo_retr(0, sd);
  5844. fd=sd->fd;
  5845. if(sd->state.gmaster_flag)
  5846. type=0xd7;
  5847. WFIFOHEAD(fd,packet_len(0x14e));
  5848. WFIFOW(fd,0)=0x14e;
  5849. WFIFOL(fd,2)=type;
  5850. WFIFOSET(fd,packet_len(0x14e));
  5851. return 0;
  5852. }
  5853. /*==========================================
  5854. * Basic Info (Territories [Valaris])
  5855. *------------------------------------------
  5856. */
  5857. int clif_guild_basicinfo(struct map_session_data *sd)
  5858. {
  5859. int fd,i,t=0;
  5860. struct guild *g;
  5861. struct guild_castle *gc=NULL;
  5862. nullpo_retr(0, sd);
  5863. fd=sd->fd;
  5864. g=guild_search(sd->status.guild_id);
  5865. if(g==NULL)
  5866. return 0;
  5867. WFIFOHEAD(fd,packet_len(0x1b6));
  5868. WFIFOW(fd, 0)=0x1b6;//0x150;
  5869. WFIFOL(fd, 2)=g->guild_id;
  5870. WFIFOL(fd, 6)=g->guild_lv;
  5871. WFIFOL(fd,10)=g->connect_member;
  5872. WFIFOL(fd,14)=g->max_member;
  5873. WFIFOL(fd,18)=g->average_lv;
  5874. WFIFOL(fd,22)=g->exp;
  5875. WFIFOL(fd,26)=g->next_exp;
  5876. WFIFOL(fd,30)=0; // Tax Points
  5877. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5878. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5879. WFIFOL(fd,42)=g->emblem_id;
  5880. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5881. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5882. for(i=0;i<MAX_GUILDCASTLE;i++){
  5883. gc=guild_castle_search(i);
  5884. if(!gc) continue;
  5885. if(g->guild_id == gc->guild_id) t++;
  5886. }
  5887. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  5888. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  5889. else
  5890. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  5891. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5892. return 0;
  5893. }
  5894. /*==========================================
  5895. * ギルド同盟/敵対情報
  5896. *------------------------------------------
  5897. */
  5898. int clif_guild_allianceinfo(struct map_session_data *sd)
  5899. {
  5900. int fd,i,c;
  5901. struct guild *g;
  5902. nullpo_retr(0, sd);
  5903. fd=sd->fd;
  5904. g=guild_search(sd->status.guild_id);
  5905. if(g==NULL)
  5906. return 0;
  5907. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5908. WFIFOW(fd, 0)=0x14c;
  5909. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5910. struct guild_alliance *a=&g->alliance[i];
  5911. if(a->guild_id>0){
  5912. WFIFOL(fd,c*32+4)=a->opposition;
  5913. WFIFOL(fd,c*32+8)=a->guild_id;
  5914. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5915. c++;
  5916. }
  5917. }
  5918. WFIFOW(fd, 2)=c*32+4;
  5919. WFIFOSET(fd,WFIFOW(fd,2));
  5920. return 0;
  5921. }
  5922. /*==========================================
  5923. * ギルドメンバーリスト
  5924. *------------------------------------------
  5925. */
  5926. int clif_guild_memberlist(struct map_session_data *sd)
  5927. {
  5928. int fd;
  5929. int i,c;
  5930. struct guild *g;
  5931. nullpo_retr(0, sd);
  5932. fd=sd->fd;
  5933. if (!fd)
  5934. return 0;
  5935. g=guild_search(sd->status.guild_id);
  5936. if(g==NULL)
  5937. return 0;
  5938. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5939. WFIFOW(fd, 0)=0x154;
  5940. for(i=0,c=0;i<g->max_member;i++){
  5941. struct guild_member *m=&g->member[i];
  5942. if(m->account_id==0)
  5943. continue;
  5944. WFIFOL(fd,c*104+ 4)=m->account_id;
  5945. WFIFOL(fd,c*104+ 8)=m->char_id;
  5946. WFIFOW(fd,c*104+12)=m->hair;
  5947. WFIFOW(fd,c*104+14)=m->hair_color;
  5948. WFIFOW(fd,c*104+16)=m->gender;
  5949. WFIFOW(fd,c*104+18)=m->class_;
  5950. WFIFOW(fd,c*104+20)=m->lv;
  5951. WFIFOL(fd,c*104+22)=m->exp;
  5952. WFIFOL(fd,c*104+26)=m->online;
  5953. WFIFOL(fd,c*104+30)=m->position;
  5954. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5955. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5956. c++;
  5957. }
  5958. WFIFOW(fd, 2)=c*104+4;
  5959. WFIFOSET(fd,WFIFOW(fd,2));
  5960. return 0;
  5961. }
  5962. /*==========================================
  5963. * ギルド役職名リスト
  5964. *------------------------------------------
  5965. */
  5966. int clif_guild_positionnamelist(struct map_session_data *sd)
  5967. {
  5968. int i,fd;
  5969. struct guild *g;
  5970. nullpo_retr(0, sd);
  5971. fd=sd->fd;
  5972. g=guild_search(sd->status.guild_id);
  5973. if(g==NULL)
  5974. return 0;
  5975. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5976. WFIFOW(fd, 0)=0x166;
  5977. for(i=0;i<MAX_GUILDPOSITION;i++){
  5978. WFIFOL(fd,i*28+4)=i;
  5979. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5980. }
  5981. WFIFOW(fd,2)=i*28+4;
  5982. WFIFOSET(fd,WFIFOW(fd,2));
  5983. return 0;
  5984. }
  5985. /*==========================================
  5986. * ギルド役職情報リスト
  5987. *------------------------------------------
  5988. */
  5989. int clif_guild_positioninfolist(struct map_session_data *sd)
  5990. {
  5991. int i,fd;
  5992. struct guild *g;
  5993. nullpo_retr(0, sd);
  5994. fd=sd->fd;
  5995. g=guild_search(sd->status.guild_id);
  5996. if(g==NULL)
  5997. return 0;
  5998. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5999. WFIFOW(fd, 0)=0x160;
  6000. for(i=0;i<MAX_GUILDPOSITION;i++){
  6001. struct guild_position *p=&g->position[i];
  6002. WFIFOL(fd,i*16+ 4)=i;
  6003. WFIFOL(fd,i*16+ 8)=p->mode;
  6004. WFIFOL(fd,i*16+12)=i;
  6005. WFIFOL(fd,i*16+16)=p->exp_mode;
  6006. }
  6007. WFIFOW(fd, 2)=i*16+4;
  6008. WFIFOSET(fd,WFIFOW(fd,2));
  6009. return 0;
  6010. }
  6011. /*==========================================
  6012. * ギルド役職変更通知
  6013. *------------------------------------------
  6014. */
  6015. int clif_guild_positionchanged(struct guild *g,int idx)
  6016. {
  6017. struct map_session_data *sd;
  6018. unsigned char buf[128];
  6019. nullpo_retr(0, g);
  6020. WBUFW(buf, 0)=0x174;
  6021. WBUFW(buf, 2)=44;
  6022. WBUFL(buf, 4)=idx;
  6023. WBUFL(buf, 8)=g->position[idx].mode;
  6024. WBUFL(buf,12)=idx;
  6025. WBUFL(buf,16)=g->position[idx].exp_mode;
  6026. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6027. if( (sd=guild_getavailablesd(g))!=NULL )
  6028. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6029. return 0;
  6030. }
  6031. /*==========================================
  6032. * ギルドメンバ変更通知
  6033. *------------------------------------------
  6034. */
  6035. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6036. {
  6037. struct map_session_data *sd;
  6038. unsigned char buf[64];
  6039. nullpo_retr(0, g);
  6040. WBUFW(buf, 0)=0x156;
  6041. WBUFW(buf, 2)=16;
  6042. WBUFL(buf, 4)=g->member[idx].account_id;
  6043. WBUFL(buf, 8)=g->member[idx].char_id;
  6044. WBUFL(buf,12)=g->member[idx].position;
  6045. if( (sd=guild_getavailablesd(g))!=NULL )
  6046. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6047. return 0;
  6048. }
  6049. /*==========================================
  6050. * ギルドエンブレム送信
  6051. *------------------------------------------
  6052. */
  6053. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6054. {
  6055. int fd;
  6056. nullpo_retr(0, sd);
  6057. nullpo_retr(0, g);
  6058. fd=sd->fd;
  6059. if(g->emblem_len<=0)
  6060. return 0;
  6061. WFIFOHEAD(fd,g->emblem_len+12);
  6062. WFIFOW(fd,0)=0x152;
  6063. WFIFOW(fd,2)=g->emblem_len+12;
  6064. WFIFOL(fd,4)=g->guild_id;
  6065. WFIFOL(fd,8)=g->emblem_id;
  6066. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6067. WFIFOSET(fd,WFIFOW(fd,2));
  6068. return 0;
  6069. }
  6070. /*==========================================
  6071. * ギルドスキル送信
  6072. *------------------------------------------
  6073. */
  6074. int clif_guild_skillinfo(struct map_session_data *sd)
  6075. {
  6076. int fd;
  6077. int i,id,c,up=1;
  6078. struct guild *g;
  6079. nullpo_retr(0, sd);
  6080. fd=sd->fd;
  6081. g=guild_search(sd->status.guild_id);
  6082. if(g==NULL)
  6083. return 0;
  6084. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6085. WFIFOW(fd,0)=0x0162;
  6086. WFIFOW(fd,4)=g->skill_point;
  6087. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6088. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6089. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6090. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  6091. WFIFOW(fd,c*37+10) = 0;
  6092. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6093. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6094. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6095. strncpy(WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH);
  6096. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6097. up = 1;
  6098. else
  6099. up = 0;
  6100. WFIFOB(fd,c*37+42)= up;
  6101. c++;
  6102. }
  6103. }
  6104. WFIFOW(fd,2)=c*37+6;
  6105. WFIFOSET(fd,WFIFOW(fd,2));
  6106. return 0;
  6107. }
  6108. /*==========================================
  6109. * ギルド告知送信
  6110. *------------------------------------------
  6111. */
  6112. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6113. {
  6114. int fd;
  6115. nullpo_retr(0, sd);
  6116. nullpo_retr(0, g);
  6117. fd = sd->fd;
  6118. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6119. return 0;
  6120. if (fd <= 0)
  6121. return 0;
  6122. if(*g->mes1==0 && *g->mes2==0)
  6123. return 0;
  6124. WFIFOHEAD(fd,packet_len(0x16f));
  6125. WFIFOW(fd,0)=0x16f;
  6126. memcpy(WFIFOP(fd,2),g->mes1,60);
  6127. memcpy(WFIFOP(fd,62),g->mes2,120);
  6128. WFIFOSET(fd,packet_len(0x16f));
  6129. return 0;
  6130. }
  6131. /*==========================================
  6132. * ギルドメンバ勧誘
  6133. *------------------------------------------
  6134. */
  6135. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6136. {
  6137. int fd;
  6138. nullpo_retr(0, sd);
  6139. nullpo_retr(0, g);
  6140. fd=sd->fd;
  6141. WFIFOHEAD(fd,packet_len(0x16a));
  6142. WFIFOW(fd,0)=0x16a;
  6143. WFIFOL(fd,2)=g->guild_id;
  6144. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6145. WFIFOSET(fd,packet_len(0x16a));
  6146. return 0;
  6147. }
  6148. /*==========================================
  6149. * ギルドメンバ勧誘結果
  6150. *------------------------------------------
  6151. */
  6152. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6153. {
  6154. int fd;
  6155. nullpo_retr(0, sd);
  6156. fd=sd->fd;
  6157. WFIFOHEAD(fd,packet_len(0x169));
  6158. WFIFOW(fd,0)=0x169;
  6159. WFIFOB(fd,2)=flag;
  6160. WFIFOSET(fd,packet_len(0x169));
  6161. return 0;
  6162. }
  6163. /*==========================================
  6164. * ギルドメンバ脱退通知
  6165. *------------------------------------------
  6166. */
  6167. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6168. {
  6169. unsigned char buf[128];
  6170. nullpo_retr(0, sd);
  6171. WBUFW(buf, 0)=0x15a;
  6172. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6173. memcpy(WBUFP(buf,26),mes,40);
  6174. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  6175. return 0;
  6176. }
  6177. /*==========================================
  6178. * ギルドメンバ追放通知
  6179. *------------------------------------------
  6180. */
  6181. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  6182. int account_id)
  6183. {
  6184. unsigned char buf[128];
  6185. nullpo_retr(0, sd);
  6186. WBUFW(buf, 0)=0x15c;
  6187. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6188. memcpy(WBUFP(buf,26),mes,40);
  6189. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6190. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  6191. return 0;
  6192. }
  6193. /*==========================================
  6194. * ギルド追放メンバリスト
  6195. *------------------------------------------
  6196. */
  6197. int clif_guild_expulsionlist(struct map_session_data *sd)
  6198. {
  6199. int fd;
  6200. int i,c;
  6201. struct guild *g;
  6202. nullpo_retr(0, sd);
  6203. fd=sd->fd;
  6204. g=guild_search(sd->status.guild_id);
  6205. if(g==NULL)
  6206. return 0;
  6207. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  6208. WFIFOW(fd,0)=0x163;
  6209. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  6210. struct guild_expulsion *e=&g->expulsion[i];
  6211. if(e->account_id>0){
  6212. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6213. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6214. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6215. c++;
  6216. }
  6217. }
  6218. WFIFOW(fd,2)=c*88+4;
  6219. WFIFOSET(fd,WFIFOW(fd,2));
  6220. return 0;
  6221. }
  6222. /*==========================================
  6223. * ギルド会話
  6224. *------------------------------------------
  6225. */
  6226. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6227. {
  6228. struct map_session_data *sd;
  6229. unsigned char *buf;
  6230. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6231. WBUFW(buf, 0) = 0x17f;
  6232. WBUFW(buf, 2) = len + 4;
  6233. memcpy(WBUFP(buf,4), mes, len);
  6234. if ((sd = guild_getavailablesd(g)) != NULL)
  6235. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6236. if(buf) aFree(buf);
  6237. return 0;
  6238. }
  6239. /*==========================================
  6240. * ギルドスキル割り振り通知
  6241. *------------------------------------------
  6242. */
  6243. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6244. {
  6245. int fd;
  6246. nullpo_retr(0, sd);
  6247. fd=sd->fd;
  6248. WFIFOHEAD(fd,11);
  6249. WFIFOW(fd,0) = 0x10e;
  6250. WFIFOW(fd,2) = skill_num;
  6251. WFIFOW(fd,4) = lv;
  6252. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6253. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6254. WFIFOB(fd,10) = 1;
  6255. WFIFOSET(fd,11);
  6256. return 0;
  6257. }
  6258. /*==========================================
  6259. * ギルド同盟要請
  6260. *------------------------------------------
  6261. */
  6262. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6263. {
  6264. int fd;
  6265. nullpo_retr(0, sd);
  6266. fd=sd->fd;
  6267. WFIFOHEAD(fd,packet_len(0x171));
  6268. WFIFOW(fd,0)=0x171;
  6269. WFIFOL(fd,2)=account_id;
  6270. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6271. WFIFOSET(fd,packet_len(0x171));
  6272. return 0;
  6273. }
  6274. /*==========================================
  6275. * Reply to alliance request.
  6276. * Flag values are:
  6277. * 0: Already allied.
  6278. * 1: You rejected the offer.
  6279. * 2: You accepted the offer.
  6280. * 3: They have too any alliances
  6281. * 4: You have too many alliances.
  6282. *------------------------------------------
  6283. */
  6284. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6285. {
  6286. int fd;
  6287. nullpo_retr(0, sd);
  6288. fd=sd->fd;
  6289. WFIFOHEAD(fd,packet_len(0x173));
  6290. WFIFOW(fd,0)=0x173;
  6291. WFIFOL(fd,2)=flag;
  6292. WFIFOSET(fd,packet_len(0x173));
  6293. return 0;
  6294. }
  6295. /*==========================================
  6296. * ギルド関係解消通知
  6297. *------------------------------------------
  6298. */
  6299. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6300. {
  6301. int fd;
  6302. nullpo_retr(0, sd);
  6303. fd = sd->fd;
  6304. if (fd <= 0)
  6305. return 0;
  6306. WFIFOHEAD(fd,packet_len(0x184));
  6307. WFIFOW(fd,0)=0x184;
  6308. WFIFOL(fd,2)=guild_id;
  6309. WFIFOL(fd,6)=flag;
  6310. WFIFOSET(fd,packet_len(0x184));
  6311. return 0;
  6312. }
  6313. /*==========================================
  6314. * ギルド敵対結果
  6315. *------------------------------------------
  6316. */
  6317. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6318. {
  6319. int fd;
  6320. nullpo_retr(0, sd);
  6321. fd=sd->fd;
  6322. WFIFOHEAD(fd,packet_len(0x181));
  6323. WFIFOW(fd,0)=0x181;
  6324. WFIFOB(fd,2)=flag;
  6325. WFIFOSET(fd,packet_len(0x181));
  6326. return 0;
  6327. }
  6328. /*==========================================
  6329. * ギルド関係追加
  6330. *------------------------------------------
  6331. */
  6332. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6333. {
  6334. unsigned char buf[64];
  6335. WBUFW(fd,0)=0x185;
  6336. WBUFL(fd,2)=g->alliance[idx].opposition;
  6337. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6338. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6339. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6340. return 0;
  6341. }*/
  6342. /*==========================================
  6343. * ギルド解散通知
  6344. *------------------------------------------
  6345. */
  6346. int clif_guild_broken(struct map_session_data *sd,int flag)
  6347. {
  6348. int fd;
  6349. nullpo_retr(0, sd);
  6350. fd=sd->fd;
  6351. WFIFOHEAD(fd,packet_len(0x15e));
  6352. WFIFOW(fd,0)=0x15e;
  6353. WFIFOL(fd,2)=flag;
  6354. WFIFOSET(fd,packet_len(0x15e));
  6355. return 0;
  6356. }
  6357. /*==========================================
  6358. * エモーション
  6359. *------------------------------------------
  6360. */
  6361. void clif_emotion(struct block_list *bl,int type)
  6362. {
  6363. unsigned char buf[8];
  6364. nullpo_retv(bl);
  6365. WBUFW(buf,0)=0xc0;
  6366. WBUFL(buf,2)=bl->id;
  6367. WBUFB(buf,6)=type;
  6368. clif_send(buf,packet_len(0xc0),bl,AREA);
  6369. }
  6370. /*==========================================
  6371. * トーキーボックス
  6372. *------------------------------------------
  6373. */
  6374. void clif_talkiebox(struct block_list *bl,char* talkie)
  6375. {
  6376. unsigned char buf[86];
  6377. nullpo_retv(bl);
  6378. WBUFW(buf,0)=0x191;
  6379. WBUFL(buf,2)=bl->id;
  6380. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6381. clif_send(buf,packet_len(0x191),bl,AREA);
  6382. }
  6383. /*==========================================
  6384. * 結婚エフェクト
  6385. *------------------------------------------
  6386. */
  6387. void clif_wedding_effect(struct block_list *bl) {
  6388. unsigned char buf[6];
  6389. nullpo_retv(bl);
  6390. WBUFW(buf,0) = 0x1ea;
  6391. WBUFL(buf,2) = bl->id;
  6392. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6393. }
  6394. /*==========================================
  6395. * あなたに逢いたい使用時名前叫び
  6396. *------------------------------------------
  6397. void clif_callpartner(struct map_session_data *sd)
  6398. {
  6399. unsigned char buf[26];
  6400. char *p;
  6401. nullpo_retv(sd);
  6402. if(sd->status.partner_id){
  6403. WBUFW(buf,0)=0x1e6;
  6404. p = map_charid2nick(sd->status.partner_id);
  6405. if(p){
  6406. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6407. }else{
  6408. map_reqchariddb(sd,sd->status.partner_id);
  6409. chrif_searchcharid(sd->status.partner_id);
  6410. WBUFB(buf,2) = 0;
  6411. }
  6412. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6413. }
  6414. return;
  6415. }
  6416. */
  6417. /*==========================================
  6418. * Adopt baby [Celest]
  6419. *------------------------------------------
  6420. */
  6421. void clif_adopt_process(struct map_session_data *sd)
  6422. {
  6423. int fd;
  6424. nullpo_retv(sd);
  6425. fd=sd->fd;
  6426. WFIFOHEAD(fd,packet_len(0x1f8));
  6427. WFIFOW(fd,0)=0x1f8;
  6428. WFIFOSET(fd,packet_len(0x1f8));
  6429. }
  6430. /*==========================================
  6431. * Marry [DracoRPG]
  6432. *------------------------------------------
  6433. */
  6434. void clif_marriage_process(struct map_session_data *sd)
  6435. {
  6436. int fd;
  6437. nullpo_retv(sd);
  6438. fd=sd->fd;
  6439. WFIFOHEAD(fd,packet_len(0x1e4));
  6440. WFIFOW(fd,0)=0x1e4;
  6441. WFIFOSET(fd,packet_len(0x1e4));
  6442. }
  6443. /*==========================================
  6444. * Notice of divorce
  6445. *------------------------------------------
  6446. */
  6447. void clif_divorced(struct map_session_data *sd, char *name)
  6448. {
  6449. int fd;
  6450. nullpo_retv(sd);
  6451. fd=sd->fd;
  6452. WFIFOHEAD(fd,packet_len(0x205));
  6453. WFIFOW(fd,0)=0x205;
  6454. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6455. WFIFOSET(fd, packet_len(0x205));
  6456. }
  6457. /*==========================================
  6458. *
  6459. *------------------------------------------
  6460. */
  6461. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6462. nullpo_retv(sd);
  6463. WFIFOHEAD(fd,packet_len(0x1f6));
  6464. WFIFOW(fd,0)=0x1f6;
  6465. WFIFOSET(fd, packet_len(0x1f6));
  6466. }
  6467. /*==========================================
  6468. *
  6469. *------------------------------------------
  6470. */
  6471. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6472. nullpo_retv(sd);
  6473. WFIFOHEAD(fd,packet_len(0x1e2));
  6474. WFIFOW(fd,0)=0x1e2;
  6475. WFIFOSET(fd, packet_len(0x1e2));
  6476. }
  6477. /*==========================================
  6478. * 座る
  6479. *------------------------------------------
  6480. */
  6481. void clif_sitting(struct map_session_data *sd)
  6482. {
  6483. unsigned char buf[64];
  6484. nullpo_retv(sd);
  6485. WBUFW(buf, 0) = 0x8a;
  6486. WBUFL(buf, 2) = sd->bl.id;
  6487. WBUFB(buf,26) = 2;
  6488. clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
  6489. }
  6490. /*==========================================
  6491. *
  6492. *------------------------------------------
  6493. */
  6494. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  6495. {
  6496. int fd;
  6497. nullpo_retr(0, sd);
  6498. fd = sd->fd;
  6499. if (!fd || !len) return 0; //Disconnected player.
  6500. WFIFOHEAD(fd, len+5);
  6501. WFIFOW(fd, 0) = 0x17f;
  6502. WFIFOW(fd, 2) = len + 5;
  6503. memcpy(WFIFOP(fd,4), mes, len);
  6504. WFIFOSET(fd, WFIFOW(fd,2));
  6505. return 1;
  6506. }
  6507. /*==========================================
  6508. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6509. *------------------------------------------
  6510. */
  6511. void clif_disp_message(struct block_list *src, char *mes, int len, int type)
  6512. {
  6513. unsigned char buf[1024];
  6514. if (!len) return;
  6515. WBUFW(buf, 0) = 0x17f;
  6516. WBUFW(buf, 2) = len + 5;
  6517. memcpy(WBUFP(buf,4), mes, len);
  6518. clif_send(buf, WBUFW(buf,2), src, type);
  6519. return;
  6520. }
  6521. /*==========================================
  6522. *
  6523. *------------------------------------------
  6524. */
  6525. int clif_GM_kickack(struct map_session_data *sd, int id)
  6526. {
  6527. int fd;
  6528. nullpo_retr(0, sd);
  6529. fd = sd->fd;
  6530. WFIFOHEAD(fd,packet_len(0xcd));
  6531. WFIFOW(fd,0) = 0xcd;
  6532. WFIFOL(fd,2) = id;
  6533. WFIFOSET(fd, packet_len(0xcd));
  6534. return 0;
  6535. }
  6536. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6537. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6538. {
  6539. int fd = tsd->fd;
  6540. WFIFOHEAD(fd,packet_len(0x18b));
  6541. if(type)
  6542. clif_GM_kickack(sd,tsd->status.account_id);
  6543. if (!fd) {
  6544. map_quit(tsd);
  6545. return 0;
  6546. }
  6547. WFIFOW(fd,0) = 0x18b;
  6548. WFIFOW(fd,2) = 0;
  6549. WFIFOSET(fd,packet_len(0x18b));
  6550. clif_setwaitclose(fd);
  6551. return 0;
  6552. }
  6553. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6554. {
  6555. int fd;
  6556. nullpo_retr(0, sd);
  6557. nullpo_retr(0, tsd);
  6558. fd = tsd->fd;
  6559. if (fd <= 0)
  6560. return 0;
  6561. WFIFOHEAD(fd,packet_len(0x14b));
  6562. WFIFOW(fd,0) = 0x14b;
  6563. WFIFOB(fd,2) = 0;
  6564. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6565. WFIFOSET(fd, packet_len(0x14b));
  6566. return 0;
  6567. }
  6568. /*==========================================
  6569. *
  6570. *------------------------------------------
  6571. */
  6572. int clif_timedout(struct map_session_data *sd)
  6573. {
  6574. nullpo_retr(0, sd);
  6575. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6576. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6577. clif_setwaitclose(sd->fd); // Set session to EOF
  6578. return 0;
  6579. }
  6580. /*==========================================
  6581. * Wis拒否許可応答
  6582. *------------------------------------------
  6583. */
  6584. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6585. {
  6586. int fd;
  6587. nullpo_retr(0, sd);
  6588. fd=sd->fd;
  6589. WFIFOHEAD(fd,packet_len(0xd1));
  6590. WFIFOW(fd,0)=0xd1;
  6591. WFIFOB(fd,2)=type;
  6592. WFIFOB(fd,3)=flag;
  6593. WFIFOSET(fd,packet_len(0xd1));
  6594. return 0;
  6595. }
  6596. /*==========================================
  6597. * Wis全拒否許可応答
  6598. *------------------------------------------
  6599. */
  6600. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6601. {
  6602. int fd;
  6603. nullpo_retr(0, sd);
  6604. fd=sd->fd;
  6605. WFIFOHEAD(fd,packet_len(0xd2));
  6606. WFIFOW(fd,0)=0xd2;
  6607. WFIFOB(fd,2)=type;
  6608. WFIFOB(fd,3)=flag;
  6609. WFIFOSET(fd,packet_len(0xd2));
  6610. return 0;
  6611. }
  6612. /*==========================================
  6613. * サウンドエフェクト
  6614. *------------------------------------------
  6615. */
  6616. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  6617. {
  6618. int fd;
  6619. nullpo_retv(sd);
  6620. nullpo_retv(bl);
  6621. fd=sd->fd;
  6622. WFIFOHEAD(fd,packet_len(0x1d3));
  6623. WFIFOW(fd,0)=0x1d3;
  6624. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6625. WFIFOB(fd,26)=type;
  6626. WFIFOL(fd,27)=0;
  6627. WFIFOL(fd,31)=bl->id;
  6628. WFIFOSET(fd,packet_len(0x1d3));
  6629. return;
  6630. }
  6631. int clif_soundeffectall(struct block_list *bl, char *name, int type, int coverage)
  6632. {
  6633. unsigned char buf[40];
  6634. memset(buf, 0, packet_len(0x1d3));
  6635. if(coverage < 0 || coverage > 22){
  6636. ShowError("clif_soundeffectall: undefined coverage.\n");
  6637. return 0;
  6638. }
  6639. nullpo_retr(0, bl);
  6640. WBUFW(buf,0)=0x1d3;
  6641. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6642. WBUFB(buf,26)=type;
  6643. WBUFL(buf,27)=0;
  6644. WBUFL(buf,31)=bl->id;
  6645. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6646. return 0;
  6647. }
  6648. // displaying special effects (npcs, weather, etc) [Valaris]
  6649. int clif_specialeffect(struct block_list *bl, int type, int flag)
  6650. {
  6651. unsigned char buf[24];
  6652. nullpo_retr(0, bl);
  6653. memset(buf, 0, packet_len(0x1f3));
  6654. WBUFW(buf,0) = 0x1f3;
  6655. WBUFL(buf,2) = bl->id;
  6656. WBUFL(buf,6) = type;
  6657. clif_send(buf, packet_len(0x1f3), bl, flag);
  6658. if (disguised(bl)) {
  6659. WBUFL(buf,2) = -bl->id;
  6660. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6661. }
  6662. return 0;
  6663. }
  6664. // refresh the client's screen, getting rid of any effects
  6665. int clif_refresh(struct map_session_data *sd) {
  6666. nullpo_retr(-1, sd);
  6667. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6668. clif_inventorylist(sd);
  6669. if(pc_iscarton(sd)){
  6670. clif_cartlist(sd);
  6671. clif_updatestatus(sd,SP_CARTINFO);
  6672. }
  6673. clif_updatestatus(sd,SP_MAXWEIGHT);
  6674. clif_updatestatus(sd,SP_WEIGHT);
  6675. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6676. clif_weather_check(sd);
  6677. return 0;
  6678. }
  6679. // updates the object's (bl) name on client
  6680. int clif_charnameack (int fd, struct block_list *bl)
  6681. {
  6682. unsigned char buf[103];
  6683. int cmd = 0x95;
  6684. nullpo_retr(0, bl);
  6685. WBUFW(buf,0) = cmd;
  6686. WBUFL(buf,2) = bl->id;
  6687. switch(bl->type) {
  6688. case BL_PC:
  6689. {
  6690. struct map_session_data *ssd = (struct map_session_data *)bl;
  6691. struct party_data *p = NULL;
  6692. struct guild *g = NULL;
  6693. //Requesting your own "shadow" name. [Skotlex]
  6694. if (ssd->fd == fd && ssd->disguise)
  6695. WBUFL(buf,2) = -bl->id;
  6696. if (strlen(ssd->fakename)>1) {
  6697. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6698. break;
  6699. }
  6700. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6701. if (ssd->status.party_id > 0)
  6702. p = party_search(ssd->status.party_id);
  6703. if (ssd->status.guild_id > 0)
  6704. g = guild_search(ssd->status.guild_id);
  6705. if (p == NULL && g == NULL)
  6706. break;
  6707. WBUFW(buf, 0) = cmd = 0x195;
  6708. if (p)
  6709. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6710. else
  6711. WBUFB(buf,30) = 0;
  6712. if (g)
  6713. {
  6714. int i, ps = -1;
  6715. for(i = 0; i < g->max_member; i++) {
  6716. if (g->member[i].account_id == ssd->status.account_id &&
  6717. g->member[i].char_id == ssd->status.char_id )
  6718. {
  6719. ps = g->member[i].position;
  6720. break;
  6721. }
  6722. }
  6723. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6724. {
  6725. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6726. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6727. } else { //Assume no guild.
  6728. WBUFB(buf,54) = 0;
  6729. WBUFB(buf,78) = 0;
  6730. }
  6731. } else {
  6732. WBUFB(buf,54) = 0;
  6733. WBUFB(buf,78) = 0;
  6734. }
  6735. }
  6736. break;
  6737. //[blackhole89]
  6738. case BL_HOM:
  6739. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6740. break;
  6741. case BL_PET:
  6742. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6743. break;
  6744. case BL_NPC:
  6745. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6746. break;
  6747. case BL_MOB:
  6748. {
  6749. struct mob_data *md = (struct mob_data *)bl;
  6750. nullpo_retr(0, md);
  6751. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6752. if (md->guardian_data && md->guardian_data->guild_id) {
  6753. WBUFW(buf, 0) = cmd = 0x195;
  6754. WBUFB(buf,30) = 0;
  6755. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6756. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6757. } else if (battle_config.show_mob_info) {
  6758. char mobhp[50], *str_p = mobhp;
  6759. WBUFW(buf, 0) = cmd = 0x195;
  6760. if (battle_config.show_mob_info&4)
  6761. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6762. if (battle_config.show_mob_info&1)
  6763. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6764. if (battle_config.show_mob_info&2)
  6765. str_p += sprintf(str_p, "HP: %d%% | ",
  6766. md->status.max_hp > 10000?
  6767. md->status.hp/(md->status.max_hp/100):
  6768. 100*md->status.hp/md->status.max_hp);
  6769. //Even thought mobhp ain't a name, we send it as one so the client
  6770. //can parse it. [Skotlex]
  6771. if (str_p != mobhp) {
  6772. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6773. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6774. WBUFB(buf,54) = 0;
  6775. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6776. }
  6777. }
  6778. }
  6779. break;
  6780. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6781. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6782. // break;
  6783. return 0;
  6784. default:
  6785. if (battle_config.error_log)
  6786. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6787. return 0;
  6788. }
  6789. // if no receipient specified just update nearby clients
  6790. if (fd == 0)
  6791. clif_send(buf, packet_len(cmd), bl, AREA);
  6792. else {
  6793. WFIFOHEAD(fd, packet_len(cmd));
  6794. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6795. WFIFOSET(fd, packet_len(cmd));
  6796. }
  6797. return 0;
  6798. }
  6799. //Used to update when a char leaves a party/guild. [Skotlex]
  6800. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6801. int clif_charnameupdate (struct map_session_data *ssd)
  6802. {
  6803. unsigned char buf[103];
  6804. int cmd = 0x195;
  6805. struct party_data *p = NULL;
  6806. struct guild *g = NULL;
  6807. nullpo_retr(0, ssd);
  6808. if (strlen(ssd->fakename)>1)
  6809. return 0; //No need to update as the party/guild was not displayed anyway.
  6810. WBUFW(buf,0) = cmd;
  6811. WBUFL(buf,2) = ssd->bl.id;
  6812. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6813. if (ssd->status.party_id > 0)
  6814. p = party_search(ssd->status.party_id);
  6815. if (ssd->status.guild_id > 0)
  6816. g = guild_search(ssd->status.guild_id);
  6817. if (p)
  6818. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6819. else
  6820. WBUFB(buf,30) = 0;
  6821. if (g)
  6822. {
  6823. int i, ps = -1;
  6824. for(i = 0; i < g->max_member; i++) {
  6825. if (g->member[i].account_id == ssd->status.account_id &&
  6826. g->member[i].char_id == ssd->status.char_id )
  6827. {
  6828. ps = g->member[i].position;
  6829. break;
  6830. }
  6831. }
  6832. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6833. {
  6834. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6835. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6836. } else { //Assume no guild.
  6837. WBUFB(buf,54) = 0;
  6838. WBUFB(buf,78) = 0;
  6839. }
  6840. } else {
  6841. WBUFB(buf,54) = 0;
  6842. WBUFB(buf,78) = 0;
  6843. }
  6844. // Update nearby clients
  6845. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6846. return 0;
  6847. }
  6848. int clif_slide(struct block_list *bl, int x, int y){
  6849. unsigned char buf[10];
  6850. nullpo_retr(0, bl);
  6851. WBUFW(buf, 0) = 0x01ff;
  6852. WBUFL(buf, 2) = bl->id;
  6853. WBUFW(buf, 6) = x;
  6854. WBUFW(buf, 8) = y;
  6855. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6856. return 0;
  6857. }
  6858. /*------------------------------------------
  6859. * @me command by lordalfa, rewritten implementation by Skotlex
  6860. *------------------------------------------
  6861. */
  6862. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  6863. {
  6864. unsigned char buf[256]; //This should be more than sufficient, the theorical max is MESSAGE_SIZE+NAME_LENGTH + 8 (pads and extra inserted crap)
  6865. int len_mes = strlen(mes)+1; //Account for \0
  6866. if (len_mes + 8 >= 256) {
  6867. if (battle_config.error_log)
  6868. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6869. len_mes = 247; //Trunk it to avoid problems.
  6870. }
  6871. // send message to others
  6872. WBUFW(buf,0) = 0x8d;
  6873. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6874. WBUFL(buf,4) = sd->bl.id;
  6875. memcpy(WBUFP(buf,8), mes, len_mes);
  6876. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6877. // send back message to the speaker
  6878. WBUFW(buf,0) = 0x8e;
  6879. WBUFW(buf, 2) = len_mes + 4;
  6880. memcpy(WBUFP(buf,4), mes, len_mes);
  6881. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6882. return 0;
  6883. }
  6884. /*==========================
  6885. * Minimap fix [Kevin]
  6886. * Remove dot from minimap
  6887. *--------------------------
  6888. */
  6889. int clif_party_xy_remove(struct map_session_data *sd)
  6890. {
  6891. unsigned char buf[16];
  6892. nullpo_retr(0, sd);
  6893. WBUFW(buf,0)=0x107;
  6894. WBUFL(buf,2)=sd->status.account_id;
  6895. WBUFW(buf,6)=-1;
  6896. WBUFW(buf,8)=-1;
  6897. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6898. return 0;
  6899. }
  6900. //Displays gospel-buff information (thanks to Rayce):
  6901. //Type determines message based on this table:
  6902. /*
  6903. 0x15 End all negative status
  6904. 0x16 Immunity to all status
  6905. 0x17 MaxHP +100%
  6906. 0x18 MaxSP +100%
  6907. 0x19 All stats +20
  6908. 0x1c Enchant weapon with Holy element
  6909. 0x1d Enchant armor with Holy element
  6910. 0x1e DEF +25%
  6911. 0x1f ATK +100%
  6912. 0x20 HIT/Flee +50
  6913. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6914. */
  6915. void clif_gospel_info(struct map_session_data *sd, int type)
  6916. {
  6917. int fd=sd->fd;
  6918. WFIFOHEAD(fd,packet_len(0x215));
  6919. WFIFOW(fd,0)=0x215;
  6920. WFIFOL(fd,2)=type;
  6921. WFIFOSET(fd, packet_len(0x215));
  6922. }
  6923. /*==========================================
  6924. * Info about Star Glaldiator save map [Komurka]
  6925. * type: 1: Information, 0: Map registered
  6926. *------------------------------------------
  6927. */
  6928. void clif_feel_info(struct map_session_data *sd, unsigned char feel_level, unsigned char type)
  6929. {
  6930. int fd=sd->fd;
  6931. WFIFOHEAD(fd,packet_len(0x20e));
  6932. WFIFOW(fd,0)=0x20e;
  6933. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  6934. WFIFOL(fd,26)=sd->bl.id;
  6935. WFIFOB(fd,30)=feel_level;
  6936. WFIFOB(fd,31)=type?1:0;
  6937. WFIFOSET(fd, packet_len(0x20e));
  6938. }
  6939. /*==========================================
  6940. * Info about Star Glaldiator hate mob [Komurka]
  6941. * type: 1: Register mob, 0: Information.
  6942. *------------------------------------------
  6943. */
  6944. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6945. {
  6946. int fd=sd->fd;
  6947. WFIFOHEAD(fd,packet_len(0x20e));
  6948. WFIFOW(fd,0)=0x20e;
  6949. if (pcdb_checkid(class_))
  6950. strncpy(WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6951. else if (mobdb_checkid(class_))
  6952. strncpy(WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6953. else //Really shouldn't happen...
  6954. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6955. WFIFOL(fd,26)=sd->bl.id;
  6956. WFIFOB(fd,30)=hate_level;
  6957. WFIFOB(fd,31)=type?10:11; //Register/Info
  6958. WFIFOSET(fd, packet_len(0x20e));
  6959. }
  6960. /*==========================================
  6961. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6962. *------------------------------------------
  6963. */
  6964. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6965. {
  6966. int fd=sd->fd;
  6967. WFIFOHEAD(fd,packet_len(0x20e));
  6968. WFIFOW(fd,0)=0x20e;
  6969. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6970. WFIFOL(fd,26)=mob_id;
  6971. WFIFOB(fd,30)=progress; //Message to display
  6972. WFIFOB(fd,31)=20;
  6973. WFIFOSET(fd, packet_len(0x20e));
  6974. }
  6975. /*==========================================
  6976. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6977. *------------------------------------------
  6978. */
  6979. void clif_feel_hate_reset(struct map_session_data *sd)
  6980. {
  6981. int fd=sd->fd;
  6982. WFIFOHEAD(fd,packet_len(0x20e));
  6983. WFIFOW(fd,0)=0x20e;
  6984. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6985. WFIFOL(fd,26)=sd->bl.id;
  6986. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6987. WFIFOB(fd,31)=30;
  6988. WFIFOSET(fd, packet_len(0x20e));
  6989. }
  6990. // ---------------------
  6991. // clif_guess_PacketVer
  6992. // ---------------------
  6993. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6994. // error codes:
  6995. // 0 - Success
  6996. // 1 - Unknown packet_ver
  6997. // 2 - Invalid account_id
  6998. // 3 - Invalid char_id
  6999. // 4 - Invalid login_id1 (reserved)
  7000. // 5 - Invalid client_tick (reserved)
  7001. // 6 - Invalid sex
  7002. // Only the first 'invalid' error that appears is used.
  7003. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7004. {
  7005. static int err = 1;
  7006. static int packet_ver = -1;
  7007. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7008. RFIFOHEAD(fd);
  7009. if (get_previous)
  7010. {//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]
  7011. if( error )
  7012. *error = err;
  7013. return packet_ver;
  7014. }
  7015. //By default, start searching on the default one.
  7016. err = 1;
  7017. packet_ver = clif_config.packet_db_ver;
  7018. cmd = RFIFOW(fd,0);
  7019. packet_len = RFIFOREST(fd);
  7020. #define SET_ERROR(n) \
  7021. if( err == 1 )\
  7022. err = n;\
  7023. //define SET_ERROR
  7024. #define CHECK_PACKET_VER() \
  7025. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7026. ;/* not wanttoconnection or wrong length */\
  7027. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  7028. { SET_ERROR(2); }/* invalid account_id */\
  7029. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  7030. { SET_ERROR(3); }/* invalid char_id */\
  7031. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7032. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7033. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7034. { SET_ERROR(6); }/* invalid sex */\
  7035. else\
  7036. {\
  7037. err = 0;\
  7038. if( error )\
  7039. *error = 0;\
  7040. return packet_ver;\
  7041. }\
  7042. //define CHECK_PACKET_VER
  7043. CHECK_PACKET_VER();//Default packet version found.
  7044. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7045. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7046. CHECK_PACKET_VER();
  7047. }
  7048. if( error )
  7049. *error = err;
  7050. packet_ver = -1;
  7051. return -1;
  7052. #undef SET_ERROR
  7053. #undef CHECK_PACKET_VER
  7054. }
  7055. // ------------
  7056. // clif_parse_*
  7057. // ------------
  7058. // パケット読み取って色々操作
  7059. /*==========================================
  7060. *
  7061. *------------------------------------------
  7062. */
  7063. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7064. {
  7065. int cmd, account_id, char_id, login_id1, sex;
  7066. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7067. 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])
  7068. RFIFOHEAD(fd);
  7069. if (sd) {
  7070. if (battle_config.error_log)
  7071. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  7072. return;
  7073. }
  7074. // Only valid packet version get here
  7075. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7076. cmd = RFIFOW(fd,0);
  7077. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7078. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7079. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7080. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7081. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7082. if( packet_ver < 5 || // reject really old client versions
  7083. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7084. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7085. {// packet version rejected
  7086. WFIFOHEAD(fd,packet_len(0x6a));
  7087. WFIFOW(fd,0) = 0x6a;
  7088. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7089. WFIFOSET(fd,packet_len(0x6a));
  7090. clif_setwaitclose(fd);
  7091. return;
  7092. } else
  7093. {// packet version accepted
  7094. TBL_PC* old_sd;
  7095. struct block_list* bl;
  7096. if( (bl=map_id2bl(account_id)) != NULL && bl->type != BL_PC )
  7097. {// non-player object already has that id
  7098. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7099. WFIFOHEAD(fd,packet_len(0x6a));
  7100. WFIFOW(fd,0) = 0x6a;
  7101. WFIFOB(fd,2) = 3; // Rejected by server
  7102. WFIFOSET(fd,packet_len(0x6a));
  7103. clif_setwaitclose(fd);
  7104. return;
  7105. }
  7106. if( (old_sd=map_id2sd(account_id)) != NULL ){
  7107. // if same account already connected, we disconnect the 2 sessions
  7108. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  7109. if (old_sd->state.finalsave || !old_sd->state.auth)
  7110. ; //Previous player is not done loading.
  7111. //Or he has quit, but is not done saving on the charserver.
  7112. else if (old_sd->fd)
  7113. clif_authfail_fd(old_sd->fd, 2); // same id
  7114. else
  7115. map_quit(old_sd);
  7116. clif_authfail_fd(fd, 8); // still recognizes last connection
  7117. return;
  7118. }
  7119. }
  7120. CREATE(sd, TBL_PC, 1);
  7121. sd->fd = fd;
  7122. sd->packet_ver = packet_ver;
  7123. session[fd]->session_data = sd;
  7124. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7125. WFIFOHEAD(fd,4);
  7126. WFIFOL(fd,0) = sd->bl.id;
  7127. WFIFOSET(fd,4);
  7128. chrif_authreq(sd);
  7129. return;
  7130. }
  7131. static int clif_nighttimer(int tid, unsigned int tick, int id, int data)
  7132. {
  7133. TBL_PC *sd;
  7134. sd=map_id2sd(id);
  7135. if (!sd) return 0;
  7136. //Check if character didn't instant-warped after logging in.
  7137. if (sd->bl.prev!=NULL) {
  7138. sd->state.night = 1;
  7139. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7140. }
  7141. return 0;
  7142. }
  7143. /*==========================================
  7144. * 007d クライアント側マップ読み込み完了
  7145. * map侵入時に必要なデータを全て送りつける
  7146. *------------------------------------------
  7147. */
  7148. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7149. {
  7150. if(sd->bl.prev != NULL)
  7151. return;
  7152. if (!sd->state.auth)
  7153. { //Character loading is not complete yet!
  7154. //Let pc_reg_received reinvoke this when ready.
  7155. sd->state.connect_new = 0;
  7156. return;
  7157. }
  7158. if (sd->state.rewarp)
  7159. { //Rewarp player.
  7160. sd->state.rewarp = 0;
  7161. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7162. return;
  7163. }
  7164. // look
  7165. #if PACKETVER < 4
  7166. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7167. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7168. #else
  7169. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7170. #endif
  7171. if(sd->vd.cloth_color)
  7172. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7173. // item
  7174. pc_checkitem(sd);
  7175. clif_inventorylist(sd);
  7176. // cart
  7177. if(pc_iscarton(sd)){
  7178. clif_cartlist(sd);
  7179. clif_updatestatus(sd,SP_CARTINFO);
  7180. }
  7181. // weight max , now
  7182. clif_updatestatus(sd,SP_MAXWEIGHT);
  7183. clif_updatestatus(sd,SP_WEIGHT);
  7184. if(battle_config.pc_invincible_time > 0) {
  7185. if(map_flag_gvg(sd->bl.m))
  7186. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7187. else
  7188. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7189. }
  7190. map_addblock(&sd->bl); // ブロック登録
  7191. clif_spawn(&sd->bl); // spawn
  7192. // Party
  7193. if(sd->status.party_id) {
  7194. party_send_movemap(sd);
  7195. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7196. }
  7197. // guild
  7198. if(sd->status.guild_id)
  7199. guild_send_memberinfoshort(sd,1);
  7200. if(map[sd->bl.m].flag.pvp){
  7201. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7202. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7203. sd->pvp_timer= add_timer(gettick()+200,
  7204. pc_calc_pvprank_timer,sd->bl.id,0);
  7205. sd->pvp_rank=0;
  7206. sd->pvp_lastusers=0;
  7207. sd->pvp_point=5;
  7208. sd->pvp_won=0;
  7209. sd->pvp_lost=0;
  7210. }
  7211. clif_set0199(fd,1);
  7212. } else
  7213. // set flag, if it's a duel [LuzZza]
  7214. if(sd->duel_group)
  7215. clif_set0199(fd, 1);
  7216. if (map[sd->bl.m].flag.gvg_dungeon)
  7217. {
  7218. clif_set0199(fd,2); //TODO: Figure out the real thing to do here.
  7219. if (!sd->pvp_point)
  7220. sd->pvp_point=5; //Need to die twice to be warped out.
  7221. }
  7222. if(map_flag_gvg(sd->bl.m))
  7223. clif_set0199(fd,3);
  7224. // pet
  7225. if(sd->pd) {
  7226. map_addblock(&sd->pd->bl);
  7227. clif_spawn(&sd->pd->bl);
  7228. clif_send_petdata(sd,0,0);
  7229. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7230. clif_send_petstatus(sd);
  7231. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7232. }
  7233. //homunculus [blackhole89]
  7234. if(merc_is_hom_active(sd->hd)) {
  7235. map_addblock(&sd->hd->bl);
  7236. clif_spawn(&sd->hd->bl);
  7237. clif_hominfo(sd,sd->hd,1);
  7238. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7239. clif_send_homdata(sd,0,0);
  7240. clif_homskillinfoblock(sd);
  7241. //Homunc mimic their master's speed on each map change. [Skotlex]
  7242. if (battle_config.hom_setting&0x8)
  7243. status_calc_bl(&sd->hd->bl, SCB_SPEED);
  7244. // Since hom is inmune to land effects, unneeded.
  7245. // skill_unit_move(&sd->hd->bl,gettick(),1);
  7246. }
  7247. if(sd->state.connect_new) {
  7248. int lv;
  7249. sd->state.connect_new = 0;
  7250. clif_skillinfoblock(sd);
  7251. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7252. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7253. clif_updatestatus(sd,SP_SKILLPOINT);
  7254. clif_initialstatus(sd);
  7255. if (sd->sc.option&OPTION_FALCON)
  7256. clif_status_load(&sd->bl, SI_FALCON, 1);
  7257. if (sd->sc.option&OPTION_RIDING)
  7258. clif_status_load(&sd->bl, SI_RIDING, 1);
  7259. if(sd->status.manner < 0)
  7260. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7261. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7262. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7263. if(sd->bl.m == sd->feel_map[0].m
  7264. || sd->bl.m == sd->feel_map[1].m
  7265. || sd->bl.m == sd->feel_map[2].m)
  7266. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7267. }
  7268. if(sd->pd && sd->pd->pet.intimate > 900)
  7269. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7270. if(merc_is_hom_active(sd->hd))
  7271. merc_hom_init_timers(sd->hd);
  7272. //Delayed night effect on log-on fix for the glow-issue. Thanks to Larry.
  7273. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7274. add_timer(gettick()+1000,clif_nighttimer,sd->bl.id,0);
  7275. // Notify everyone that this char logged in [Skotlex].
  7276. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7277. //Login Event
  7278. npc_script_event(sd, NPCE_LOGIN);
  7279. } else {
  7280. //For some reason the client "loses" these on map-change.
  7281. clif_updatestatus(sd,SP_STR);
  7282. clif_updatestatus(sd,SP_AGI);
  7283. clif_updatestatus(sd,SP_VIT);
  7284. clif_updatestatus(sd,SP_INT);
  7285. clif_updatestatus(sd,SP_DEX);
  7286. clif_updatestatus(sd,SP_LUK);
  7287. sd->state.using_fake_npc = 0;
  7288. //New 'night' effect by dynamix [Skotlex]
  7289. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7290. { //Display night.
  7291. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  7292. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7293. else
  7294. sd->state.night = 1;
  7295. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7296. } else if (sd->state.night) { //Clear night display.
  7297. sd->state.night = 0;
  7298. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7299. }
  7300. if(sd->npc_id)
  7301. npc_event_dequeue(sd);
  7302. }
  7303. // Lance
  7304. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  7305. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  7306. npc_script_event(sd, NPCE_LOADMAP);
  7307. }
  7308. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7309. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7310. clif_weather_check(sd);
  7311. map_foreachinarea(clif_getareachar,sd->bl.m,
  7312. sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,
  7313. BL_ALL,sd);
  7314. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7315. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7316. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7317. else
  7318. sd->areanpc_id = 0;
  7319. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7320. if(pc_isdead(sd))
  7321. clif_clearchar_area(&sd->bl,1);
  7322. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7323. // else
  7324. // clif_changed_dir(&sd->bl, SELF);
  7325. // Trigger skill effects if you appear standing on them
  7326. if(!battle_config.pc_invincible_time)
  7327. skill_unit_move(&sd->bl,gettick(),1);
  7328. }
  7329. /*==========================================
  7330. *
  7331. *------------------------------------------
  7332. */
  7333. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7334. RFIFOHEAD(fd);
  7335. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7336. WFIFOHEAD(fd, packet_len(0x7f));
  7337. WFIFOW(fd,0)=0x7f;
  7338. WFIFOL(fd,2)=gettick();
  7339. WFIFOSET(fd,packet_len(0x7f));
  7340. // removed until the socket problems are fixed. [FlavioJS]
  7341. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7342. return;
  7343. }
  7344. static int clif_walktoxy_timer(int tid, unsigned int tick, int id, int data)
  7345. {
  7346. struct map_session_data *sd;
  7347. short x,y;
  7348. if (!session[id] || (sd = session[id]->session_data) == NULL)
  7349. return 0;
  7350. if (!unit_can_move(&sd->bl))
  7351. return 0;
  7352. x = data>>16;
  7353. y = data&0xffff;
  7354. unit_walktoxy(&sd->bl, x, y, 0);
  7355. return 1;
  7356. }
  7357. /*==========================================
  7358. *
  7359. *------------------------------------------
  7360. */
  7361. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7362. int x, y;
  7363. int cmd;
  7364. unsigned int tick;
  7365. RFIFOHEAD(fd);
  7366. if (pc_isdead(sd)) {
  7367. clif_clearchar_area(&sd->bl, 1);
  7368. return;
  7369. }
  7370. if (clif_cant_act(sd) && sd->sc.opt1 != OPT1_STONEWAIT)
  7371. return;
  7372. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7373. return;
  7374. pc_stop_attack(sd);
  7375. if (sd->invincible_timer != -1)
  7376. pc_delinvincibletimer(sd);
  7377. cmd = RFIFOW(fd,0);
  7378. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7379. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7380. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7381. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7382. //Set last idle time... [Skotlex]
  7383. sd->idletime = last_tick;
  7384. tick = gettick();
  7385. if (DIFF_TICK(sd->ud.canmove_tick, tick) > 0 &&
  7386. DIFF_TICK(sd->ud.canmove_tick, tick) < 2000)
  7387. { // Delay walking command. [Skotlex]
  7388. add_timer(sd->ud.canmove_tick+1, clif_walktoxy_timer, fd, (x<<16)|y);
  7389. return;
  7390. }
  7391. if (!unit_can_move(&sd->bl))
  7392. return;
  7393. unit_walktoxy(&sd->bl, x, y, 0);
  7394. }
  7395. /*==========================================
  7396. *
  7397. *------------------------------------------
  7398. */
  7399. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7400. WFIFOHEAD(fd,packet_len(0x18b));
  7401. WFIFOW(fd,0) = 0x18b;
  7402. /* Rovert's prevent logout option fixed [Valaris] */
  7403. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7404. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7405. ) {
  7406. clif_setwaitclose(fd);
  7407. WFIFOW(fd,2)=0;
  7408. } else {
  7409. WFIFOW(fd,2)=1;
  7410. }
  7411. WFIFOSET(fd,packet_len(0x18b));
  7412. }
  7413. /*==========================================
  7414. *
  7415. *------------------------------------------
  7416. */
  7417. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7418. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7419. /* if (target_id == server_char_id) {
  7420. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7421. sprintf(message_to_gm, msg_txt(536), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake player).
  7422. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7423. // if we block people
  7424. if (battle_config.ban_bot < 0) {
  7425. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7426. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7427. // message about the ban
  7428. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7429. // if we ban people
  7430. } else if (battle_config.ban_bot > 0) {
  7431. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7432. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7433. // message about the ban
  7434. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7435. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7436. // message about the ban
  7437. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7438. }
  7439. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7440. // send this info cause the bot ask until get an answer, damn spam
  7441. memset(WPACKETP(0), 0, packet_len(0x95));
  7442. WPACKETW(0) = 0x95;
  7443. WPACKETL(2) = server_char_id;
  7444. strncpy(WPACKETP(6), sd->status.name, 24);
  7445. SENDPACKET(fd, packet_len(0x95));
  7446. // take fake player out of screen
  7447. WPACKETW(0) = 0x80;
  7448. WPACKETL(2) = server_char_id;
  7449. WPACKETB(6) = 0;
  7450. SENDPACKET(fd, packet_len(0x80));
  7451. // take fake mob out of screen
  7452. WPACKETW(0) = 0x80;
  7453. WPACKETL(2) = server_fake_mob_id;
  7454. WPACKETB(6) = 0;
  7455. SENDPACKET(fd, packet_len(0x80));
  7456. }
  7457. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7458. if (target_id == server_fake_mob_id) {
  7459. int fake_mob;
  7460. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7461. sprintf(message_to_gm, msg_txt(537), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake mob).
  7462. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7463. // if we block people
  7464. if (battle_config.ban_bot < 0) {
  7465. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7466. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7467. // message about the ban
  7468. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7469. // if we ban people
  7470. } else if (battle_config.ban_bot > 0) {
  7471. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7472. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7473. // message about the ban
  7474. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7475. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7476. // message about the ban
  7477. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7478. }
  7479. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7480. // send this info cause the bot ask until get an answer, damn spam
  7481. memset(WPACKETP(0), 0, packet_len(0x95));
  7482. WPACKETW(0) = 0x95;
  7483. WPACKETL(2) = server_fake_mob_id;
  7484. fake_mob = fake_mob_list[(sd->bl.m + sd->fd + sd->status.char_id) % (sizeof(fake_mob_list) / sizeof(fake_mob_list[0]))]; // never same mob
  7485. if (!mobdb_checkid(fake_mob))
  7486. fake_mob = 1002; // poring (default)
  7487. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7488. SENDPACKET(fd, packet_len(0x95));
  7489. // take fake mob out of screen
  7490. WPACKETW(0) = 0x80;
  7491. WPACKETL(2) = server_fake_mob_id;
  7492. WPACKETB(6) = 0;
  7493. SENDPACKET(fd, packet_len(0x80));
  7494. // take fake player out of screen
  7495. WPACKETW(0) = 0x80;
  7496. WPACKETL(2) = server_char_id;
  7497. WPACKETB(6) = 0;
  7498. SENDPACKET(fd, packet_len(0x80));
  7499. }
  7500. */
  7501. return;
  7502. }
  7503. /*==========================================
  7504. *
  7505. *------------------------------------------
  7506. */
  7507. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7508. int account_id;
  7509. struct block_list* bl;
  7510. struct status_change *sc;
  7511. RFIFOHEAD(fd);
  7512. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7513. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7514. account_id= sd->bl.id;
  7515. bl = map_id2bl(account_id);
  7516. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7517. if (!bl) return;
  7518. sc = status_get_sc(bl);
  7519. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) && pc_isGM(sd) < battle_config.hack_info_GM_level)
  7520. {
  7521. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7522. //Asked name of invisible player, this shouldn't be possible!
  7523. //Possible bot? Thanks to veider and qspirit
  7524. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7525. unsigned char gm_msg[256];
  7526. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requests name of invisible chars.", sd->status.name, sd->status.account_id);
  7527. ShowWarning(gm_msg);
  7528. // information is sended to all online GM
  7529. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7530. return;
  7531. }
  7532. clif_charnameack(fd, bl);
  7533. }
  7534. /*==========================================
  7535. *
  7536. *------------------------------------------
  7537. */
  7538. void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
  7539. char *message, *buf, buf2[128];
  7540. RFIFOHEAD(fd);
  7541. WFIFOHEAD(fd, RFIFOW(fd,2) + 4);
  7542. message = (unsigned char*)RFIFOP(fd,4);
  7543. if (strlen(message) < strlen(sd->status.name) || //If the incoming string is too short...
  7544. strncmp(message, sd->status.name, strlen(sd->status.name)) != 0) //Or the name does not matches...
  7545. {
  7546. //Hacked message, or infamous "client desynch" issue where they pick
  7547. //one char while loading another. Just kick them out to correct it.
  7548. clif_setwaitclose(fd);
  7549. return;
  7550. }
  7551. if ((is_atcommand(fd, sd, message) != AtCommand_None) ||
  7552. (is_charcommand(fd, sd, message) != CharCommand_None))
  7553. return;
  7554. if (sd->sc.count &&
  7555. (sd->sc.data[SC_BERSERK].timer != -1 ||
  7556. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)))
  7557. return;
  7558. if (battle_config.min_chat_delay)
  7559. { //[Skotlex]
  7560. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7561. return;
  7562. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7563. }
  7564. if (RFIFOW(fd,2)+4 < 128)
  7565. buf = buf2; //Use a static buffer.
  7566. else
  7567. buf = (unsigned char*)aMallocA((RFIFOW(fd,2) + 4)*sizeof(char));
  7568. // send message to others
  7569. WBUFW(buf,0) = 0x8d;
  7570. WBUFW(buf,2) = RFIFOW(fd,2) + 4; // len of message - 4 + 8
  7571. WBUFL(buf,4) = sd->bl.id;
  7572. memcpy(WBUFP(buf,8), message, RFIFOW(fd,2) - 4);
  7573. clif_send(buf, WBUFW(buf,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7574. if(buf != buf2) aFree(buf);
  7575. // send back message to the speaker
  7576. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7577. WFIFOW(fd,0) = 0x8e;
  7578. WFIFOSET(fd, WFIFOW(fd,2));
  7579. #ifdef PCRE_SUPPORT
  7580. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7581. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7582. #endif
  7583. // Celest
  7584. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7585. int next = pc_nextbaseexp(sd);
  7586. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7587. switch (sd->state.snovice_flag) {
  7588. case 0:
  7589. if (strstr(message, msg_txt(504)))
  7590. sd->state.snovice_flag++;
  7591. break;
  7592. case 1:
  7593. sprintf(buf2, msg_txt(505), sd->status.name);
  7594. if (strstr(message, buf2))
  7595. sd->state.snovice_flag++;
  7596. break;
  7597. case 2:
  7598. if (strstr(message, msg_txt(506)))
  7599. sd->state.snovice_flag++;
  7600. break;
  7601. case 3:
  7602. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7603. break; //Do not override the noskill mapflag. [Skotlex]
  7604. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7605. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7606. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7607. sd->state.snovice_flag = 0;
  7608. break;
  7609. }
  7610. }
  7611. }
  7612. return;
  7613. }
  7614. int clif_message(struct block_list *bl, char* msg)
  7615. {
  7616. unsigned short msg_len = strlen(msg) + 1;
  7617. unsigned char buf[256];
  7618. nullpo_retr(0, bl);
  7619. WBUFW(buf, 0) = 0x8d;
  7620. WBUFW(buf, 2) = msg_len + 8;
  7621. WBUFL(buf, 4) = bl->id;
  7622. memcpy(WBUFP(buf, 8), msg, msg_len);
  7623. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7624. return 0;
  7625. }
  7626. /*==========================================
  7627. *
  7628. *------------------------------------------
  7629. */
  7630. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7631. // /m /mapmove (as @rura GM command)
  7632. char output[30]; // 17+4+4=26, 30 max.
  7633. char message[34]; // "/mm "+output
  7634. char map_name[MAP_NAME_LENGTH]; //Err... map names are 15+'\0' in size, not 16+'\0' [Skotlex]
  7635. RFIFOHEAD(fd);
  7636. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7637. (pc_isGM(sd) >= get_atcommand_level(AtCommand_MapMove))) {
  7638. memcpy(map_name, RFIFOP(fd,2), MAP_NAME_LENGTH-1);
  7639. map_name[MAP_NAME_LENGTH-1]='\0';
  7640. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7641. atcommand_rura(fd, sd, "@rura", output);
  7642. if((log_config.gm) && (get_atcommand_level(AtCommand_MapMove) >= log_config.gm)) {
  7643. sprintf(message, "/mm %s", output);
  7644. log_atcommand(sd, message);
  7645. }
  7646. }
  7647. return;
  7648. }
  7649. /*==========================================
  7650. *
  7651. *------------------------------------------
  7652. */
  7653. void clif_changed_dir(struct block_list *bl, int type) {
  7654. unsigned char buf[64];
  7655. WBUFW(buf,0) = 0x9c;
  7656. WBUFL(buf,2) = bl->id;
  7657. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7658. WBUFB(buf,8) = unit_getdir(bl);
  7659. clif_send(buf, packet_len(0x9c), bl, type);
  7660. if (disguised(bl)) {
  7661. WBUFL(buf,2) = -bl->id;
  7662. WBUFW(buf,6) = 0;
  7663. clif_send(buf, packet_len(0x9c), bl, SELF);
  7664. }
  7665. return;
  7666. }
  7667. /*==========================================
  7668. *
  7669. *------------------------------------------
  7670. */
  7671. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7672. unsigned char headdir, dir;
  7673. RFIFOHEAD(fd);
  7674. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7675. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7676. pc_setdir(sd, dir, headdir);
  7677. clif_changed_dir(&sd->bl, AREA_WOS);
  7678. return;
  7679. }
  7680. /*==========================================
  7681. *
  7682. *------------------------------------------
  7683. */
  7684. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7685. unsigned char buf[64];
  7686. RFIFOHEAD(fd);
  7687. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7688. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7689. clif_skill_fail(sd, 1, 0, 1);
  7690. return;
  7691. }
  7692. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7693. if (sd->emotionlasttime >= time(NULL)) {
  7694. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7695. clif_skill_fail(sd, 1, 0, 1);
  7696. return;
  7697. }
  7698. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7699. WBUFW(buf,0) = 0xc0;
  7700. WBUFL(buf,2) = sd->bl.id;
  7701. WBUFB(buf,6) = RFIFOB(fd,2);
  7702. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7703. } else
  7704. clif_skill_fail(sd, 1, 0, 1);
  7705. }
  7706. /*==========================================
  7707. *
  7708. *------------------------------------------
  7709. */
  7710. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7711. WFIFOHEAD(fd,packet_len(0xc2));
  7712. WFIFOW(fd,0) = 0xc2;
  7713. WFIFOL(fd,2) = map_getusers();
  7714. WFIFOSET(fd,packet_len(0xc2));
  7715. }
  7716. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7717. {
  7718. unsigned char buf[64];
  7719. if (pc_isdead(sd)) {
  7720. clif_clearchar_area(&sd->bl, 1);
  7721. return;
  7722. }
  7723. if (sd->sc.count &&
  7724. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7725. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7726. sd->sc.data[SC_BLADESTOP].timer != -1))
  7727. return;
  7728. pc_stop_walking(sd, 1);
  7729. pc_stop_attack(sd);
  7730. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7731. target_id = sd->bl.id;
  7732. switch(action_type) {
  7733. case 0x00: // once attack
  7734. case 0x07: // continuous attack
  7735. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7736. return;
  7737. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  7738. return;
  7739. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7740. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7741. clif_skill_fail(sd, 1, 4, 0);
  7742. return;
  7743. }
  7744. }
  7745. if (sd->invincible_timer != -1)
  7746. pc_delinvincibletimer(sd);
  7747. sd->idletime = last_tick;
  7748. unit_attack(&sd->bl, target_id, action_type != 0);
  7749. break;
  7750. case 0x02: // sitdown
  7751. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7752. clif_skill_fail(sd, 1, 0, 2);
  7753. break;
  7754. }
  7755. if(pc_issit(sd)) {
  7756. //Bugged client? Just refresh them.
  7757. WBUFW(buf, 0) = 0x8a;
  7758. WBUFL(buf, 2) = sd->bl.id;
  7759. WBUFB(buf,26) = 2;
  7760. clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
  7761. return;
  7762. }
  7763. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7764. break;
  7765. if (sd->sc.count && (
  7766. sd->sc.data[SC_DANCING].timer != -1 ||
  7767. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7768. )) //No sitting during these states neither.
  7769. break;
  7770. pc_setsit(sd);
  7771. skill_sit(sd, 1);
  7772. clif_sitting(sd);
  7773. break;
  7774. case 0x03: // standup
  7775. if (!pc_issit(sd)) {
  7776. //Bugged client? Just refresh them.
  7777. WBUFW(buf, 0) = 0x8a;
  7778. WBUFL(buf, 2) = sd->bl.id;
  7779. WBUFB(buf,26) = 3;
  7780. clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
  7781. return;
  7782. }
  7783. pc_setstand(sd);
  7784. skill_sit(sd, 0);
  7785. WBUFW(buf, 0) = 0x8a;
  7786. WBUFL(buf, 2) = sd->bl.id;
  7787. WBUFB(buf,26) = 3;
  7788. clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
  7789. break;
  7790. }
  7791. }
  7792. /*==========================================
  7793. *
  7794. *------------------------------------------
  7795. */
  7796. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  7797. RFIFOHEAD(fd);
  7798. clif_parse_ActionRequest_sub(sd,
  7799. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7800. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7801. gettick()
  7802. );
  7803. }
  7804. /*==========================================
  7805. *
  7806. *------------------------------------------
  7807. */
  7808. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  7809. RFIFOHEAD(fd);
  7810. switch(RFIFOB(fd,2)) {
  7811. case 0x00:
  7812. if (pc_isdead(sd)) {
  7813. pc_setstand(sd);
  7814. pc_setrestartvalue(sd, 3);
  7815. if (sd->sc.count && battle_config.debuff_on_logout&2) {
  7816. //For some reason food buffs are removed when you respawn.
  7817. if(sd->sc.data[SC_STRFOOD].timer!=-1)
  7818. status_change_end(&sd->bl,SC_STRFOOD,-1);
  7819. if(sd->sc.data[SC_AGIFOOD].timer!=-1)
  7820. status_change_end(&sd->bl,SC_AGIFOOD,-1);
  7821. if(sd->sc.data[SC_VITFOOD].timer!=-1)
  7822. status_change_end(&sd->bl,SC_VITFOOD,-1);
  7823. if(sd->sc.data[SC_INTFOOD].timer!=-1)
  7824. status_change_end(&sd->bl,SC_INTFOOD,-1);
  7825. if(sd->sc.data[SC_DEXFOOD].timer!=-1)
  7826. status_change_end(&sd->bl,SC_DEXFOOD,-1);
  7827. if(sd->sc.data[SC_LUKFOOD].timer!=-1)
  7828. status_change_end(&sd->bl,SC_LUKFOOD,-1);
  7829. if(sd->sc.data[SC_HITFOOD].timer!=-1)
  7830. status_change_end(&sd->bl,SC_HITFOOD,-1);
  7831. if(sd->sc.data[SC_FLEEFOOD].timer!=-1)
  7832. status_change_end(&sd->bl,SC_FLEEFOOD,-1);
  7833. if(sd->sc.data[SC_BATKFOOD].timer!=-1)
  7834. status_change_end(&sd->bl,SC_BATKFOOD,-1);
  7835. if(sd->sc.data[SC_WATKFOOD].timer!=-1)
  7836. status_change_end(&sd->bl,SC_WATKFOOD,-1);
  7837. if(sd->sc.data[SC_MATKFOOD].timer!=-1)
  7838. status_change_end(&sd->bl,SC_MATKFOOD,-1);
  7839. }
  7840. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  7841. }
  7842. // in case the player's status somehow wasn't updated yet [Celest]
  7843. else if (sd->battle_status.hp <= 0)
  7844. pc_setdead(sd);
  7845. break;
  7846. case 0x01:
  7847. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7848. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7849. { //Send to char-server for character selection.
  7850. chrif_charselectreq(sd, session[fd]->client_addr.sin_addr.s_addr);
  7851. } else {
  7852. WFIFOHEAD(fd,packet_len(0x18b));
  7853. WFIFOW(fd,0)=0x18b;
  7854. WFIFOW(fd,2)=1;
  7855. WFIFOSET(fd,packet_len(0x018b));
  7856. }
  7857. break;
  7858. }
  7859. }
  7860. /*==========================================
  7861. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7862. *------------------------------------------
  7863. */
  7864. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  7865. char *command, *msg;
  7866. struct map_session_data *dstsd;
  7867. int i=0;
  7868. struct npc_data *npc;
  7869. char split_data[10][50];
  7870. char target[NAME_LENGTH+1];
  7871. char output[256];
  7872. unsigned int len;
  7873. RFIFOHEAD(fd);
  7874. len = RFIFOW(fd,2); //Packet length
  7875. if (len < 28)
  7876. { //Invalid packet, specified size is less than minimum! [Skotlex]
  7877. ShowWarning("Hack on Whisper: %s (AID/CID: %d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  7878. clif_setwaitclose(fd);
  7879. return;
  7880. }
  7881. if (len == 28) return; //Not sure if client really lets you send a blank line.
  7882. len-=28; //Message length
  7883. // 24+3+(RFIFOW(fd,2)-28)+1 <- last 1 is '\0'
  7884. command = (char*)aMallocA((NAME_LENGTH+4+len) * sizeof(char));
  7885. //No need for out of memory checks, malloc.c aborts the map when that happens.
  7886. msg = command;
  7887. msg+= sprintf(command, "%s : ", sd->status.name);
  7888. memcpy(msg, RFIFOP(fd, 28), len);
  7889. msg[len]='\0'; //Force a terminator
  7890. if ((is_charcommand(fd, sd, command) != CharCommand_None) ||
  7891. (is_atcommand(fd, sd, command) != AtCommand_None)) {
  7892. aFree(command);
  7893. return;
  7894. }
  7895. if (sd->sc.count &&
  7896. (sd->sc.data[SC_BERSERK].timer!=-1 ||
  7897. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))) {
  7898. aFree(command);
  7899. return;
  7900. }
  7901. if (battle_config.min_chat_delay)
  7902. { //[Skotlex]
  7903. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7904. aFree(command);
  7905. return;
  7906. }
  7907. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7908. }
  7909. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7910. target[NAME_LENGTH]='\0';
  7911. //Chat Logging type 'W' / Whisper
  7912. if(log_config.chat&1 //we log everything then
  7913. || ( log_config.chat&2 //if Whisper bit is on
  7914. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  7915. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, msg);
  7916. //-------------------------------------------------------//
  7917. // Lordalfa - Paperboy - To whisper NPC commands //
  7918. //-------------------------------------------------------//
  7919. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7920. char *str= target+4; //Skip the NPC: string part.
  7921. if ((npc = npc_name2id(str)))
  7922. {
  7923. char *split;
  7924. str = msg;
  7925. for( i=0; i < 10; ++i )
  7926. {// Splits the message using '#' as separators
  7927. split = strchr(str,'#');
  7928. if( split == NULL )
  7929. { // use the remaining string
  7930. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7931. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7932. for( ++i; i < 10; ++i )
  7933. split_data[i][0] = '\0';
  7934. break;
  7935. }
  7936. *split = '\0';
  7937. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7938. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7939. str = split+1;
  7940. }
  7941. for (i=0;i<10;i++)
  7942. {
  7943. sprintf(output, "@whispervar%d$", i);
  7944. set_var(sd,output,(char *) split_data[i]);
  7945. }
  7946. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7947. npc_event(sd,output,0); // Calls the NPC label
  7948. aFree(command);
  7949. return;
  7950. }
  7951. }
  7952. // Main chat [LuzZza]
  7953. if(strcmpi(target, main_chat_nick) == 0) {
  7954. if(!sd->state.mainchat)
  7955. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7956. else {
  7957. snprintf(output, sizeof(output)/sizeof(char), msg_txt(386), sd->status.name, msg);
  7958. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7959. }
  7960. aFree(command);
  7961. return;
  7962. }
  7963. // searching destination character
  7964. dstsd = map_nick2sd(target);
  7965. // player is not on this map-server
  7966. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7967. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7968. // and if we ask for 'Test', we must not contact 'test' player
  7969. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7970. if (dstsd == NULL ||
  7971. strcmp(dstsd->status.name, target) != 0)
  7972. { // send message to inter-server
  7973. intif_wis_message(sd, target, msg, len);
  7974. aFree(command);
  7975. return;
  7976. }
  7977. // player is on this map-server
  7978. if (dstsd->fd == fd) {
  7979. // if you send to your self, don't send anything to others
  7980. // but, normaly, it's impossible!
  7981. clif_wis_message(fd, wisp_server_name,
  7982. "You can not page yourself. Sorry.",
  7983. strlen("You can not page yourself. Sorry.") + 1);
  7984. aFree(command);
  7985. return;
  7986. }
  7987. // otherwise, send message and answer immediatly
  7988. if (dstsd->state.ignoreAll) {
  7989. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7990. clif_wis_end(fd, 1); // 1: target character is not loged in
  7991. else
  7992. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7993. aFree(command);
  7994. return;
  7995. }
  7996. // if player ignore the source character
  7997. for(i = 0; i < MAX_IGNORE_LIST &&
  7998. dstsd->ignore[i].name[0] != '\0' &&
  7999. strcmp(dstsd->ignore[i].name, sd->status.name) != 0
  8000. ; i++);
  8001. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8002. { //Ignored
  8003. clif_wis_end(fd, 2); // 2: ignored by target
  8004. aFree(command);
  8005. return;
  8006. }
  8007. // if source player not found in ignore list
  8008. if(dstsd->away_message[0] != '\0') { // Send away automessage [LuzZza]
  8009. //(Automessage has been sent)
  8010. sprintf(output, "%s %s", msg, msg_txt(543));
  8011. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  8012. clif_wis_end(fd, 0); // 0: success to send wisper
  8013. if(dstsd->state.autotrade)
  8014. //"Away [AT] - \"%s\""
  8015. sprintf(output, msg_txt(544), dstsd->away_message);
  8016. else
  8017. //"Away - \"%s\""
  8018. sprintf(output, msg_txt(545), dstsd->away_message);
  8019. aFree(command);
  8020. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  8021. return;
  8022. }
  8023. // Normal message
  8024. clif_wis_message(dstsd->fd, sd->status.name, msg, len);
  8025. clif_wis_end(fd, 0); // 0: success to send wisper
  8026. aFree(command);
  8027. return;
  8028. }
  8029. /*==========================================
  8030. *
  8031. *------------------------------------------
  8032. */
  8033. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  8034. // /b
  8035. char message[MESSAGE_SIZE];
  8036. RFIFOHEAD(fd);
  8037. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8038. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast))) {
  8039. intif_GMmessage((char*)RFIFOP(fd,4), RFIFOW(fd,2)-4, 0);
  8040. if((log_config.gm) && (get_atcommand_level(AtCommand_Broadcast) >= log_config.gm)) {
  8041. snprintf(message, RFIFOW(fd,2)-1, "/b %s", RFIFOP(fd,4));
  8042. log_atcommand(sd, message);
  8043. }
  8044. }
  8045. }
  8046. /*==========================================
  8047. *
  8048. *------------------------------------------
  8049. */
  8050. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  8051. struct flooritem_data *fitem;
  8052. int map_object_id;
  8053. RFIFOHEAD(fd);
  8054. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8055. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8056. do {
  8057. if (pc_isdead(sd)) {
  8058. clif_clearchar_area(&sd->bl, 1);
  8059. break;
  8060. }
  8061. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8062. break;
  8063. if (clif_cant_act(sd))
  8064. break;
  8065. //Disable cloaking/chasewalking characters from looting [Skotlex]
  8066. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  8067. break;
  8068. if(sd->sc.count && (
  8069. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  8070. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  8071. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  8072. )
  8073. break;
  8074. if (!pc_takeitem(sd, fitem))
  8075. break;
  8076. return;
  8077. } while (0);
  8078. // Client REQUIRES a fail packet or you can no longer pick items.
  8079. clif_additem(sd,0,0,6);
  8080. }
  8081. /*==========================================
  8082. *
  8083. *------------------------------------------
  8084. */
  8085. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  8086. int item_index, item_amount;
  8087. RFIFOHEAD(fd);
  8088. if (pc_isdead(sd)) {
  8089. clif_clearchar_area(&sd->bl, 1);
  8090. return;
  8091. }
  8092. if (clif_cant_act(sd))
  8093. return;
  8094. if (sd->sc.count && (
  8095. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  8096. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  8097. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  8098. ))
  8099. return;
  8100. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8101. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8102. if (!pc_dropitem(sd, item_index, item_amount))
  8103. //Because the client does not likes being ignored.
  8104. clif_delitem(sd, item_index,0);
  8105. }
  8106. /*==========================================
  8107. *
  8108. *------------------------------------------
  8109. */
  8110. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  8111. int n;
  8112. RFIFOHEAD(fd);
  8113. if (pc_isdead(sd)) {
  8114. clif_clearchar_area(&sd->bl, 1);
  8115. return;
  8116. }
  8117. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8118. return;
  8119. //This flag enables you to use items while in an NPC. [Skotlex]
  8120. if (sd->npc_id) {
  8121. if (sd->npc_id != sd->npc_item_flag)
  8122. return;
  8123. } else
  8124. if (clif_trading(sd))
  8125. return;
  8126. if (sd->invincible_timer != -1)
  8127. pc_delinvincibletimer(sd);
  8128. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8129. sd->idletime = last_tick;
  8130. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8131. if(n <0 || n >= MAX_INVENTORY)
  8132. return;
  8133. if (!pc_useitem(sd,n))
  8134. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8135. }
  8136. /*==========================================
  8137. *
  8138. *------------------------------------------
  8139. */
  8140. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8141. {
  8142. int index;
  8143. RFIFOHEAD(fd);
  8144. if(pc_isdead(sd)) {
  8145. clif_clearchar_area(&sd->bl,1);
  8146. return;
  8147. }
  8148. index = RFIFOW(fd,2)-2;
  8149. if (index < 0 || index >= MAX_INVENTORY)
  8150. return; //Out of bounds check.
  8151. if(sd->npc_id) {
  8152. if (sd->npc_id != sd->npc_item_flag)
  8153. return;
  8154. } else if (sd->state.storage_flag || sd->sc.opt1)
  8155. ; //You can equip/unequip stuff while storage is open/under status changes
  8156. else if (clif_cant_act(sd))
  8157. return;
  8158. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  8159. return;
  8160. if(!sd->status.inventory[index].identify) { // 未鑑定
  8161. clif_equipitemack(sd,index,0,0); // fail
  8162. return;
  8163. }
  8164. //ペット用装備であるかないか
  8165. if(sd->inventory_data[index]) {
  8166. if(sd->inventory_data[index]->type != IT_PETARMOR){
  8167. if(sd->inventory_data[index]->type == IT_AMMO)
  8168. pc_equipitem(sd,index,EQP_AMMO); //Client doesn't sends the position.
  8169. else
  8170. pc_equipitem(sd,index,RFIFOW(fd,4));
  8171. } else
  8172. pet_equipitem(sd,index);
  8173. }
  8174. }
  8175. /*==========================================
  8176. *
  8177. *------------------------------------------
  8178. */
  8179. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8180. {
  8181. int index;
  8182. RFIFOHEAD(fd);
  8183. if(pc_isdead(sd)) {
  8184. clif_clearchar_area(&sd->bl,1);
  8185. return;
  8186. }
  8187. if (sd->state.storage_flag)
  8188. ; //You can equip/unequip stuff while storage is open.
  8189. else if (clif_cant_act(sd))
  8190. return;
  8191. index = RFIFOW(fd,2)-2;
  8192. pc_unequipitem(sd,index,1);
  8193. }
  8194. /*==========================================
  8195. *
  8196. *------------------------------------------
  8197. */
  8198. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8199. {
  8200. struct block_list *bl;
  8201. RFIFOHEAD(fd);
  8202. if(pc_isdead(sd)) {
  8203. clif_clearchar_area(&sd->bl,1);
  8204. return;
  8205. }
  8206. if (clif_cant_act(sd))
  8207. return;
  8208. bl = map_id2bl(RFIFOL(fd,2));
  8209. if (!bl) return;
  8210. switch (bl->type) {
  8211. case BL_MOB:
  8212. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  8213. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8214. break;
  8215. case BL_PC:
  8216. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8217. break;
  8218. case BL_NPC:
  8219. npc_click(sd,(TBL_NPC*)bl);
  8220. break;
  8221. }
  8222. return;
  8223. }
  8224. /*==========================================
  8225. *
  8226. *------------------------------------------
  8227. */
  8228. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8229. {
  8230. RFIFOHEAD(fd);
  8231. if (sd->state.trading)
  8232. return;
  8233. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8234. }
  8235. /*==========================================
  8236. *
  8237. *------------------------------------------
  8238. */
  8239. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8240. {
  8241. int fail=0,n;
  8242. unsigned short *item_list;
  8243. RFIFOHEAD(fd);
  8244. n = (RFIFOW(fd,2)-4) /4;
  8245. item_list = (unsigned short*)RFIFOP(fd,4);
  8246. if (sd->state.trading|| !sd->npc_shopid)
  8247. fail = 1;
  8248. else
  8249. fail = npc_buylist(sd,n,item_list);
  8250. sd->npc_shopid = 0; //Clear shop data.
  8251. WFIFOHEAD(fd,packet_len(0xca));
  8252. WFIFOW(fd,0)=0xca;
  8253. WFIFOB(fd,2)=fail;
  8254. WFIFOSET(fd,packet_len(0xca));
  8255. }
  8256. /*==========================================
  8257. *
  8258. *------------------------------------------
  8259. */
  8260. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8261. {
  8262. int fail=0,n;
  8263. unsigned short *item_list;
  8264. RFIFOHEAD(fd);
  8265. n = (RFIFOW(fd,2)-4) /4;
  8266. item_list = (unsigned short*)RFIFOP(fd,4);
  8267. if (sd->state.trading || !sd->npc_shopid)
  8268. fail = 1;
  8269. else
  8270. fail = npc_selllist(sd,n,item_list);
  8271. sd->npc_shopid = 0; //Clear shop data.
  8272. WFIFOHEAD(fd,packet_len(0xcb));
  8273. WFIFOW(fd,0)=0xcb;
  8274. WFIFOB(fd,2)=fail;
  8275. WFIFOSET(fd,packet_len(0xcb));
  8276. }
  8277. /*==========================================
  8278. *
  8279. *------------------------------------------
  8280. */
  8281. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8282. {
  8283. RFIFOHEAD(fd);
  8284. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8285. return;
  8286. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8287. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8288. } else
  8289. clif_skill_fail(sd,1,0,3);
  8290. }
  8291. /*==========================================
  8292. *
  8293. *------------------------------------------
  8294. */
  8295. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8296. {
  8297. RFIFOHEAD(fd);
  8298. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8299. }
  8300. /*==========================================
  8301. *
  8302. *------------------------------------------
  8303. */
  8304. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8305. {
  8306. RFIFOHEAD(fd);
  8307. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8308. }
  8309. /*==========================================
  8310. *
  8311. *------------------------------------------
  8312. */
  8313. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8314. {
  8315. RFIFOHEAD(fd);
  8316. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8317. }
  8318. /*==========================================
  8319. *
  8320. *------------------------------------------
  8321. */
  8322. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8323. {
  8324. RFIFOHEAD(fd);
  8325. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8326. }
  8327. /*==========================================
  8328. *
  8329. *------------------------------------------
  8330. */
  8331. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8332. {
  8333. chat_leavechat(sd);
  8334. }
  8335. //Handles notifying asker and rejecter of what has just ocurred.
  8336. //Type is used to determine the correct msg_txt to use:
  8337. //0:
  8338. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8339. {
  8340. char *msg, output[256];
  8341. // Your request has been rejected by autoreject option.
  8342. msg = msg_txt(392);
  8343. clif_disp_onlyself(src, msg, strlen(msg));
  8344. //Notice that a request was rejected.
  8345. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8346. clif_disp_onlyself(target, output, strlen(output));
  8347. }
  8348. /*==========================================
  8349. * 取引要請を相手に送る
  8350. *------------------------------------------
  8351. */
  8352. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8353. {
  8354. struct map_session_data *t_sd;
  8355. RFIFOHEAD(fd);
  8356. t_sd = map_id2sd(RFIFOL(fd,2));
  8357. if(!sd->chatID && clif_cant_act(sd))
  8358. return; //You can trade while in a chatroom.
  8359. // @noask [LuzZza]
  8360. if(t_sd && t_sd->state.noask) {
  8361. clif_noask_sub(sd, t_sd, 0);
  8362. return;
  8363. }
  8364. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8365. trade_traderequest(sd,t_sd);
  8366. } else
  8367. clif_skill_fail(sd,1,0,0);
  8368. }
  8369. /*==========================================
  8370. * 取引要請
  8371. *------------------------------------------
  8372. */
  8373. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8374. {
  8375. RFIFOHEAD(fd);
  8376. trade_tradeack(sd,RFIFOB(fd,2));
  8377. }
  8378. /*==========================================
  8379. * アイテム追加
  8380. *------------------------------------------
  8381. */
  8382. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8383. {
  8384. RFIFOHEAD(fd);
  8385. trade_tradeadditem(sd,RFIFOW(fd,2),RFIFOL(fd,4));
  8386. }
  8387. /*==========================================
  8388. * アイテム追加完了(ok押し)
  8389. *------------------------------------------
  8390. */
  8391. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8392. {
  8393. trade_tradeok(sd);
  8394. }
  8395. /*==========================================
  8396. * 取引キャンセル
  8397. *------------------------------------------
  8398. */
  8399. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8400. {
  8401. trade_tradecancel(sd);
  8402. }
  8403. /*==========================================
  8404. * 取引許諾(trade押し)
  8405. *------------------------------------------
  8406. */
  8407. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8408. {
  8409. trade_tradecommit(sd);
  8410. }
  8411. /*==========================================
  8412. *
  8413. *------------------------------------------
  8414. */
  8415. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8416. {
  8417. pc_stop_attack(sd);
  8418. }
  8419. /*==========================================
  8420. * カートへアイテムを移す
  8421. *------------------------------------------
  8422. */
  8423. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8424. {
  8425. RFIFOHEAD(fd);
  8426. if (clif_trading(sd))
  8427. return;
  8428. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8429. }
  8430. /*==========================================
  8431. * カートからアイテムを出す
  8432. *------------------------------------------
  8433. */
  8434. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8435. {
  8436. RFIFOHEAD(fd);
  8437. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8438. }
  8439. /*==========================================
  8440. * 付属品(鷹,ペコ,カート)をはずす
  8441. *------------------------------------------
  8442. */
  8443. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8444. {
  8445. //Can only remove Cart/Riding/Falcon.
  8446. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8447. }
  8448. /*==========================================
  8449. * チェンジカート
  8450. *------------------------------------------
  8451. */
  8452. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8453. {
  8454. RFIFOHEAD(fd);
  8455. pc_setcart(sd,RFIFOW(fd,2));
  8456. }
  8457. /*==========================================
  8458. * ステータスアップ
  8459. *------------------------------------------
  8460. */
  8461. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8462. {
  8463. RFIFOHEAD(fd);
  8464. pc_statusup(sd,RFIFOW(fd,2));
  8465. }
  8466. /*==========================================
  8467. * スキルレベルアップ
  8468. *------------------------------------------
  8469. */
  8470. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8471. {
  8472. RFIFOHEAD(fd);
  8473. pc_skillup(sd,RFIFOW(fd,2));
  8474. }
  8475. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, int skillnum, int skilllv, int target_id)
  8476. {
  8477. int lv;
  8478. if (!hd)
  8479. return;
  8480. if (skillnotok_hom(skillnum, hd)) //[orn]
  8481. return;
  8482. if (hd->bl.id != target_id &&
  8483. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8484. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8485. if (hd->ud.skilltimer != -1) {
  8486. if (skillnum != SA_CASTCANCEL)
  8487. return;
  8488. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8489. return;
  8490. lv = merc_hom_checkskill(hd, skillnum);
  8491. if (skilllv > lv)
  8492. skilllv = lv;
  8493. if (skilllv)
  8494. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8495. }
  8496. /*==========================================
  8497. * スキル使用(ID指定)
  8498. *------------------------------------------
  8499. */
  8500. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8501. int skillnum, skilllv, tmp, target_id;
  8502. unsigned int tick = gettick();
  8503. RFIFOHEAD(fd);
  8504. if (clif_cant_act(sd))
  8505. return;
  8506. if (pc_issit(sd))
  8507. return;
  8508. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8509. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8510. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8511. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8512. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8513. sd->idletime = last_tick;
  8514. tmp = skill_get_inf(skillnum);
  8515. if (tmp&INF_GROUND_SKILL)
  8516. return; //Using a ground skill on a target? WRONG.
  8517. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8518. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8519. return;
  8520. }
  8521. if (skillnotok(skillnum, sd))
  8522. return;
  8523. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8524. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8525. if (sd->ud.skilltimer != -1) {
  8526. if (skillnum != SA_CASTCANCEL)
  8527. return;
  8528. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8529. clif_skill_fail(sd, skillnum, 4, 0);
  8530. return;
  8531. }
  8532. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8533. return;
  8534. if (sd->invincible_timer != -1)
  8535. pc_delinvincibletimer(sd);
  8536. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8537. target_id = sd->bl.id;
  8538. if (sd->skillitem == skillnum) {
  8539. if (skilllv != sd->skillitemlv)
  8540. skilllv = sd->skillitemlv;
  8541. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8542. return;
  8543. }
  8544. sd->skillitem = sd->skillitemlv = 0;
  8545. if (skillnum == MO_EXTREMITYFIST) {
  8546. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8547. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8548. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8549. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8550. if (!sd->state.skill_flag ) {
  8551. sd->state.skill_flag = 1;
  8552. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8553. return;
  8554. } else if (sd->bl.id == target_id) {
  8555. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8556. return;
  8557. }
  8558. }
  8559. }
  8560. if (skillnum == TK_JUMPKICK) {
  8561. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8562. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8563. if (!sd->state.skill_flag ) {
  8564. sd->state.skill_flag = 1;
  8565. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8566. return;
  8567. } else if (sd->bl.id == target_id) {
  8568. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8569. return;
  8570. }
  8571. }
  8572. }
  8573. if (skillnum >= GD_SKILLBASE) {
  8574. if (sd->state.gmaster_flag)
  8575. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8576. else
  8577. skilllv = 0;
  8578. } else {
  8579. tmp = pc_checkskill(sd, skillnum);
  8580. if (skilllv > tmp)
  8581. skilllv = tmp;
  8582. }
  8583. if (skilllv)
  8584. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8585. if (sd->state.skill_flag)
  8586. sd->state.skill_flag = 0;
  8587. }
  8588. /*==========================================
  8589. * スキル使用(場所指定)
  8590. *------------------------------------------
  8591. */
  8592. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8593. {
  8594. int lv;
  8595. unsigned int tick = gettick();
  8596. RFIFOHEAD(fd);
  8597. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8598. sd->idletime = last_tick;
  8599. if (skillnotok(skillnum, sd))
  8600. return;
  8601. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8602. return; //Using a target skill on the ground? WRONG.
  8603. if (skillmoreinfo != -1) {
  8604. if (pc_issit(sd)) {
  8605. clif_skill_fail(sd, skillnum, 0, 0);
  8606. return;
  8607. }
  8608. memcpy(talkie_mes, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8609. talkie_mes[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8610. }
  8611. if (sd->ud.skilltimer != -1)
  8612. return;
  8613. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8614. {
  8615. clif_skill_fail(sd, skillnum, 4, 0);
  8616. return;
  8617. }
  8618. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8619. return;
  8620. if (sd->invincible_timer != -1)
  8621. pc_delinvincibletimer(sd);
  8622. if (sd->skillitem == skillnum) {
  8623. if (skilllv != sd->skillitemlv)
  8624. skilllv = sd->skillitemlv;
  8625. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8626. } else {
  8627. sd->skillitem = sd->skillitemlv = 0;
  8628. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8629. if (skilllv > lv)
  8630. skilllv = lv;
  8631. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8632. }
  8633. }
  8634. }
  8635. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8636. RFIFOHEAD(fd);
  8637. if (clif_cant_act(sd))
  8638. return;
  8639. if (pc_issit(sd))
  8640. return;
  8641. clif_parse_UseSkillToPosSub(fd, sd,
  8642. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8643. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8644. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8645. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8646. -1 //Skill more info.
  8647. );
  8648. }
  8649. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8650. RFIFOHEAD(fd);
  8651. if (clif_cant_act(sd))
  8652. return;
  8653. if (pc_issit(sd))
  8654. return;
  8655. clif_parse_UseSkillToPosSub(fd, sd,
  8656. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8657. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8658. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8659. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8660. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8661. );
  8662. }
  8663. /*==========================================
  8664. * スキル使用(map指定)
  8665. *------------------------------------------
  8666. */
  8667. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8668. {
  8669. RFIFOHEAD(fd);
  8670. if (clif_cant_act(sd))
  8671. return;
  8672. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8673. return;
  8674. if(sd->invincible_timer != -1)
  8675. pc_delinvincibletimer(sd);
  8676. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8677. }
  8678. /*==========================================
  8679. * メモ要求
  8680. *------------------------------------------
  8681. */
  8682. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8683. {
  8684. if (!pc_isdead(sd))
  8685. pc_memo(sd,-1);
  8686. }
  8687. /*==========================================
  8688. * アイテム合成
  8689. *------------------------------------------
  8690. */
  8691. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8692. {
  8693. RFIFOHEAD(fd);
  8694. if (sd->menuskill_id != AM_PHARMACY)
  8695. return;
  8696. if (clif_trading(sd)) {
  8697. //Make it fail to avoid shop exploits where you sell something different than you see.
  8698. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8699. sd->menuskill_lv = sd->menuskill_id = 0;
  8700. return;
  8701. }
  8702. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8703. sd->menuskill_lv = sd->menuskill_id = 0;
  8704. }
  8705. /*==========================================
  8706. * 武器修理
  8707. *------------------------------------------
  8708. */
  8709. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8710. {
  8711. RFIFOHEAD(fd);
  8712. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8713. return;
  8714. if (clif_trading(sd)) {
  8715. //Make it fail to avoid shop exploits where you sell something different than you see.
  8716. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8717. sd->menuskill_lv = sd->menuskill_id = 0;
  8718. return;
  8719. }
  8720. skill_repairweapon(sd,RFIFOW(fd,2));
  8721. sd->menuskill_lv = sd->menuskill_id = 0;
  8722. }
  8723. /*==========================================
  8724. *
  8725. *------------------------------------------
  8726. */
  8727. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8728. int idx;
  8729. RFIFOHEAD(fd);
  8730. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8731. return;
  8732. if (clif_trading(sd)) {
  8733. //Make it fail to avoid shop exploits where you sell something different than you see.
  8734. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8735. sd->menuskill_lv = sd->menuskill_id = 0;
  8736. return;
  8737. }
  8738. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8739. skill_weaponrefine(sd, idx-2);
  8740. sd->menuskill_lv = sd->menuskill_id = 0;
  8741. }
  8742. /*==========================================
  8743. *
  8744. *------------------------------------------
  8745. */
  8746. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8747. {
  8748. unsigned char select;
  8749. RFIFOHEAD(fd);
  8750. select = RFIFOB(fd,6);
  8751. if((select > sd->max_menu && select != 0xff) || !select){
  8752. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8753. clif_GM_kick(sd,sd,0);
  8754. } else {
  8755. sd->npc_menu=select;
  8756. npc_scriptcont(sd,RFIFOL(fd,2));
  8757. }
  8758. }
  8759. /*==========================================
  8760. *
  8761. *------------------------------------------
  8762. */
  8763. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8764. {
  8765. RFIFOHEAD(fd);
  8766. npc_scriptcont(sd,RFIFOL(fd,2));
  8767. }
  8768. /*==========================================
  8769. *
  8770. *------------------------------------------
  8771. */
  8772. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8773. {
  8774. RFIFOHEAD(fd);
  8775. sd->npc_amount=(int)RFIFOL(fd,6);
  8776. npc_scriptcont(sd,RFIFOL(fd,2));
  8777. }
  8778. /*==========================================
  8779. *
  8780. *------------------------------------------
  8781. */
  8782. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8783. {
  8784. short message_len;
  8785. RFIFOHEAD(fd);
  8786. message_len = RFIFOW(fd,2)-7;
  8787. if(message_len < 1)
  8788. return; //Blank message?
  8789. if(message_len >= sizeof(sd->npc_str)){
  8790. ShowWarning("clif: input string too long !\n");
  8791. message_len = sizeof(sd->npc_str);
  8792. }
  8793. // Exploit prevention if crafted packets (without null) is being sent. [Lance]
  8794. memcpy(sd->npc_str,RFIFOP(fd,8),message_len);
  8795. sd->npc_str[message_len-1]=0;
  8796. npc_scriptcont(sd,RFIFOL(fd,4));
  8797. }
  8798. /*==========================================
  8799. *
  8800. *------------------------------------------
  8801. */
  8802. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8803. {
  8804. RFIFOHEAD(fd);
  8805. if (sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8806. npc_scriptcont(sd,RFIFOL(fd,2));
  8807. }
  8808. /*==========================================
  8809. * アイテム鑑定
  8810. *------------------------------------------
  8811. */
  8812. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8813. {
  8814. RFIFOHEAD(fd);
  8815. if (sd->menuskill_id != MC_IDENTIFY)
  8816. return;
  8817. skill_identify(sd,RFIFOW(fd,2)-2);
  8818. sd->menuskill_lv = sd->menuskill_id = 0;
  8819. }
  8820. /*==========================================
  8821. * 矢作成
  8822. *------------------------------------------
  8823. */
  8824. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8825. {
  8826. RFIFOHEAD(fd);
  8827. if (sd->menuskill_id != AC_MAKINGARROW)
  8828. return;
  8829. if (clif_trading(sd)) {
  8830. //Make it fail to avoid shop exploits where you sell something different than you see.
  8831. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8832. sd->menuskill_lv = sd->menuskill_id = 0;
  8833. return;
  8834. }
  8835. skill_arrow_create(sd,RFIFOW(fd,2));
  8836. sd->menuskill_lv = sd->menuskill_id = 0;
  8837. }
  8838. /*==========================================
  8839. * オートスペル受信
  8840. *------------------------------------------
  8841. */
  8842. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8843. {
  8844. RFIFOHEAD(fd);
  8845. if (sd->menuskill_id != SA_AUTOSPELL)
  8846. return;
  8847. skill_autospell(sd,RFIFOW(fd,2));
  8848. sd->menuskill_lv = sd->menuskill_id = 0;
  8849. }
  8850. /*==========================================
  8851. * カード使用
  8852. *------------------------------------------
  8853. */
  8854. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8855. {
  8856. RFIFOHEAD(fd);
  8857. if (sd->state.trading!= 0)
  8858. return;
  8859. clif_use_card(sd,RFIFOW(fd,2)-2);
  8860. }
  8861. /*==========================================
  8862. * カード挿入装備選択
  8863. *------------------------------------------
  8864. */
  8865. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8866. {
  8867. RFIFOHEAD(fd);
  8868. if (sd->state.trading!= 0)
  8869. return;
  8870. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8871. }
  8872. /*==========================================
  8873. * 0193 キャラID名前引き
  8874. *------------------------------------------
  8875. */
  8876. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8877. int char_id;
  8878. RFIFOHEAD(fd);
  8879. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8880. clif_solved_charname(sd, char_id);
  8881. }
  8882. /*==========================================
  8883. * 0197 /resetskill /resetstate
  8884. *------------------------------------------
  8885. */
  8886. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8887. RFIFOHEAD(fd);
  8888. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8889. pc_isGM(sd) >= get_atcommand_level(AtCommand_ResetState)) {
  8890. switch(RFIFOW(fd,2)){
  8891. case 0:
  8892. pc_resetstate(sd);
  8893. break;
  8894. case 1:
  8895. pc_resetskill(sd,1);
  8896. break;
  8897. }
  8898. if((log_config.gm) && (get_atcommand_level(AtCommand_ResetState) >= log_config.gm)) {
  8899. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8900. }
  8901. }
  8902. }
  8903. /*==========================================
  8904. * 019c /lb等
  8905. *------------------------------------------
  8906. */
  8907. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  8908. unsigned char buf[512];
  8909. char message[MESSAGE_SIZE];
  8910. RFIFOHEAD(fd);
  8911. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8912. (pc_isGM(sd) >= get_atcommand_level(AtCommand_LocalBroadcast))) {
  8913. WBUFW(buf,0) = 0x9a;
  8914. WBUFW(buf,2) = RFIFOW(fd,2);
  8915. memcpy(WBUFP(buf,4), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  8916. clif_send(buf, RFIFOW(fd,2), &sd->bl, ALL_SAMEMAP);
  8917. if((log_config.gm) && (get_atcommand_level(AtCommand_LocalBroadcast) >= log_config.gm)) {
  8918. snprintf(message, RFIFOW(fd,2), "/lb %s", RFIFOP(fd,4));
  8919. log_atcommand(sd, message);
  8920. }
  8921. }
  8922. }
  8923. /*==========================================
  8924. * カプラ倉庫へ入れる
  8925. *------------------------------------------
  8926. */
  8927. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  8928. int item_index, item_amount;
  8929. RFIFOHEAD(fd);
  8930. if (clif_trading(sd))
  8931. return;
  8932. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8933. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8934. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8935. return;
  8936. if (sd->state.storage_flag == 1)
  8937. storage_storageadd(sd, item_index, item_amount);
  8938. else if (sd->state.storage_flag == 2)
  8939. storage_guild_storageadd(sd, item_index, item_amount);
  8940. }
  8941. /*==========================================
  8942. * カプラ倉庫から出す
  8943. *------------------------------------------
  8944. */
  8945. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  8946. int item_index, item_amount;
  8947. RFIFOHEAD(fd);
  8948. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8949. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8950. if (sd->state.storage_flag == 1)
  8951. storage_storageget(sd, item_index, item_amount);
  8952. else if(sd->state.storage_flag == 2)
  8953. storage_guild_storageget(sd, item_index, item_amount);
  8954. }
  8955. /*==========================================
  8956. * カプラ倉庫へカートから入れる
  8957. *------------------------------------------
  8958. */
  8959. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  8960. RFIFOHEAD(fd);
  8961. if(sd->vender_id)
  8962. return;
  8963. if (sd->state.storage_flag == 1)
  8964. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8965. else if (sd->state.storage_flag == 2)
  8966. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8967. }
  8968. /*==========================================
  8969. * カプラ倉庫から出す
  8970. *------------------------------------------
  8971. */
  8972. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  8973. RFIFOHEAD(fd);
  8974. if (sd->vender_id)
  8975. return;
  8976. if (sd->state.storage_flag == 1)
  8977. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8978. else if (sd->state.storage_flag == 2)
  8979. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8980. }
  8981. /*==========================================
  8982. * カプラ倉庫を閉じる
  8983. *------------------------------------------
  8984. */
  8985. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  8986. if (sd->state.storage_flag == 1)
  8987. storage_storageclose(sd);
  8988. else if (sd->state.storage_flag == 2)
  8989. storage_guild_storageclose(sd);
  8990. }
  8991. /*==========================================
  8992. * パーティを作る
  8993. *------------------------------------------
  8994. */
  8995. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  8996. RFIFOHEAD(fd);
  8997. if(map[sd->bl.m].flag.partylock)
  8998. { //Guild locked.
  8999. clif_displaymessage(fd, msg_txt(227));
  9000. return;
  9001. }
  9002. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  9003. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  9004. } else
  9005. clif_skill_fail(sd,1,0,4);
  9006. }
  9007. /*==========================================
  9008. * パーティを作る
  9009. *------------------------------------------
  9010. */
  9011. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  9012. if(map[sd->bl.m].flag.partylock)
  9013. { //Guild locked.
  9014. clif_displaymessage(fd, msg_txt(227));
  9015. return;
  9016. }
  9017. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  9018. RFIFOHEAD(fd);
  9019. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  9020. } else
  9021. clif_skill_fail(sd,1,0,4);
  9022. }
  9023. /*==========================================
  9024. * パーティに勧誘
  9025. *------------------------------------------
  9026. */
  9027. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  9028. struct map_session_data *t_sd;
  9029. RFIFOHEAD(fd);
  9030. if(map[sd->bl.m].flag.partylock)
  9031. { //Guild locked.
  9032. clif_displaymessage(fd, msg_txt(227));
  9033. return;
  9034. }
  9035. t_sd = map_id2sd(RFIFOL(fd,2));
  9036. // @noask [LuzZza]
  9037. if(t_sd && t_sd->state.noask) {
  9038. clif_noask_sub(sd, t_sd, 1);
  9039. return;
  9040. }
  9041. party_invite(sd, t_sd);
  9042. }
  9043. /*==========================================
  9044. * パーティ勧誘返答
  9045. *------------------------------------------
  9046. */
  9047. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  9048. RFIFOHEAD(fd);
  9049. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  9050. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9051. } else {
  9052. party_reply_invite(sd,RFIFOL(fd,2),-1);
  9053. clif_skill_fail(sd,1,0,4);
  9054. }
  9055. }
  9056. /*==========================================
  9057. * パーティ脱退要求
  9058. *------------------------------------------
  9059. */
  9060. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  9061. if(map[sd->bl.m].flag.partylock)
  9062. { //Guild locked.
  9063. clif_displaymessage(fd, msg_txt(227));
  9064. return;
  9065. }
  9066. party_leave(sd);
  9067. }
  9068. /*==========================================
  9069. * パーティ除名要求
  9070. *------------------------------------------
  9071. */
  9072. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  9073. RFIFOHEAD(fd);
  9074. if(map[sd->bl.m].flag.partylock)
  9075. { //Guild locked.
  9076. clif_displaymessage(fd, msg_txt(227));
  9077. return;
  9078. }
  9079. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9080. }
  9081. /*==========================================
  9082. * パーティ設定変更要求
  9083. *------------------------------------------
  9084. */
  9085. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  9086. struct party_data *p;
  9087. RFIFOHEAD(fd);
  9088. if(!sd->status.party_id)
  9089. return;
  9090. p = party_search(sd->status.party_id);
  9091. if (!p) return;
  9092. //The client no longer can change the item-field, therefore it always
  9093. //comes as zero. Here, resend the item data as it is.
  9094. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  9095. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  9096. }
  9097. /*==========================================
  9098. * パーティメッセージ送信要求
  9099. *------------------------------------------
  9100. */
  9101. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  9102. RFIFOHEAD(fd);
  9103. if (is_charcommand(fd, sd, (char*)RFIFOP(fd,4)) != CharCommand_None ||
  9104. is_atcommand(fd, sd, (char*)RFIFOP(fd,4)) != AtCommand_None)
  9105. return;
  9106. if (sd->sc.count && (
  9107. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9108. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9109. ))
  9110. return;
  9111. if (battle_config.min_chat_delay)
  9112. { //[Skotlex]
  9113. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9114. return;
  9115. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9116. }
  9117. party_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9118. }
  9119. /*==========================================
  9120. * 露店閉鎖
  9121. *------------------------------------------
  9122. */
  9123. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  9124. vending_closevending(sd);
  9125. }
  9126. /*==========================================
  9127. * 露店アイテムリスト要求
  9128. *------------------------------------------
  9129. */
  9130. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  9131. RFIFOHEAD(fd);
  9132. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9133. if(sd->npc_id)
  9134. npc_event_dequeue(sd);
  9135. }
  9136. /*==========================================
  9137. * 露店アイテム購入
  9138. *------------------------------------------
  9139. */
  9140. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  9141. RFIFOHEAD(fd);
  9142. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  9143. }
  9144. /*==========================================
  9145. * 露店開設
  9146. *------------------------------------------
  9147. */
  9148. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  9149. RFIFOHEAD(fd);
  9150. if (clif_trading(sd))
  9151. return;
  9152. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  9153. return;
  9154. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  9155. }
  9156. /*==========================================
  9157. * ギルドを作る
  9158. *------------------------------------------
  9159. */
  9160. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  9161. RFIFOHEAD(fd);
  9162. if(map[sd->bl.m].flag.guildlock)
  9163. { //Guild locked.
  9164. clif_displaymessage(fd, msg_txt(228));
  9165. return;
  9166. }
  9167. guild_create(sd, (char*)RFIFOP(fd,6));
  9168. }
  9169. /*==========================================
  9170. * ギルドマスターかどうか確認
  9171. *------------------------------------------
  9172. */
  9173. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  9174. clif_guild_masterormember(sd);
  9175. }
  9176. /*==========================================
  9177. * ギルド情報要求
  9178. *------------------------------------------
  9179. */
  9180. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  9181. RFIFOHEAD(fd);
  9182. if (!sd->status.guild_id) return;
  9183. switch(RFIFOL(fd,2)){
  9184. case 0: // ギルド基本情報、同盟敵対情報
  9185. clif_guild_basicinfo(sd);
  9186. clif_guild_allianceinfo(sd);
  9187. break;
  9188. case 1: // メンバーリスト、役職名リスト
  9189. clif_guild_positionnamelist(sd);
  9190. clif_guild_memberlist(sd);
  9191. break;
  9192. case 2: // 役職名リスト、役職情報リスト
  9193. clif_guild_positionnamelist(sd);
  9194. clif_guild_positioninfolist(sd);
  9195. break;
  9196. case 3: // スキルリスト
  9197. clif_guild_skillinfo(sd);
  9198. break;
  9199. case 4: // 追放リスト
  9200. clif_guild_expulsionlist(sd);
  9201. break;
  9202. default:
  9203. if (battle_config.error_log)
  9204. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9205. break;
  9206. }
  9207. }
  9208. /*==========================================
  9209. * ギルド役職変更
  9210. *------------------------------------------
  9211. */
  9212. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  9213. int i;
  9214. RFIFOHEAD(fd);
  9215. if(!sd->state.gmaster_flag)
  9216. return;
  9217. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9218. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9219. }
  9220. }
  9221. /*==========================================
  9222. * ギルドメンバ役職変更
  9223. *------------------------------------------
  9224. */
  9225. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  9226. int i;
  9227. RFIFOHEAD(fd);
  9228. if(!sd->state.gmaster_flag)
  9229. return;
  9230. for(i=4;i<RFIFOW(fd,2);i+=12){
  9231. guild_change_memberposition(sd->status.guild_id,
  9232. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9233. }
  9234. }
  9235. /*==========================================
  9236. * ギルドエンブレム要求
  9237. *------------------------------------------
  9238. */
  9239. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  9240. struct guild *g;
  9241. RFIFOHEAD(fd);
  9242. g=guild_search(RFIFOL(fd,2));
  9243. if(g!=NULL)
  9244. clif_guild_emblem(sd,g);
  9245. }
  9246. /*==========================================
  9247. * ギルドエンブレム変更
  9248. *------------------------------------------
  9249. */
  9250. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  9251. RFIFOHEAD(fd);
  9252. if(!sd->state.gmaster_flag)
  9253. return;
  9254. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9255. }
  9256. /*==========================================
  9257. * ギルド告知変更
  9258. *------------------------------------------
  9259. */
  9260. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  9261. RFIFOHEAD(fd);
  9262. if(!sd->state.gmaster_flag)
  9263. return;
  9264. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  9265. }
  9266. /*==========================================
  9267. * ギルド勧誘
  9268. *------------------------------------------
  9269. */
  9270. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  9271. struct map_session_data *t_sd;
  9272. RFIFOHEAD(fd);
  9273. if(map[sd->bl.m].flag.guildlock)
  9274. { //Guild locked.
  9275. clif_displaymessage(fd, msg_txt(228));
  9276. return;
  9277. }
  9278. t_sd = map_id2sd(RFIFOL(fd,2));
  9279. // @noask [LuzZza]
  9280. if(t_sd && t_sd->state.noask) {
  9281. clif_noask_sub(sd, t_sd, 2);
  9282. return;
  9283. }
  9284. guild_invite(sd,t_sd);
  9285. }
  9286. /*==========================================
  9287. * ギルド勧誘返信
  9288. *------------------------------------------
  9289. */
  9290. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9291. RFIFOHEAD(fd);
  9292. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9293. }
  9294. /*==========================================
  9295. * ギルド脱退
  9296. *------------------------------------------
  9297. */
  9298. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9299. RFIFOHEAD(fd);
  9300. if(map[sd->bl.m].flag.guildlock)
  9301. { //Guild locked.
  9302. clif_displaymessage(fd, msg_txt(228));
  9303. return;
  9304. }
  9305. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9306. }
  9307. /*==========================================
  9308. * ギルド追放
  9309. *------------------------------------------
  9310. */
  9311. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd) {
  9312. RFIFOHEAD(fd);
  9313. if(map[sd->bl.m].flag.guildlock)
  9314. { //Guild locked.
  9315. clif_displaymessage(fd, msg_txt(228));
  9316. return;
  9317. }
  9318. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9319. }
  9320. /*==========================================
  9321. * ギルド会話
  9322. *------------------------------------------
  9323. */
  9324. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9325. RFIFOHEAD(fd);
  9326. if (is_charcommand(fd, sd, (char*)RFIFOP(fd, 4)) != CharCommand_None ||
  9327. is_atcommand(fd, sd, (char*)RFIFOP(fd, 4)) != AtCommand_None)
  9328. return;
  9329. if (sd->sc.count && (
  9330. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9331. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9332. ))
  9333. return;
  9334. if (battle_config.min_chat_delay)
  9335. { //[Skotlex]
  9336. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9337. return;
  9338. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9339. }
  9340. guild_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9341. }
  9342. /*==========================================
  9343. * ギルド同盟要求
  9344. *------------------------------------------
  9345. */
  9346. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9347. struct map_session_data *t_sd;
  9348. RFIFOHEAD(fd);
  9349. if(!sd->state.gmaster_flag)
  9350. return;
  9351. if(map[sd->bl.m].flag.guildlock)
  9352. { //Guild locked.
  9353. clif_displaymessage(fd, msg_txt(228));
  9354. return;
  9355. }
  9356. t_sd = map_id2sd(RFIFOL(fd,2));
  9357. // @noask [LuzZza]
  9358. if(t_sd && t_sd->state.noask) {
  9359. clif_noask_sub(sd, t_sd, 3);
  9360. return;
  9361. }
  9362. guild_reqalliance(sd,t_sd);
  9363. }
  9364. /*==========================================
  9365. * ギルド同盟要求返信
  9366. *------------------------------------------
  9367. */
  9368. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9369. RFIFOHEAD(fd);
  9370. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9371. }
  9372. /*==========================================
  9373. * ギルド関係解消
  9374. *------------------------------------------
  9375. */
  9376. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9377. RFIFOHEAD(fd);
  9378. if(!sd->state.gmaster_flag)
  9379. return;
  9380. if(map[sd->bl.m].flag.guildlock)
  9381. { //Guild locked.
  9382. clif_displaymessage(fd, msg_txt(228));
  9383. return;
  9384. }
  9385. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9386. }
  9387. /*==========================================
  9388. * ギルド敵対
  9389. *------------------------------------------
  9390. */
  9391. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9392. struct map_session_data *t_sd;
  9393. RFIFOHEAD(fd);
  9394. if(!sd->state.gmaster_flag)
  9395. return;
  9396. if(map[sd->bl.m].flag.guildlock)
  9397. { //Guild locked.
  9398. clif_displaymessage(fd, msg_txt(228));
  9399. return;
  9400. }
  9401. t_sd = map_id2sd(RFIFOL(fd,2));
  9402. // @noask [LuzZza]
  9403. if(t_sd && t_sd->state.noask) {
  9404. clif_noask_sub(sd, t_sd, 4);
  9405. return;
  9406. }
  9407. guild_opposition(sd,t_sd);
  9408. }
  9409. /*==========================================
  9410. * ギルド解散
  9411. *------------------------------------------
  9412. */
  9413. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9414. RFIFOHEAD(fd);
  9415. if(map[sd->bl.m].flag.guildlock)
  9416. { //Guild locked.
  9417. clif_displaymessage(fd, msg_txt(228));
  9418. return;
  9419. }
  9420. guild_break(sd,(char*)RFIFOP(fd,2));
  9421. }
  9422. // pet
  9423. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9424. RFIFOHEAD(fd);
  9425. pet_menu(sd,RFIFOB(fd,2));
  9426. }
  9427. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9428. RFIFOHEAD(fd);
  9429. pet_catch_process2(sd,RFIFOL(fd,2));
  9430. }
  9431. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9432. RFIFOHEAD(fd);
  9433. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  9434. return;
  9435. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9436. sd->menuskill_lv = sd->menuskill_id = 0;
  9437. }
  9438. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9439. if(sd->pd) {
  9440. RFIFOHEAD(fd);
  9441. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9442. }
  9443. }
  9444. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9445. RFIFOHEAD(fd);
  9446. pet_change_name(sd,(char*)RFIFOP(fd,2), 0);
  9447. }
  9448. // Kick (right click menu for GM "(name) force to quit")
  9449. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9450. struct block_list *target;
  9451. int tid;
  9452. char message[MESSAGE_SIZE];
  9453. RFIFOHEAD(fd);
  9454. tid = RFIFOL(fd,2);
  9455. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9456. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Kick))) {
  9457. target = map_id2bl(tid);
  9458. if (target) {
  9459. if (target->type == BL_PC) {
  9460. struct map_session_data *tsd = (struct map_session_data *)target;
  9461. if (pc_isGM(sd) > pc_isGM(tsd)) {
  9462. clif_GM_kick(sd, tsd, 1);
  9463. if((log_config.gm) && (get_atcommand_level(AtCommand_Kick) >= log_config.gm)) {
  9464. sprintf(message, "/kick %d", tsd->status.char_id);
  9465. log_atcommand(sd, message);
  9466. }
  9467. } else
  9468. clif_GM_kickack(sd, 0);
  9469. } else if (target->type == BL_MOB) {
  9470. status_percent_damage(&sd->bl, target, 100, 0);
  9471. sprintf(message, "/kick %d %d %d %d", tid, target->id, target->type, target->subtype);
  9472. if((log_config.gm) && (get_atcommand_level(AtCommand_Kick) >= log_config.gm)) {
  9473. sprintf(message, "/kick %s", ((struct mob_data*)target)->db->sprite);
  9474. log_atcommand(sd, message);
  9475. }
  9476. } else
  9477. clif_GM_kickack(sd, 0);
  9478. } else
  9479. clif_GM_kickack(sd, 0);
  9480. }
  9481. }
  9482. /*==========================================
  9483. * /shift
  9484. *------------------------------------------
  9485. */
  9486. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9487. char player_name[NAME_LENGTH];
  9488. char message[MESSAGE_SIZE];
  9489. memset(player_name, '\0', sizeof(player_name));
  9490. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9491. (pc_isGM(sd) >= get_atcommand_level(AtCommand_JumpTo))) {
  9492. RFIFOHEAD(fd);
  9493. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9494. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9495. if((log_config.gm) && (get_atcommand_level(AtCommand_JumpTo) >= log_config.gm)) {
  9496. sprintf(message, "/shift %s", player_name);
  9497. log_atcommand(sd, message);
  9498. }
  9499. }
  9500. return;
  9501. }
  9502. /*==========================================
  9503. * /recall
  9504. *------------------------------------------
  9505. */
  9506. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9507. char player_name[NAME_LENGTH];
  9508. char message[MESSAGE_SIZE];
  9509. memset(player_name, '\0', sizeof(player_name));
  9510. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9511. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Recall))) {
  9512. RFIFOHEAD(fd);
  9513. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9514. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9515. if((log_config.gm) && (get_atcommand_level(AtCommand_Recall) >= log_config.gm)) {
  9516. sprintf(message, "/recall %s", player_name);
  9517. log_atcommand(sd, message);
  9518. }
  9519. }
  9520. return;
  9521. }
  9522. /*==========================================
  9523. * /monster /item rewriten by [Yor]
  9524. *------------------------------------------
  9525. */
  9526. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9527. char monster_item_name[NAME_LENGTH+10]; //Additional space is for logging, eg: "@monster Poring"
  9528. int level;
  9529. memset(monster_item_name, '\0', sizeof(monster_item_name));
  9530. if (battle_config.atc_gmonly == 0 || pc_isGM(sd)) {
  9531. RFIFOHEAD(fd);
  9532. memcpy(monster_item_name, RFIFOP(fd,2), NAME_LENGTH);
  9533. if (mobdb_searchname(monster_item_name) != 0) {
  9534. if (pc_isGM(sd) >= (level =get_atcommand_level(AtCommand_Spawn))) // changed from AtCommand_Monster for Skots [Reddozen]
  9535. {
  9536. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9537. if(log_config.gm && level >= log_config.gm)
  9538. { //Log action. [Skotlex]
  9539. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@spawn %s", RFIFOP(fd,2));
  9540. log_atcommand(sd, monster_item_name);
  9541. }
  9542. }
  9543. } else if (itemdb_searchname(monster_item_name) != NULL) {
  9544. if (pc_isGM(sd) >= (level = get_atcommand_level(AtCommand_Item)))
  9545. {
  9546. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9547. if(log_config.gm && level >= log_config.gm)
  9548. { //Log action. [Skotlex]
  9549. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@item %s", RFIFOP(fd,2));
  9550. log_atcommand(sd, monster_item_name);
  9551. }
  9552. }
  9553. }
  9554. }
  9555. }
  9556. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9557. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9558. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) {
  9559. if (sd->sc.option & OPTION_INVISIBLE) {
  9560. sd->sc.option &= ~OPTION_INVISIBLE;
  9561. if (sd->disguise)
  9562. status_set_viewdata(&sd->bl, sd->disguise);
  9563. else
  9564. status_set_viewdata(&sd->bl, sd->status.class_);
  9565. clif_displaymessage(fd, "Invisible: Off.");
  9566. } else {
  9567. sd->sc.option |= OPTION_INVISIBLE;
  9568. //Experimental hidden mode, changes your view class to invisible [Skotlex]
  9569. sd->vd.class_ = INVISIBLE_CLASS;
  9570. clif_displaymessage(fd, "Invisible: On.");
  9571. if((log_config.gm) && (get_atcommand_level(AtCommand_Hide) >= log_config.gm)) {
  9572. log_atcommand(sd, "/hide");
  9573. }
  9574. }
  9575. clif_changeoption(&sd->bl);
  9576. }
  9577. }
  9578. /*==========================================
  9579. * GMによるチャット禁止時間付与
  9580. *------------------------------------------
  9581. */
  9582. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9583. {
  9584. int type, limit, level;
  9585. struct block_list *bl;
  9586. struct map_session_data *dstsd;
  9587. RFIFOHEAD(fd);
  9588. bl = map_id2bl(RFIFOL(fd,2));
  9589. if (!bl || bl->type != BL_PC)
  9590. return;
  9591. nullpo_retv(dstsd =(struct map_session_data *)bl);
  9592. type = RFIFOB(fd,6);
  9593. limit = RFIFOW(fd,7);
  9594. if (type == 0)
  9595. limit = 0 - limit;
  9596. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9597. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9598. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9599. return;
  9600. if (
  9601. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9602. || (type == 2 && !level)) {
  9603. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9604. dstsd->status.manner -= limit;
  9605. if(dstsd->status.manner < 0)
  9606. sc_start(bl,SC_NOCHAT,100,0,0);
  9607. else
  9608. {
  9609. dstsd->status.manner = 0;
  9610. status_change_end(bl,SC_NOCHAT,-1);
  9611. }
  9612. }
  9613. return;
  9614. }
  9615. /*==========================================
  9616. * GMによるチャット禁止時間参照(?)
  9617. *------------------------------------------
  9618. */
  9619. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9620. {
  9621. int tid;
  9622. RFIFOHEAD(fd);
  9623. tid = RFIFOL(fd,2);
  9624. WFIFOHEAD(fd,packet_len(0x1e0));
  9625. WFIFOW(fd,0) = 0x1e0;
  9626. WFIFOL(fd,2) = tid;
  9627. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9628. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9629. WFIFOSET(fd, packet_len(0x1e0));
  9630. return;
  9631. }
  9632. static int pstrcmp(const void *a, const void *b)
  9633. {
  9634. char *name1 = (char *)a;
  9635. char *name2 = (char *)b;
  9636. if (name1[0] && name2[0])
  9637. return strcmp(name1, name2);
  9638. //Since names are sorted in ascending order, send blank entries to the bottom.
  9639. if (name1[0])
  9640. return -1;
  9641. if (name2[0])
  9642. return 1;
  9643. return 0;
  9644. }
  9645. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9646. char output[512];
  9647. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9648. int i;
  9649. WFIFOHEAD(fd,packet_len(0xd1));
  9650. RFIFOHEAD(fd);
  9651. memset(output, '\0', sizeof(output));
  9652. nick = (char*)RFIFOP(fd,2); // speed up
  9653. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9654. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9655. WFIFOB(fd,2) = RFIFOB(fd,26);
  9656. // deny action (we add nick only if it's not already exist
  9657. if (RFIFOB(fd,26) == 0) { // Add block
  9658. for(i = 0; i < MAX_IGNORE_LIST &&
  9659. sd->ignore[i].name[0] != '\0' &&
  9660. strcmp(sd->ignore[i].name, nick) != 0
  9661. ; i++);
  9662. if (i == MAX_IGNORE_LIST) { //Full List
  9663. WFIFOB(fd,3) = 1; // fail
  9664. WFIFOSET(fd, packet_len(0x0d1));
  9665. if (strcmp(wisp_server_name, nick) == 0)
  9666. { // to found possible bot users who automaticaly ignore people.
  9667. 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);
  9668. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9669. }
  9670. return;
  9671. }
  9672. if(sd->ignore[i].name[0] != '\0')
  9673. { //Name already exists.
  9674. WFIFOB(fd,3) = 0; // Aegis reports success.
  9675. WFIFOSET(fd, packet_len(0x0d1));
  9676. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9677. sprintf(output, "Character '%s' (account: %d) has tried AGAIN to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  9678. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9679. }
  9680. return;
  9681. }
  9682. //Insert in position i
  9683. memcpy(sd->ignore[i].name, nick, NAME_LENGTH-1);
  9684. WFIFOB(fd,3) = 0; // success
  9685. WFIFOSET(fd, packet_len(0x0d1));
  9686. if (strcmp(wisp_server_name, nick) == 0)
  9687. { // to found possible bot users who automaticaly ignore people.
  9688. 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);
  9689. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9690. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9691. clif_wis_message(fd, wisp_server_name,
  9692. "Adding me in your ignore list will not block my wisps.",
  9693. strlen("Adding me in your ignore list will not block my wisps.") + 1);
  9694. }
  9695. //Sort the ignore list.
  9696. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9697. return;
  9698. }
  9699. //Remove name
  9700. for(i = 0; i < MAX_IGNORE_LIST &&
  9701. sd->ignore[i].name[0] != '\0' &&
  9702. strcmp(sd->ignore[i].name, nick) != 0
  9703. ; i++);
  9704. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0')
  9705. { //Not found
  9706. WFIFOB(fd,3) = 1; // fail
  9707. WFIFOSET(fd, packet_len(0x0d1));
  9708. return;
  9709. }
  9710. //Move everything one place down to overwrite removed entry.
  9711. memmove(sd->ignore[i].name, sd->ignore[i+1].name,
  9712. (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9713. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9714. // success
  9715. WFIFOB(fd,3) = 0;
  9716. WFIFOSET(fd, packet_len(0x0d1));
  9717. // for debug only
  9718. // for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++) /
  9719. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9720. return;
  9721. }
  9722. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9723. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9724. RFIFOHEAD(fd);
  9725. WFIFOHEAD(fd,packet_len(0xd2));
  9726. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9727. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9728. WFIFOW(fd,0) = 0x0d2;
  9729. WFIFOB(fd,2) = RFIFOB(fd,2);
  9730. if (RFIFOB(fd,2) == 0) { //Deny all
  9731. if (sd->state.ignoreAll) {
  9732. WFIFOB(fd,3) = 1; // fail
  9733. WFIFOSET(fd, packet_len(0x0d2));
  9734. return;
  9735. }
  9736. sd->state.ignoreAll = 1;
  9737. WFIFOB(fd,3) = 0; // success
  9738. WFIFOSET(fd, packet_len(0x0d2));
  9739. return;
  9740. }
  9741. //Unblock everyone
  9742. if (!sd->state.ignoreAll) {
  9743. if (sd->ignore[0].name[0] != '\0')
  9744. { //Wipe the ignore list.
  9745. memset(sd->ignore, 0, sizeof(sd->ignore));
  9746. WFIFOB(fd,3) = 0;
  9747. WFIFOSET(fd, packet_len(0x0d2));
  9748. return;
  9749. }
  9750. WFIFOB(fd,3) = 1; // fail
  9751. WFIFOSET(fd, packet_len(0x0d2));
  9752. return;
  9753. }
  9754. sd->state.ignoreAll = 0;
  9755. WFIFOB(fd,3) = 0; // success
  9756. WFIFOSET(fd, packet_len(0x0d2));
  9757. return;
  9758. }
  9759. /*==========================================
  9760. * Wis拒否リスト
  9761. *------------------------------------------
  9762. */
  9763. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9764. {
  9765. int i;
  9766. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9767. WFIFOW(fd,0) = 0xd4;
  9768. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9769. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9770. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9771. WFIFOSET(fd, WFIFOW(fd,2));
  9772. return;
  9773. }
  9774. /*==========================================
  9775. * スパノビの/doridoriによるSPR2倍
  9776. *------------------------------------------
  9777. */
  9778. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9779. if (sd->state.doridori) return;
  9780. switch (sd->class_&MAPID_UPPERMASK)
  9781. {
  9782. case MAPID_SOUL_LINKER:
  9783. case MAPID_STAR_GLADIATOR:
  9784. case MAPID_TAEKWON:
  9785. if (!sd->state.rest)
  9786. break;
  9787. case MAPID_SUPER_NOVICE:
  9788. sd->state.doridori=1;
  9789. break;
  9790. }
  9791. return;
  9792. }
  9793. /*==========================================
  9794. * スパノビの爆裂波動
  9795. *------------------------------------------
  9796. */
  9797. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9798. {
  9799. if(sd){
  9800. int nextbaseexp=pc_nextbaseexp(sd);
  9801. if (battle_config.etc_log){
  9802. if(nextbaseexp != 0)
  9803. 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));
  9804. else
  9805. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9806. }
  9807. 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){
  9808. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9809. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9810. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9811. }
  9812. }
  9813. return;
  9814. }
  9815. // random notes:
  9816. // 0x214: monster/player info ?
  9817. /*==========================================
  9818. * Friends List
  9819. *------------------------------------------
  9820. */
  9821. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9822. { //Toggles a single friend online/offline [Skotlex]
  9823. int i, fd = sd->fd;
  9824. //Seek friend.
  9825. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9826. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9827. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9828. return; //Not found
  9829. WFIFOHEAD(fd,packet_len(0x206));
  9830. WFIFOW(fd, 0) = 0x206;
  9831. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9832. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9833. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9834. WFIFOSET(fd, packet_len(0x206));
  9835. }
  9836. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9837. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9838. {
  9839. int account_id, char_id, online;
  9840. account_id = va_arg(ap, int);
  9841. char_id = va_arg(ap, int);
  9842. online = va_arg(ap, int);
  9843. clif_friendslist_toggle(sd, account_id, char_id, online);
  9844. return 0;
  9845. }
  9846. //For sending the whole friends list.
  9847. void clif_friendslist_send(struct map_session_data *sd) {
  9848. int i = 0, n, fd = sd->fd;
  9849. // Send friends list
  9850. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9851. WFIFOW(fd, 0) = 0x201;
  9852. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9853. {
  9854. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9855. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9856. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9857. }
  9858. if (i) {
  9859. WFIFOW(fd,2) = 4 + 32 * i;
  9860. WFIFOSET(fd, WFIFOW(fd,2));
  9861. }
  9862. for (n = 0; n < i; n++)
  9863. { //Sending the online players
  9864. if (map_charid2sd(sd->status.friends[n].char_id))
  9865. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9866. }
  9867. }
  9868. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9869. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9870. {
  9871. int fd;
  9872. nullpo_retv(sd);
  9873. fd = sd->fd;
  9874. WFIFOHEAD(fd,packet_len(0x209));
  9875. WFIFOW(fd,0) = 0x209;
  9876. WFIFOW(fd,2) = type;
  9877. if (f_sd)
  9878. {
  9879. WFIFOW(fd,4) = f_sd->status.account_id;
  9880. WFIFOW(fd,8) = f_sd->status.char_id;
  9881. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9882. }
  9883. WFIFOSET(fd, packet_len(0x209));
  9884. }
  9885. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9886. struct map_session_data *f_sd;
  9887. int i, f_fd;
  9888. RFIFOHEAD(fd);
  9889. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9890. // Friend doesn't exist (no player with this name)
  9891. if (f_sd == NULL) {
  9892. clif_displaymessage(fd, msg_txt(3));
  9893. return;
  9894. }
  9895. // @noask [LuzZza]
  9896. if(f_sd->state.noask) {
  9897. clif_noask_sub(sd, f_sd, 5);
  9898. return;
  9899. }
  9900. // Friend already exists
  9901. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9902. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9903. clif_displaymessage(fd, "Friend already exists.");
  9904. return;
  9905. }
  9906. }
  9907. if (i == MAX_FRIENDS) {
  9908. //No space, list full.
  9909. clif_friendslist_reqack(sd, f_sd, 2);
  9910. return;
  9911. }
  9912. f_fd = f_sd->fd;
  9913. WFIFOHEAD(f_fd,packet_len(0x207));
  9914. WFIFOW(f_fd,0) = 0x207;
  9915. WFIFOL(f_fd,2) = sd->status.account_id;
  9916. WFIFOL(f_fd,6) = sd->status.char_id;
  9917. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9918. WFIFOSET(f_fd, packet_len(0x207));
  9919. return;
  9920. }
  9921. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9922. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9923. struct map_session_data *f_sd;
  9924. int char_id, account_id;
  9925. char reply;
  9926. RFIFOHEAD(fd);
  9927. account_id = RFIFOL(fd,2);
  9928. char_id = RFIFOL(fd,6);
  9929. reply = RFIFOB(fd,10);
  9930. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9931. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9932. if (f_sd == NULL)
  9933. return;
  9934. if (reply == 0)
  9935. clif_friendslist_reqack(f_sd, sd, 1);
  9936. else {
  9937. int i;
  9938. // Find an empty slot
  9939. for (i = 0; i < MAX_FRIENDS; i++)
  9940. if (f_sd->status.friends[i].char_id == 0)
  9941. break;
  9942. if (i == MAX_FRIENDS) {
  9943. clif_friendslist_reqack(f_sd, sd, 2);
  9944. return;
  9945. }
  9946. f_sd->status.friends[i].account_id = sd->status.account_id;
  9947. f_sd->status.friends[i].char_id = sd->status.char_id;
  9948. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9949. clif_friendslist_reqack(f_sd, sd, 0);
  9950. if (battle_config.friend_auto_add) {
  9951. // Also add f_sd to sd's friendlist.
  9952. for (i = 0; i < MAX_FRIENDS; i++) {
  9953. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9954. return; //No need to add anything.
  9955. if (sd->status.friends[i].char_id == 0)
  9956. break;
  9957. }
  9958. if (i == MAX_FRIENDS) {
  9959. clif_friendslist_reqack(sd, f_sd, 2);
  9960. return;
  9961. }
  9962. sd->status.friends[i].account_id = f_sd->status.account_id;
  9963. sd->status.friends[i].char_id = f_sd->status.char_id;
  9964. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9965. clif_friendslist_reqack(sd, f_sd, 0);
  9966. }
  9967. }
  9968. return;
  9969. }
  9970. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9971. // 0x203 </o> <ID to be removed W 4B>
  9972. int account_id, char_id;
  9973. int i, j;
  9974. RFIFOHEAD(fd);
  9975. account_id = RFIFOL(fd,2);
  9976. char_id = RFIFOL(fd,6);
  9977. // Search friend
  9978. for (i = 0; i < MAX_FRIENDS &&
  9979. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9980. if (i == MAX_FRIENDS) {
  9981. clif_displaymessage(fd, "Name not found in list.");
  9982. return;
  9983. }
  9984. // move all chars down
  9985. for(j = i + 1; j < MAX_FRIENDS; j++)
  9986. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9987. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9988. clif_displaymessage(fd, "Friend removed");
  9989. WFIFOHEAD(fd,packet_len(0x20a));
  9990. WFIFOW(fd,0) = 0x20a;
  9991. WFIFOL(fd,2) = account_id;
  9992. WFIFOL(fd,6) = char_id;
  9993. WFIFOSET(fd, packet_len(0x20a));
  9994. // clif_friendslist_send(sd); //This is not needed anymore.
  9995. return;
  9996. }
  9997. /*==========================================
  9998. * /killall
  9999. *------------------------------------------
  10000. */
  10001. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  10002. {
  10003. char message[50];
  10004. strncpy(message,sd->status.name, NAME_LENGTH);
  10005. is_atcommand(fd, sd, strcat(message," : @kickall"));
  10006. return;
  10007. }
  10008. /*==========================================
  10009. * /pvpinfo
  10010. *------------------------------------------
  10011. */
  10012. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10013. {
  10014. WFIFOHEAD(fd,packet_len(0x210));
  10015. WFIFOW(fd,0) = 0x210;
  10016. //WFIFOL(fd,2) = 0; // not sure what for yet
  10017. //WFIFOL(fd,6) = 0;
  10018. WFIFOL(fd,10) = sd->pvp_won; // times won
  10019. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10020. WFIFOL(fd,18) = sd->pvp_point;
  10021. WFIFOSET(fd, packet_len(0x210));
  10022. return;
  10023. }
  10024. /*==========================================
  10025. * /blacksmith
  10026. *------------------------------------------
  10027. */
  10028. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10029. {
  10030. int i;
  10031. char *name;
  10032. WFIFOHEAD(fd,packet_len(0x219));
  10033. WFIFOW(fd,0) = 0x219;
  10034. //Packet size limits this list to 10 elements. [Skotlex]
  10035. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10036. if (smith_fame_list[i].id > 0) {
  10037. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10038. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10039. {
  10040. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10041. } else
  10042. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10043. } else
  10044. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10045. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10046. }
  10047. for(;i < 10; i++) { //In case the MAX is less than 10.
  10048. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10049. WFIFOL(fd, 242 + i * 4) = 0;
  10050. }
  10051. WFIFOSET(fd, packet_len(0x219));
  10052. }
  10053. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  10054. {
  10055. int fd = sd->fd;
  10056. WFIFOHEAD(fd,packet_len(0x21b));
  10057. WFIFOW(fd,0) = 0x21b;
  10058. WFIFOL(fd,2) = points;
  10059. WFIFOL(fd,6) = sd->status.fame;
  10060. WFIFOSET(fd, packet_len(0x21b));
  10061. return 0;
  10062. }
  10063. /*==========================================
  10064. * /alchemist
  10065. *------------------------------------------
  10066. */
  10067. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10068. {
  10069. int i;
  10070. char *name;
  10071. WFIFOHEAD(fd,packet_len(0x21a));
  10072. WFIFOW(fd,0) = 0x21a;
  10073. //Packet size limits this list to 10 elements. [Skotlex]
  10074. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10075. if (chemist_fame_list[i].id > 0) {
  10076. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10077. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10078. {
  10079. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10080. } else
  10081. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10082. } else
  10083. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10084. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10085. }
  10086. for(;i < 10; i++) { //In case the MAX is less than 10.
  10087. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10088. WFIFOL(fd, 242 + i * 4) = 0;
  10089. }
  10090. WFIFOSET(fd, packet_len(0x21a));
  10091. }
  10092. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10093. {
  10094. int fd = sd->fd;
  10095. WFIFOHEAD(fd,packet_len(0x21c));
  10096. WFIFOW(fd,0) = 0x21c;
  10097. WFIFOL(fd,2) = points;
  10098. WFIFOL(fd,6) = sd->status.fame;
  10099. WFIFOSET(fd, packet_len(0x21c));
  10100. return 0;
  10101. }
  10102. /*==========================================
  10103. * /taekwon
  10104. *------------------------------------------
  10105. */
  10106. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10107. {
  10108. int i;
  10109. char *name;
  10110. WFIFOHEAD(fd,packet_len(0x226));
  10111. WFIFOW(fd,0) = 0x226;
  10112. //Packet size limits this list to 10 elements. [Skotlex]
  10113. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10114. if (taekwon_fame_list[i].id > 0) {
  10115. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10116. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10117. {
  10118. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10119. } else
  10120. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10121. } else
  10122. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10123. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10124. }
  10125. for(;i < 10; i++) { //In case the MAX is less than 10.
  10126. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10127. WFIFOL(fd, 242 + i * 4) = 0;
  10128. }
  10129. WFIFOSET(fd, packet_len(0x226));
  10130. }
  10131. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10132. {
  10133. int fd = sd->fd;
  10134. WFIFOHEAD(fd,packet_len(0x224));
  10135. WFIFOW(fd,0) = 0x224;
  10136. WFIFOL(fd,2) = points;
  10137. WFIFOL(fd,6) = sd->status.fame;
  10138. WFIFOSET(fd, packet_len(0x224));
  10139. return 0;
  10140. }
  10141. /*==========================================
  10142. * PK Ranking table?
  10143. *------------------------------------------
  10144. */
  10145. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10146. {
  10147. int i;
  10148. WFIFOHEAD(fd,packet_len(0x238));
  10149. WFIFOW(fd,0) = 0x238;
  10150. for(i=0;i<10;i++){
  10151. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10152. WFIFOL(fd,i*4+242) = 0;
  10153. }
  10154. WFIFOSET(fd, packet_len(0x238));
  10155. return;
  10156. }
  10157. /*==========================================
  10158. * SG Feel save OK [Komurka]
  10159. *------------------------------------------
  10160. */
  10161. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10162. {
  10163. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  10164. int i;
  10165. if (sd->menuskill_id != SG_FEEL)
  10166. return;
  10167. i = sd->menuskill_lv-1;
  10168. if (i<0 || i > 2) return; //Bug?
  10169. sd->feel_map[i].index = map[sd->bl.m].index;
  10170. sd->feel_map[i].m = sd->bl.m;
  10171. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  10172. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10173. // clif_misceffect2(&sd->bl, 0x1b0);
  10174. // clif_misceffect2(&sd->bl, 0x21f);
  10175. clif_feel_info(sd, i, 0);
  10176. sd->menuskill_lv = sd->menuskill_id = 0;
  10177. }
  10178. /*==========================================
  10179. * Question about Star Glaldiator save map [Komurka]
  10180. *------------------------------------------
  10181. */
  10182. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  10183. WFIFOHEAD(fd,packet_len(0x253));
  10184. WFIFOW(fd,0)=0x253;
  10185. WFIFOSET(fd, packet_len(0x253));
  10186. sd->menuskill_id=SG_FEEL;
  10187. sd->menuskill_lv=skilllv;
  10188. }
  10189. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd) {
  10190. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  10191. //Missing packets are the client's reply packets to the adopt request one.
  10192. //[Skotlex]
  10193. int account_id;
  10194. struct map_session_data *sd2;
  10195. RFIFOHEAD(fd);
  10196. account_id = RFIFOL(fd,2);
  10197. sd2 = map_id2sd(account_id);
  10198. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  10199. fd = sd2->fd;
  10200. WFIFOHEAD(fd,packet_len(0x1f9));
  10201. WFIFOW(fd,0)=0x1f9;
  10202. WFIFOSET(fd, packet_len(0x1f9));
  10203. }
  10204. }
  10205. /*==========================================
  10206. * パケットデバッグ
  10207. *------------------------------------------
  10208. */
  10209. void clif_parse_debug(int fd,struct map_session_data *sd)
  10210. {
  10211. int i, cmd, len;
  10212. RFIFOHEAD(fd);
  10213. cmd = RFIFOW(fd,0);
  10214. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10215. ShowDebug("packet debug 0x%4X\n",cmd);
  10216. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10217. for(i=0;i<len;i++){
  10218. if((i&15)==0)
  10219. printf("\n%04X ",i);
  10220. printf("%02X ",RFIFOB(fd,i));
  10221. }
  10222. printf("\n");
  10223. }
  10224. /*==========================================
  10225. * クライアントからのパケット解析
  10226. * socket.cのdo_parsepacketから呼び出される
  10227. *------------------------------------------
  10228. */
  10229. int clif_parse(int fd) {
  10230. int packet_len = 0, cmd, packet_ver, err, dump = 0;
  10231. TBL_PC *sd;
  10232. RFIFOHEAD(fd);
  10233. if (fd <= 0)
  10234. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  10235. ShowError("clif_parse: Received invalid session %d\n", fd);
  10236. return 0;
  10237. }
  10238. sd = (TBL_PC *)session[fd]->session_data;
  10239. if (session[fd]->eof) {
  10240. if (sd) {
  10241. if (sd->state.autotrade) {
  10242. //Disassociate character from the socket connection.
  10243. session[fd]->session_data = NULL;
  10244. sd->fd = 0;
  10245. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n",
  10246. (pc_isGM(sd))?"GM ":"",sd->status.name);
  10247. } else
  10248. if (sd->state.auth) {
  10249. // Player logout display [Valaris]
  10250. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n",
  10251. (pc_isGM(sd))?"GM ":"",sd->status.name);
  10252. clif_quitsave(fd, sd);
  10253. } else {
  10254. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n",
  10255. sd->bl.id, sd->status.char_id);
  10256. map_quit(sd);
  10257. }
  10258. } else {
  10259. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  10260. ShowInfo("Closed connection from '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip[0],ip[1],ip[2],ip[3]);
  10261. }
  10262. do_close(fd);
  10263. return 0;
  10264. }
  10265. if (RFIFOREST(fd) < 2)
  10266. return 0;
  10267. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  10268. cmd = RFIFOW(fd,0);
  10269. // get packet version before to parse
  10270. packet_ver = 0;
  10271. if (sd) {
  10272. packet_ver = sd->packet_ver;
  10273. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  10274. ShowWarning("clif_parse: Disconnecting session #%d (AID:%d/CID:%d) for having invalid packet_ver=%d.", fd, sd->status.account_id, sd->status.char_id, packet_ver);
  10275. session[fd]->eof = 1;
  10276. return 0;
  10277. }
  10278. } else {
  10279. // check authentification packet to know packet version
  10280. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10281. if( err )
  10282. {// failed to identify packet version
  10283. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10284. err == 1 ? "" :
  10285. err == 2 ? ", possibly for having an invalid account_id" :
  10286. err == 3 ? ", possibly for having an invalid char_id." :
  10287. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10288. err == 4 ? ", possibly for having an invalid login_id1." :
  10289. err == 5 ? ", possibly for having an invalid client_tick." :
  10290. */
  10291. err == 6 ? ", possibly for having an invalid sex." :
  10292. ". ERROR invalid error code"));
  10293. WFIFOHEAD(fd,packet_len(0x6a));
  10294. WFIFOW(fd,0) = 0x6a;
  10295. WFIFOB(fd,2) = 3; // Rejected from Server
  10296. WFIFOSET(fd,packet_len(0x6a));
  10297. RFIFOSKIP(fd, RFIFOREST(fd));
  10298. clif_setwaitclose(fd);
  10299. /*
  10300. //## TODO check if it still doesn't send and why. [FlavioJS]
  10301. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  10302. session[fd]->func_send(fd);
  10303. */
  10304. return 0;
  10305. }
  10306. }
  10307. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  10308. if (cmd >= MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) { // if packet is not inside these values: session is incorrect?? or auth packet is unknown
  10309. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10310. session[fd]->eof = 1;
  10311. return 0;
  10312. }
  10313. // パケット長を計算
  10314. packet_len = packet_db[packet_ver][cmd].len;
  10315. if (packet_len == -1) {
  10316. if (RFIFOREST(fd) < 4)
  10317. return 0; // 可変長パケットで長さの所までデータが来てない
  10318. packet_len = RFIFOW(fd,2);
  10319. if (packet_len < 4 || packet_len > 32768) {
  10320. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10321. session[fd]->eof =1;
  10322. return 0;
  10323. }
  10324. }
  10325. if ((int)RFIFOREST(fd) < packet_len)
  10326. return 0; // まだ1パケット分データが揃ってない
  10327. #if DUMP_ALL_PACKETS
  10328. {
  10329. int i;
  10330. FILE *fp;
  10331. char packet_txt[256] = "save/packet.txt";
  10332. time_t now;
  10333. dump = 1;
  10334. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10335. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10336. return 1;
  10337. } else {
  10338. time(&now);
  10339. if (sd && sd->state.auth) {
  10340. if (sd->status.name != NULL)
  10341. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent packet:\n",
  10342. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10343. else
  10344. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10345. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10346. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10347. fprintf(fp, "\tsession #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10348. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10349. for(i = 0; i < packet_len; i++) {
  10350. if ((i & 15) == 0)
  10351. fprintf(fp, "\n\t%04X ", i);
  10352. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10353. }
  10354. fprintf(fp, "\n\n");
  10355. fclose(fp);
  10356. }
  10357. }
  10358. #endif
  10359. if (sd && sd->state.waitingdisconnect == 1) {
  10360. // 切断待ちの場合パケットを処理しない
  10361. } else if (packet_db[packet_ver][cmd].func) {
  10362. if (sd && sd->bl.prev == NULL &&
  10363. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10364. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10365. else
  10366. if (sd
  10367. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10368. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10369. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10370. packet_db[packet_ver][cmd].func(fd, sd);
  10371. }
  10372. #if DUMP_UNKNOWN_PACKET
  10373. else if (battle_config.error_log)
  10374. {
  10375. int i;
  10376. FILE *fp;
  10377. char packet_txt[256] = "save/packet.txt";
  10378. time_t now;
  10379. dump = 1;
  10380. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10381. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10382. return 1;
  10383. } else {
  10384. time(&now);
  10385. if (sd && sd->state.auth) {
  10386. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10387. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10388. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10389. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10390. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10391. for(i = 0; i < packet_len; i++) {
  10392. if ((i & 15) == 0)
  10393. fprintf(fp, "\n\t%04X ", i);
  10394. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10395. }
  10396. fprintf(fp, "\n\n");
  10397. fclose(fp);
  10398. }
  10399. }
  10400. #endif
  10401. if (dump) {
  10402. int i;
  10403. if (fd)
  10404. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10405. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10406. for(i = 0; i < packet_len; i++) {
  10407. if ((i & 15) == 0)
  10408. printf("\n%04X ",i);
  10409. printf("%02X ", RFIFOB(fd,i));
  10410. }
  10411. printf("\n");
  10412. if (sd && sd->state.auth) {
  10413. if (sd->status.name != NULL)
  10414. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10415. sd->status.account_id, sd->status.char_id, sd->status.name);
  10416. else
  10417. printf("\nAccount ID %d.\n", sd->bl.id);
  10418. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10419. printf("\nAccount ID %d.\n", sd->bl.id);
  10420. }
  10421. RFIFOSKIP(fd, packet_len);
  10422. return 0;
  10423. }
  10424. /*==========================================
  10425. * パケットデータベース読み込み
  10426. *------------------------------------------
  10427. */
  10428. static int packetdb_readdb(void)
  10429. {
  10430. FILE *fp;
  10431. char line[1024];
  10432. int ln=0;
  10433. int cmd,i,j,k,packet_ver;
  10434. int max_cmd=-1;
  10435. int skip_ver = 0;
  10436. int warned = 0;
  10437. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10438. int packet_len_table[0x260] = {
  10439. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10443. //#0x0040
  10444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10446. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10447. #if PACKETVER < 2
  10448. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10449. #else // 78-7b 亀島以降 lv99エフェクト用
  10450. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10451. #endif
  10452. //#0x0080
  10453. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10454. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10455. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10456. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10457. //#0x00C0
  10458. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10459. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10460. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10461. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10462. //#0x0100
  10463. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10464. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10465. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10466. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10467. //#0x0140
  10468. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10469. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10470. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10471. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10472. //#0x0180
  10473. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10474. #if PACKETVER < 1
  10475. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10476. #else // 196 comodo以降 状態表示アイコン用
  10477. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10478. #endif
  10479. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10480. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10481. //#0x01C0, Set 0x1d5=-1
  10482. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10483. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10484. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10485. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10486. //#0x0200
  10487. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10488. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282,10, 10, -1, -1, 66,
  10489. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10490. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  10491. //#0x0240
  10492. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  10493. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4, 0
  10494. };
  10495. struct {
  10496. void (*func)(int, struct map_session_data *);
  10497. char *name;
  10498. } clif_parse_func[]={
  10499. {clif_parse_WantToConnection,"wanttoconnection"},
  10500. {clif_parse_LoadEndAck,"loadendack"},
  10501. {clif_parse_TickSend,"ticksend"},
  10502. {clif_parse_WalkToXY,"walktoxy"},
  10503. {clif_parse_QuitGame,"quitgame"},
  10504. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10505. {clif_parse_GlobalMessage,"globalmessage"},
  10506. {clif_parse_MapMove,"mapmove"},
  10507. {clif_parse_ChangeDir,"changedir"},
  10508. {clif_parse_Emotion,"emotion"},
  10509. {clif_parse_HowManyConnections,"howmanyconnections"},
  10510. {clif_parse_ActionRequest,"actionrequest"},
  10511. {clif_parse_Restart,"restart"},
  10512. {clif_parse_Wis,"wis"},
  10513. {clif_parse_GMmessage,"gmmessage"},
  10514. {clif_parse_TakeItem,"takeitem"},
  10515. {clif_parse_DropItem,"dropitem"},
  10516. {clif_parse_UseItem,"useitem"},
  10517. {clif_parse_EquipItem,"equipitem"},
  10518. {clif_parse_UnequipItem,"unequipitem"},
  10519. {clif_parse_NpcClicked,"npcclicked"},
  10520. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10521. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10522. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10523. {clif_parse_CreateChatRoom,"createchatroom"},
  10524. {clif_parse_ChatAddMember,"chataddmember"},
  10525. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10526. {clif_parse_ChangeChatOwner,"changechatowner"},
  10527. {clif_parse_KickFromChat,"kickfromchat"},
  10528. {clif_parse_ChatLeave,"chatleave"},
  10529. {clif_parse_TradeRequest,"traderequest"},
  10530. {clif_parse_TradeAck,"tradeack"},
  10531. {clif_parse_TradeAddItem,"tradeadditem"},
  10532. {clif_parse_TradeOk,"tradeok"},
  10533. {clif_parse_TradeCancel,"tradecancel"},
  10534. {clif_parse_TradeCommit,"tradecommit"},
  10535. {clif_parse_StopAttack,"stopattack"},
  10536. {clif_parse_PutItemToCart,"putitemtocart"},
  10537. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10538. {clif_parse_RemoveOption,"removeoption"},
  10539. {clif_parse_ChangeCart,"changecart"},
  10540. {clif_parse_StatusUp,"statusup"},
  10541. {clif_parse_SkillUp,"skillup"},
  10542. {clif_parse_UseSkillToId,"useskilltoid"},
  10543. {clif_parse_UseSkillToPos,"useskilltopos"},
  10544. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10545. {clif_parse_UseSkillMap,"useskillmap"},
  10546. {clif_parse_RequestMemo,"requestmemo"},
  10547. {clif_parse_ProduceMix,"producemix"},
  10548. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10549. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10550. {clif_parse_NpcAmountInput,"npcamountinput"},
  10551. {clif_parse_NpcStringInput,"npcstringinput"},
  10552. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10553. {clif_parse_ItemIdentify,"itemidentify"},
  10554. {clif_parse_SelectArrow,"selectarrow"},
  10555. {clif_parse_AutoSpell,"autospell"},
  10556. {clif_parse_UseCard,"usecard"},
  10557. {clif_parse_InsertCard,"insertcard"},
  10558. {clif_parse_RepairItem,"repairitem"},
  10559. {clif_parse_WeaponRefine,"weaponrefine"},
  10560. {clif_parse_SolveCharName,"solvecharname"},
  10561. {clif_parse_ResetChar,"resetchar"},
  10562. {clif_parse_LGMmessage,"lgmmessage"},
  10563. {clif_parse_MoveToKafra,"movetokafra"},
  10564. {clif_parse_MoveFromKafra,"movefromkafra"},
  10565. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10566. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10567. {clif_parse_CloseKafra,"closekafra"},
  10568. {clif_parse_CreateParty,"createparty"},
  10569. {clif_parse_CreateParty2,"createparty2"},
  10570. {clif_parse_PartyInvite,"partyinvite"},
  10571. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10572. {clif_parse_LeaveParty,"leaveparty"},
  10573. {clif_parse_RemovePartyMember,"removepartymember"},
  10574. {clif_parse_PartyChangeOption,"partychangeoption"},
  10575. {clif_parse_PartyMessage,"partymessage"},
  10576. {clif_parse_CloseVending,"closevending"},
  10577. {clif_parse_VendingListReq,"vendinglistreq"},
  10578. {clif_parse_PurchaseReq,"purchasereq"},
  10579. {clif_parse_OpenVending,"openvending"},
  10580. {clif_parse_CreateGuild,"createguild"},
  10581. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10582. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10583. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10584. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10585. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10586. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10587. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10588. {clif_parse_GuildInvite,"guildinvite"},
  10589. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10590. {clif_parse_GuildLeave,"guildleave"},
  10591. {clif_parse_GuildExpulsion,"guildexplusion"},
  10592. {clif_parse_GuildMessage,"guildmessage"},
  10593. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10594. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10595. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10596. {clif_parse_GuildOpposition,"guildopposition"},
  10597. {clif_parse_GuildBreak,"guildbreak"},
  10598. {clif_parse_PetMenu,"petmenu"},
  10599. {clif_parse_CatchPet,"catchpet"},
  10600. {clif_parse_SelectEgg,"selectegg"},
  10601. {clif_parse_SendEmotion,"sendemotion"},
  10602. {clif_parse_ChangePetName,"changepetname"},
  10603. {clif_parse_GMKick,"gmkick"},
  10604. {clif_parse_GMHide,"gmhide"},
  10605. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10606. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10607. {clif_parse_NoviceDoriDori,"sndoridori"},
  10608. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10609. {clif_parse_PMIgnore,"wisexin"},
  10610. {clif_parse_PMIgnoreList,"wisexlist"},
  10611. {clif_parse_PMIgnoreAll,"wisall"},
  10612. {clif_parse_FriendsListAdd,"friendslistadd"},
  10613. {clif_parse_FriendsListRemove,"friendslistremove"},
  10614. {clif_parse_FriendsListReply,"friendslistreply"},
  10615. {clif_parse_GMKillAll,"killall"},
  10616. {clif_parse_Recall,"summon"},
  10617. {clif_parse_GM_Monster_Item,"itemmonster"},
  10618. {clif_parse_Shift,"shift"},
  10619. {clif_parse_Blacksmith,"blacksmith"},
  10620. {clif_parse_Alchemist,"alchemist"},
  10621. {clif_parse_Taekwon,"taekwon"},
  10622. {clif_parse_RankingPk,"rankingpk"},
  10623. {clif_parse_FeelSaveOk,"feelsaveok"},
  10624. {clif_parse_AdoptRequest,"adopt"},
  10625. {clif_parse_debug,"debug"},
  10626. //[blackhole89] //[orn]
  10627. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10628. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10629. {clif_parse_HomMoveTo,"hommoveto"},
  10630. {clif_parse_HomAttack,"homattack"},
  10631. {clif_parse_HomMenu,"hommenu"},
  10632. {NULL,NULL}
  10633. };
  10634. // Set server packet lengths - packet_db[SERVER]
  10635. memset(packet_db,0,sizeof(packet_db));
  10636. for( i = 0; i < 0x260; ++i )
  10637. packet_len(i) = packet_len_table[i];
  10638. sprintf(line, "%s/packet_db.txt", db_path);
  10639. if( (fp=fopen(line,"r"))==NULL ){
  10640. ShowFatalError("can't read %s\n", line);
  10641. exit(1);
  10642. }
  10643. clif_config.packet_db_ver = MAX_PACKET_VER;
  10644. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10645. while(fgets(line,1020,fp)){
  10646. if(line[0]=='/' && line[1]=='/')
  10647. continue;
  10648. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10649. if(strcmpi(w1,"packet_ver")==0) {
  10650. int prev_ver = packet_ver;
  10651. skip_ver = 0;
  10652. packet_ver = atoi(w2);
  10653. if ( packet_ver > MAX_PACKET_VER )
  10654. { //Check to avoid overflowing. [Skotlex]
  10655. if( (warned&1) == 0 )
  10656. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10657. warned &= 1;
  10658. skip_ver = 1;
  10659. }
  10660. else if( packet_ver < 0 )
  10661. {
  10662. if( (warned&2) == 0 )
  10663. ShowWarning("Negative packet versions are not supported.\n");
  10664. warned &= 2;
  10665. skip_ver = 1;
  10666. }
  10667. else if( packet_ver == SERVER )
  10668. {
  10669. if( (warned&4) == 0 )
  10670. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10671. warned &= 4;
  10672. skip_ver = 1;
  10673. }
  10674. if( skip_ver )
  10675. {
  10676. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10677. packet_ver = prev_ver;
  10678. continue;
  10679. }
  10680. // copy from previous version into new version and continue
  10681. // - indicating all following packets should be read into the newer version
  10682. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10683. continue;
  10684. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10685. //This is the preferred version.
  10686. if(strcmpi(w2,"default")==0)
  10687. clif_config.packet_db_ver = MAX_PACKET_VER;
  10688. else {
  10689. // to manually set the packet DB version
  10690. clif_config.packet_db_ver = atoi(w2);
  10691. // check for invalid version
  10692. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10693. clif_config.packet_db_ver < 0)
  10694. clif_config.packet_db_ver = MAX_PACKET_VER;
  10695. }
  10696. continue;
  10697. }
  10698. }
  10699. if( skip_ver != 0 )
  10700. continue; // Skipping current packet version
  10701. memset(str,0,sizeof(str));
  10702. for(j=0,p=line;j<4 && p;j++){
  10703. str[j]=p;
  10704. p=strchr(p,',');
  10705. if(p) *p++=0;
  10706. }
  10707. if(str[0]==NULL)
  10708. continue;
  10709. cmd=strtol(str[0],(char **)NULL,0);
  10710. if(max_cmd < cmd)
  10711. max_cmd = cmd;
  10712. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10713. continue;
  10714. if(str[1]==NULL){
  10715. ShowError("packet_db: packet len error\n");
  10716. continue;
  10717. }
  10718. k = atoi(str[1]);
  10719. packet_db[packet_ver][cmd].len = k;
  10720. if(str[2]==NULL){
  10721. packet_db[packet_ver][cmd].func = NULL;
  10722. ln++;
  10723. continue;
  10724. }
  10725. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10726. if(clif_parse_func[j].name != NULL &&
  10727. strcmp(str[2],clif_parse_func[j].name)==0)
  10728. {
  10729. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10730. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10731. for(i=0;i<MAX_PACKET_DB;i++){
  10732. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10733. {
  10734. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10735. break;
  10736. }
  10737. }
  10738. }
  10739. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10740. break;
  10741. }
  10742. }
  10743. // set the identifying cmd for the packet_db version
  10744. if (strcmp(str[2],"wanttoconnection")==0)
  10745. clif_config.connect_cmd[packet_ver] = cmd;
  10746. if(str[3]==NULL){
  10747. ShowError("packet_db: packet error\n");
  10748. exit(1);
  10749. }
  10750. for(j=0,p2=str[3];p2;j++){
  10751. str2[j]=p2;
  10752. p2=strchr(p2,':');
  10753. if(p2) *p2++=0;
  10754. k = atoi(str2[j]);
  10755. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10756. packet_db[packet_ver][cmd].pos[j] = k;
  10757. }
  10758. ln++;
  10759. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10760. // printf("packet_db ver %d: %d 0x%x %d %s %p\n",packet_ver,ln,cmd,packet_db[packet_ver][cmd].len,str[2],packet_db[packet_ver][cmd].func);
  10761. }
  10762. fclose(fp);
  10763. if(max_cmd > MAX_PACKET_DB)
  10764. {
  10765. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10766. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10767. }
  10768. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10769. { //Locate the nearest version that we still support. [Skotlex]
  10770. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10771. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10772. }
  10773. 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);
  10774. return 0;
  10775. }
  10776. /*==========================================
  10777. *
  10778. *------------------------------------------
  10779. */
  10780. int do_init_clif(void) {
  10781. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10782. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10783. memset(packet_db,0,sizeof(packet_db));
  10784. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10785. packetdb_readdb();
  10786. set_defaultparse(clif_parse);
  10787. if (!make_listen_bind(bind_ip,map_port)) {
  10788. ShowFatalError("cant bind game port\n");
  10789. exit(1);
  10790. }
  10791. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10792. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10793. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10794. add_timer_func_list(clif_nighttimer, "clif_nighttimer");
  10795. add_timer_func_list(clif_walktoxy_timer, "clif_walktoxy_timer");
  10796. return 0;
  10797. }