clif.c 332 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120
  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 <limits.h>
  11. #include <time.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. static const int packet_len_table[MAX_PACKET_DB] = {
  49. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  50. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  51. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  52. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  53. //#0x0040
  54. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  55. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  56. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  57. #if PACKETVER < 2
  58. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  59. #else // 78-7b 亀島以降 lv99エフェクト用
  60. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  61. #endif
  62. //#0x0080
  63. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  64. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  65. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  66. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  67. //#0x00C0
  68. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  69. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  70. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  71. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  72. //#0x0100
  73. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  74. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  75. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  76. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  77. //#0x0140
  78. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  79. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  80. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  81. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  82. //#0x0180
  83. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  84. #if PACKETVER < 1
  85. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  86. #else // 196 comodo以降 状態表示アイコン用
  87. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  88. #endif
  89. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  90. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  91. //#0x01C0, Set 0x1d5=-1
  92. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  93. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  94. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  95. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  96. //#0x200
  97. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  98. 22, 0, 26, 26, 42, -1, -1, 2, 2,282,282,10, 10, -1, -1, 66,
  99. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  100. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  101. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  102. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4
  103. };
  104. //Converts item type in case of pet eggs.
  105. #define itemtype(a) (a == 7)?4:a
  106. #define WBUFPOS(p,pos,x,y,dir) { unsigned char *__p = (p); __p+=(pos); __p[0] = (x)>>2; __p[1] = ((x)<<6) | (((y)>>4)&0x3f); __p[2] = ((y)<<4)|((dir)&0xf); }
  107. #define WBUFPOS2(p,pos,x0,y0,x1,y1) { unsigned char *__p = (p); __p+=(pos); __p[0] = (unsigned char)((x0)>>2); __p[1] = (unsigned char)(((x0)<<6) | (((y0)>>4)&0x3f)); __p[2] = (unsigned char)(((y0)<<4) | (((x1)>>6)&0x0f)); __p[3]=(unsigned char)(((x1)<<2) | (((y1)>>8)&0x03)); __p[4]=(unsigned char)(y1); }
  108. #define WFIFOPOS(fd,pos,x,y,dir) { WBUFPOS (WFIFOP(fd,pos),0,x,y,dir); }
  109. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1) { WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1); }
  110. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  111. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  112. //Removed sd->npc_shopid because there is no packet sent from the client when you cancel a buy!
  113. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  114. #define clif_cant_act(sd) (sd->npc_id || sd->vender_id || sd->chatID || sd->sc.opt1 || sd->state.trading || sd->state.storage_flag)
  115. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  116. #define clif_trading(sd) (sd->npc_id || sd->vender_id || sd->state.trading )
  117. //To idenfity disguised characters.
  118. #define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
  119. static char map_ip_str[128];
  120. static in_addr_t map_ip;
  121. static in_addr_t bind_ip = INADDR_ANY;
  122. static int map_port = 5121;
  123. int map_fd;
  124. char talkie_mes[MESSAGE_SIZE];
  125. //These two will be used to verify the incoming player's validity.
  126. //It helps identify their client packet version correctly. [Skotlex]
  127. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  128. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  129. int clif_parse (int fd);
  130. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  131. /*==========================================
  132. * map鯖のip設定
  133. *------------------------------------------
  134. */
  135. int clif_setip(char *ip)
  136. {
  137. char ip_str[16];
  138. map_ip = resolve_hostbyname(ip,NULL,ip_str);
  139. if (!map_ip) {
  140. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  141. return 0;
  142. }
  143. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  144. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str);
  145. return 1;
  146. }
  147. void clif_setbindip(char *ip)
  148. {
  149. unsigned char ip_str[4];
  150. bind_ip = resolve_hostbyname(ip,ip_str,NULL);
  151. if (bind_ip) {
  152. 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]);
  153. } else {
  154. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  155. }
  156. }
  157. /*==========================================
  158. * map鯖のport設定
  159. *------------------------------------------
  160. */
  161. void clif_setport(int port)
  162. {
  163. map_port = port;
  164. }
  165. /*==========================================
  166. * map鯖のip読み出し
  167. *------------------------------------------
  168. */
  169. in_addr_t clif_getip(void)
  170. {
  171. return map_ip;
  172. }
  173. //Returns the ip casted as a basic type, to avoid needing to include the socket/net related libs by calling modules.
  174. unsigned long clif_getip_long(void)
  175. {
  176. return (unsigned long)map_ip;
  177. }
  178. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it
  179. //returns 0.
  180. unsigned long clif_refresh_ip(void) {
  181. in_addr_t new_ip;
  182. new_ip = resolve_hostbyname(map_ip_str, NULL, NULL);
  183. if (new_ip && new_ip != map_ip) {
  184. map_ip = new_ip;
  185. ShowInfo("Updating IP resolution of [%s].\n",map_ip_str);
  186. return (unsigned long)map_ip;
  187. }
  188. return 0;
  189. }
  190. /*==========================================
  191. * map鯖のport読み出し
  192. *------------------------------------------
  193. */
  194. int clif_getport(void)
  195. {
  196. return map_port;
  197. }
  198. /*==========================================
  199. * Counts connected players.
  200. *------------------------------------------
  201. */
  202. int clif_countusers(void)
  203. {
  204. int users = 0, i;
  205. struct map_session_data *sd;
  206. for(i = 0; i < fd_max; i++) {
  207. if (session[i] && session[i]->func_parse == clif_parse &&
  208. (sd = (struct map_session_data*)session[i]->session_data) &&
  209. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  210. users++;
  211. }
  212. return users;
  213. }
  214. /*==========================================
  215. * 全てのclientに対してfunc()実行
  216. *------------------------------------------
  217. */
  218. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  219. {
  220. int i;
  221. va_list ap;
  222. struct map_session_data *sd;
  223. va_start(ap,func);
  224. for(i = 0; i < fd_max; i++) {
  225. if ( session[i] && session[i]->func_parse == clif_parse) {
  226. sd = (struct map_session_data*)session[i]->session_data;
  227. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  228. func(sd, ap);
  229. }
  230. }
  231. va_end(ap);
  232. return 0;
  233. }
  234. /*==========================================
  235. * clif_sendでAREA*指定時用
  236. *------------------------------------------
  237. */
  238. int clif_send_sub(struct block_list *bl, va_list ap)
  239. {
  240. struct block_list *src_bl;
  241. struct map_session_data *sd;
  242. unsigned char *buf;
  243. int len, type;
  244. nullpo_retr(0, bl);
  245. nullpo_retr(0, ap);
  246. nullpo_retr(0, sd = (struct map_session_data *)bl);
  247. if (!sd->fd) //Avoid attempting to send to disconnected chars (may prevent buffer overrun errors?) [Skotlex]
  248. return 0;
  249. buf = va_arg(ap,unsigned char*);
  250. len = va_arg(ap,int);
  251. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  252. type = va_arg(ap,int);
  253. switch(type) {
  254. case AREA_WOS:
  255. if (bl == src_bl)
  256. return 0;
  257. break;
  258. case AREA_WOC:
  259. if (sd->chatID || bl == src_bl)
  260. return 0;
  261. break;
  262. case AREA_WOSC:
  263. {
  264. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  265. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  266. return 0;
  267. }
  268. break;
  269. }
  270. if (session[sd->fd] != NULL) {
  271. WFIFOHEAD(sd->fd, len);
  272. if (WFIFOP(sd->fd,0) == buf) {
  273. printf("WARNING: Invalid use of clif_send function\n");
  274. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  275. printf(" Please correct your code.\n");
  276. // don't send to not move the pointer of the packet for next sessions in the loop
  277. } else {
  278. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  279. memcpy(WFIFOP(sd->fd,0), buf, len);
  280. //Check if hidden, better to modify the char's buffer than the
  281. //given buffer to prevent intravision affecting the packet as
  282. //it's being received by everyone. [Skotlex]
  283. /* New implementation... not quite correct yet as the client no longer
  284. * displays correctly the SI_INTRAVISION effect.
  285. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 )
  286. && bl != src_bl && WFIFOW(sd->fd,0) == 0x0196)
  287. { //New intravision method, just modify the status change/start packet. [Skotlex]
  288. switch (WFIFOW(sd->fd,2)) {
  289. case SI_HIDING:
  290. case SI_CLOAKING:
  291. case SI_CHASEWALK:
  292. WFIFOW(sd->fd,2) = SI_INTRAVISION;
  293. }
  294. }
  295. */
  296. // Previous implementation.
  297. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 ) && bl != src_bl) {
  298. struct status_change *sc = status_get_sc(src_bl);
  299. if(sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK)))
  300. { //optionの修正
  301. switch(((unsigned short*)buf)[0])
  302. {
  303. #if PACKETVER > 6
  304. case 0x229:
  305. WFIFOL(sd->fd,10) &= ~(OPTION_HIDE|OPTION_CLOAK);
  306. break;
  307. case 0x22a:
  308. case 0x22b:
  309. case 0x22c:
  310. WFIFOL(sd->fd,12) &=~(OPTION_HIDE|OPTION_CLOAK);
  311. break;
  312. #endif
  313. #if PACKETVER > 3
  314. case 0x119:
  315. WFIFOW(sd->fd,10) &= ~(OPTION_HIDE|OPTION_CLOAK);
  316. break;
  317. case 0x1d8:
  318. case 0x1d9:
  319. case 0x1da:
  320. #endif
  321. case 0x78:
  322. case 0x79:
  323. case 0x7a:
  324. case 0x7b:
  325. case 0x7c:
  326. WFIFOW(sd->fd,12) &=~(OPTION_HIDE|OPTION_CLOAK);
  327. break;
  328. }
  329. }
  330. }
  331. WFIFOSET(sd->fd,len);
  332. }
  333. }
  334. }
  335. return 0;
  336. }
  337. /*==========================================
  338. *
  339. *------------------------------------------
  340. */
  341. int clif_send (unsigned char *buf, int len, struct block_list *bl, int type) {
  342. int i;
  343. struct map_session_data *sd = NULL;
  344. struct party_data *p = NULL;
  345. struct guild *g = NULL;
  346. int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
  347. if (type != ALL_CLIENT &&
  348. type != CHAT_MAINCHAT) {
  349. nullpo_retr(0, bl);
  350. if (bl->type == BL_PC) {
  351. sd = (struct map_session_data *)bl;
  352. }
  353. }
  354. switch(type) {
  355. case ALL_CLIENT: //All player clients.
  356. for (i = 0; i < fd_max; i++) {
  357. if (session[i] && session[i]->func_parse == clif_parse &&
  358. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  359. sd->state.auth) {
  360. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  361. WFIFOHEAD(i, len);
  362. memcpy(WFIFOP(i,0), buf, len);
  363. WFIFOSET(i,len);
  364. }
  365. }
  366. }
  367. break;
  368. case ALL_SAMEMAP: //All players on the same map
  369. for(i = 0; i < fd_max; i++) {
  370. if (session[i] && session[i]->func_parse == clif_parse &&
  371. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  372. sd->state.auth && sd->bl.m == bl->m) {
  373. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  374. WFIFOHEAD(i,len);
  375. memcpy(WFIFOP(i,0), buf, len);
  376. WFIFOSET(i,len);
  377. }
  378. }
  379. }
  380. break;
  381. case AREA:
  382. case AREA_WOSC:
  383. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  384. clif_send (buf, len, bl, SELF);
  385. case AREA_WOC:
  386. case AREA_WOS:
  387. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  388. BL_PC, buf, len, bl, type);
  389. break;
  390. case AREA_CHAT_WOC:
  391. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  392. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  393. break;
  394. case CHAT:
  395. case CHAT_WOS:
  396. {
  397. struct chat_data *cd;
  398. if (sd) {
  399. cd = (struct chat_data*)map_id2bl(sd->chatID);
  400. } else if (bl->type == BL_CHAT) {
  401. cd = (struct chat_data*)bl;
  402. } else break;
  403. if (cd == NULL)
  404. break;
  405. for(i = 0; i < cd->users; i++) {
  406. if (type == CHAT_WOS && cd->usersd[i] == sd)
  407. continue;
  408. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  409. if (cd->usersd[i]->fd >0 && session[cd->usersd[i]->fd]) // Added check to see if session exists [PoW]
  410. {
  411. WFIFOHEAD(cd->usersd[i]->fd,len);
  412. memcpy(WFIFOP(cd->usersd[i]->fd,0), buf, len);
  413. WFIFOSET(cd->usersd[i]->fd,len);
  414. }
  415. }
  416. }
  417. }
  418. break;
  419. case CHAT_MAINCHAT: //[LuzZza]
  420. for(i=1; i<fd_max; i++) {
  421. if (session[i] && session[i]->func_parse == clif_parse &&
  422. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  423. sd->state.mainchat && sd->fd) {
  424. WFIFOHEAD(sd->fd, len);
  425. memcpy(WFIFOP(sd->fd,0), buf, len);
  426. WFIFOSET(sd->fd, len);
  427. }
  428. }
  429. break;
  430. case PARTY_AREA:
  431. case PARTY_AREA_WOS:
  432. x0 = bl->x - AREA_SIZE;
  433. y0 = bl->y - AREA_SIZE;
  434. x1 = bl->x + AREA_SIZE;
  435. y1 = bl->y + AREA_SIZE;
  436. case PARTY:
  437. case PARTY_WOS:
  438. case PARTY_SAMEMAP:
  439. case PARTY_SAMEMAP_WOS:
  440. if (sd && sd->status.party_id)
  441. p = party_search(sd->status.party_id);
  442. if (p) {
  443. for(i=0;i<MAX_PARTY;i++){
  444. if ((sd = p->data[i].sd) == NULL)
  445. continue;
  446. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  447. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  448. continue;
  449. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  450. continue;
  451. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  452. continue;
  453. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  454. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  455. continue;
  456. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  457. WFIFOHEAD(sd->fd,len);
  458. memcpy(WFIFOP(sd->fd,0), buf, len);
  459. WFIFOSET(sd->fd,len);
  460. }
  461. }
  462. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  463. break;
  464. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  465. if (session[i] && session[i]->func_parse == clif_parse &&
  466. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  467. sd->state.auth && sd->fd && sd->partyspy == p->party.party_id)
  468. {
  469. if (sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  470. WFIFOHEAD(sd->fd,len);
  471. memcpy(WFIFOP(sd->fd,0), buf, len);
  472. WFIFOSET(sd->fd,len);
  473. }
  474. }
  475. }
  476. }
  477. break;
  478. case DUEL:
  479. case DUEL_WOS:
  480. if (!sd || !sd->duel_group) break; //Invalid usage.
  481. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  482. for (i = 0; i < fd_max; i++) {
  483. if (session[i] && session[i]->func_parse == clif_parse &&
  484. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  485. sd->state.auth && sd->duel_group == x0) {
  486. if (type == DUEL_WOS && bl->id == sd->bl.id)
  487. continue;
  488. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  489. WFIFOHEAD(i, len);
  490. memcpy(WFIFOP(i,0), buf, len);
  491. WFIFOSET(i,len);
  492. }
  493. }
  494. }
  495. break;
  496. case SELF:
  497. if (sd && sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  498. WFIFOHEAD(sd->fd,len);
  499. memcpy(WFIFOP(sd->fd,0), buf, len);
  500. WFIFOSET(sd->fd,len);
  501. }
  502. break;
  503. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  504. case GUILD_AREA:
  505. case GUILD_AREA_WOS:
  506. x0 = bl->x - AREA_SIZE;
  507. y0 = bl->y - AREA_SIZE;
  508. x1 = bl->x + AREA_SIZE;
  509. y1 = bl->y + AREA_SIZE;
  510. case GUILD_SAMEMAP:
  511. case GUILD_SAMEMAP_WOS:
  512. case GUILD:
  513. case GUILD_WOS:
  514. if (sd && sd->status.guild_id)
  515. g = guild_search(sd->status.guild_id);
  516. if (g) {
  517. for(i = 0; i < g->max_member; i++) {
  518. if ((sd = g->member[i].sd) != NULL) {
  519. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  520. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  521. continue;
  522. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  523. continue;
  524. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  525. continue;
  526. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  527. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  528. continue;
  529. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  530. WFIFOHEAD(sd->fd,len);
  531. memcpy(WFIFOP(sd->fd,0), buf, len);
  532. WFIFOSET(sd->fd,len);
  533. }
  534. }
  535. }
  536. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  537. break;
  538. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  539. if (session[i] && session[i]->func_parse == clif_parse &&
  540. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  541. sd->state.auth && sd->fd && sd->guildspy == g->guild_id) {
  542. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  543. WFIFOHEAD(sd->fd,len);
  544. memcpy(WFIFOP(sd->fd,0), buf, len);
  545. WFIFOSET(sd->fd,len);
  546. }
  547. }
  548. }
  549. }
  550. break;
  551. /* End [Valaris] */
  552. default:
  553. if (battle_config.error_log)
  554. ShowError("clif_send: Unrecognized type %d\n",type);
  555. return -1;
  556. }
  557. return 0;
  558. }
  559. //
  560. // パケット作って送信
  561. //
  562. /*==========================================
  563. *
  564. *------------------------------------------
  565. */
  566. int clif_authok(struct map_session_data *sd) {
  567. int fd;
  568. if (!sd->fd)
  569. return 0;
  570. fd = sd->fd;
  571. WFIFOHEAD(fd, packet_len_table[0x73]);
  572. WFIFOW(fd, 0) = 0x73;
  573. WFIFOL(fd, 2) = gettick();
  574. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  575. WFIFOB(fd, 9) = 5;
  576. WFIFOB(fd,10) = 5;
  577. WFIFOSET(fd,packet_len_table[0x73]);
  578. return 0;
  579. }
  580. /*==========================================
  581. *
  582. *------------------------------------------
  583. */
  584. int clif_authfail_fd(int fd, int type) {
  585. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  586. return 0;
  587. WFIFOHEAD(fd, packet_len_table[0x81]);
  588. WFIFOW(fd,0) = 0x81;
  589. WFIFOB(fd,2) = type;
  590. WFIFOSET(fd,packet_len_table[0x81]);
  591. clif_setwaitclose(fd);
  592. return 0;
  593. }
  594. /*==========================================
  595. * Used to know which is the max valid account/char id [Skotlex]
  596. *------------------------------------------
  597. */
  598. void clif_updatemaxid(int account_id, int char_id)
  599. {
  600. max_account_id = account_id;
  601. max_char_id = char_id;
  602. }
  603. /*==========================================
  604. *
  605. *------------------------------------------
  606. */
  607. int clif_charselectok(int id) {
  608. struct map_session_data *sd;
  609. int fd;
  610. if ((sd = map_id2sd(id)) == NULL)
  611. return 1;
  612. if (!sd->fd)
  613. return 1;
  614. fd = sd->fd;
  615. WFIFOHEAD(fd, packet_len_table[0xb3]);
  616. WFIFOW(fd,0) = 0xb3;
  617. WFIFOB(fd,2) = 1;
  618. WFIFOSET(fd,packet_len_table[0xb3]);
  619. return 0;
  620. }
  621. /*==========================================
  622. *
  623. *------------------------------------------
  624. */
  625. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  626. int view;
  627. nullpo_retr(0, fitem);
  628. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  629. WBUFW(buf, 0) = 0x9e;
  630. WBUFL(buf, 2) = fitem->bl.id;
  631. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  632. WBUFW(buf, 6) = view;
  633. else
  634. WBUFW(buf, 6) = fitem->item_data.nameid;
  635. WBUFB(buf, 8) = fitem->item_data.identify;
  636. WBUFW(buf, 9) = fitem->bl.x;
  637. WBUFW(buf,11) = fitem->bl.y;
  638. WBUFB(buf,13) = fitem->subx;
  639. WBUFB(buf,14) = fitem->suby;
  640. WBUFW(buf,15) = fitem->item_data.amount;
  641. return packet_len_table[0x9e];
  642. }
  643. /*==========================================
  644. *
  645. *------------------------------------------
  646. */
  647. int clif_dropflooritem(struct flooritem_data *fitem) {
  648. unsigned char buf[64];
  649. nullpo_retr(0, fitem);
  650. if (fitem->item_data.nameid <= 0)
  651. return 0;
  652. clif_set009e(fitem, buf);
  653. clif_send(buf, packet_len_table[0x9e], &fitem->bl, AREA);
  654. return 0;
  655. }
  656. /*==========================================
  657. *
  658. *------------------------------------------
  659. */
  660. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  661. unsigned char buf[16];
  662. nullpo_retr(0, fitem);
  663. WBUFW(buf,0) = 0xa1;
  664. WBUFL(buf,2) = fitem->bl.id;
  665. if (fd == 0) {
  666. clif_send(buf, packet_len_table[0xa1], &fitem->bl, AREA);
  667. } else {
  668. WFIFOHEAD(fd,packet_len_table[0xa1]);
  669. memcpy(WFIFOP(fd,0), buf, 6);
  670. WFIFOSET(fd,packet_len_table[0xa1]);
  671. }
  672. return 0;
  673. }
  674. /*==========================================
  675. *
  676. *------------------------------------------
  677. */
  678. int clif_clearchar(struct block_list *bl, int type) {
  679. unsigned char buf[16];
  680. nullpo_retr(0, bl);
  681. WBUFW(buf,0) = 0x80;
  682. WBUFL(buf,2) = bl->id;
  683. WBUFB(buf,6) = type;
  684. clif_send(buf, packet_len_table[0x80], bl, type == 1 ? AREA : AREA_WOS);
  685. if(disguised(bl)) {
  686. WBUFL(buf,2) = -bl->id;
  687. clif_send(buf, packet_len_table[0x80], bl, SELF);
  688. }
  689. return 0;
  690. }
  691. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  692. struct block_list *bl = (struct block_list *)id;
  693. clif_clearchar(bl,data);
  694. aFree(bl);
  695. return 0;
  696. }
  697. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  698. struct block_list *tbl;
  699. tbl = aMalloc(sizeof (struct block_list));
  700. memcpy (tbl, bl, sizeof (struct block_list));
  701. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  702. return 0;
  703. }
  704. /*==========================================
  705. *
  706. *------------------------------------------
  707. */
  708. int clif_clearchar_id(int id, int type, int fd) {
  709. WFIFOHEAD(fd, packet_len_table[0x80]);
  710. WFIFOW(fd,0) = 0x80;
  711. WFIFOL(fd,2) = id;
  712. WFIFOB(fd,6) = (char)type; // Why use int for a char in the first place?
  713. WFIFOSET(fd, packet_len_table[0x80]);
  714. return 0;
  715. }
  716. void clif_get_weapon_view(TBL_PC* sd, unsigned short *rhand, unsigned short *lhand)
  717. {
  718. #if PACKETVER > 3
  719. struct item_data *id;
  720. #endif
  721. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  722. {
  723. *rhand = *lhand = 0;
  724. return;
  725. }
  726. #if PACKETVER < 4
  727. *rhand = sd->status.weapon;
  728. *lhand = sd->status.shield;
  729. #else
  730. if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]])
  731. {
  732. id = sd->inventory_data[sd->equip_index[9]];
  733. if (id->view_id > 0)
  734. *rhand = id->view_id;
  735. else
  736. *rhand = id->nameid;
  737. } else
  738. *rhand = 0;
  739. if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
  740. && sd->inventory_data[sd->equip_index[8]])
  741. {
  742. id = sd->inventory_data[sd->equip_index[8]];
  743. if (id->view_id > 0)
  744. *lhand = id->view_id;
  745. else
  746. *lhand = id->nameid;
  747. } else
  748. *lhand = 0;
  749. #endif
  750. }
  751. static void clif_get_guild_data(struct block_list *bl, long *guild_id, short *emblem_id)
  752. {
  753. //TODO: There has to be a way to clean this up.
  754. switch (bl->type) {
  755. case BL_PC:
  756. *guild_id = ((TBL_PC*)bl)->status.guild_id;
  757. *emblem_id = ((TBL_PC*)bl)->guild_emblem_id;
  758. break;
  759. case BL_MOB:
  760. if (((TBL_MOB*)bl)->guardian_data) {
  761. *guild_id =((TBL_MOB*)bl)->guardian_data->guild_id;
  762. *emblem_id =((TBL_MOB*)bl)->guardian_data->emblem_id;
  763. }
  764. break;
  765. case BL_NPC:
  766. if (bl->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) {
  767. struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id);
  768. if (g) {
  769. *guild_id =g->guild_id;
  770. *emblem_id =g->emblem_id;
  771. }
  772. }
  773. break;
  774. default:
  775. *guild_id = status_get_guild_id(bl);
  776. }
  777. return;
  778. }
  779. /*==========================================
  780. *
  781. *------------------------------------------
  782. */
  783. static int clif_set0078(struct block_list *bl, struct view_data *vd, unsigned char *buf) {
  784. struct status_change *sc;
  785. struct map_session_data *sd;
  786. long guild_id=0;
  787. unsigned short emblem_id=0, lv;
  788. unsigned short dir;
  789. nullpo_retr(0, bl);
  790. BL_CAST(BL_PC, bl, sd);
  791. sc = status_get_sc(bl);
  792. clif_get_guild_data(bl, &guild_id, &emblem_id);
  793. dir = unit_getdir(bl);
  794. lv = status_get_lv(bl);
  795. if(pcdb_checkid(vd->class_)) {
  796. #if PACKETVER > 6
  797. malloc_set(buf,0,packet_len_table[0x22a]);
  798. WBUFW(buf,0)=0x22a;
  799. WBUFL(buf,2)=bl->id;
  800. WBUFW(buf,6)=status_get_speed(bl);
  801. if (sc) {
  802. WBUFW(buf,8)=sc->opt1;
  803. WBUFW(buf,10)=sc->opt2;
  804. WBUFL(buf,12)=sc->option;
  805. WBUFL(buf,44)=sc->opt3;
  806. }
  807. WBUFW(buf,16)=vd->class_;
  808. WBUFW(buf,18)=vd->hair_style;
  809. WBUFW(buf,20)=vd->weapon;
  810. WBUFW(buf,22)=vd->shield;
  811. WBUFW(buf,24)=vd->head_bottom;
  812. WBUFW(buf,26)=vd->head_top;
  813. WBUFW(buf,28)=vd->head_mid;
  814. WBUFW(buf,30)=vd->hair_color;
  815. WBUFW(buf,32)=vd->cloth_color;
  816. WBUFW(buf,34)=sd?sd->head_dir:dir;
  817. WBUFL(buf,36)=guild_id;
  818. WBUFW(buf,40)=emblem_id;
  819. if (sd) {
  820. WBUFW(buf,42)=sd->status.manner;
  821. WBUFB(buf,48)=sd->status.karma;
  822. }
  823. WBUFB(buf,49)=vd->sex;
  824. WBUFPOS(buf,50,bl->x,bl->y,dir);
  825. WBUFB(buf,53)=5;
  826. WBUFB(buf,54)=5;
  827. WBUFB(buf,55)=vd->dead_sit;
  828. WBUFW(buf,56)=clif_setlevel(lv);
  829. return packet_len_table[0x22a];
  830. #elif PACKETVER > 3
  831. malloc_set(buf,0,packet_len_table[0x1d8]);
  832. WBUFW(buf,0)=0x1d8;
  833. WBUFL(buf,2)=bl->id;
  834. WBUFW(buf,6)=status_get_speed(bl);
  835. if (sc) {
  836. WBUFW(buf,8)=sc->opt1;
  837. WBUFW(buf,10)=sc->opt2;
  838. WBUFW(buf,12)=sc->option;
  839. WBUFW(buf,42)=sc->opt3;
  840. }
  841. WBUFW(buf,14)=vd->class_;
  842. WBUFW(buf,16)=vd->hair_style;
  843. WBUFW(buf,18)=vd->weapon;
  844. WBUFW(buf,20)=vd->shield;
  845. WBUFW(buf,22)=vd->head_bottom;
  846. WBUFW(buf,24)=vd->head_top;
  847. WBUFW(buf,26)=vd->head_mid;
  848. WBUFW(buf,28)=vd->hair_color;
  849. WBUFW(buf,30)=vd->cloth_color;
  850. WBUFW(buf,32)=sd?sd->head_dir:dir;
  851. WBUFL(buf,34)=guild_id;
  852. WBUFW(buf,38)=emblem_id;
  853. if (sd) {
  854. WBUFW(buf,40)=sd->status.manner;
  855. WBUFB(buf,44)=sd->status.karma;
  856. }
  857. WBUFB(buf,45)=vd->sex;
  858. WBUFPOS(buf,46,bl->x,bl->y,dir);
  859. WBUFB(buf,49)=5;
  860. WBUFB(buf,50)=5;
  861. WBUFB(buf,51)=vd->dead_sit;
  862. WBUFW(buf,52)=clif_setlevel(lv);
  863. return packet_len_table[0x1d8];
  864. #else
  865. malloc_set(buf,0,packet_len_table[0x78]);
  866. WBUFW(buf,0)=0x78;
  867. WBUFL(buf,2)=bl->id;
  868. WBUFW(buf,6)=status_get_speed(bl);
  869. if (sc) {
  870. WBUFW(buf,8)=sc->opt1;
  871. WBUFW(buf,10)=sc->opt2;
  872. WBUFW(buf,12)=sc->option;
  873. WBUFW(buf,42)=sc->opt3;
  874. }
  875. WBUFW(buf,14)=vd->class_;
  876. WBUFW(buf,16)=vd->hair_style;
  877. WBUFW(buf,18)=vd->weapon;
  878. WBUFW(buf,20)=vd->head_bottom;
  879. WBUFW(buf,22)=vd->shield;
  880. WBUFW(buf,24)=vd->head_top;
  881. WBUFW(buf,26)=vd->head_mid;
  882. WBUFW(buf,28)=vd->hair_color;
  883. WBUFW(buf,30)=vd->cloth_color;
  884. WBUFW(buf,32)=sd?sd->head_dir:dir;
  885. WBUFL(buf,34)=guild_id;
  886. WBUFL(buf,38)=emblem_id;
  887. if (sd)
  888. WBUFB(buf,44)=sd->status.karma;
  889. WBUFB(buf,45)=vd->sex;
  890. WBUFPOS(buf,46,bl->x,bl->y,dir);
  891. WBUFB(buf,49)=5;
  892. WBUFB(buf,50)=5;
  893. WBUFB(buf,51)=vd->dead_sit;
  894. WBUFW(buf,52)=clif_setlevel(lv);
  895. return packet_len_table[0x78];
  896. #endif
  897. }
  898. //Non-player sprites need just a few fields filled.
  899. malloc_set(buf,0,packet_len_table[0x78]);
  900. WBUFW(buf,0)=0x78;
  901. WBUFL(buf,2)=bl->id;
  902. WBUFW(buf,6)=status_get_speed(bl);
  903. if (sc) {
  904. WBUFW(buf,8)=sc->opt1;
  905. WBUFW(buf,10)=sc->opt2;
  906. WBUFW(buf,12)=sc->option;
  907. WBUFW(buf,42)=sc->opt3;
  908. }
  909. WBUFW(buf,14)=vd->class_;
  910. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  911. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  912. if (bl->type == BL_NPC && vd->class_ == 722)
  913. { //The hell, why flags work like this?
  914. WBUFL(buf,22)=emblem_id;
  915. WBUFL(buf,26)=guild_id;
  916. }
  917. WBUFW(buf,32)=dir;
  918. WBUFL(buf,34)=guild_id;
  919. WBUFL(buf,38)=emblem_id;
  920. WBUFPOS(buf,46,bl->x,bl->y,dir);
  921. WBUFB(buf,49)=5;
  922. WBUFB(buf,50)=5;
  923. WBUFW(buf,52)=clif_setlevel(lv);
  924. return packet_len_table[0x78];
  925. }
  926. /*==========================================
  927. *
  928. *------------------------------------------
  929. */
  930. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf) {
  931. struct status_change *sc;
  932. struct map_session_data *sd;
  933. long guild_id=0;
  934. unsigned short emblem_id=0, lv;
  935. nullpo_retr(0, bl);
  936. BL_CAST(BL_PC, bl, sd);
  937. sc = status_get_sc(bl);
  938. clif_get_guild_data(bl, &guild_id, &emblem_id);
  939. lv = status_get_lv(bl);
  940. if(pcdb_checkid(vd->class_)) {
  941. #if PACKETVER > 6
  942. malloc_set(buf,0,packet_len_table[0x22c]);
  943. WBUFW(buf,0)=0x22c;
  944. WBUFL(buf,2)=bl->id;
  945. WBUFW(buf,6)=status_get_speed(bl);
  946. if (sc) {
  947. WBUFW(buf,8)= sc->opt1;
  948. WBUFW(buf,10)= sc->opt2;
  949. WBUFL(buf,12)= sc->option;
  950. WBUFL(buf,48)= sc->opt3;
  951. }
  952. WBUFW(buf,16)=vd->class_;
  953. WBUFW(buf,18)=vd->hair_style;
  954. WBUFW(buf,20)=vd->weapon;
  955. WBUFW(buf,22)=vd->shield;
  956. WBUFW(buf,24)=vd->head_bottom;
  957. WBUFL(buf,26)=gettick();
  958. WBUFW(buf,30)=vd->head_top;
  959. WBUFW(buf,32)=vd->head_mid;
  960. WBUFW(buf,34)=vd->hair_color;
  961. WBUFW(buf,36)=vd->cloth_color;
  962. WBUFW(buf,38)=sd?sd->head_dir:unit_getdir(bl);
  963. WBUFL(buf,40)=guild_id;
  964. WBUFW(buf,44)=emblem_id;
  965. if (sd) {
  966. WBUFW(buf,46)=sd->status.manner;
  967. WBUFB(buf,52)=sd->status.karma;
  968. }
  969. WBUFB(buf,53)=vd->sex;
  970. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  971. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  972. WBUFB(buf,60)=0;
  973. WBUFB(buf,61)=0;
  974. WBUFW(buf,62)=clif_setlevel(lv);
  975. return packet_len_table[0x22c];
  976. #elif PACKETVER > 3
  977. malloc_set(buf,0,packet_len_table[0x1da]);
  978. WBUFW(buf,0)=0x1da;
  979. WBUFL(buf,2)=bl->id;
  980. WBUFW(buf,6)=status_get_speed(bl);
  981. if (sc) {
  982. WBUFW(buf,8)=sc->opt1;
  983. WBUFW(buf,10)=sc->opt2;
  984. WBUFW(buf,12)=sc->option;
  985. WBUFW(buf,46)=sc->opt3;
  986. }
  987. WBUFW(buf,14)=vd->class_;
  988. WBUFW(buf,16)=vd->hair_style;
  989. WBUFW(buf,18)=vd->weapon;
  990. WBUFW(buf,20)=vd->shield;
  991. WBUFW(buf,22)=vd->head_bottom;
  992. WBUFL(buf,24)=gettick();
  993. WBUFW(buf,28)=vd->head_top;
  994. WBUFW(buf,30)=vd->head_mid;
  995. WBUFW(buf,32)=vd->hair_color;
  996. WBUFW(buf,34)=vd->cloth_color;
  997. WBUFW(buf,36)=sd?sd->head_dir:unit_getdir(bl);
  998. WBUFL(buf,38)=guild_id;
  999. WBUFW(buf,42)=emblem_id;
  1000. if (sd) {
  1001. WBUFW(buf,44)=sd->status.manner;
  1002. WBUFB(buf,48)=sd->status.karma;
  1003. }
  1004. WBUFB(buf,49)=vd->sex;
  1005. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1006. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1007. WBUFB(buf,56)=5;
  1008. WBUFB(buf,57)=5;
  1009. WBUFW(buf,58)=clif_setlevel(lv);
  1010. return packet_len_table[0x1da];
  1011. #else
  1012. malloc_set(buf,0,packet_len_table[0x7b]);
  1013. WBUFW(buf,0)=0x7b;
  1014. WBUFL(buf,2)=bl->id;
  1015. WBUFW(buf,6)=status_get_speed(bl);
  1016. if (sc) {
  1017. WBUFW(buf,8)=sc->opt1;
  1018. WBUFW(buf,10)=sc->opt2;
  1019. WBUFW(buf,12)=sc->option;
  1020. WBUFW(buf,46)=sc->opt3;
  1021. }
  1022. WBUFW(buf,14)=vd->class_;
  1023. WBUFW(buf,16)=vd->hair_style;
  1024. WBUFW(buf,18)=vd->weapon;
  1025. WBUFW(buf,20)=vd->head_bottom;
  1026. WBUFL(buf,22)=gettick();
  1027. WBUFW(buf,26)=vd->shield;
  1028. WBUFW(buf,28)=vd->head_top;
  1029. WBUFW(buf,30)=vd->head_mid;
  1030. WBUFW(buf,32)=vd->hair_color;
  1031. WBUFW(buf,34)=vd->cloth_color;
  1032. WBUFW(buf,36)=sd?sd->head_dir:unit_getdir(bl);
  1033. WBUFL(buf,38)=guild_id;
  1034. WBUFL(buf,42)=emblem_id;
  1035. if (sd)
  1036. WBUFB(buf,48)=sd->status.karma;
  1037. WBUFB(buf,49)=vd->sex;
  1038. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1039. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1040. WBUFB(buf,56)=5;
  1041. WBUFB(buf,57)=5;
  1042. WBUFW(buf,58)=clif_setlevel(lv);
  1043. return packet_len_table[0x7b];
  1044. #endif
  1045. }
  1046. //Non-player sprites only require a few fields.
  1047. #if PACKETVER > 6
  1048. malloc_set(buf,0,packet_len_table[0x22c]);
  1049. WBUFW(buf,0)=0x22c;
  1050. WBUFL(buf,2)=bl->id;
  1051. WBUFW(buf,6)=status_get_speed(bl);
  1052. if (sc) {
  1053. WBUFW(buf,8)=sc->opt1;
  1054. WBUFW(buf,10)=sc->opt2;
  1055. WBUFL(buf,12)=sc->option;
  1056. WBUFL(buf,48)=sc->opt3;
  1057. }
  1058. WBUFW(buf,16)=vd->class_;
  1059. WBUFW(buf,18)=vd->hair_style; //For pets
  1060. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  1061. WBUFL(buf,26)=gettick();
  1062. WBUFW(buf,38)=unit_getdir(bl);
  1063. WBUFL(buf,40)=guild_id;
  1064. WBUFL(buf,44)=emblem_id;
  1065. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  1066. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  1067. WBUFB(buf,60)=0;
  1068. WBUFB(buf,61)=0;
  1069. WBUFW(buf,62)=clif_setlevel(lv);
  1070. return packet_len_table[0x22c];
  1071. #else
  1072. malloc_set(buf,0,packet_len_table[0x7b]);
  1073. WBUFW(buf,0)=0x7b;
  1074. WBUFL(buf,2)=bl->id;
  1075. WBUFW(buf,6)=status_get_speed(bl);
  1076. if (sc) {
  1077. WBUFW(buf,8)=sc->opt1;
  1078. WBUFW(buf,10)=sc->opt2;
  1079. WBUFW(buf,12)=sc->option;
  1080. WBUFW(buf,46)=sc->opt3;
  1081. }
  1082. WBUFW(buf,14)=vd->class_;
  1083. WBUFW(buf,16)=vd->hair_style; //For pets
  1084. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  1085. WBUFL(buf,22)=gettick();
  1086. WBUFW(buf,36)=unit_getdir(bl);
  1087. WBUFL(buf,38)=guild_id;
  1088. WBUFL(buf,42)=emblem_id;
  1089. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1090. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1091. WBUFB(buf,56)=5;
  1092. WBUFB(buf,57)=5;
  1093. WBUFW(buf,58)=clif_setlevel(lv);
  1094. return packet_len_table[0x7b];
  1095. #endif
  1096. }
  1097. //Modifies the buffer for disguise characters and sends it to self.
  1098. //Flag = 0: change id to negative, buf will have disguise data.
  1099. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1100. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1101. //But no longer holds true for those packet of PACKETVER 7.
  1102. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag) {
  1103. if (flag) {
  1104. #if PACKETVER > 6
  1105. switch (WBUFW(buf,0)) {
  1106. case 0x22c:
  1107. case 0x22b:
  1108. case 0x22a:
  1109. WBUFL(buf,12)=OPTION_INVISIBLE;
  1110. WBUFW(buf,16)=sd->status.class_;
  1111. break;
  1112. default:
  1113. #endif
  1114. WBUFL(buf,2)=sd->bl.id;
  1115. WBUFW(buf,12)=OPTION_INVISIBLE;
  1116. WBUFW(buf,14)=sd->status.class_;
  1117. #if PACKETVER > 6
  1118. break;
  1119. }
  1120. #endif
  1121. } else {
  1122. WBUFL(buf,2)=-sd->bl.id;
  1123. }
  1124. clif_send(buf, len, &sd->bl, SELF);
  1125. }
  1126. /*==========================================
  1127. * クラスチェンジ typeはMobの場合は1で他は0?
  1128. *------------------------------------------
  1129. */
  1130. int clif_class_change(struct block_list *bl,int class_,int type)
  1131. {
  1132. unsigned char buf[16];
  1133. nullpo_retr(0, bl);
  1134. if(!pcdb_checkid(class_)) {
  1135. WBUFW(buf,0)=0x1b0;
  1136. WBUFL(buf,2)=bl->id;
  1137. WBUFB(buf,6)=type;
  1138. WBUFL(buf,7)=class_;
  1139. clif_send(buf,packet_len_table[0x1b0],bl,AREA);
  1140. }
  1141. return 0;
  1142. }
  1143. /*==========================================
  1144. *
  1145. *------------------------------------------
  1146. */
  1147. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1148. {
  1149. WFIFOHEAD(fd, packet_len_table[0x1e1]);
  1150. WFIFOW(fd,0)=0x1e1;
  1151. WFIFOL(fd,2)=sd->bl.id;
  1152. WFIFOW(fd,6)=sd->spiritball;
  1153. WFIFOSET(fd, packet_len_table[0x1e1]);
  1154. }
  1155. /*==========================================
  1156. *
  1157. *------------------------------------------
  1158. */
  1159. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1160. WFIFOHEAD(fd, packet_len_table[0x192]);
  1161. WFIFOW(fd,0) = 0x192;
  1162. WFIFOW(fd,2) = x;
  1163. WFIFOW(fd,4) = y;
  1164. WFIFOW(fd,6) = type;
  1165. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1166. WFIFOSET(fd,packet_len_table[0x192]);
  1167. return 0;
  1168. }
  1169. // new and improved weather display [Valaris]
  1170. static void clif_weather_sub(int fd, int id, int type) {
  1171. WFIFOHEAD(fd, packet_len_table[0x1f3]);
  1172. WFIFOW(fd,0) = 0x1f3;
  1173. WFIFOL(fd,2) = id;
  1174. WFIFOL(fd,6) = type;
  1175. WFIFOSET(fd,packet_len_table[0x1f3]);
  1176. }
  1177. /*==========================================
  1178. *
  1179. *------------------------------------------
  1180. */
  1181. static void clif_weather_check(struct map_session_data *sd) {
  1182. int m = sd->bl.m, fd = sd->fd;
  1183. if (map[m].flag.snow
  1184. || map[m].flag.clouds
  1185. || map[m].flag.fog
  1186. || map[m].flag.fireworks
  1187. || map[m].flag.sakura
  1188. || map[m].flag.leaves
  1189. || map[m].flag.rain
  1190. || map[m].flag.clouds2)
  1191. {
  1192. if (map[m].flag.snow)
  1193. clif_weather_sub(fd, sd->bl.id, 162);
  1194. if (map[m].flag.clouds)
  1195. clif_weather_sub(fd, sd->bl.id, 233);
  1196. if (map[m].flag.clouds2)
  1197. clif_weather_sub(fd, sd->bl.id, 516);
  1198. if (map[m].flag.fog)
  1199. clif_weather_sub(fd, sd->bl.id, 515);
  1200. if (map[m].flag.fireworks) {
  1201. clif_weather_sub(fd, sd->bl.id, 297);
  1202. clif_weather_sub(fd, sd->bl.id, 299);
  1203. clif_weather_sub(fd, sd->bl.id, 301);
  1204. }
  1205. if (map[m].flag.sakura)
  1206. clif_weather_sub(fd, sd->bl.id, 163);
  1207. if (map[m].flag.leaves)
  1208. clif_weather_sub(fd, sd->bl.id, 333);
  1209. if (map[m].flag.rain)
  1210. clif_weather_sub(fd, sd->bl.id, 161);
  1211. }
  1212. }
  1213. int clif_weather(int m) {
  1214. int i;
  1215. struct map_session_data *sd=NULL;
  1216. for(i = 0; i < fd_max; i++) {
  1217. if (session[i] && session[i]->func_parse == clif_parse &&
  1218. (sd = session[i]->session_data) != NULL &&
  1219. sd->state.auth && sd->bl.m == m) {
  1220. clif_weather_check(sd);
  1221. }
  1222. }
  1223. return 0;
  1224. }
  1225. int clif_spawn(struct block_list *bl)
  1226. {
  1227. unsigned char buf[128];
  1228. struct view_data *vd;
  1229. nullpo_retr(0, bl);
  1230. vd = status_get_viewdata(bl);
  1231. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1232. return 0;
  1233. if (pcdb_checkid(vd->class_))
  1234. { //Player spawn packet.
  1235. clif_set0078(bl, vd, buf);
  1236. switch(WBUFW(buf,0)) {
  1237. case 0x78: //Convert to 0x79
  1238. WBUFW(buf, 0) = 0x79;
  1239. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1240. clif_send(buf, packet_len_table[0x79], bl, AREA_WOS);
  1241. if (disguised(bl))
  1242. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x79], 0);
  1243. break;
  1244. #if PACKETVER > 3
  1245. case 0x1d8: //Convert to 0x1d9
  1246. WBUFW(buf, 0) = 0x1d9;
  1247. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1248. clif_send(buf, packet_len_table[0x1d9], bl, AREA_WOS);
  1249. if (disguised(bl))
  1250. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x1d9], 0);
  1251. break;
  1252. #endif
  1253. #if PACKETVER > 6
  1254. case 0x22a: //Convert to 0x22b
  1255. WBUFW(buf, 0) = 0x22b;
  1256. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1257. clif_send(buf, packet_len_table[0x22b], bl, AREA_WOS);
  1258. if (disguised(bl))
  1259. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x22b], 0);
  1260. break;
  1261. #endif
  1262. }
  1263. } else { //Mob spawn packet.
  1264. struct status_change *sc = status_get_sc(bl);
  1265. malloc_tsetdword(buf,0,sizeof(buf));
  1266. WBUFW(buf,0)=0x7c;
  1267. WBUFL(buf,2)=bl->id;
  1268. WBUFW(buf,6)=status_get_speed(bl);
  1269. if (sc) {
  1270. WBUFW(buf,8)=sc->opt1;
  1271. WBUFW(buf,10)=sc->opt2;
  1272. WBUFW(buf,12)=sc->option;
  1273. }
  1274. WBUFW(buf,20)=vd->class_;
  1275. WBUFW(buf,22)=vd->hair_style; //Required for pets.
  1276. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  1277. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1278. clif_send(buf,packet_len_table[0x7c],bl,AREA_WOS);
  1279. if (disguised(bl)) {
  1280. WBUFL(buf,2)=-bl->id;
  1281. clif_send(buf,packet_len_table[0x7c],bl,SELF);
  1282. }
  1283. }
  1284. if (vd->cloth_color)
  1285. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1286. switch (bl->type)
  1287. {
  1288. case BL_PC:
  1289. {
  1290. TBL_PC *sd = ((TBL_PC*)bl);
  1291. if (sd->spiritball > 0)
  1292. clif_spiritball(sd);
  1293. if(sd->state.size==2) // tiny/big players [Valaris]
  1294. clif_specialeffect(bl,423,AREA);
  1295. else if(sd->state.size==1)
  1296. clif_specialeffect(bl,421,AREA);
  1297. }
  1298. break;
  1299. case BL_MOB:
  1300. {
  1301. TBL_MOB *md = ((TBL_MOB*)bl);
  1302. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1303. clif_specialeffect(&md->bl,423,AREA);
  1304. else if(md->special_state.size==1)
  1305. clif_specialeffect(&md->bl,421,AREA);
  1306. }
  1307. break;
  1308. }
  1309. return 0;
  1310. }
  1311. //[orn]
  1312. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1313. {
  1314. struct status_data *status;
  1315. unsigned char buf[128];
  1316. nullpo_retr(0, hd);
  1317. status = &hd->battle_status;
  1318. malloc_set(buf,0,packet_len_table[0x22e]);
  1319. WBUFW(buf,0)=0x22e;
  1320. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1321. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1322. WBUFB(buf,26)=hd->homunculus.rename_flag | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1323. WBUFW(buf,27)=hd->homunculus.level;
  1324. WBUFW(buf,29)=hd->homunculus.hunger;
  1325. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1326. WBUFW(buf,33)=0; // equip id
  1327. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1328. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1329. WBUFW(buf,39)=status->hit;
  1330. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1331. WBUFW(buf,43)=status->def + status->vit ;
  1332. WBUFW(buf,45)=status->mdef;
  1333. WBUFW(buf,47)=status->flee;
  1334. WBUFW(buf,49)=(flag)?0:status->amotion;
  1335. if (status->max_hp > SHRT_MAX) {
  1336. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1337. WBUFW(buf,53) = 100;
  1338. } else {
  1339. WBUFW(buf,51)=status->hp;
  1340. WBUFW(buf,53)=status->max_hp;
  1341. }
  1342. if (status->max_sp > SHRT_MAX) {
  1343. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1344. WBUFW(buf,57) = 100;
  1345. } else {
  1346. WBUFW(buf,55)=status->sp;
  1347. WBUFW(buf,57)=status->max_sp;
  1348. }
  1349. WBUFL(buf,59)=hd->homunculus.exp;
  1350. WBUFL(buf,63)=hd->exp_next;
  1351. WBUFW(buf,67)=hd->homunculus.skillpts;
  1352. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1353. clif_send(buf,packet_len_table[0x22e],&sd->bl,SELF);
  1354. return 0;
  1355. }
  1356. void clif_send_homdata(struct map_session_data *sd, int type, int param) { //[orn]
  1357. int fd;
  1358. nullpo_retv(sd);
  1359. nullpo_retv(sd->hd);
  1360. fd=sd->fd;
  1361. WFIFOW(fd,0)=0x230;
  1362. WFIFOW(fd,2)=type;
  1363. WFIFOL(fd,4)=sd->hd->bl.id;
  1364. WFIFOL(fd,8)=param;
  1365. WFIFOSET(fd,packet_len_table[0x230]);
  1366. return;
  1367. }
  1368. int clif_homskillinfoblock(struct map_session_data *sd) { //[orn]
  1369. struct homun_data *hd;
  1370. int fd;
  1371. int i,j,len=4,id;
  1372. nullpo_retr(0, sd);
  1373. hd = sd->hd;
  1374. if ( !hd )
  1375. return 0 ;
  1376. fd=sd->fd;
  1377. WFIFOW(fd,0)=0x235;
  1378. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1379. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1380. j = id - HM_SKILLBASE - 1 ;
  1381. WFIFOW(fd,len ) = id ;
  1382. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1383. WFIFOW(fd,len+4) = 0 ;
  1384. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1385. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1386. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1387. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1388. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1389. len+=37;
  1390. }
  1391. }
  1392. WFIFOW(fd,2)=len;
  1393. WFIFOSET(fd,len);
  1394. return 0;
  1395. }
  1396. void clif_homskillup(struct map_session_data *sd, int skill_num) { //[orn]
  1397. struct homun_data *hd;
  1398. int fd,skillid;
  1399. nullpo_retv(sd);
  1400. skillid = skill_num - HM_SKILLBASE - 1;
  1401. fd=sd->fd;
  1402. hd=sd->hd;
  1403. WFIFOW(fd,0) = 0x239;
  1404. WFIFOW(fd,2) = skill_num;
  1405. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1406. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1407. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1408. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1409. WFIFOSET(fd,packet_len_table[0x239]);
  1410. return;
  1411. }
  1412. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd) { //[orn]
  1413. struct homun_data *hd;
  1414. nullpo_retv(sd);
  1415. if((hd=sd->hd) == NULL)
  1416. return;
  1417. RFIFOHEAD(fd);
  1418. memcpy(hd->homunculus.name,RFIFOP(fd,2),24);
  1419. hd->homunculus.rename_flag = 1;
  1420. clif_hominfo(sd,hd,0);
  1421. clif_charnameack(sd->fd,&hd->bl);
  1422. }
  1423. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd) { //[orn]
  1424. nullpo_retv(sd);
  1425. if(!merc_is_hom_active(sd->hd))
  1426. return;
  1427. if (!unit_can_move(&sd->hd->bl))
  1428. return;
  1429. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 0);
  1430. }
  1431. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd) { //[orn]
  1432. int x,y,cmd;
  1433. nullpo_retv(sd);
  1434. if(!merc_is_hom_active(sd->hd))
  1435. return;
  1436. cmd = RFIFOW(fd,0);
  1437. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  1438. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  1439. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  1440. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  1441. if (!unit_can_move(&sd->hd->bl))
  1442. return;
  1443. unit_walktoxy(&(sd->hd->bl),x,y,0);
  1444. }
  1445. void clif_parse_HomAttack(int fd,struct map_session_data *sd) { //[orn]
  1446. struct block_list *target;
  1447. nullpo_retv(sd);
  1448. if(!merc_is_hom_active(sd->hd))
  1449. return;
  1450. if ((target = map_id2bl(RFIFOL(fd,6))) == NULL || status_isdead(target))
  1451. return;
  1452. merc_stop_walking(sd->hd, 1);
  1453. merc_stop_attack(sd->hd);
  1454. unit_attack(&sd->hd->bl,RFIFOL(fd,6),1) ;
  1455. }
  1456. void clif_parse_HomMenu(int fd, struct map_session_data *sd) { //[orn]
  1457. int cmd;
  1458. RFIFOHEAD(fd);
  1459. cmd = RFIFOW(fd,0);
  1460. if(!merc_is_hom_active(sd->hd))
  1461. return;
  1462. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  1463. }
  1464. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1465. {
  1466. int fd;
  1467. nullpo_retr(0, sd);
  1468. fd=sd->fd;
  1469. WFIFOHEAD(fd,packet_len_table[0x22f]);
  1470. WFIFOW(fd,0)=0x22f;
  1471. WFIFOB(fd,2)=fail;
  1472. WFIFOW(fd,3)=foodid;
  1473. WFIFOSET(fd,packet_len_table[0x22f]);
  1474. return 0;
  1475. }
  1476. /*==========================================
  1477. *
  1478. *------------------------------------------
  1479. */
  1480. int clif_walkok(struct map_session_data *sd)
  1481. {
  1482. int fd;
  1483. nullpo_retr(0, sd);
  1484. fd=sd->fd;
  1485. WFIFOHEAD(fd, packet_len_table[0x87]);
  1486. WFIFOW(fd,0)=0x87;
  1487. WFIFOL(fd,2)=gettick();
  1488. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1489. WFIFOB(fd,11)=0x88;
  1490. WFIFOSET(fd,packet_len_table[0x87]);
  1491. return 0;
  1492. }
  1493. /*==========================================
  1494. *
  1495. *------------------------------------------
  1496. */
  1497. int clif_movepc(struct map_session_data *sd) {
  1498. unsigned char buf[256];
  1499. nullpo_retr(0, sd);
  1500. if (map[sd->bl.m].flag.snow
  1501. || map[sd->bl.m].flag.clouds
  1502. || map[sd->bl.m].flag.fog
  1503. || map[sd->bl.m].flag.fireworks
  1504. || map[sd->bl.m].flag.sakura
  1505. || map[sd->bl.m].flag.leaves
  1506. || map[sd->bl.m].flag.rain
  1507. || map[sd->bl.m].flag.clouds2
  1508. ) {
  1509. malloc_set(buf,0,packet_len_table[0x7b]);
  1510. WBUFW(buf,0)=0x7b;
  1511. WBUFL(buf,2)=-10;
  1512. WBUFW(buf,6)=sd->battle_status.speed;
  1513. WBUFW(buf,8)=0;
  1514. WBUFW(buf,10)=0;
  1515. WBUFW(buf,12)=OPTION_INVISIBLE;
  1516. WBUFW(buf,14)=100;
  1517. WBUFL(buf,22)=gettick();
  1518. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1519. WBUFB(buf,56)=5;
  1520. WBUFB(buf,57)=5;
  1521. clif_send(buf, packet_len_table[0x7b], &sd->bl, SELF);
  1522. }
  1523. return 0;
  1524. }
  1525. /*==========================================
  1526. *
  1527. *------------------------------------------
  1528. */
  1529. int clif_move(struct block_list *bl) {
  1530. struct view_data *vd;
  1531. struct unit_data *ud;
  1532. unsigned char buf[256];
  1533. int len;
  1534. nullpo_retr(0, bl);
  1535. vd = status_get_viewdata(bl);
  1536. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1537. return 0;
  1538. ud = unit_bl2ud(bl);
  1539. nullpo_retr(0, ud);
  1540. len = clif_set007b(bl,vd,ud,buf);
  1541. clif_send(buf,len,bl,AREA_WOS);
  1542. if (disguised(bl))
  1543. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1544. //Stupid client that needs this resent every time someone walks :X
  1545. if(vd->cloth_color)
  1546. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1547. switch(bl->type)
  1548. {
  1549. case BL_PC:
  1550. {
  1551. TBL_PC *sd = ((TBL_PC*)bl);
  1552. // clif_movepc(sd);
  1553. if(sd->state.size==2) // tiny/big players [Valaris]
  1554. clif_specialeffect(&sd->bl,423,AREA);
  1555. else if(sd->state.size==1)
  1556. clif_specialeffect(&sd->bl,421,AREA);
  1557. }
  1558. break;
  1559. case BL_MOB:
  1560. {
  1561. TBL_MOB *md = ((TBL_MOB*)bl);
  1562. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1563. clif_specialeffect(&md->bl,423,AREA);
  1564. else if(md->special_state.size==1)
  1565. clif_specialeffect(&md->bl,421,AREA);
  1566. }
  1567. break;
  1568. }
  1569. return 0;
  1570. }
  1571. /*==========================================
  1572. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1573. *------------------------------------------
  1574. */
  1575. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1576. struct map_session_data *sd = NULL;
  1577. //Remove player from map server
  1578. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1579. map_quit(sd);
  1580. return 0;
  1581. }
  1582. /*==========================================
  1583. *
  1584. *------------------------------------------
  1585. */
  1586. void clif_quitsave(int fd,struct map_session_data *sd)
  1587. {
  1588. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1589. !battle_config.prevent_logout ||
  1590. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1591. map_quit(sd);
  1592. else if (sd->fd)
  1593. { //Disassociate session from player (session is deleted after this function was called)
  1594. //And set a timer to make him quit later.
  1595. session[fd]->session_data = NULL;
  1596. sd->fd = 0;
  1597. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1598. }
  1599. }
  1600. /*==========================================
  1601. *
  1602. *------------------------------------------
  1603. */
  1604. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1605. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1606. session[id]->eof = 1;
  1607. return 0;
  1608. }
  1609. /*==========================================
  1610. *
  1611. *------------------------------------------
  1612. */
  1613. void clif_setwaitclose(int fd) {
  1614. struct map_session_data *sd;
  1615. // if player is not already in the game (double connection probably)
  1616. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1617. // limited timer, just to send information.
  1618. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1619. } else
  1620. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1621. }
  1622. /*==========================================
  1623. *
  1624. *------------------------------------------
  1625. */
  1626. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1627. int fd;
  1628. nullpo_retr(0, sd);
  1629. fd = sd->fd;
  1630. WFIFOHEAD(fd, packet_len_table[0x91]);
  1631. WFIFOW(fd,0) = 0x91;
  1632. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1633. WFIFOW(fd,18) = x;
  1634. WFIFOW(fd,20) = y;
  1635. WFIFOSET(fd, packet_len_table[0x91]);
  1636. return 0;
  1637. }
  1638. /*==========================================
  1639. *
  1640. *------------------------------------------
  1641. */
  1642. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1643. int fd;
  1644. nullpo_retr(0, sd);
  1645. fd = sd->fd;
  1646. WFIFOHEAD(fd, packet_len_table[0x92]);
  1647. WFIFOW(fd,0) = 0x92;
  1648. //Better not trust the null-terminator is there. [Skotlex]
  1649. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1650. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1651. WFIFOW(fd,18) = x;
  1652. WFIFOW(fd,20) = y;
  1653. WFIFOL(fd,22) = ip;
  1654. WFIFOW(fd,26) = port;
  1655. WFIFOSET(fd, packet_len_table[0x92]);
  1656. return 0;
  1657. }
  1658. int clif_blown(struct block_list *bl) {
  1659. //Previous Aegis versions simply used clif_fixpos, but it seems clif_slide works better on current clients.
  1660. // return clif_fixpos(bl);
  1661. return clif_slide(bl, bl->x, bl->y);
  1662. }
  1663. /*==========================================
  1664. *
  1665. *------------------------------------------
  1666. */
  1667. int clif_fixpos(struct block_list *bl) {
  1668. unsigned char buf[16];
  1669. nullpo_retr(0, bl);
  1670. WBUFW(buf,0)=0x88;
  1671. WBUFL(buf,2)=bl->id;
  1672. WBUFW(buf,6)=bl->x;
  1673. WBUFW(buf,8)=bl->y;
  1674. clif_send(buf, packet_len_table[0x88], bl, AREA);
  1675. if (disguised(bl)) {
  1676. WBUFL(buf,2)=-bl->id;
  1677. clif_send(buf, packet_len_table[0x88], bl, SELF);
  1678. }
  1679. return 0;
  1680. }
  1681. /*==========================================
  1682. *
  1683. *------------------------------------------
  1684. */
  1685. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1686. int fd;
  1687. nullpo_retr(0, sd);
  1688. fd=sd->fd;
  1689. WFIFOHEAD(fd, packet_len_table[0xc4]);
  1690. WFIFOW(fd,0)=0xc4;
  1691. WFIFOL(fd,2)=id;
  1692. WFIFOSET(fd,packet_len_table[0xc4]);
  1693. return 0;
  1694. }
  1695. /*==========================================
  1696. *
  1697. *------------------------------------------
  1698. */
  1699. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1700. struct item_data *id;
  1701. int fd,i,val;
  1702. nullpo_retr(0, sd);
  1703. nullpo_retr(0, nd);
  1704. fd=sd->fd;
  1705. WFIFOHEAD(fd, 200 * 11 + 4);
  1706. WFIFOW(fd,0)=0xc6;
  1707. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1708. id = itemdb_search(nd->u.shop_item[i].nameid);
  1709. val=nd->u.shop_item[i].value;
  1710. WFIFOL(fd,4+i*11)=val;
  1711. if (!id->flag.value_notdc)
  1712. val=pc_modifybuyvalue(sd,val);
  1713. WFIFOL(fd,8+i*11)=val;
  1714. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1715. if (id->view_id > 0)
  1716. WFIFOW(fd,13+i*11)=id->view_id;
  1717. else
  1718. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1719. }
  1720. WFIFOW(fd,2)=i*11+4;
  1721. WFIFOSET(fd,WFIFOW(fd,2));
  1722. return 0;
  1723. }
  1724. /*==========================================
  1725. *
  1726. *------------------------------------------
  1727. */
  1728. int clif_selllist(struct map_session_data *sd) {
  1729. int fd,i,c=0,val;
  1730. nullpo_retr(0, sd);
  1731. fd=sd->fd;
  1732. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1733. WFIFOW(fd,0)=0xc7;
  1734. for(i=0;i<MAX_INVENTORY;i++) {
  1735. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1736. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1737. continue;
  1738. val=sd->inventory_data[i]->value_sell;
  1739. if (val < 0)
  1740. continue;
  1741. WFIFOW(fd,4+c*10)=i+2;
  1742. WFIFOL(fd,6+c*10)=val;
  1743. if (!sd->inventory_data[i]->flag.value_notoc)
  1744. val=pc_modifysellvalue(sd,val);
  1745. WFIFOL(fd,10+c*10)=val;
  1746. c++;
  1747. }
  1748. }
  1749. WFIFOW(fd,2)=c*10+4;
  1750. WFIFOSET(fd,WFIFOW(fd,2));
  1751. return 0;
  1752. }
  1753. /*==========================================
  1754. *
  1755. *------------------------------------------
  1756. */
  1757. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  1758. int fd;
  1759. int slen = strlen(mes) + 9;
  1760. WFIFOHEAD(fd, slen);
  1761. nullpo_retr(0, sd);
  1762. fd=sd->fd;
  1763. WFIFOW(fd,0)=0xb4;
  1764. WFIFOW(fd,2)=slen;
  1765. WFIFOL(fd,4)=npcid;
  1766. strcpy((char*)WFIFOP(fd,8),mes);
  1767. WFIFOSET(fd,WFIFOW(fd,2));
  1768. return 0;
  1769. }
  1770. /*==========================================
  1771. *
  1772. *------------------------------------------
  1773. */
  1774. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  1775. int fd;
  1776. nullpo_retr(0, sd);
  1777. fd=sd->fd;
  1778. WFIFOHEAD(fd, packet_len_table[0xb5]);
  1779. WFIFOW(fd,0)=0xb5;
  1780. WFIFOL(fd,2)=npcid;
  1781. WFIFOSET(fd,packet_len_table[0xb5]);
  1782. return 0;
  1783. }
  1784. /*==========================================
  1785. *
  1786. *------------------------------------------
  1787. */
  1788. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  1789. int fd;
  1790. nullpo_retr(0, sd);
  1791. fd=sd->fd;
  1792. WFIFOHEAD(fd, packet_len_table[0xb6]);
  1793. WFIFOW(fd,0)=0xb6;
  1794. WFIFOL(fd,2)=npcid;
  1795. WFIFOSET(fd,packet_len_table[0xb6]);
  1796. return 0;
  1797. }
  1798. /*==========================================
  1799. *
  1800. *------------------------------------------
  1801. */
  1802. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1803. int fd = sd->fd;
  1804. //sd->npc_id = npcid;
  1805. sd->state.using_fake_npc = 1;
  1806. malloc_set(WFIFOP(fd,0), 0, packet_len_table[0x78]);
  1807. WFIFOW(fd,0)=0x78;
  1808. WFIFOL(fd,2)=npcid;
  1809. WFIFOW(fd,14)=111;
  1810. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1811. WFIFOB(fd,49)=5;
  1812. WFIFOB(fd,50)=5;
  1813. WFIFOSET(fd, packet_len_table[0x78]);
  1814. return;
  1815. }
  1816. /*==========================================
  1817. *
  1818. *------------------------------------------
  1819. */
  1820. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  1821. int fd;
  1822. int slen = strlen(mes) + 8;
  1823. struct block_list *bl = NULL;
  1824. WFIFOHEAD(fd, slen);
  1825. nullpo_retr(0, sd);
  1826. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1827. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1828. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1829. clif_sendfakenpc(sd, npcid);
  1830. fd=sd->fd;
  1831. WFIFOW(fd,0)=0xb7;
  1832. WFIFOW(fd,2)=slen;
  1833. WFIFOL(fd,4)=npcid;
  1834. strcpy((char*)WFIFOP(fd,8),mes);
  1835. WFIFOSET(fd,WFIFOW(fd,2));
  1836. return 0;
  1837. }
  1838. /*==========================================
  1839. *
  1840. *------------------------------------------
  1841. */
  1842. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  1843. int fd;
  1844. struct block_list *bl = NULL;
  1845. nullpo_retr(0, sd);
  1846. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1847. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1848. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1849. clif_sendfakenpc(sd, npcid);
  1850. fd=sd->fd;
  1851. WFIFOHEAD(fd, packet_len_table[0x142]);
  1852. WFIFOW(fd,0)=0x142;
  1853. WFIFOL(fd,2)=npcid;
  1854. WFIFOSET(fd,packet_len_table[0x142]);
  1855. return 0;
  1856. }
  1857. /*==========================================
  1858. *
  1859. *------------------------------------------
  1860. */
  1861. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1862. int fd;
  1863. struct block_list *bl = NULL;
  1864. nullpo_retr(0, sd);
  1865. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1866. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1867. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1868. clif_sendfakenpc(sd, npcid);
  1869. fd=sd->fd;
  1870. WFIFOHEAD(fd, packet_len_table[0x1d4]);
  1871. WFIFOW(fd,0)=0x1d4;
  1872. WFIFOL(fd,2)=npcid;
  1873. WFIFOSET(fd,packet_len_table[0x1d4]);
  1874. return 0;
  1875. }
  1876. /*==========================================
  1877. *
  1878. *------------------------------------------
  1879. */
  1880. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  1881. int fd;
  1882. nullpo_retr(0, sd);
  1883. fd=sd->fd;
  1884. WFIFOHEAD(fd, packet_len_table[0x144]);
  1885. WFIFOW(fd,0)=0x144;
  1886. WFIFOL(fd,2)=npc_id;
  1887. WFIFOL(fd,6)=type;
  1888. WFIFOL(fd,10)=x;
  1889. WFIFOL(fd,14)=y;
  1890. WFIFOB(fd,18)=id;
  1891. WFIFOL(fd,19)=color;
  1892. WFIFOSET(fd,packet_len_table[0x144]);
  1893. return 0;
  1894. }
  1895. /*==========================================
  1896. *
  1897. *------------------------------------------
  1898. */
  1899. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  1900. int fd;
  1901. nullpo_retr(0, sd);
  1902. fd=sd->fd;
  1903. WFIFOHEAD(fd, packet_len_table[0x1b3]);
  1904. WFIFOW(fd,0)=0x1b3;
  1905. strncpy((char*)WFIFOP(fd,2),image,64);
  1906. WFIFOB(fd,66)=type;
  1907. WFIFOSET(fd,packet_len_table[0x1b3]);
  1908. return 0;
  1909. }
  1910. /*==========================================
  1911. * Fills in card data from the given item and into the buffer. [Skotlex]
  1912. *------------------------------------------
  1913. */
  1914. static void clif_addcards(unsigned char* buf, struct item* item)
  1915. {
  1916. int i=0,j;
  1917. if (item == NULL) { //Blank data
  1918. WBUFW(buf,0)=0;
  1919. WBUFW(buf,2)=0;
  1920. WBUFW(buf,4)=0;
  1921. WBUFW(buf,6)=0;
  1922. return;
  1923. }
  1924. if(item->card[0]==CARD0_PET) { //pet eggs
  1925. WBUFW(buf,0)=0;
  1926. WBUFW(buf,2)=0;
  1927. WBUFW(buf,4)=0;
  1928. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1929. return;
  1930. }
  1931. if(item->card[0]==CARD0_FORGE || item->card[0]==CARD0_CREATE) { //Forged/created items
  1932. WBUFW(buf,0)=item->card[0];
  1933. WBUFW(buf,2)=item->card[1];
  1934. WBUFW(buf,4)=item->card[2];
  1935. WBUFW(buf,6)=item->card[3];
  1936. return;
  1937. }
  1938. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1939. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1940. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1941. //Normal items.
  1942. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1943. WBUFW(buf,0)=j;
  1944. else
  1945. WBUFW(buf,0)= item->card[i];
  1946. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1947. WBUFW(buf,2)=j;
  1948. else
  1949. WBUFW(buf,2)=item->card[i];
  1950. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1951. WBUFW(buf,4)=j;
  1952. else
  1953. WBUFW(buf,4)=item->card[i];
  1954. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1955. WBUFW(buf,6)=j;
  1956. else
  1957. WBUFW(buf,6)=item->card[i];
  1958. }
  1959. /*==========================================
  1960. *
  1961. *------------------------------------------
  1962. */
  1963. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  1964. int fd;
  1965. unsigned char *buf;
  1966. nullpo_retr(0, sd);
  1967. fd = sd->fd;
  1968. if (!session_isActive(fd)) //Sasuke-
  1969. return 0;
  1970. WFIFOHEAD(fd,packet_len_table[0xa0]);
  1971. buf = WFIFOP(fd,0);
  1972. if(fail) {
  1973. WBUFW(buf,0)=0xa0;
  1974. WBUFW(buf,2)=n+2;
  1975. WBUFW(buf,4)=amount;
  1976. WBUFW(buf,6)=0;
  1977. WBUFB(buf,8)=0;
  1978. WBUFB(buf,9)=0;
  1979. WBUFB(buf,10)=0;
  1980. WBUFW(buf,11)=0;
  1981. WBUFW(buf,13)=0;
  1982. WBUFW(buf,15)=0;
  1983. WBUFW(buf,17)=0;
  1984. WBUFW(buf,19)=0;
  1985. WBUFB(buf,21)=0;
  1986. WBUFB(buf,22)=fail;
  1987. } else {
  1988. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1989. return 1;
  1990. WBUFW(buf,0)=0xa0;
  1991. WBUFW(buf,2)=n+2;
  1992. WBUFW(buf,4)=amount;
  1993. if (sd->inventory_data[n]->view_id > 0)
  1994. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  1995. else
  1996. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  1997. WBUFB(buf,8)=sd->status.inventory[n].identify;
  1998. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  1999. WBUFB(buf,10)=sd->status.inventory[n].refine;
  2000. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  2001. WBUFW(buf,19)=pc_equippoint(sd,n);
  2002. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  2003. WBUFB(buf,22)=fail;
  2004. }
  2005. WFIFOSET(fd,packet_len_table[0xa0]);
  2006. return 0;
  2007. }
  2008. /*==========================================
  2009. *
  2010. *------------------------------------------
  2011. */
  2012. int clif_delitem(struct map_session_data *sd,int n,int amount)
  2013. {
  2014. int fd;
  2015. nullpo_retr(0, sd);
  2016. fd=sd->fd;
  2017. WFIFOHEAD(fd, packet_len_table[0xaf]);
  2018. WFIFOW(fd,0)=0xaf;
  2019. WFIFOW(fd,2)=n+2;
  2020. WFIFOW(fd,4)=amount;
  2021. WFIFOSET(fd,packet_len_table[0xaf]);
  2022. return 0;
  2023. }
  2024. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2025. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2026. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2027. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  2028. {
  2029. if (id->view_id > 0)
  2030. WBUFW(buf,n)=id->view_id;
  2031. else
  2032. WBUFW(buf,n)=i->nameid;
  2033. WBUFB(buf,n+2)=itemtype(id->type);
  2034. WBUFB(buf,n+3)=i->identify;
  2035. if (equip >= 0) { //Equippable item
  2036. WBUFW(buf,n+4)=equip;
  2037. WBUFW(buf,n+6)=i->equip;
  2038. WBUFB(buf,n+8)=i->attribute;
  2039. WBUFB(buf,n+9)=i->refine;
  2040. } else { //Stackable item.
  2041. WBUFW(buf,n+4)=i->amount;
  2042. if (equip == -2 && id->equip == EQP_AMMO)
  2043. WBUFW(buf,n+6)=EQP_AMMO;
  2044. else
  2045. WBUFW(buf,n+6)=0;
  2046. }
  2047. }
  2048. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2049. void clif_inventorylist(struct map_session_data *sd)
  2050. {
  2051. int i,n,ne,fd = sd->fd,arrow=-1;
  2052. unsigned char *buf;
  2053. unsigned char bufe[MAX_INVENTORY*20+4];
  2054. #if PACKETVER < 5
  2055. const int s = 10; //Entry size.
  2056. #else
  2057. const int s = 18;
  2058. #endif
  2059. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  2060. buf = WFIFOP(fd,0);
  2061. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  2062. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2063. continue;
  2064. if(!itemdb_isstackable2(sd->inventory_data[i]))
  2065. { //Non-stackable (Equippable)
  2066. WBUFW(bufe,ne*20+4)=i+2;
  2067. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2068. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  2069. ne++;
  2070. } else { //Stackable.
  2071. WBUFW(buf,n*s+4)=i+2;
  2072. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2073. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  2074. sd->status.inventory[i].equip)
  2075. arrow=i;
  2076. #if PACKETVER >= 5
  2077. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  2078. #endif
  2079. n++;
  2080. }
  2081. }
  2082. if (n) {
  2083. #if PACKETVER < 5
  2084. WBUFW(buf,0)=0xa3;
  2085. #else
  2086. WBUFW(buf,0)=0x1ee;
  2087. #endif
  2088. WBUFW(buf,2)=4+n*s;
  2089. WFIFOSET(fd,WFIFOW(fd,2));
  2090. }
  2091. if(arrow >= 0)
  2092. clif_arrowequip(sd,arrow);
  2093. if(ne){
  2094. WBUFW(bufe,0)=0xa4;
  2095. WBUFW(bufe,2)=4+ne*20;
  2096. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2097. }
  2098. }
  2099. //Required when items break/get-repaired. Only sends equippable item list.
  2100. void clif_equiplist(struct map_session_data *sd)
  2101. {
  2102. int i,n,fd = sd->fd;
  2103. unsigned char *buf;
  2104. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  2105. buf = WFIFOP(fd,0);
  2106. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2107. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2108. continue;
  2109. if(itemdb_isstackable2(sd->inventory_data[i]))
  2110. continue;
  2111. //Equippable
  2112. WBUFW(buf,n*20+4)=i+2;
  2113. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2114. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  2115. n++;
  2116. }
  2117. if (n) {
  2118. WBUFW(buf,0)=0xa4;
  2119. WBUFW(buf,2)=4+n*20;
  2120. WFIFOSET(fd,WFIFOW(fd,2));
  2121. }
  2122. }
  2123. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2124. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  2125. {
  2126. struct item_data *id;
  2127. int i,n,ne,fd=sd->fd;
  2128. unsigned char *buf;
  2129. unsigned char bufe[MAX_STORAGE*20+4];
  2130. #if PACKETVER < 5
  2131. const int s = 10; //Entry size.
  2132. #else
  2133. const int s = 18;
  2134. #endif
  2135. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  2136. buf = WFIFOP(fd,0);
  2137. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  2138. if(stor->storage_[i].nameid<=0)
  2139. continue;
  2140. id = itemdb_search(stor->storage_[i].nameid);
  2141. if(!itemdb_isstackable2(id))
  2142. { //Equippable
  2143. WBUFW(bufe,ne*20+4)=i+1;
  2144. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2145. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2146. ne++;
  2147. } else { //Stackable
  2148. WBUFW(buf,n*s+4)=i+1;
  2149. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2150. #if PACKETVER >= 5
  2151. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2152. #endif
  2153. n++;
  2154. }
  2155. }
  2156. if(n){
  2157. #if PACKETVER < 5
  2158. WBUFW(buf,0)=0xa5;
  2159. #else
  2160. WBUFW(buf,0)=0x1f0;
  2161. #endif
  2162. WBUFW(buf,2)=4+n*s;
  2163. WFIFOSET(fd,WFIFOW(fd,2));
  2164. }
  2165. if(ne){
  2166. WBUFW(bufe,0)=0xa6;
  2167. WBUFW(bufe,2)=4+ne*20;
  2168. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2169. }
  2170. }
  2171. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2172. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  2173. {
  2174. struct item_data *id;
  2175. int i,n,ne,fd=sd->fd;
  2176. unsigned char *buf;
  2177. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  2178. #if PACKETVER < 5
  2179. const int s = 10; //Entry size.
  2180. #else
  2181. const int s = 18;
  2182. #endif
  2183. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  2184. buf = WFIFOP(fd,0);
  2185. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  2186. if(stor->storage_[i].nameid<=0)
  2187. continue;
  2188. id = itemdb_search(stor->storage_[i].nameid);
  2189. if(!itemdb_isstackable2(id))
  2190. { //Equippable
  2191. WBUFW(bufe,ne*20+4)=i+1;
  2192. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2193. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2194. ne++;
  2195. } else { //Stackable
  2196. WBUFW(buf,n*s+4)=i+1;
  2197. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2198. #if PACKETVER >= 5
  2199. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2200. #endif
  2201. n++;
  2202. }
  2203. }
  2204. if(n){
  2205. #if PACKETVER < 5
  2206. WBUFW(buf,0)=0xa5;
  2207. #else
  2208. WBUFW(buf,0)=0x1f0;
  2209. #endif
  2210. WBUFW(buf,2)=4+n*s;
  2211. WFIFOSET(fd,WFIFOW(fd,2));
  2212. }
  2213. if(ne){
  2214. WBUFW(bufe,0)=0xa6;
  2215. WBUFW(bufe,2)=4+ne*20;
  2216. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2217. }
  2218. }
  2219. void clif_cartlist(struct map_session_data *sd)
  2220. {
  2221. struct item_data *id;
  2222. int i,n,ne,fd=sd->fd;
  2223. unsigned char *buf;
  2224. unsigned char bufe[MAX_CART*20+4];
  2225. #if PACKETVER < 5
  2226. const int s = 10; //Entry size.
  2227. #else
  2228. const int s = 18;
  2229. #endif
  2230. WFIFOHEAD(fd, MAX_CART * s + 4);
  2231. buf = WFIFOP(fd,0);
  2232. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2233. if(sd->status.cart[i].nameid<=0)
  2234. continue;
  2235. id = itemdb_search(sd->status.cart[i].nameid);
  2236. if(!itemdb_isstackable2(id))
  2237. { //Equippable
  2238. WBUFW(bufe,ne*20+4)=i+2;
  2239. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2240. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2241. ne++;
  2242. } else { //Stackable
  2243. WBUFW(buf,n*s+4)=i+2;
  2244. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2245. #if PACKETVER >= 5
  2246. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2247. #endif
  2248. n++;
  2249. }
  2250. }
  2251. if(n){
  2252. #if PACKETVER < 5
  2253. WBUFW(buf,0)=0x123;
  2254. #else
  2255. WBUFW(buf,0)=0x1ef;
  2256. #endif
  2257. WBUFW(buf,2)=4+n*s;
  2258. WFIFOSET(fd,WFIFOW(fd,2));
  2259. }
  2260. if(ne){
  2261. WBUFW(bufe,0)=0x122;
  2262. WBUFW(bufe,2)=4+ne*20;
  2263. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2264. }
  2265. return;
  2266. }
  2267. // Guild XY locators [Valaris]
  2268. int clif_guild_xy(struct map_session_data *sd)
  2269. {
  2270. unsigned char buf[10];
  2271. nullpo_retr(0, sd);
  2272. WBUFW(buf,0)=0x1eb;
  2273. WBUFL(buf,2)=sd->status.account_id;
  2274. WBUFW(buf,6)=sd->bl.x;
  2275. WBUFW(buf,8)=sd->bl.y;
  2276. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2277. return 0;
  2278. }
  2279. /*==========================================
  2280. * Sends x/y dot to a single fd. [Skotlex]
  2281. *------------------------------------------
  2282. */
  2283. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2284. {
  2285. WFIFOHEAD(fd,packet_len_table[0x1eb]);
  2286. WFIFOW(fd,0)=0x1eb;
  2287. WFIFOL(fd,2)=sd->status.account_id;
  2288. WFIFOW(fd,6)=sd->bl.x;
  2289. WFIFOW(fd,8)=sd->bl.y;
  2290. WFIFOSET(fd,packet_len_table[0x1eb]);
  2291. return 0;
  2292. }
  2293. // Guild XY locators [Valaris]
  2294. int clif_guild_xy_remove(struct map_session_data *sd)
  2295. {
  2296. unsigned char buf[10];
  2297. nullpo_retr(0, sd);
  2298. WBUFW(buf,0)=0x1eb;
  2299. WBUFL(buf,2)=sd->status.account_id;
  2300. WBUFW(buf,6)=-1;
  2301. WBUFW(buf,8)=-1;
  2302. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2303. return 0;
  2304. }
  2305. /*==========================================
  2306. * ステータスを送りつける
  2307. * 表示専用数字はこの中で計算して送る
  2308. *------------------------------------------
  2309. */
  2310. int clif_updatestatus(struct map_session_data *sd,int type)
  2311. {
  2312. int fd,len=8;
  2313. nullpo_retr(0, sd);
  2314. fd=sd->fd;
  2315. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2316. return 0;
  2317. WFIFOHEAD(fd, 14);
  2318. WFIFOW(fd,0)=0xb0;
  2319. WFIFOW(fd,2)=type;
  2320. switch(type){
  2321. // 00b0
  2322. case SP_WEIGHT:
  2323. pc_checkweighticon(sd);
  2324. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_checkweighticon can alter the buffer. [Skotlex]
  2325. WFIFOW(fd,2)=type;
  2326. WFIFOL(fd,4)=sd->weight;
  2327. break;
  2328. case SP_MAXWEIGHT:
  2329. WFIFOL(fd,4)=sd->max_weight;
  2330. break;
  2331. case SP_SPEED:
  2332. WFIFOL(fd,4)=sd->battle_status.speed;
  2333. break;
  2334. case SP_BASELEVEL:
  2335. WFIFOL(fd,4)=sd->status.base_level;
  2336. break;
  2337. case SP_JOBLEVEL:
  2338. WFIFOL(fd,4)=sd->status.job_level;
  2339. break;
  2340. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2341. WFIFOL(fd,4)=sd->status.karma;
  2342. break;
  2343. case SP_MANNER:
  2344. WFIFOL(fd,4)=sd->status.manner;
  2345. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2346. break;
  2347. case SP_STATUSPOINT:
  2348. WFIFOL(fd,4)=sd->status.status_point;
  2349. break;
  2350. case SP_SKILLPOINT:
  2351. WFIFOL(fd,4)=sd->status.skill_point;
  2352. break;
  2353. case SP_HIT:
  2354. WFIFOL(fd,4)=sd->battle_status.hit;
  2355. break;
  2356. case SP_FLEE1:
  2357. WFIFOL(fd,4)=sd->battle_status.flee;
  2358. break;
  2359. case SP_FLEE2:
  2360. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2361. break;
  2362. case SP_MAXHP:
  2363. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2364. break;
  2365. case SP_MAXSP:
  2366. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2367. break;
  2368. case SP_HP:
  2369. WFIFOL(fd,4)=sd->battle_status.hp;
  2370. if (battle_config.disp_hpmeter)
  2371. clif_hpmeter(sd);
  2372. if (!battle_config.party_hp_mode && sd->status.party_id)
  2373. clif_party_hp(sd);
  2374. break;
  2375. case SP_SP:
  2376. WFIFOL(fd,4)=sd->battle_status.sp;
  2377. break;
  2378. case SP_ASPD:
  2379. WFIFOL(fd,4)=sd->battle_status.amotion;
  2380. break;
  2381. case SP_ATK1:
  2382. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2383. break;
  2384. case SP_DEF1:
  2385. WFIFOL(fd,4)=sd->battle_status.def;
  2386. break;
  2387. case SP_MDEF1:
  2388. WFIFOL(fd,4)=sd->battle_status.mdef;
  2389. break;
  2390. case SP_ATK2:
  2391. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2392. break;
  2393. case SP_DEF2:
  2394. WFIFOL(fd,4)=sd->battle_status.def2;
  2395. break;
  2396. case SP_MDEF2:
  2397. //negative check (in case you have something like Berserk active)
  2398. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2399. if (len < 0) len = 0;
  2400. WFIFOL(fd,4)= len;
  2401. len = 8;
  2402. break;
  2403. case SP_CRITICAL:
  2404. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2405. break;
  2406. case SP_MATK1:
  2407. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2408. break;
  2409. case SP_MATK2:
  2410. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2411. break;
  2412. case SP_ZENY:
  2413. WFIFOW(fd,0)=0xb1;
  2414. WFIFOL(fd,4)=sd->status.zeny;
  2415. break;
  2416. case SP_BASEEXP:
  2417. WFIFOW(fd,0)=0xb1;
  2418. WFIFOL(fd,4)=sd->status.base_exp;
  2419. break;
  2420. case SP_JOBEXP:
  2421. WFIFOW(fd,0)=0xb1;
  2422. WFIFOL(fd,4)=sd->status.job_exp;
  2423. break;
  2424. case SP_NEXTBASEEXP:
  2425. WFIFOW(fd,0)=0xb1;
  2426. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2427. break;
  2428. case SP_NEXTJOBEXP:
  2429. WFIFOW(fd,0)=0xb1;
  2430. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2431. break;
  2432. // 00be 終了
  2433. case SP_USTR:
  2434. case SP_UAGI:
  2435. case SP_UVIT:
  2436. case SP_UINT:
  2437. case SP_UDEX:
  2438. case SP_ULUK:
  2439. WFIFOW(fd,0)=0xbe;
  2440. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2441. len=5;
  2442. break;
  2443. // 013a 終了
  2444. case SP_ATTACKRANGE:
  2445. WFIFOW(fd,0)=0x13a;
  2446. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2447. len=4;
  2448. break;
  2449. // 0141 終了
  2450. case SP_STR:
  2451. WFIFOW(fd,0)=0x141;
  2452. WFIFOL(fd,2)=type;
  2453. WFIFOL(fd,6)=sd->status.str;
  2454. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2455. len=14;
  2456. break;
  2457. case SP_AGI:
  2458. WFIFOW(fd,0)=0x141;
  2459. WFIFOL(fd,2)=type;
  2460. WFIFOL(fd,6)=sd->status.agi;
  2461. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2462. len=14;
  2463. break;
  2464. case SP_VIT:
  2465. WFIFOW(fd,0)=0x141;
  2466. WFIFOL(fd,2)=type;
  2467. WFIFOL(fd,6)=sd->status.vit;
  2468. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2469. len=14;
  2470. break;
  2471. case SP_INT:
  2472. WFIFOW(fd,0)=0x141;
  2473. WFIFOL(fd,2)=type;
  2474. WFIFOL(fd,6)=sd->status.int_;
  2475. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2476. len=14;
  2477. break;
  2478. case SP_DEX:
  2479. WFIFOW(fd,0)=0x141;
  2480. WFIFOL(fd,2)=type;
  2481. WFIFOL(fd,6)=sd->status.dex;
  2482. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2483. len=14;
  2484. break;
  2485. case SP_LUK:
  2486. WFIFOW(fd,0)=0x141;
  2487. WFIFOL(fd,2)=type;
  2488. WFIFOL(fd,6)=sd->status.luk;
  2489. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2490. len=14;
  2491. break;
  2492. case SP_CARTINFO:
  2493. WFIFOW(fd,0)=0x121;
  2494. WFIFOW(fd,2)=sd->cart_num;
  2495. WFIFOW(fd,4)=sd->cart_max_num;
  2496. WFIFOL(fd,6)=sd->cart_weight;
  2497. WFIFOL(fd,10)=sd->cart_max_weight;
  2498. len=14;
  2499. break;
  2500. default:
  2501. if(battle_config.error_log)
  2502. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2503. return 1;
  2504. }
  2505. WFIFOSET(fd,len);
  2506. return 0;
  2507. }
  2508. int clif_changestatus(struct block_list *bl,int type,int val)
  2509. {
  2510. unsigned char buf[12];
  2511. struct map_session_data *sd = NULL;
  2512. nullpo_retr(0, bl);
  2513. if(bl->type == BL_PC)
  2514. sd = (struct map_session_data *)bl;
  2515. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2516. if(sd){
  2517. WBUFW(buf,0)=0x1ab;
  2518. WBUFL(buf,2)=bl->id;
  2519. WBUFW(buf,6)=type;
  2520. switch(type){
  2521. case SP_MANNER:
  2522. WBUFL(buf,8)=val;
  2523. break;
  2524. default:
  2525. if(battle_config.error_log)
  2526. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2527. return 1;
  2528. }
  2529. clif_send(buf,packet_len_table[0x1ab],bl,AREA_WOS);
  2530. }
  2531. return 0;
  2532. }
  2533. /*==========================================
  2534. *
  2535. *------------------------------------------
  2536. */
  2537. int clif_changelook(struct block_list *bl,int type,int val)
  2538. {
  2539. unsigned char buf[32];
  2540. struct map_session_data *sd = NULL;
  2541. struct view_data *vd;
  2542. vd = status_get_viewdata(bl);
  2543. nullpo_retr(0, vd);
  2544. if(bl->type == BL_PC)
  2545. sd = (struct map_session_data *)bl;
  2546. switch(type) {
  2547. case LOOK_WEAPON:
  2548. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2549. else vd->weapon = val;
  2550. break;
  2551. case LOOK_SHIELD:
  2552. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2553. else vd->shield = val;
  2554. break;
  2555. case LOOK_BASE:
  2556. vd->class_ = val;
  2557. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2558. vd->weapon = vd->shield = 0;
  2559. if (vd->cloth_color && (
  2560. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2561. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2562. ))
  2563. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2564. break;
  2565. case LOOK_HAIR:
  2566. vd->hair_style = val;
  2567. break;
  2568. case LOOK_HEAD_BOTTOM:
  2569. vd->head_bottom = val;
  2570. break;
  2571. case LOOK_HEAD_TOP:
  2572. vd->head_top = val;
  2573. break;
  2574. case LOOK_HEAD_MID:
  2575. vd->head_mid = val;
  2576. break;
  2577. case LOOK_HAIR_COLOR:
  2578. vd->hair_color = val;
  2579. break;
  2580. case LOOK_CLOTHES_COLOR:
  2581. if (val && (
  2582. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2583. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2584. ))
  2585. val = 0;
  2586. vd->cloth_color = val;
  2587. break;
  2588. case LOOK_SHOES:
  2589. #if PACKETVER > 3
  2590. if (sd) {
  2591. int n;
  2592. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2593. if(sd->inventory_data[n]->view_id > 0)
  2594. val = sd->inventory_data[n]->view_id;
  2595. else
  2596. val = sd->status.inventory[n].nameid;
  2597. }
  2598. val = 0;
  2599. }
  2600. #endif
  2601. //Shoes? No packet uses this....
  2602. break;
  2603. }
  2604. #if PACKETVER < 4
  2605. WBUFW(buf,0)=0xc3;
  2606. WBUFL(buf,2)=bl->id;
  2607. WBUFB(buf,6)=type;
  2608. WBUFB(buf,7)=val;
  2609. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2610. #else
  2611. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2612. WBUFW(buf,0)=0x1d7;
  2613. WBUFL(buf,2)=bl->id;
  2614. WBUFB(buf,6)=LOOK_WEAPON;
  2615. WBUFW(buf,7)=vd->weapon;
  2616. WBUFW(buf,9)=vd->shield;
  2617. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2618. }
  2619. else
  2620. {
  2621. WBUFW(buf,0)=0x1d7;
  2622. WBUFL(buf,2)=bl->id;
  2623. WBUFB(buf,6)=type;
  2624. WBUFW(buf,7)=val;
  2625. WBUFW(buf,9)=0;
  2626. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2627. }
  2628. #endif
  2629. return 0;
  2630. }
  2631. //Sends a change-base-look packet required for traps as they are triggered.
  2632. void clif_changetraplook(struct block_list *bl,int val)
  2633. {
  2634. unsigned char buf[32];
  2635. #if PACKETVER < 4
  2636. WBUFW(buf,0)=0xc3;
  2637. WBUFL(buf,2)=bl->id;
  2638. WBUFB(buf,6)=LOOK_BASE;
  2639. WBUFB(buf,7)=val;
  2640. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2641. #else
  2642. WBUFW(buf,0)=0x1d7;
  2643. WBUFL(buf,2)=bl->id;
  2644. WBUFB(buf,6)=LOOK_BASE;
  2645. WBUFW(buf,7)=val;
  2646. WBUFW(buf,9)=0;
  2647. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2648. #endif
  2649. }
  2650. //For the stupid cloth-dye bug. Resends the given view data
  2651. //to the area specified by bl.
  2652. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2653. {
  2654. unsigned char buf[32];
  2655. #if PACKETVER < 4
  2656. WBUFW(buf,0)=0xc3;
  2657. WBUFL(buf,2)=id;
  2658. WBUFB(buf,6)=type;
  2659. WBUFB(buf,7)=val;
  2660. clif_send(buf,packet_len_table[0xc3],bl,area);
  2661. #else
  2662. WBUFW(buf,0)=0x1d7;
  2663. WBUFL(buf,2)=id;
  2664. WBUFB(buf,6)=type;
  2665. WBUFW(buf,7)=val;
  2666. WBUFW(buf,9)=0;
  2667. clif_send(buf,packet_len_table[0x1d7],bl,area);
  2668. #endif
  2669. return;
  2670. }
  2671. /*==========================================
  2672. *
  2673. *------------------------------------------
  2674. */
  2675. int clif_initialstatus(struct map_session_data *sd)
  2676. {
  2677. int fd;
  2678. unsigned char *buf;
  2679. nullpo_retr(0, sd);
  2680. fd=sd->fd;
  2681. WFIFOHEAD(fd,packet_len_table[0xbd]);
  2682. buf=WFIFOP(fd,0);
  2683. WBUFW(buf,0)=0xbd;
  2684. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2685. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2686. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2687. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2688. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2689. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2690. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2691. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2692. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2693. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2694. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2695. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2696. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2697. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2698. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2699. WBUFW(buf,20) = sd->battle_status.matk_max;
  2700. WBUFW(buf,22) = sd->battle_status.matk_min;
  2701. WBUFW(buf,24) = sd->battle_status.def; // def
  2702. WBUFW(buf,26) = sd->battle_status.def2;
  2703. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2704. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2705. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2706. WBUFW(buf,30) = fd;
  2707. fd = sd->fd;
  2708. WBUFW(buf,32) = sd->battle_status.hit;
  2709. WBUFW(buf,34) = sd->battle_status.flee;
  2710. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2711. WBUFW(buf,38) = sd->battle_status.cri/10;
  2712. WBUFW(buf,40) = sd->status.karma;
  2713. WBUFW(buf,42) = sd->status.manner;
  2714. WFIFOSET(fd,packet_len_table[0xbd]);
  2715. clif_updatestatus(sd,SP_STR);
  2716. clif_updatestatus(sd,SP_AGI);
  2717. clif_updatestatus(sd,SP_VIT);
  2718. clif_updatestatus(sd,SP_INT);
  2719. clif_updatestatus(sd,SP_DEX);
  2720. clif_updatestatus(sd,SP_LUK);
  2721. clif_updatestatus(sd,SP_ATTACKRANGE);
  2722. clif_updatestatus(sd,SP_ASPD);
  2723. return 0;
  2724. }
  2725. /*==========================================
  2726. *矢装備
  2727. *------------------------------------------
  2728. */
  2729. int clif_arrowequip(struct map_session_data *sd,int val)
  2730. {
  2731. int fd;
  2732. nullpo_retr(0, sd);
  2733. pc_stop_attack(sd); // [Valaris]
  2734. fd=sd->fd;
  2735. WFIFOHEAD(fd, packet_len_table[0x013c]);
  2736. WFIFOW(fd,0)=0x013c;
  2737. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2738. WFIFOSET(fd,packet_len_table[0x013c]);
  2739. return 0;
  2740. }
  2741. /*==========================================
  2742. *
  2743. *------------------------------------------
  2744. */
  2745. int clif_arrow_fail(struct map_session_data *sd,int type)
  2746. {
  2747. int fd;
  2748. nullpo_retr(0, sd);
  2749. fd=sd->fd;
  2750. WFIFOHEAD(fd, packet_len_table[0x013b]);
  2751. WFIFOW(fd,0)=0x013b;
  2752. WFIFOW(fd,2)=type;
  2753. WFIFOSET(fd,packet_len_table[0x013b]);
  2754. return 0;
  2755. }
  2756. /*==========================================
  2757. * 作成可能 矢リスト送信
  2758. *------------------------------------------
  2759. */
  2760. int clif_arrow_create_list(struct map_session_data *sd)
  2761. {
  2762. int i, c, j;
  2763. int fd;
  2764. nullpo_retr(0, sd);
  2765. fd = sd->fd;
  2766. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2767. WFIFOW(fd,0) = 0x1ad;
  2768. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2769. if (skill_arrow_db[i].nameid > 0 &&
  2770. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2771. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2772. {
  2773. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2774. WFIFOW(fd,c*2+4) = j;
  2775. else
  2776. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2777. c++;
  2778. }
  2779. }
  2780. WFIFOW(fd,2) = c*2+4;
  2781. WFIFOSET(fd, WFIFOW(fd,2));
  2782. if (c > 0) {
  2783. sd->menuskill_id = AC_MAKINGARROW;
  2784. sd->menuskill_lv = c;
  2785. }
  2786. return 0;
  2787. }
  2788. /*==========================================
  2789. *
  2790. *------------------------------------------
  2791. */
  2792. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2793. {
  2794. int fd;
  2795. nullpo_retr(0, sd);
  2796. fd=sd->fd;
  2797. WFIFOHEAD(fd,packet_len_table[0xbc]);
  2798. WFIFOW(fd,0)=0xbc;
  2799. WFIFOW(fd,2)=type;
  2800. WFIFOB(fd,4)=ok;
  2801. WFIFOB(fd,5)=val;
  2802. WFIFOSET(fd,packet_len_table[0xbc]);
  2803. return 0;
  2804. }
  2805. /*==========================================
  2806. *
  2807. *------------------------------------------
  2808. */
  2809. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2810. {
  2811. int fd;
  2812. nullpo_retr(0, sd);
  2813. fd=sd->fd;
  2814. WFIFOHEAD(fd,packet_len_table[0xaa]);
  2815. WFIFOW(fd,0)=0xaa;
  2816. WFIFOW(fd,2)=n+2;
  2817. WFIFOW(fd,4)=pos;
  2818. WFIFOB(fd,6)=ok;
  2819. WFIFOSET(fd,packet_len_table[0xaa]);
  2820. return 0;
  2821. }
  2822. /*==========================================
  2823. *
  2824. *------------------------------------------
  2825. */
  2826. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2827. {
  2828. int fd;
  2829. nullpo_retr(0, sd);
  2830. fd=sd->fd;
  2831. WFIFOHEAD(fd,packet_len_table[0xac]);
  2832. WFIFOW(fd,0)=0xac;
  2833. WFIFOW(fd,2)=n+2;
  2834. WFIFOW(fd,4)=pos;
  2835. WFIFOB(fd,6)=ok;
  2836. WFIFOSET(fd,packet_len_table[0xac]);
  2837. return 0;
  2838. }
  2839. /*==========================================
  2840. *
  2841. *------------------------------------------
  2842. */
  2843. int clif_misceffect(struct block_list* bl,int type)
  2844. {
  2845. unsigned char buf[32];
  2846. nullpo_retr(0, bl);
  2847. WBUFW(buf,0) = 0x19b;
  2848. WBUFL(buf,2) = bl->id;
  2849. WBUFL(buf,6) = type;
  2850. clif_send(buf,packet_len_table[0x19b],bl,AREA);
  2851. return 0;
  2852. }
  2853. int clif_misceffect2(struct block_list *bl, int type) {
  2854. unsigned char buf[24];
  2855. nullpo_retr(0, bl);
  2856. malloc_set(buf, 0, packet_len_table[0x1f3]);
  2857. WBUFW(buf,0) = 0x1f3;
  2858. WBUFL(buf,2) = bl->id;
  2859. WBUFL(buf,6) = type;
  2860. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  2861. return 0;
  2862. }
  2863. /*==========================================
  2864. * 表示オプション変更
  2865. *------------------------------------------
  2866. */
  2867. int clif_changeoption(struct block_list* bl)
  2868. {
  2869. unsigned char buf[32];
  2870. struct status_change *sc;
  2871. nullpo_retr(0, bl);
  2872. sc = status_get_sc(bl);
  2873. if (!sc) return 0; //How can an option change if there's no sc?
  2874. #if PACKETVER > 6
  2875. WBUFW(buf,0) = 0x229;
  2876. WBUFL(buf,2) = bl->id;
  2877. WBUFW(buf,6) = sc->opt1;
  2878. WBUFW(buf,8) = sc->opt2;
  2879. WBUFL(buf,10) = sc->option;
  2880. WBUFB(buf,14) = 0; // ??
  2881. if(disguised(bl)) {
  2882. clif_send(buf,packet_len_table[0x229],bl,AREA_WOS);
  2883. WBUFL(buf,2) = -bl->id;
  2884. clif_send(buf,packet_len_table[0x229],bl,SELF);
  2885. WBUFL(buf,2) = bl->id;
  2886. WBUFL(buf,10) = OPTION_INVISIBLE;
  2887. clif_send(buf,packet_len_table[0x229],bl,SELF);
  2888. } else
  2889. clif_send(buf,packet_len_table[0x229],bl,AREA);
  2890. #else
  2891. WBUFW(buf,0) = 0x119;
  2892. WBUFL(buf,2) = bl->id;
  2893. WBUFW(buf,6) = sc->opt1;
  2894. WBUFW(buf,8) = sc->opt2;
  2895. WBUFW(buf,10) = sc->option;
  2896. WBUFB(buf,12) = 0; // ??
  2897. if(disguised(bl)) {
  2898. clif_send(buf,packet_len_table[0x119],bl,AREA_WOS);
  2899. WBUFL(buf,2) = -bl->id;
  2900. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2901. WBUFL(buf,2) = bl->id;
  2902. WBUFW(buf,10) = OPTION_INVISIBLE;
  2903. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2904. } else
  2905. clif_send(buf,packet_len_table[0x119],bl,AREA);
  2906. #endif
  2907. return 0;
  2908. }
  2909. /*==========================================
  2910. *
  2911. *------------------------------------------
  2912. */
  2913. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2914. {
  2915. nullpo_retr(0, sd);
  2916. if(!ok) {
  2917. int fd=sd->fd;
  2918. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2919. WFIFOW(fd,0)=0xa8;
  2920. WFIFOW(fd,2)=index+2;
  2921. WFIFOW(fd,4)=amount;
  2922. WFIFOB(fd,6)=ok;
  2923. WFIFOSET(fd,packet_len_table[0xa8]);
  2924. }
  2925. else {
  2926. #if PACKETVER < 3
  2927. int fd=sd->fd;
  2928. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2929. WFIFOW(fd,0)=0xa8;
  2930. WFIFOW(fd,2)=index+2;
  2931. WFIFOW(fd,4)=amount;
  2932. WFIFOB(fd,6)=ok;
  2933. WFIFOSET(fd,packet_len_table[0xa8]);
  2934. #else
  2935. unsigned char buf[32];
  2936. WBUFW(buf,0)=0x1c8;
  2937. WBUFW(buf,2)=index+2;
  2938. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2939. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2940. else
  2941. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2942. WBUFL(buf,6)=sd->bl.id;
  2943. WBUFW(buf,10)=amount;
  2944. WBUFB(buf,12)=ok;
  2945. clif_send(buf,packet_len_table[0x1c8],&sd->bl,AREA);
  2946. #endif
  2947. }
  2948. return 0;
  2949. }
  2950. /*==========================================
  2951. *
  2952. *------------------------------------------
  2953. */
  2954. int clif_createchat(struct map_session_data *sd,int fail)
  2955. {
  2956. int fd;
  2957. nullpo_retr(0, sd);
  2958. fd=sd->fd;
  2959. WFIFOHEAD(fd,packet_len_table[0xd6]);
  2960. WFIFOW(fd,0)=0xd6;
  2961. WFIFOB(fd,2)=fail;
  2962. WFIFOSET(fd,packet_len_table[0xd6]);
  2963. return 0;
  2964. }
  2965. /*==========================================
  2966. *
  2967. *------------------------------------------
  2968. */
  2969. int clif_dispchat(struct chat_data *cd,int fd)
  2970. {
  2971. unsigned char buf[128]; // 最大title(60バイト)+17
  2972. if(cd==NULL || *cd->owner==NULL)
  2973. return 1;
  2974. WBUFW(buf,0)=0xd7;
  2975. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  2976. WBUFL(buf,4)=(*cd->owner)->id;
  2977. WBUFL(buf,8)=cd->bl.id;
  2978. WBUFW(buf,12)=cd->limit;
  2979. WBUFW(buf,14)=cd->users;
  2980. WBUFB(buf,16)=cd->pub;
  2981. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2982. if(fd){
  2983. WFIFOHEAD(fd, WBUFW(buf,2));
  2984. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2985. WFIFOSET(fd,WBUFW(buf,2));
  2986. } else {
  2987. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  2988. }
  2989. return 0;
  2990. }
  2991. /*==========================================
  2992. * chatの状態変更成功
  2993. * 外部の人用と命令コード(d7->df)が違うだけ
  2994. *------------------------------------------
  2995. */
  2996. int clif_changechatstatus(struct chat_data *cd)
  2997. {
  2998. unsigned char buf[128]; // 最大title(60バイト)+17
  2999. if(cd==NULL || cd->usersd[0]==NULL)
  3000. return 1;
  3001. WBUFW(buf,0)=0xdf;
  3002. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  3003. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  3004. WBUFL(buf,8)=cd->bl.id;
  3005. WBUFW(buf,12)=cd->limit;
  3006. WBUFW(buf,14)=cd->users;
  3007. WBUFB(buf,16)=cd->pub;
  3008. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  3009. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  3010. return 0;
  3011. }
  3012. /*==========================================
  3013. *
  3014. *------------------------------------------
  3015. */
  3016. int clif_clearchat(struct chat_data *cd,int fd)
  3017. {
  3018. unsigned char buf[32];
  3019. nullpo_retr(0, cd);
  3020. WBUFW(buf,0)=0xd8;
  3021. WBUFL(buf,2)=cd->bl.id;
  3022. if(fd){
  3023. WFIFOHEAD(fd,packet_len_table[0xd8]);
  3024. memcpy(WFIFOP(fd,0),buf,packet_len_table[0xd8]);
  3025. WFIFOSET(fd,packet_len_table[0xd8]);
  3026. } else {
  3027. clif_send(buf,packet_len_table[0xd8],*cd->owner,AREA_WOSC);
  3028. }
  3029. return 0;
  3030. }
  3031. /*==========================================
  3032. *
  3033. *------------------------------------------
  3034. */
  3035. int clif_joinchatfail(struct map_session_data *sd,int fail)
  3036. {
  3037. int fd;
  3038. nullpo_retr(0, sd);
  3039. fd=sd->fd;
  3040. WFIFOHEAD(fd,packet_len_table[0xda]);
  3041. WFIFOW(fd,0)=0xda;
  3042. WFIFOB(fd,2)=fail;
  3043. WFIFOSET(fd,packet_len_table[0xda]);
  3044. return 0;
  3045. }
  3046. /*==========================================
  3047. *
  3048. *------------------------------------------
  3049. */
  3050. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3051. {
  3052. int fd;
  3053. int i;
  3054. nullpo_retr(0, sd);
  3055. nullpo_retr(0, cd);
  3056. fd = sd->fd;
  3057. if (!session_isActive(fd))
  3058. return 0;
  3059. WFIFOHEAD(fd, 8 + (28*cd->users));
  3060. WFIFOW(fd, 0) = 0xdb;
  3061. WFIFOW(fd, 2) = 8 + (28*cd->users);
  3062. WFIFOL(fd, 4) = cd->bl.id;
  3063. for (i = 0; i < cd->users; i++) {
  3064. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  3065. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3066. }
  3067. WFIFOSET(fd, WFIFOW(fd, 2));
  3068. return 0;
  3069. }
  3070. /*==========================================
  3071. *
  3072. *------------------------------------------
  3073. */
  3074. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3075. {
  3076. unsigned char buf[32];
  3077. nullpo_retr(0, sd);
  3078. nullpo_retr(0, cd);
  3079. WBUFW(buf, 0) = 0x0dc;
  3080. WBUFW(buf, 2) = cd->users;
  3081. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3082. clif_send(buf,packet_len_table[0xdc],&sd->bl,CHAT_WOS);
  3083. return 0;
  3084. }
  3085. /*==========================================
  3086. *
  3087. *------------------------------------------
  3088. */
  3089. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  3090. {
  3091. unsigned char buf[64];
  3092. nullpo_retr(0, sd);
  3093. nullpo_retr(0, cd);
  3094. WBUFW(buf, 0) = 0xe1;
  3095. WBUFL(buf, 2) = 1;
  3096. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3097. WBUFW(buf,30) = 0xe1;
  3098. WBUFL(buf,32) = 0;
  3099. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3100. clif_send(buf,packet_len_table[0xe1]*2,&sd->bl,CHAT);
  3101. return 0;
  3102. }
  3103. /*==========================================
  3104. *
  3105. *------------------------------------------
  3106. */
  3107. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  3108. {
  3109. unsigned char buf[32];
  3110. nullpo_retr(0, sd);
  3111. nullpo_retr(0, cd);
  3112. WBUFW(buf, 0) = 0xdd;
  3113. WBUFW(buf, 2) = cd->users-1;
  3114. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3115. WBUFB(buf,28) = 0;
  3116. clif_send(buf,packet_len_table[0xdd],&sd->bl,CHAT);
  3117. return 0;
  3118. }
  3119. /*==========================================
  3120. * 取り引き要請受け
  3121. *------------------------------------------
  3122. */
  3123. int clif_traderequest(struct map_session_data *sd,char *name)
  3124. {
  3125. int fd;
  3126. nullpo_retr(0, sd);
  3127. fd=sd->fd;
  3128. WFIFOHEAD(fd,packet_len_table[0xe5]);
  3129. WFIFOW(fd,0)=0xe5;
  3130. strcpy((char*)WFIFOP(fd,2),name);
  3131. WFIFOSET(fd,packet_len_table[0xe5]);
  3132. return 0;
  3133. }
  3134. /*==========================================
  3135. * 取り引き要求応答
  3136. *------------------------------------------
  3137. */
  3138. int clif_tradestart(struct map_session_data *sd,int type)
  3139. {
  3140. int fd;
  3141. nullpo_retr(0, sd);
  3142. fd=sd->fd;
  3143. WFIFOHEAD(fd,packet_len_table[0xe7]);
  3144. WFIFOW(fd,0)=0xe7;
  3145. WFIFOB(fd,2)=type;
  3146. WFIFOSET(fd,packet_len_table[0xe7]);
  3147. return 0;
  3148. }
  3149. /*==========================================
  3150. * 相手方からのアイテム追加
  3151. *------------------------------------------
  3152. */
  3153. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  3154. {
  3155. int fd;
  3156. nullpo_retr(0, sd);
  3157. nullpo_retr(0, tsd);
  3158. fd=tsd->fd;
  3159. WFIFOHEAD(fd,packet_len_table[0xe9]);
  3160. WFIFOW(fd,0)=0xe9;
  3161. WFIFOL(fd,2)=amount;
  3162. if(index==0){
  3163. WFIFOW(fd,6) = 0; // type id
  3164. WFIFOB(fd,8) = 0; //identify flag
  3165. WFIFOB(fd,9) = 0; // attribute
  3166. WFIFOB(fd,10)= 0; //refine
  3167. WFIFOW(fd,11)= 0; //card (4w)
  3168. WFIFOW(fd,13)= 0; //card (4w)
  3169. WFIFOW(fd,15)= 0; //card (4w)
  3170. WFIFOW(fd,17)= 0; //card (4w)
  3171. }
  3172. else{
  3173. index-=2; //index fix
  3174. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3175. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3176. else
  3177. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3178. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3179. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3180. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3181. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3182. }
  3183. WFIFOSET(fd,packet_len_table[0xe9]);
  3184. return 0;
  3185. }
  3186. /*==========================================
  3187. * アイテム追加成功/失敗
  3188. *------------------------------------------
  3189. */
  3190. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3191. {
  3192. int fd;
  3193. nullpo_retr(0, sd);
  3194. fd=sd->fd;
  3195. WFIFOHEAD(fd,packet_len_table[0xea]);
  3196. WFIFOW(fd,0)=0xea;
  3197. WFIFOW(fd,2)=index;
  3198. WFIFOB(fd,4)=fail;
  3199. WFIFOSET(fd,packet_len_table[0xea]);
  3200. return 0;
  3201. }
  3202. /*==========================================
  3203. * 取り引きok押し
  3204. *------------------------------------------
  3205. */
  3206. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3207. {
  3208. int fd;
  3209. nullpo_retr(0, sd);
  3210. fd=sd->fd;
  3211. WFIFOHEAD(fd,packet_len_table[0xec]);
  3212. WFIFOW(fd,0)=0xec;
  3213. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3214. WFIFOSET(fd,packet_len_table[0xec]);
  3215. return 0;
  3216. }
  3217. /*==========================================
  3218. * 取り引きがキャンセルされました
  3219. *------------------------------------------
  3220. */
  3221. int clif_tradecancelled(struct map_session_data *sd)
  3222. {
  3223. int fd;
  3224. nullpo_retr(0, sd);
  3225. fd=sd->fd;
  3226. WFIFOHEAD(fd,packet_len_table[0xee]);
  3227. WFIFOW(fd,0)=0xee;
  3228. WFIFOSET(fd,packet_len_table[0xee]);
  3229. return 0;
  3230. }
  3231. /*==========================================
  3232. * 取り引き完了
  3233. *------------------------------------------
  3234. */
  3235. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3236. {
  3237. int fd;
  3238. nullpo_retr(0, sd);
  3239. fd=sd->fd;
  3240. WFIFOHEAD(fd,packet_len_table[0xf0]);
  3241. WFIFOW(fd,0)=0xf0;
  3242. WFIFOB(fd,2)=fail;
  3243. WFIFOSET(fd,packet_len_table[0xf0]);
  3244. return 0;
  3245. }
  3246. /*==========================================
  3247. * カプラ倉庫のアイテム数を更新
  3248. *------------------------------------------
  3249. */
  3250. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3251. {
  3252. int fd;
  3253. nullpo_retr(0, sd);
  3254. nullpo_retr(0, stor);
  3255. fd=sd->fd;
  3256. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3257. WFIFOW(fd,0) = 0xf2; // update storage amount
  3258. WFIFOW(fd,2) = stor->storage_amount; //items
  3259. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3260. WFIFOSET(fd,packet_len_table[0xf2]);
  3261. return 0;
  3262. }
  3263. /*==========================================
  3264. * カプラ倉庫にアイテムを追加する
  3265. *------------------------------------------
  3266. */
  3267. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3268. {
  3269. int view,fd;
  3270. nullpo_retr(0, sd);
  3271. nullpo_retr(0, stor);
  3272. fd=sd->fd;
  3273. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3274. WFIFOW(fd,0) =0xf4; // Storage item added
  3275. WFIFOW(fd,2) =index+1; // index
  3276. WFIFOL(fd,4) =amount; // amount
  3277. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3278. WFIFOW(fd,8) =view;
  3279. else
  3280. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3281. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3282. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3283. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3284. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3285. WFIFOSET(fd,packet_len_table[0xf4]);
  3286. return 0;
  3287. }
  3288. /*==========================================
  3289. *
  3290. *------------------------------------------
  3291. */
  3292. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3293. {
  3294. int fd;
  3295. nullpo_retr(0, sd);
  3296. nullpo_retr(0, stor);
  3297. fd=sd->fd;
  3298. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3299. WFIFOW(fd,0) = 0xf2; // update storage amount
  3300. WFIFOW(fd,2) = stor->storage_amount; //items
  3301. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3302. WFIFOSET(fd,packet_len_table[0xf2]);
  3303. return 0;
  3304. }
  3305. /*==========================================
  3306. *
  3307. *------------------------------------------
  3308. */
  3309. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3310. {
  3311. int view,fd;
  3312. nullpo_retr(0, sd);
  3313. nullpo_retr(0, stor);
  3314. fd=sd->fd;
  3315. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3316. WFIFOW(fd,0) =0xf4; // Storage item added
  3317. WFIFOW(fd,2) =index+1; // index
  3318. WFIFOL(fd,4) =amount; // amount
  3319. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3320. WFIFOW(fd,8) =view;
  3321. else
  3322. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3323. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3324. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3325. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3326. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3327. WFIFOSET(fd,packet_len_table[0xf4]);
  3328. return 0;
  3329. }
  3330. /*==========================================
  3331. * カプラ倉庫からアイテムを取り去る
  3332. *------------------------------------------
  3333. */
  3334. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3335. {
  3336. int fd;
  3337. nullpo_retr(0, sd);
  3338. fd=sd->fd;
  3339. WFIFOHEAD(fd,packet_len_table[0xf6]);
  3340. WFIFOW(fd,0)=0xf6; // Storage item removed
  3341. WFIFOW(fd,2)=index+1;
  3342. WFIFOL(fd,4)=amount;
  3343. WFIFOSET(fd,packet_len_table[0xf6]);
  3344. return 0;
  3345. }
  3346. /*==========================================
  3347. * カプラ倉庫を閉じる
  3348. *------------------------------------------
  3349. */
  3350. int clif_storageclose(struct map_session_data *sd)
  3351. {
  3352. int fd;
  3353. nullpo_retr(0, sd);
  3354. fd=sd->fd;
  3355. WFIFOHEAD(fd,packet_len_table[0xf8]);
  3356. WFIFOW(fd,0)=0xf8; // Storage Closed
  3357. WFIFOSET(fd,packet_len_table[0xf8]);
  3358. return 0;
  3359. }
  3360. //
  3361. // callback系 ?
  3362. //
  3363. /*==========================================
  3364. * PC表示
  3365. *------------------------------------------
  3366. */
  3367. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3368. {
  3369. int len;
  3370. if(dstsd->chatID){
  3371. struct chat_data *cd;
  3372. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3373. if(cd && cd->usersd[0]==dstsd)
  3374. clif_dispchat(cd,sd->fd);
  3375. }
  3376. if(dstsd->vender_id)
  3377. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3378. if(dstsd->spiritball > 0)
  3379. clif_spiritball_single(sd->fd, dstsd);
  3380. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3381. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3382. )
  3383. clif_hpmeter_single(sd->fd, dstsd);
  3384. if(dstsd->status.manner < 0)
  3385. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3386. // pvp circle for duel [LuzZza]
  3387. /*
  3388. if(dstsd->duel_group)
  3389. clif_specialeffect(&dstsd->bl, 159, 4);
  3390. */
  3391. }
  3392. void clif_getareachar_char(struct map_session_data* sd,struct block_list *bl)
  3393. {
  3394. struct unit_data *ud;
  3395. struct view_data *vd;
  3396. int len;
  3397. vd = status_get_viewdata(bl);
  3398. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3399. return;
  3400. ud = unit_bl2ud(bl);
  3401. if (ud && ud->walktimer != -1)
  3402. {
  3403. #if PACKETVER > 6
  3404. WFIFOHEAD(sd->fd, packet_len_table[0x22c]);
  3405. #elif PACKETVER > 3
  3406. WFIFOHEAD(sd->fd, packet_len_table[0x1da]);
  3407. #else
  3408. WFIFOHEAD(sd->fd, packet_len_table[0x7b]);
  3409. #endif
  3410. len = clif_set007b(bl,vd,ud,WFIFOP(sd->fd,0));
  3411. WFIFOSET(sd->fd,len);
  3412. } else {
  3413. #if PACKETVER > 6
  3414. WFIFOHEAD(sd->fd,packet_len_table[0x22a]);
  3415. #elif PACKETVER > 3
  3416. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3417. #else
  3418. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3419. #endif
  3420. len = clif_set0078(bl,vd,WFIFOP(sd->fd,0));
  3421. WFIFOSET(sd->fd,len);
  3422. }
  3423. if (vd->cloth_color)
  3424. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3425. switch (bl->type)
  3426. {
  3427. case BL_PC:
  3428. {
  3429. TBL_PC* tsd = (TBL_PC*)bl;
  3430. clif_getareachar_pc(sd, tsd);
  3431. if(tsd->state.size==2) // tiny/big players [Valaris]
  3432. clif_specialeffect(bl,423,AREA);
  3433. else if(tsd->state.size==1)
  3434. clif_specialeffect(bl,421,AREA);
  3435. }
  3436. break;
  3437. case BL_NPC:
  3438. {
  3439. if(((TBL_NPC*)bl)->chat_id)
  3440. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3441. }
  3442. break;
  3443. case BL_MOB:
  3444. {
  3445. TBL_MOB* md = (TBL_MOB*)bl;
  3446. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3447. clif_specialeffect(bl,423,AREA);
  3448. else if(md->special_state.size==1)
  3449. clif_specialeffect(bl,421,AREA);
  3450. }
  3451. break;
  3452. }
  3453. }
  3454. /*==========================================
  3455. * Older fix pos packet.
  3456. *------------------------------------------
  3457. */
  3458. int clif_fixpos2(struct block_list* bl)
  3459. {
  3460. struct unit_data *ud;
  3461. struct view_data *vd;
  3462. unsigned char buf[256];
  3463. int len;
  3464. nullpo_retr(0, bl);
  3465. ud = unit_bl2ud(bl);
  3466. vd = status_get_viewdata(bl);
  3467. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3468. return 0;
  3469. if(ud && ud->walktimer != -1)
  3470. len = clif_set007b(bl,vd,ud,buf);
  3471. else
  3472. len = clif_set0078(bl,vd,buf);
  3473. if (disguised(bl)) {
  3474. clif_send(buf,len,bl,AREA_WOS);
  3475. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  3476. clif_setdisguise((TBL_PC*)bl, buf, len, 1);
  3477. } else
  3478. clif_send(buf,len,bl,AREA);
  3479. return 0;
  3480. }
  3481. //Modifies the type of damage according to status changes [Skotlex]
  3482. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3483. /*==========================================
  3484. * Estimates walk delay based on the damage criteria. [Skotlex]
  3485. *------------------------------------------
  3486. */
  3487. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3488. if (type == 4 || type == 9 || damage <=0)
  3489. return 0;
  3490. if (bl->type == BL_PC) {
  3491. if (battle_config.pc_walk_delay_rate != 100)
  3492. delay = delay*battle_config.pc_walk_delay_rate/100;
  3493. } else
  3494. if (battle_config.walk_delay_rate != 100)
  3495. delay = delay*battle_config.walk_delay_rate/100;
  3496. if (div_ > 1) //Multi-hit skills mean higher delays.
  3497. delay += battle_config.multihit_delay*(div_-1);
  3498. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3499. }
  3500. /*==========================================
  3501. * 通常攻撃エフェクト&ダメージ
  3502. *------------------------------------------
  3503. */
  3504. 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)
  3505. {
  3506. unsigned char buf[256];
  3507. struct status_change *sc;
  3508. nullpo_retr(0, src);
  3509. nullpo_retr(0, dst);
  3510. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3511. sc = status_get_sc(dst);
  3512. if(sc && sc->count) {
  3513. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3514. if(damage > 0)
  3515. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3516. if(damage2 > 0)
  3517. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3518. }
  3519. }
  3520. WBUFW(buf,0)=0x8a;
  3521. WBUFL(buf,2)=src->id;
  3522. WBUFL(buf,6)=dst->id;
  3523. WBUFL(buf,10)=tick;
  3524. WBUFL(buf,14)=sdelay;
  3525. WBUFL(buf,18)=ddelay;
  3526. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3527. WBUFW(buf,22)=damage?div:0;
  3528. WBUFW(buf,27)=damage2?div:0;
  3529. } else {
  3530. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3531. WBUFW(buf,27)=damage2;
  3532. }
  3533. WBUFW(buf,24)=div;
  3534. WBUFB(buf,26)=type;
  3535. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3536. if(disguised(src)) {
  3537. WBUFL(buf,2)=-src->id;
  3538. if(damage > 0)
  3539. WBUFW(buf,22)=-1;
  3540. if(damage2 > 0)
  3541. WBUFW(buf,27)=-1;
  3542. clif_send(buf,packet_len_table[0x8a],src,SELF);
  3543. }
  3544. if (disguised(dst)) {
  3545. WBUFL(buf,6)=-dst->id;
  3546. if (disguised(src))
  3547. WBUFL(buf,2)=src->id;
  3548. else {
  3549. if(damage > 0)
  3550. WBUFW(buf,22)=-1;
  3551. if(damage2 > 0)
  3552. WBUFW(buf,27)=-1;
  3553. }
  3554. clif_send(buf,packet_len_table[0x8a],dst,SELF);
  3555. }
  3556. //Return adjusted can't walk delay for further processing.
  3557. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3558. }
  3559. /*==========================================
  3560. *
  3561. *------------------------------------------
  3562. */
  3563. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3564. {
  3565. int view,fd;
  3566. fd=sd->fd;
  3567. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3568. WFIFOHEAD(fd,packet_len_table[0x9d]);
  3569. WFIFOW(fd,0)=0x9d;
  3570. WFIFOL(fd,2)=fitem->bl.id;
  3571. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3572. WFIFOW(fd,6)=view;
  3573. else
  3574. WFIFOW(fd,6)=fitem->item_data.nameid;
  3575. WFIFOB(fd,8)=fitem->item_data.identify;
  3576. WFIFOW(fd,9)=fitem->bl.x;
  3577. WFIFOW(fd,11)=fitem->bl.y;
  3578. WFIFOW(fd,13)=fitem->item_data.amount;
  3579. WFIFOB(fd,15)=fitem->subx;
  3580. WFIFOB(fd,16)=fitem->suby;
  3581. WFIFOSET(fd,packet_len_table[0x9d]);
  3582. }
  3583. /*==========================================
  3584. * 場所スキルエフェクトが視界に入る
  3585. *------------------------------------------
  3586. */
  3587. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3588. {
  3589. int fd;
  3590. struct block_list *bl;
  3591. fd=sd->fd;
  3592. bl=map_id2bl(unit->group->src_id);
  3593. #if PACKETVER >= 3
  3594. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3595. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3596. malloc_set(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3597. WFIFOW(fd, 0)=0x1c9;
  3598. WFIFOL(fd, 2)=unit->bl.id;
  3599. WFIFOL(fd, 6)=unit->group->src_id;
  3600. WFIFOW(fd,10)=unit->bl.x;
  3601. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3602. WFIFOB(fd,14)=unit->group->unit_id;
  3603. WFIFOB(fd,15)=1;
  3604. WFIFOB(fd,16)=1;
  3605. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3606. WFIFOSET(fd,packet_len_table[0x1c9]);
  3607. return 0;
  3608. }
  3609. #endif
  3610. WFIFOHEAD(fd,packet_len_table[0x11f]);
  3611. malloc_set(WFIFOP(fd,0),0,packet_len_table[0x11f]);
  3612. WFIFOW(fd, 0)=0x11f;
  3613. WFIFOL(fd, 2)=unit->bl.id;
  3614. WFIFOL(fd, 6)=unit->group->src_id;
  3615. WFIFOW(fd,10)=unit->bl.x;
  3616. WFIFOW(fd,12)=unit->bl.y;
  3617. //Use invisible unit id for traps.
  3618. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3619. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3620. else
  3621. WFIFOB(fd,14)=unit->group->unit_id;
  3622. WFIFOB(fd,15)=0;
  3623. WFIFOSET(fd,packet_len_table[0x11f]);
  3624. if(unit->group->skill_id == WZ_ICEWALL)
  3625. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3626. return 0;
  3627. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3628. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3629. malloc_set(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3630. WFIFOW(fd, 0)=0x1c9;
  3631. WFIFOL(fd, 2)=unit->bl.id;
  3632. WFIFOL(fd, 6)=unit->group->src_id;
  3633. WFIFOW(fd,10)=unit->bl.x;
  3634. WFIFOW(fd,12)=unit->bl.y;
  3635. WFIFOB(fd,14)=unit->group->unit_id;
  3636. WFIFOB(fd,15)=1;
  3637. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3638. WFIFOB(fd,16)=1;
  3639. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3640. } else {
  3641. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3642. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3643. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3644. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3645. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3646. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3647. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3648. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3649. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3650. //37-39
  3651. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3652. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3653. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3654. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3655. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3656. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3657. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3658. //65-68
  3659. //69-72
  3660. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3661. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3662. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3663. }
  3664. WFIFOSET(fd,packet_len_table[0x1c9]);
  3665. #endif
  3666. if(unit->group->skill_id == WZ_ICEWALL)
  3667. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3668. return 0;
  3669. */
  3670. }
  3671. /*==========================================
  3672. * 場所スキルエフェクトが視界から消える
  3673. *------------------------------------------
  3674. */
  3675. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3676. {
  3677. nullpo_retr(0, unit);
  3678. WFIFOHEAD(fd,packet_len_table[0x120]);
  3679. WFIFOW(fd, 0)=0x120;
  3680. WFIFOL(fd, 2)=unit->bl.id;
  3681. WFIFOSET(fd,packet_len_table[0x120]);
  3682. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3683. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3684. return 0;
  3685. }
  3686. /*==========================================
  3687. *
  3688. *------------------------------------------
  3689. */
  3690. int clif_01ac(struct block_list *bl)
  3691. {
  3692. unsigned char buf[32];
  3693. nullpo_retr(0, bl);
  3694. WBUFW(buf, 0) = 0x1ac;
  3695. WBUFL(buf, 2) = bl->id;
  3696. clif_send(buf,packet_len_table[0x1ac],bl,AREA);
  3697. return 0;
  3698. }
  3699. /*==========================================
  3700. *
  3701. *------------------------------------------
  3702. */
  3703. int clif_getareachar(struct block_list* bl,va_list ap)
  3704. {
  3705. struct map_session_data *sd;
  3706. nullpo_retr(0, bl);
  3707. nullpo_retr(0, ap);
  3708. sd=va_arg(ap,struct map_session_data*);
  3709. if (sd == NULL || session[sd->fd] == NULL)
  3710. return 0;
  3711. switch(bl->type){
  3712. case BL_ITEM:
  3713. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3714. break;
  3715. case BL_SKILL:
  3716. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3717. break;
  3718. default:
  3719. if(&sd->bl == bl)
  3720. break;
  3721. clif_getareachar_char(sd,bl);
  3722. break;
  3723. }
  3724. return 0;
  3725. }
  3726. /*==========================================
  3727. * tbl has gone out of view-size of bl
  3728. *------------------------------------------
  3729. */
  3730. int clif_outsight(struct block_list *bl,va_list ap)
  3731. {
  3732. struct block_list *tbl;
  3733. struct view_data *vd;
  3734. TBL_PC *sd, *tsd;
  3735. tbl=va_arg(ap,struct block_list*);
  3736. if(bl == tbl) return 0;
  3737. BL_CAST(BL_PC, bl, sd);
  3738. BL_CAST(BL_PC, tbl, tsd);
  3739. if (tsd && tsd->fd)
  3740. { //tsd has lost sight of the bl object.
  3741. switch(bl->type){
  3742. case BL_PC:
  3743. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3744. clif_clearchar_id(bl->id,0,tsd->fd);
  3745. if(sd->chatID){
  3746. struct chat_data *cd;
  3747. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3748. if(cd->usersd[0]==sd)
  3749. clif_dispchat(cd,tsd->fd);
  3750. }
  3751. if(sd->vender_id)
  3752. clif_closevendingboard(bl,tsd->fd);
  3753. break;
  3754. case BL_ITEM:
  3755. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3756. break;
  3757. case BL_SKILL:
  3758. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3759. break;
  3760. default:
  3761. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3762. clif_clearchar_id(bl->id,0,tsd->fd);
  3763. break;
  3764. }
  3765. }
  3766. if (sd && sd->fd)
  3767. { //sd is watching tbl go out of view.
  3768. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3769. clif_clearchar_id(tbl->id,0,sd->fd);
  3770. }
  3771. return 0;
  3772. }
  3773. /*==========================================
  3774. * tbl has come into view of bl
  3775. *------------------------------------------
  3776. */
  3777. int clif_insight(struct block_list *bl,va_list ap)
  3778. {
  3779. struct block_list *tbl;
  3780. TBL_PC *sd, *tsd;
  3781. tbl=va_arg(ap,struct block_list*);
  3782. if (bl == tbl) return 0;
  3783. BL_CAST(BL_PC, bl, sd);
  3784. BL_CAST(BL_PC, tbl, tsd);
  3785. if (tsd && tsd->fd)
  3786. { //Tell tsd that bl entered into his view
  3787. switch(bl->type){
  3788. case BL_ITEM:
  3789. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3790. break;
  3791. case BL_SKILL:
  3792. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3793. break;
  3794. default:
  3795. clif_getareachar_char(tsd,bl);
  3796. break;
  3797. }
  3798. }
  3799. if (sd && sd->fd)
  3800. { //Tell sd that tbl walked into his view
  3801. clif_getareachar_char(sd,tbl);
  3802. }
  3803. return 0;
  3804. }
  3805. /*==========================================
  3806. *
  3807. *------------------------------------------
  3808. */
  3809. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3810. {
  3811. int fd,id, inf2;
  3812. nullpo_retr(0, sd);
  3813. fd=sd->fd;
  3814. if( (id=sd->status.skill[skillid].id) <= 0 )
  3815. return 0;
  3816. WFIFOHEAD(fd,packet_len_table[0x147]);
  3817. WFIFOW(fd,0)=0x147;
  3818. WFIFOW(fd,2) = id;
  3819. if(type < 0)
  3820. WFIFOW(fd,4) = skill_get_inf(id);
  3821. else
  3822. WFIFOW(fd,4) = type;
  3823. WFIFOW(fd,6) = 0;
  3824. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3825. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3826. if(range < 0)
  3827. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3828. WFIFOW(fd,12)= range;
  3829. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3830. inf2 = skill_get_inf2(id);
  3831. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3832. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3833. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill))
  3834. //WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_get_max(id) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3835. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3836. else
  3837. WFIFOB(fd,38) = 0;
  3838. WFIFOSET(fd,packet_len_table[0x147]);
  3839. return 0;
  3840. }
  3841. /*==========================================
  3842. * スキルリストを送信する
  3843. *------------------------------------------
  3844. */
  3845. int clif_skillinfoblock(struct map_session_data *sd)
  3846. {
  3847. int fd;
  3848. int i,c,len=4,id, inf2;
  3849. nullpo_retr(0, sd);
  3850. fd=sd->fd;
  3851. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3852. WFIFOW(fd,0)=0x10f;
  3853. for ( i = c = 0; i < MAX_SKILL; i++){
  3854. if( (id=sd->status.skill[i].id)!=0 ){
  3855. WFIFOW(fd,len ) = id;
  3856. WFIFOW(fd,len+2) = skill_get_inf(id);
  3857. WFIFOW(fd,len+4) = 0;
  3858. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3859. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3860. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3861. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3862. inf2 = skill_get_inf2(id);
  3863. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3864. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3865. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill) )
  3866. WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[i].flag ==0 )? 1:0;
  3867. else
  3868. WFIFOB(fd,len+36) = 0;
  3869. len+=37;
  3870. c++;
  3871. }
  3872. }
  3873. WFIFOW(fd,2)=len;
  3874. WFIFOSET(fd,len);
  3875. return 0;
  3876. }
  3877. /*==========================================
  3878. * スキル割り振り通知
  3879. *------------------------------------------
  3880. */
  3881. int clif_skillup(struct map_session_data *sd,int skill_num)
  3882. {
  3883. int fd;
  3884. nullpo_retr(0, sd);
  3885. fd=sd->fd;
  3886. WFIFOHEAD(fd,packet_len_table[0x10e]);
  3887. WFIFOW(fd,0) = 0x10e;
  3888. WFIFOW(fd,2) = skill_num;
  3889. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3890. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3891. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3892. //WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_get_max(sd->status.skill[skill_num].id)) ? 1 : 0;
  3893. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3894. WFIFOSET(fd,packet_len_table[0x10e]);
  3895. return 0;
  3896. }
  3897. /*==========================================
  3898. * スキル詠唱エフェクトを送信する
  3899. *------------------------------------------
  3900. */
  3901. int clif_skillcasting(struct block_list* bl,
  3902. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  3903. {
  3904. int pl = skill_get_pl(skill_num);
  3905. unsigned char buf[32];
  3906. WBUFW(buf,0) = 0x13e;
  3907. WBUFL(buf,2) = src_id;
  3908. WBUFL(buf,6) = dst_id;
  3909. WBUFW(buf,10) = dst_x;
  3910. WBUFW(buf,12) = dst_y;
  3911. WBUFW(buf,14) = skill_num;
  3912. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3913. WBUFL(buf,20) = casttime;
  3914. clif_send(buf,packet_len_table[0x13e], bl, AREA);
  3915. if (disguised(bl)) {
  3916. WBUFL(buf,2) = -src_id;
  3917. WBUFL(buf,20) = 0;
  3918. clif_send(buf,packet_len_table[0x13e], bl, SELF);
  3919. }
  3920. return 0;
  3921. }
  3922. /*==========================================
  3923. *
  3924. *------------------------------------------
  3925. */
  3926. int clif_skillcastcancel(struct block_list* bl)
  3927. {
  3928. unsigned char buf[16];
  3929. nullpo_retr(0, bl);
  3930. WBUFW(buf,0) = 0x1b9;
  3931. WBUFL(buf,2) = bl->id;
  3932. clif_send(buf,packet_len_table[0x1b9], bl, AREA);
  3933. return 0;
  3934. }
  3935. /*==========================================
  3936. * スキル詠唱失敗
  3937. *------------------------------------------
  3938. */
  3939. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3940. {
  3941. int fd;
  3942. if (!sd) { //Since this is the most common nullpo....
  3943. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3944. return 0;
  3945. }
  3946. fd=sd->fd;
  3947. if(battle_config.display_skill_fail&1)
  3948. return 0; //Disable all skill failed messages
  3949. if(type==0x4 && !sd->state.showdelay)
  3950. return 0; //Disable delay failed messages
  3951. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3952. return 0;
  3953. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3954. return 0;
  3955. WFIFOHEAD(fd,packet_len_table[0x110]);
  3956. WFIFOW(fd,0) = 0x110;
  3957. WFIFOW(fd,2) = skill_id;
  3958. WFIFOW(fd,4) = btype;
  3959. WFIFOW(fd,6) = 0;
  3960. WFIFOB(fd,8) = 0;
  3961. WFIFOB(fd,9) = type;
  3962. WFIFOSET(fd,packet_len_table[0x110]);
  3963. return 1;
  3964. }
  3965. /*==========================================
  3966. * スキル攻撃エフェクト&ダメージ
  3967. *------------------------------------------
  3968. */
  3969. int clif_skill_damage(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. #if PACKETVER < 3
  3984. WBUFW(buf,0)=0x114;
  3985. WBUFW(buf,2)=skill_id;
  3986. WBUFL(buf,4)=src->id;
  3987. WBUFL(buf,8)=dst->id;
  3988. WBUFL(buf,12)=tick;
  3989. WBUFL(buf,16)=sdelay;
  3990. WBUFL(buf,20)=ddelay;
  3991. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3992. WBUFW(buf,24)=damage?div:0;
  3993. } else {
  3994. WBUFW(buf,24)=damage;
  3995. }
  3996. WBUFW(buf,26)=skill_lv;
  3997. WBUFW(buf,28)=div;
  3998. WBUFB(buf,30)=type;
  3999. clif_send(buf,packet_len_table[0x114],src,AREA);
  4000. if(disguised(src)) {
  4001. WBUFL(buf,4)=-src->id;
  4002. if(damage > 0)
  4003. WBUFW(buf,24)=-1;
  4004. clif_send(buf,packet_len_table[0x114],src,SELF);
  4005. }
  4006. if (disguised(dst)) {
  4007. WBUFL(buf,8)=-dst->id;
  4008. if (disguised(src))
  4009. WBUFL(buf,4)=src->id;
  4010. else if(damage > 0)
  4011. WBUFW(buf,24)=-1;
  4012. clif_send(buf,packet_len_table[0x114],dst,SELF);
  4013. }
  4014. #else
  4015. WBUFW(buf,0)=0x1de;
  4016. WBUFW(buf,2)=skill_id;
  4017. WBUFL(buf,4)=src->id;
  4018. WBUFL(buf,8)=dst->id;
  4019. WBUFL(buf,12)=tick;
  4020. WBUFL(buf,16)=sdelay;
  4021. WBUFL(buf,20)=ddelay;
  4022. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4023. WBUFL(buf,24)=damage?div:0;
  4024. } else {
  4025. WBUFL(buf,24)=damage;
  4026. }
  4027. WBUFW(buf,28)=skill_lv;
  4028. WBUFW(buf,30)=div;
  4029. WBUFB(buf,32)=type;
  4030. clif_send(buf,packet_len_table[0x1de],src,AREA);
  4031. if(disguised(src)) {
  4032. WBUFL(buf,4)=-src->id;
  4033. if(damage > 0)
  4034. WBUFW(buf,24)=-1;
  4035. clif_send(buf,packet_len_table[0x1de],src,SELF);
  4036. }
  4037. if (disguised(dst)) {
  4038. WBUFL(buf,8)=-dst->id;
  4039. if (disguised(src))
  4040. WBUFL(buf,4)=src->id;
  4041. else if(damage > 0)
  4042. WBUFW(buf,24)=-1;
  4043. clif_send(buf,packet_len_table[0x1de],dst,SELF);
  4044. }
  4045. #endif
  4046. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4047. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4048. }
  4049. /*==========================================
  4050. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  4051. *------------------------------------------
  4052. */
  4053. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  4054. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4055. {
  4056. unsigned char buf[64];
  4057. struct status_change *sc;
  4058. nullpo_retr(0, src);
  4059. nullpo_retr(0, dst);
  4060. type = (type>0)?type:skill_get_hit(skill_id);
  4061. type = clif_calc_delay(type, ddelay);
  4062. sc = status_get_sc(dst);
  4063. if(sc && sc->count) {
  4064. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  4065. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  4066. }
  4067. WBUFW(buf,0)=0x115;
  4068. WBUFW(buf,2)=skill_id;
  4069. WBUFL(buf,4)=src->id;
  4070. WBUFL(buf,8)=dst->id;
  4071. WBUFL(buf,12)=tick;
  4072. WBUFL(buf,16)=sdelay;
  4073. WBUFL(buf,20)=ddelay;
  4074. WBUFW(buf,24)=dst->x;
  4075. WBUFW(buf,26)=dst->y;
  4076. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4077. WBUFW(buf,28)=damage?div:0;
  4078. } else {
  4079. WBUFW(buf,28)=damage;
  4080. }
  4081. WBUFW(buf,30)=skill_lv;
  4082. WBUFW(buf,32)=div;
  4083. WBUFB(buf,34)=type;
  4084. clif_send(buf,packet_len_table[0x115],src,AREA);
  4085. if(disguised(src)) {
  4086. WBUFL(buf,4)=-src->id;
  4087. if(damage > 0)
  4088. WBUFW(buf,28)=-1;
  4089. clif_send(buf,packet_len_table[0x115],src,SELF);
  4090. }
  4091. if (disguised(dst)) {
  4092. WBUFL(buf,8)=-dst->id;
  4093. if (disguised(src))
  4094. WBUFL(buf,4)=src->id;
  4095. else if(damage > 0)
  4096. WBUFW(buf,28)=-1;
  4097. clif_send(buf,packet_len_table[0x115],dst,SELF);
  4098. }
  4099. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4100. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4101. }
  4102. /*==========================================
  4103. * 支援/回復スキルエフェクト
  4104. *------------------------------------------
  4105. */
  4106. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  4107. int skill_id,int heal,int fail)
  4108. {
  4109. unsigned char buf[32];
  4110. nullpo_retr(0, dst);
  4111. WBUFW(buf,0)=0x11a;
  4112. WBUFW(buf,2)=skill_id;
  4113. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  4114. WBUFL(buf,6)=dst->id;
  4115. WBUFL(buf,10)=src?src->id:0;
  4116. WBUFB(buf,14)=fail;
  4117. clif_send(buf,packet_len_table[0x11a],dst,AREA);
  4118. if (disguised(dst)) {
  4119. WBUFL(buf,6)=-dst->id;
  4120. clif_send(buf,packet_len_table[0x115],dst,SELF);
  4121. }
  4122. if(src && disguised(src)) {
  4123. WBUFL(buf,10)=-src->id;
  4124. if (disguised(dst))
  4125. WBUFL(buf,6)=dst->id;
  4126. clif_send(buf,packet_len_table[0x115],src,SELF);
  4127. }
  4128. return fail;
  4129. }
  4130. /*==========================================
  4131. * 場所スキルエフェクト
  4132. *------------------------------------------
  4133. */
  4134. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4135. {
  4136. unsigned char buf[32];
  4137. nullpo_retr(0, src);
  4138. WBUFW(buf,0)=0x117;
  4139. WBUFW(buf,2)=skill_id;
  4140. WBUFL(buf,4)=src->id;
  4141. WBUFW(buf,8)=val;
  4142. WBUFW(buf,10)=x;
  4143. WBUFW(buf,12)=y;
  4144. WBUFL(buf,14)=tick;
  4145. clif_send(buf,packet_len_table[0x117],src,AREA);
  4146. if(disguised(src)) {
  4147. WBUFL(buf,4)=-src->id;
  4148. clif_send(buf,packet_len_table[0x117],src,SELF);
  4149. }
  4150. return 0;
  4151. }
  4152. /*==========================================
  4153. * 場所スキルエフェクト表示
  4154. *------------------------------------------
  4155. */
  4156. int clif_skill_setunit(struct skill_unit *unit)
  4157. {
  4158. unsigned char buf[128];
  4159. struct block_list *bl;
  4160. nullpo_retr(0, unit);
  4161. bl=map_id2bl(unit->group->src_id);
  4162. // These are invisible client-side, but are necessary because
  4163. // otherwise the client will not know who caused the attack.
  4164. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  4165. // return 0;
  4166. #if PACKETVER >= 3
  4167. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4168. malloc_set(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4169. WBUFW(buf, 0)=0x1c9;
  4170. WBUFL(buf, 2)=unit->bl.id;
  4171. WBUFL(buf, 6)=unit->group->src_id;
  4172. WBUFW(buf,10)=unit->bl.x;
  4173. WBUFW(buf,12)=unit->bl.y;
  4174. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4175. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4176. } else {
  4177. WBUFB(buf,14)=unit->group->unit_id;
  4178. }
  4179. WBUFB(buf,15)=1;
  4180. WBUFB(buf,16)=1;
  4181. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4182. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4183. return 0;
  4184. }
  4185. #endif
  4186. malloc_set(WBUFP(buf, 0),0,packet_len_table[0x11f]);
  4187. WBUFW(buf, 0)=0x11f;
  4188. WBUFL(buf, 2)=unit->bl.id;
  4189. WBUFL(buf, 6)=unit->group->src_id;
  4190. WBUFW(buf,10)=unit->bl.x;
  4191. WBUFW(buf,12)=unit->bl.y;
  4192. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4193. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4194. } else {
  4195. WBUFB(buf,14)=unit->group->unit_id;
  4196. }
  4197. WBUFB(buf,15)=0;
  4198. clif_send(buf,packet_len_table[0x11f],&unit->bl,AREA);
  4199. return 0;
  4200. /* Previous mysterious implementation noone really understands. [Skotlex]
  4201. malloc_set(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4202. WBUFW(buf, 0)=0x1c9;
  4203. WBUFL(buf, 2)=unit->bl.id;
  4204. WBUFL(buf, 6)=unit->group->src_id;
  4205. WBUFW(buf,10)=unit->bl.x;
  4206. WBUFW(buf,12)=unit->bl.y;
  4207. WBUFB(buf,14)=unit->group->unit_id;
  4208. WBUFB(buf,15)=1;
  4209. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4210. WBUFB(buf,16)=1;
  4211. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4212. } else {
  4213. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4214. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4215. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4216. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4217. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4218. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4219. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4220. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4221. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4222. //37-39
  4223. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4224. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4225. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4226. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4227. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4228. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4229. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4230. //65-68
  4231. //69-72
  4232. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4233. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4234. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4235. }
  4236. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4237. #endif
  4238. return 0;
  4239. */
  4240. }
  4241. /*==========================================
  4242. * 場所スキルエフェクト削除
  4243. *------------------------------------------
  4244. */
  4245. int clif_skill_delunit(struct skill_unit *unit)
  4246. {
  4247. unsigned char buf[16];
  4248. nullpo_retr(0, unit);
  4249. WBUFW(buf, 0)=0x120;
  4250. WBUFL(buf, 2)=unit->bl.id;
  4251. clif_send(buf,packet_len_table[0x120],&unit->bl,AREA);
  4252. return 0;
  4253. }
  4254. /*==========================================
  4255. * ワープ場所選択
  4256. *------------------------------------------
  4257. */
  4258. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4259. const char *map1,const char *map2,const char *map3,const char *map4)
  4260. {
  4261. int fd;
  4262. nullpo_retr(0, sd);
  4263. fd=sd->fd;
  4264. WFIFOHEAD(fd,packet_len_table[0x11c]);
  4265. WFIFOW(fd,0)=0x11c;
  4266. WFIFOW(fd,2)=skill_num;
  4267. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4268. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4269. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4270. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4271. WFIFOSET(fd,packet_len_table[0x11c]);
  4272. sd->menuskill_id = skill_num;
  4273. if (skill_num == AL_WARP)
  4274. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4275. else
  4276. sd->menuskill_lv = skill_lv;
  4277. return 0;
  4278. }
  4279. /*==========================================
  4280. * メモ応答
  4281. *------------------------------------------
  4282. */
  4283. int clif_skill_memo(struct map_session_data *sd,int flag)
  4284. {
  4285. int fd;
  4286. nullpo_retr(0, sd);
  4287. fd=sd->fd;
  4288. WFIFOHEAD(fd,packet_len_table[0x11e]);
  4289. WFIFOW(fd,0)=0x11e;
  4290. WFIFOB(fd,2)=flag;
  4291. WFIFOSET(fd,packet_len_table[0x11e]);
  4292. return 0;
  4293. }
  4294. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4295. {
  4296. int fd;
  4297. nullpo_retr(0, sd);
  4298. fd=sd->fd;
  4299. WFIFOHEAD(fd,packet_len_table[0x189]);
  4300. WFIFOW(fd,0)=0x189;
  4301. WFIFOW(fd,2)=flag;
  4302. WFIFOSET(fd,packet_len_table[0x189]);
  4303. return 0;
  4304. }
  4305. /*==========================================
  4306. * モンスター情報
  4307. *------------------------------------------
  4308. */
  4309. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4310. {
  4311. struct status_data *status;
  4312. unsigned char buf[64];
  4313. int i;//, fix;
  4314. nullpo_retr(0, sd);
  4315. nullpo_retr(0, dst);
  4316. if(dst->type!=BL_MOB )
  4317. return 0;
  4318. status = status_get_status_data(dst);
  4319. WBUFW(buf, 0)=0x18c;
  4320. WBUFW(buf, 2)=status_get_class(dst);
  4321. WBUFW(buf, 4)=status_get_lv(dst);
  4322. WBUFW(buf, 6)=status->size;
  4323. WBUFL(buf, 8)=status->hp;
  4324. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4325. +(battle_config.estimation_type&2?status->def2:0);
  4326. WBUFW(buf,14)=status->race;
  4327. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4328. +(battle_config.estimation_type&2?status->mdef2:0);
  4329. WBUFW(buf,18)= status->def_ele;
  4330. for(i=0;i<9;i++)
  4331. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4332. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4333. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4334. if(sd->status.party_id>0)
  4335. clif_send(buf,packet_len_table[0x18c],&sd->bl,PARTY_SAMEMAP);
  4336. else{
  4337. WFIFOHEAD(sd->fd,packet_len_table[0x18c]);
  4338. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x18c]);
  4339. WFIFOSET(sd->fd,packet_len_table[0x18c]);
  4340. }
  4341. return 0;
  4342. }
  4343. /*==========================================
  4344. * アイテム合成可能リスト
  4345. *------------------------------------------
  4346. */
  4347. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4348. {
  4349. int i,c,view,fd;
  4350. nullpo_retr(0, sd);
  4351. if(sd->menuskill_id == AM_PHARMACY)
  4352. return 0; //Avoid resending the menu twice or more times...
  4353. fd=sd->fd;
  4354. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4355. WFIFOW(fd, 0)=0x18d;
  4356. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4357. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4358. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4359. WFIFOW(fd,c*8+ 4)= view;
  4360. else
  4361. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4362. WFIFOW(fd,c*8+ 6)= 0x0012;
  4363. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4364. c++;
  4365. }
  4366. }
  4367. WFIFOW(fd, 2)=c*8+8;
  4368. WFIFOSET(fd,WFIFOW(fd,2));
  4369. if(c > 0) {
  4370. sd->menuskill_id = AM_PHARMACY;
  4371. sd->menuskill_lv = trigger;
  4372. return 1;
  4373. }
  4374. return 0;
  4375. }
  4376. /*==========================================
  4377. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4378. *------------------------------------------
  4379. */
  4380. int clif_status_load(struct block_list *bl,int type, int flag)
  4381. {
  4382. int fd;
  4383. if (type == SI_BLANK) //It shows nothing on the client...
  4384. return 0;
  4385. if (bl->type != BL_PC)
  4386. return 0;
  4387. fd = ((struct map_session_data*)bl)->fd;
  4388. WFIFOHEAD(fd,packet_len_table[0x196]);
  4389. WFIFOW(fd,0)=0x0196;
  4390. WFIFOW(fd,2)=type;
  4391. WFIFOL(fd,4)=bl->id;
  4392. WFIFOB(fd,8)=flag; //Status start
  4393. WFIFOSET(fd, packet_len_table[0x196]);
  4394. return 0;
  4395. }
  4396. /*==========================================
  4397. * 状態異常アイコン/メッセージ表示
  4398. *------------------------------------------
  4399. */
  4400. int clif_status_change(struct block_list *bl,int type,int flag)
  4401. {
  4402. unsigned char buf[16];
  4403. if (type == SI_BLANK) //It shows nothing on the client...
  4404. return 0;
  4405. nullpo_retr(0, bl);
  4406. WBUFW(buf,0)=0x0196;
  4407. WBUFW(buf,2)=type;
  4408. WBUFL(buf,4)=bl->id;
  4409. WBUFB(buf,8)=flag;
  4410. clif_send(buf,packet_len_table[0x196],bl,AREA);
  4411. return 0;
  4412. }
  4413. /*==========================================
  4414. * Send message (modified by [Yor])
  4415. *------------------------------------------
  4416. */
  4417. int clif_displaymessage(const int fd, char* mes)
  4418. {
  4419. // invalid pointer?
  4420. nullpo_retr(-1, mes);
  4421. //Console [Wizputer] //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4422. if (fd == 0)
  4423. return 0;
  4424. else {
  4425. int len_mes = strlen(mes);
  4426. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4427. WFIFOHEAD(fd, 5 + len_mes);
  4428. WFIFOW(fd,0) = 0x8e;
  4429. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4430. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4431. WFIFOSET(fd, 5 + len_mes);
  4432. }
  4433. }
  4434. return 0;
  4435. }
  4436. /*==========================================
  4437. * 天の声を送信する
  4438. *------------------------------------------
  4439. */
  4440. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4441. {
  4442. unsigned char *buf;
  4443. int lp;
  4444. lp = (flag & 0x10) ? 8 : 4;
  4445. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4446. WBUFW(buf,0) = 0x9a;
  4447. WBUFW(buf,2) = len + lp;
  4448. WBUFL(buf,4) = 0x65756c62;
  4449. memcpy(WBUFP(buf,lp), mes, len);
  4450. flag &= 0x07;
  4451. clif_send(buf, WBUFW(buf,2), bl,
  4452. (flag == 1) ? ALL_SAMEMAP :
  4453. (flag == 2) ? AREA :
  4454. (flag == 3) ? SELF :
  4455. ALL_CLIENT);
  4456. if(buf) aFree(buf);
  4457. if(use_irc && irc_announce_flag && !flag)
  4458. irc_announce(mes);
  4459. return 0;
  4460. }
  4461. /*==========================================
  4462. * グローバルメッセージ
  4463. *------------------------------------------
  4464. */
  4465. void clif_GlobalMessage(struct block_list *bl,char *message)
  4466. {
  4467. char buf[100];
  4468. int len;
  4469. nullpo_retv(bl);
  4470. if(!message)
  4471. return;
  4472. len = strlen(message)+1;
  4473. WBUFW(buf,0)=0x8d;
  4474. WBUFW(buf,2)=len+8;
  4475. WBUFL(buf,4)=bl->id;
  4476. strncpy((char *) WBUFP(buf,8),message,len);
  4477. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4478. }
  4479. /*==========================================
  4480. * Send main chat message [LuzZza]
  4481. *------------------------------------------
  4482. */
  4483. void clif_MainChatMessage(char* message) {
  4484. char buf[200];
  4485. int len;
  4486. if(!message)
  4487. return;
  4488. len = strlen(message)+1;
  4489. if (len+8 > sizeof(buf)) {
  4490. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4491. len = sizeof(buf)-8;
  4492. }
  4493. WBUFW(buf,0)=0x8d;
  4494. WBUFW(buf,2)=len+8;
  4495. WBUFL(buf,4)=0;
  4496. strncpy((char *) WBUFP(buf,8),message,len);
  4497. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4498. }
  4499. /*==========================================
  4500. * Does an announce message in the given color.
  4501. *------------------------------------------
  4502. */
  4503. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4504. {
  4505. unsigned char *buf;
  4506. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4507. WBUFW(buf,0) = 0x1c3;
  4508. WBUFW(buf,2) = len + 16;
  4509. WBUFL(buf,4) = color;
  4510. WBUFW(buf,8) = 0x190; //Font style? Type?
  4511. WBUFW(buf,10) = 0x0c; //12? Font size?
  4512. WBUFL(buf,12) = 0; //Unknown!
  4513. memcpy(WBUFP(buf,16), mes, len);
  4514. flag &= 0x07;
  4515. clif_send(buf, WBUFW(buf,2), bl,
  4516. (flag == 1) ? ALL_SAMEMAP :
  4517. (flag == 2) ? AREA :
  4518. (flag == 3) ? SELF :
  4519. ALL_CLIENT);
  4520. if(buf) aFree(buf);
  4521. return 0;
  4522. }
  4523. /*==========================================
  4524. * HPSP回復エフェクトを送信する
  4525. *------------------------------------------
  4526. */
  4527. int clif_heal(int fd,int type,int val)
  4528. {
  4529. WFIFOHEAD(fd,packet_len_table[0x13d]);
  4530. WFIFOW(fd,0)=0x13d;
  4531. WFIFOW(fd,2)=type;
  4532. WFIFOW(fd,4)=val;
  4533. WFIFOSET(fd,packet_len_table[0x13d]);
  4534. return 0;
  4535. }
  4536. /*==========================================
  4537. * 復活する
  4538. *------------------------------------------
  4539. */
  4540. int clif_resurrection(struct block_list *bl,int type)
  4541. {
  4542. unsigned char buf[16];
  4543. nullpo_retr(0, bl);
  4544. WBUFW(buf,0)=0x148;
  4545. WBUFL(buf,2)=bl->id;
  4546. WBUFW(buf,6)=type;
  4547. clif_send(buf,packet_len_table[0x148],bl,type==1 ? AREA : AREA_WOS);
  4548. if (disguised(bl))
  4549. clif_spawn(bl);
  4550. return 0;
  4551. }
  4552. /*==========================================
  4553. * PVP実装?(仮)
  4554. *------------------------------------------
  4555. */
  4556. int clif_set0199(int fd,int type)
  4557. {
  4558. WFIFOHEAD(fd,packet_len_table[0x199]);
  4559. WFIFOW(fd,0)=0x199;
  4560. WFIFOW(fd,2)=type;
  4561. WFIFOSET(fd,packet_len_table[0x199]);
  4562. return 0;
  4563. }
  4564. /*==========================================
  4565. * PVP実装?(仮)
  4566. *------------------------------------------
  4567. */
  4568. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4569. {
  4570. nullpo_retr(0, sd);
  4571. if(type == 2) {
  4572. WFIFOHEAD(sd->fd,packet_len_table[0x19a]);
  4573. WFIFOW(sd->fd,0) = 0x19a;
  4574. WFIFOL(sd->fd,2) = sd->bl.id;
  4575. WFIFOL(sd->fd,6) = pvprank;
  4576. WFIFOL(sd->fd,10) = pvpnum;
  4577. WFIFOSET(sd->fd,packet_len_table[0x19a]);
  4578. } else {
  4579. unsigned char buf[32];
  4580. WBUFW(buf,0) = 0x19a;
  4581. WBUFL(buf,2) = sd->bl.id;
  4582. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4583. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4584. else
  4585. WBUFL(buf,6) = pvprank;
  4586. WBUFL(buf,10) = pvpnum;
  4587. if(sd->sc.option&OPTION_INVISIBLE)
  4588. clif_send(buf,packet_len_table[0x19a],&sd->bl,SELF);
  4589. else if(!type)
  4590. clif_send(buf,packet_len_table[0x19a],&sd->bl,AREA);
  4591. else
  4592. clif_send(buf,packet_len_table[0x19a],&sd->bl,ALL_SAMEMAP);
  4593. }
  4594. return 0;
  4595. }
  4596. /*==========================================
  4597. *
  4598. *------------------------------------------
  4599. */
  4600. int clif_send0199(int map,int type)
  4601. {
  4602. struct block_list bl;
  4603. unsigned char buf[16];
  4604. bl.id = 0;
  4605. bl.type = BL_NUL;
  4606. bl.m = map;
  4607. WBUFW(buf,0)=0x199;
  4608. WBUFW(buf,2)=type;
  4609. clif_send(buf,packet_len_table[0x199],&bl,ALL_SAMEMAP);
  4610. return 0;
  4611. }
  4612. /*==========================================
  4613. * 精錬エフェクトを送信する
  4614. *------------------------------------------
  4615. */
  4616. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  4617. {
  4618. WFIFOHEAD(fd,packet_len_table[0x188]);
  4619. WFIFOW(fd,0)=0x188;
  4620. WFIFOW(fd,2)=fail;
  4621. WFIFOW(fd,4)=index+2;
  4622. WFIFOW(fd,6)=val;
  4623. WFIFOSET(fd,packet_len_table[0x188]);
  4624. return 0;
  4625. }
  4626. /*==========================================
  4627. * Wisp/page is transmitted to the destination player
  4628. *------------------------------------------
  4629. */
  4630. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4631. {
  4632. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4633. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4634. WFIFOW(fd,0) = 0x97;
  4635. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4636. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4637. memcpy(WFIFOP(fd,28), mes, mes_len);
  4638. WFIFOSET(fd,WFIFOW(fd,2));
  4639. return 0;
  4640. }
  4641. /*==========================================
  4642. * The transmission result of Wisp/page is transmitted to the source player
  4643. *------------------------------------------
  4644. */
  4645. 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
  4646. {
  4647. WFIFOHEAD(fd,packet_len_table[0x98]);
  4648. WFIFOW(fd,0) = 0x98;
  4649. WFIFOW(fd,2) = flag;
  4650. WFIFOSET(fd,packet_len_table[0x98]);
  4651. return 0;
  4652. }
  4653. /*==========================================
  4654. * キャラID名前引き結果を送信する
  4655. *------------------------------------------
  4656. */
  4657. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4658. {
  4659. char *p= map_charid2nick(char_id);
  4660. int fd;
  4661. nullpo_retr(0, sd);
  4662. fd=sd->fd;
  4663. if(p!=NULL){
  4664. WFIFOHEAD(fd,packet_len_table[0x194]);
  4665. WFIFOW(fd,0)=0x194;
  4666. WFIFOL(fd,2)=char_id;
  4667. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4668. WFIFOSET(fd,packet_len_table[0x194]);
  4669. }else{
  4670. map_reqchariddb(sd,char_id);
  4671. chrif_searchcharid(char_id);
  4672. }
  4673. return 0;
  4674. }
  4675. /*==========================================
  4676. * カードの挿入可能リストを返す
  4677. *------------------------------------------
  4678. */
  4679. int clif_use_card(struct map_session_data *sd,int idx)
  4680. {
  4681. int i,c,ep;
  4682. int fd=sd->fd;
  4683. nullpo_retr(0, sd);
  4684. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4685. return 0;
  4686. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4687. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4688. ep=sd->inventory_data[idx]->equip;
  4689. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4690. WFIFOW(fd,0)=0x017b;
  4691. for(i=c=0;i<MAX_INVENTORY;i++){
  4692. int j;
  4693. if(sd->inventory_data[i] == NULL)
  4694. continue;
  4695. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4696. continue;
  4697. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4698. continue;
  4699. if(sd->status.inventory[i].identify==0 ) //Not identified
  4700. continue;
  4701. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4702. continue;
  4703. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4704. continue;
  4705. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4706. if( sd->status.inventory[i].card[j]==0 )
  4707. break;
  4708. }
  4709. if(j==sd->inventory_data[i]->slot) // No room
  4710. continue;
  4711. WFIFOW(fd,4+c*2)=i+2;
  4712. c++;
  4713. }
  4714. WFIFOW(fd,2)=4+c*2;
  4715. WFIFOSET(fd,WFIFOW(fd,2));
  4716. return 0;
  4717. }
  4718. /*==========================================
  4719. * カードの挿入終了
  4720. *------------------------------------------
  4721. */
  4722. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4723. {
  4724. int fd;
  4725. nullpo_retr(0, sd);
  4726. fd=sd->fd;
  4727. WFIFOHEAD(fd,packet_len_table[0x17d]);
  4728. WFIFOW(fd,0)=0x17d;
  4729. WFIFOW(fd,2)=idx_equip+2;
  4730. WFIFOW(fd,4)=idx_card+2;
  4731. WFIFOB(fd,6)=flag;
  4732. WFIFOSET(fd,packet_len_table[0x17d]);
  4733. return 0;
  4734. }
  4735. /*==========================================
  4736. * 鑑定可能アイテムリスト送信
  4737. *------------------------------------------
  4738. */
  4739. int clif_item_identify_list(struct map_session_data *sd)
  4740. {
  4741. int i,c;
  4742. int fd;
  4743. nullpo_retr(0, sd);
  4744. fd=sd->fd;
  4745. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4746. WFIFOW(fd,0)=0x177;
  4747. for(i=c=0;i<MAX_INVENTORY;i++){
  4748. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4749. WFIFOW(fd,c*2+4)=i+2;
  4750. c++;
  4751. }
  4752. }
  4753. if(c > 0) {
  4754. WFIFOW(fd,2)=c*2+4;
  4755. WFIFOSET(fd,WFIFOW(fd,2));
  4756. sd->menuskill_id = MC_IDENTIFY;
  4757. sd->menuskill_lv = c;
  4758. }
  4759. return 0;
  4760. }
  4761. /*==========================================
  4762. * 鑑定結果
  4763. *------------------------------------------
  4764. */
  4765. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4766. {
  4767. int fd;
  4768. nullpo_retr(0, sd);
  4769. fd=sd->fd;
  4770. WFIFOHEAD(fd,packet_len_table[0x179]);
  4771. WFIFOW(fd, 0)=0x179;
  4772. WFIFOW(fd, 2)=idx+2;
  4773. WFIFOB(fd, 4)=flag;
  4774. WFIFOSET(fd,packet_len_table[0x179]);
  4775. return 0;
  4776. }
  4777. /*==========================================
  4778. * 修理可能アイテムリスト送信
  4779. *------------------------------------------
  4780. */
  4781. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4782. {
  4783. int i,c;
  4784. int fd;
  4785. int nameid;
  4786. nullpo_retr(0, sd);
  4787. nullpo_retr(0, dstsd);
  4788. fd=sd->fd;
  4789. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4790. WFIFOW(fd,0)=0x1fc;
  4791. for(i=c=0;i<MAX_INVENTORY;i++){
  4792. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4793. WFIFOW(fd,c*13+4) = i;
  4794. WFIFOW(fd,c*13+6) = nameid;
  4795. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4796. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4797. WFIFOB(fd,c*13+16)= c;
  4798. c++;
  4799. }
  4800. }
  4801. if(c > 0) {
  4802. WFIFOW(fd,2)=c*13+4;
  4803. WFIFOSET(fd,WFIFOW(fd,2));
  4804. sd->menuskill_id = BS_REPAIRWEAPON;
  4805. sd->menuskill_lv = dstsd->bl.id;
  4806. }else
  4807. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4808. return 0;
  4809. }
  4810. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4811. {
  4812. int view,fd;
  4813. nullpo_retr(0, sd);
  4814. fd=sd->fd;
  4815. WFIFOHEAD(fd,packet_len_table[0x1fe]);
  4816. WFIFOW(fd, 0)=0x1fe;
  4817. if((view = itemdb_viewid(nameid)) > 0)
  4818. WFIFOW(fd, 2)=view;
  4819. else
  4820. WFIFOW(fd, 2)=nameid;
  4821. WFIFOB(fd, 4)=flag;
  4822. WFIFOSET(fd,packet_len_table[0x1fe]);
  4823. return 0;
  4824. }
  4825. /*==========================================
  4826. * Weapon Refining - Taken from jAthena
  4827. *------------------------------------------
  4828. */
  4829. int clif_item_refine_list(struct map_session_data *sd)
  4830. {
  4831. int i,c;
  4832. int fd;
  4833. int skilllv;
  4834. int wlv;
  4835. int refine_item[5];
  4836. nullpo_retr(0, sd);
  4837. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4838. fd=sd->fd;
  4839. refine_item[0] = -1;
  4840. refine_item[1] = pc_search_inventory(sd,1010);
  4841. refine_item[2] = pc_search_inventory(sd,1011);
  4842. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4843. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4844. WFIFOW(fd,0)=0x221;
  4845. for(i=c=0;i<MAX_INVENTORY;i++){
  4846. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4847. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4848. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4849. WFIFOW(fd,c*13+ 4)=i+2;
  4850. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4851. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4852. WFIFOW(fd,c*13+10)=0;
  4853. WFIFOB(fd,c*13+12)=c;
  4854. c++;
  4855. }
  4856. }
  4857. WFIFOW(fd,2)=c*13+4;
  4858. WFIFOSET(fd,WFIFOW(fd,2));
  4859. sd->menuskill_id = WS_WEAPONREFINE;
  4860. sd->menuskill_lv = skilllv;
  4861. return 0;
  4862. }
  4863. /*==========================================
  4864. * アイテムによる一時的なスキル効果
  4865. *------------------------------------------
  4866. */
  4867. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  4868. {
  4869. int fd;
  4870. nullpo_retr(0, sd);
  4871. fd=sd->fd;
  4872. WFIFOHEAD(fd,packet_len_table[0x147]);
  4873. WFIFOW(fd, 0)=0x147;
  4874. WFIFOW(fd, 2)=skillid;
  4875. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4876. WFIFOW(fd, 6)=0;
  4877. WFIFOW(fd, 8)=skilllv;
  4878. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4879. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4880. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  4881. WFIFOB(fd,38)=0;
  4882. WFIFOSET(fd,packet_len_table[0x147]);
  4883. return 0;
  4884. }
  4885. /*==========================================
  4886. * カートにアイテム追加
  4887. *------------------------------------------
  4888. */
  4889. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4890. {
  4891. int view,fd;
  4892. unsigned char *buf;
  4893. nullpo_retr(0, sd);
  4894. fd=sd->fd;
  4895. WFIFOHEAD(fd,packet_len_table[0x124]);
  4896. buf=WFIFOP(fd,0);
  4897. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4898. return 1;
  4899. WBUFW(buf,0)=0x124;
  4900. WBUFW(buf,2)=n+2;
  4901. WBUFL(buf,4)=amount;
  4902. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4903. WBUFW(buf,8)=view;
  4904. else
  4905. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4906. WBUFB(buf,10)=sd->status.cart[n].identify;
  4907. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4908. WBUFB(buf,12)=sd->status.cart[n].refine;
  4909. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4910. WFIFOSET(fd,packet_len_table[0x124]);
  4911. return 0;
  4912. }
  4913. /*==========================================
  4914. * カートからアイテム削除
  4915. *------------------------------------------
  4916. */
  4917. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4918. {
  4919. int fd;
  4920. nullpo_retr(0, sd);
  4921. fd=sd->fd;
  4922. WFIFOHEAD(fd,packet_len_table[0x125]);
  4923. WFIFOW(fd,0)=0x125;
  4924. WFIFOW(fd,2)=n+2;
  4925. WFIFOL(fd,4)=amount;
  4926. WFIFOSET(fd,packet_len_table[0x125]);
  4927. return 0;
  4928. }
  4929. /*==========================================
  4930. * 露店開設
  4931. *------------------------------------------
  4932. */
  4933. int clif_openvendingreq(struct map_session_data *sd,int num)
  4934. {
  4935. int fd;
  4936. nullpo_retr(0, sd);
  4937. fd=sd->fd;
  4938. WFIFOHEAD(fd,packet_len_table[0x12d]);
  4939. WFIFOW(fd,0)=0x12d;
  4940. WFIFOW(fd,2)=num;
  4941. WFIFOSET(fd,packet_len_table[0x12d]);
  4942. return 0;
  4943. }
  4944. /*==========================================
  4945. * 露店看板表示
  4946. *------------------------------------------
  4947. */
  4948. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  4949. {
  4950. unsigned char buf[128];
  4951. nullpo_retr(0, bl);
  4952. WBUFW(buf,0)=0x131;
  4953. WBUFL(buf,2)=bl->id;
  4954. strncpy((char*)WBUFP(buf,6),message,80);
  4955. if(fd){
  4956. WFIFOHEAD(fd,packet_len_table[0x131]);
  4957. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x131]);
  4958. WFIFOSET(fd,packet_len_table[0x131]);
  4959. }else{
  4960. clif_send(buf,packet_len_table[0x131],bl,AREA_WOS);
  4961. }
  4962. return 0;
  4963. }
  4964. /*==========================================
  4965. * 露店看板消去
  4966. *------------------------------------------
  4967. */
  4968. int clif_closevendingboard(struct block_list* bl,int fd)
  4969. {
  4970. unsigned char buf[16];
  4971. nullpo_retr(0, bl);
  4972. WBUFW(buf,0)=0x132;
  4973. WBUFL(buf,2)=bl->id;
  4974. if(fd){
  4975. WFIFOHEAD(fd,packet_len_table[0x132]);
  4976. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x132]);
  4977. WFIFOSET(fd,packet_len_table[0x132]);
  4978. }else{
  4979. clif_send(buf,packet_len_table[0x132],bl,AREA_WOS);
  4980. }
  4981. return 0;
  4982. }
  4983. /*==========================================
  4984. * 露店アイテムリスト
  4985. *------------------------------------------
  4986. */
  4987. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  4988. {
  4989. struct item_data *data;
  4990. int i,n,index,fd;
  4991. struct map_session_data *vsd;
  4992. unsigned char *buf;
  4993. nullpo_retr(0, sd);
  4994. nullpo_retr(0, vending);
  4995. nullpo_retr(0, vsd=map_id2sd(id));
  4996. fd=sd->fd;
  4997. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  4998. buf = WFIFOP(fd,0);
  4999. for(i=0,n=0;i<vsd->vend_num;i++){
  5000. if(vending[i].amount<=0)
  5001. continue;
  5002. WBUFL(buf,8+n*22)=vending[i].value;
  5003. WBUFW(buf,12+n*22)=vending[i].amount;
  5004. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  5005. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  5006. continue;
  5007. data = itemdb_search(vsd->status.cart[index].nameid);
  5008. WBUFB(buf,16+n*22)=itemtype(data->type);
  5009. if(data->view_id > 0)
  5010. WBUFW(buf,17+n*22)=data->view_id;
  5011. else
  5012. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  5013. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  5014. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  5015. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  5016. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  5017. n++;
  5018. }
  5019. if(n > 0){
  5020. WBUFW(buf,0)=0x133;
  5021. WBUFW(buf,2)=8+n*22;
  5022. WBUFL(buf,4)=id;
  5023. WFIFOSET(fd,WFIFOW(fd,2));
  5024. }
  5025. return 0;
  5026. }
  5027. /*==========================================
  5028. * 露店アイテム購入失敗
  5029. *------------------------------------------
  5030. */
  5031. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  5032. {
  5033. int fd;
  5034. nullpo_retr(0, sd);
  5035. fd=sd->fd;
  5036. WFIFOHEAD(fd,packet_len_table[0x135]);
  5037. WFIFOW(fd,0)=0x135;
  5038. WFIFOW(fd,2)=index+2;
  5039. WFIFOW(fd,4)=amount;
  5040. WFIFOB(fd,6)=fail;
  5041. WFIFOSET(fd,packet_len_table[0x135]);
  5042. return 0;
  5043. }
  5044. /*==========================================
  5045. * 露店開設成功
  5046. *------------------------------------------
  5047. */
  5048. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  5049. {
  5050. struct item_data *data;
  5051. int i,n,index,fd;
  5052. unsigned char *buf;
  5053. nullpo_retr(0, sd);
  5054. fd=sd->fd;
  5055. WFIFOHEAD(fd, 8+sd->vend_num*22);
  5056. buf = WFIFOP(fd,0);
  5057. for(i=0,n=0;i<sd->vend_num;i++){
  5058. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  5059. WBUFL(buf,8+n*22)=vending[i].value;
  5060. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  5061. WBUFW(buf,14+n*22)=vending[i].amount;
  5062. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || !sd->status.cart[index].identify ||
  5063. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  5064. continue;
  5065. data = itemdb_search(sd->status.cart[index].nameid);
  5066. WBUFB(buf,16+n*22)=itemtype(data->type);
  5067. if(data->view_id > 0)
  5068. WBUFW(buf,17+n*22)=data->view_id;
  5069. else
  5070. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  5071. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  5072. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  5073. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  5074. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  5075. n++;
  5076. }
  5077. if(n > 0){
  5078. WBUFW(buf,0)=0x136;
  5079. WBUFW(buf,2)=8+n*22;
  5080. WBUFL(buf,4)=id;
  5081. WFIFOSET(fd,WFIFOW(fd,2));
  5082. }
  5083. return n;
  5084. }
  5085. /*==========================================
  5086. * 露店アイテム販売報告
  5087. *------------------------------------------
  5088. */
  5089. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  5090. {
  5091. int fd;
  5092. nullpo_retr(0, sd);
  5093. fd=sd->fd;
  5094. WFIFOHEAD(fd,packet_len_table[0x137]);
  5095. WFIFOW(fd,0)=0x137;
  5096. WFIFOW(fd,2)=index+2;
  5097. WFIFOW(fd,4)=amount;
  5098. WFIFOSET(fd,packet_len_table[0x137]);
  5099. return 0;
  5100. }
  5101. /*==========================================
  5102. * パーティ作成完了
  5103. *------------------------------------------
  5104. */
  5105. int clif_party_created(struct map_session_data *sd,int flag)
  5106. {
  5107. int fd;
  5108. nullpo_retr(0, sd);
  5109. fd=sd->fd;
  5110. WFIFOHEAD(fd,packet_len_table[0xfa]);
  5111. WFIFOW(fd,0)=0xfa;
  5112. WFIFOB(fd,2)=flag;
  5113. WFIFOSET(fd,packet_len_table[0xfa]);
  5114. return 0;
  5115. }
  5116. int clif_party_main_info(struct party_data *p, int fd)
  5117. {
  5118. struct map_session_data *sd;
  5119. int i;
  5120. unsigned char buf[96];
  5121. for (i=0; i<MAX_PARTY && !p->party.member[i].leader; i++);
  5122. if (i >= MAX_PARTY) return 0; //Should never happen...
  5123. sd = p->data[i].sd;
  5124. WBUFW(buf,0)=0x1e9;
  5125. WBUFL(buf,2)= p->party.member[i].account_id;
  5126. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  5127. WBUFW(buf,10)=sd?sd->bl.x:0;
  5128. WBUFW(buf,12)=sd?sd->bl.y:0;
  5129. WBUFB(buf,14)=(p->party.member[i].online)?0:1; //This byte is also unconfirmed...
  5130. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5131. memcpy(WBUFP(buf,39), p->party.member[i].name, NAME_LENGTH);
  5132. memcpy(WBUFP(buf,63), mapindex_id2name(p->party.member[i].map), MAP_NAME_LENGTH);
  5133. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5134. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5135. if(fd>=0){
  5136. WFIFOHEAD(fd,packet_len_table[0x1e9]);
  5137. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x1e9]);
  5138. WFIFOSET(fd,packet_len_table[0x1e9]);
  5139. return 1;
  5140. }
  5141. if (!sd) {
  5142. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++)
  5143. if (i >= MAX_PARTY) return 0; //Should never happen...
  5144. sd=p->data[i].sd;
  5145. }
  5146. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY);
  5147. return 1;
  5148. }
  5149. int clif_party_join_info(struct party *p, struct map_session_data *sd)
  5150. {
  5151. unsigned char buf[96];
  5152. WBUFW(buf,0)=0x1e9;
  5153. WBUFL(buf,2)= sd->status.account_id;
  5154. WBUFL(buf,6)= 0; //Apparently setting this to 1 makes you adoptable.
  5155. WBUFW(buf,10)=sd->bl.x;
  5156. WBUFW(buf,12)=sd->bl.y;
  5157. WBUFB(buf,14)=0; //Unconfirmed byte.
  5158. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5159. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5160. memcpy(WBUFP(buf,63), mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  5161. WBUFB(buf,79) = (p->item&1)?1:0;
  5162. WBUFB(buf,80) = (p->item&2)?1:0;
  5163. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY_WOS);
  5164. return 1;
  5165. }
  5166. /*==========================================
  5167. * パーティ情報送信
  5168. *------------------------------------------
  5169. */
  5170. int clif_party_info(struct party_data *p,int fd)
  5171. {
  5172. unsigned char buf[1024];
  5173. int i,c;
  5174. struct map_session_data *sd=NULL;
  5175. nullpo_retr(0, p);
  5176. WBUFW(buf,0)=0xfb;
  5177. memcpy(WBUFP(buf,4),p->party.name,NAME_LENGTH);
  5178. for(i=c=0;i<MAX_PARTY;i++){
  5179. struct party_member *m=&p->party.member[i];
  5180. if(!m->account_id)
  5181. continue;
  5182. if(sd==NULL) sd=p->data[i].sd;
  5183. WBUFL(buf,28+c*46)=m->account_id;
  5184. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5185. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5186. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5187. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5188. c++;
  5189. }
  5190. WBUFW(buf,2)=28+c*46;
  5191. if(fd>=0){ // fdが設定されてるならそれに送る
  5192. WFIFOHEAD(fd, 28+c*46);
  5193. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5194. WFIFOSET(fd,WFIFOW(fd,2));
  5195. return 9;
  5196. }
  5197. if(sd!=NULL)
  5198. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5199. return 0;
  5200. }
  5201. /*==========================================
  5202. * パーティ勧誘
  5203. *------------------------------------------
  5204. */
  5205. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5206. {
  5207. int fd;
  5208. struct party_data *p;
  5209. nullpo_retr(0, sd);
  5210. nullpo_retr(0, tsd);
  5211. fd=tsd->fd;
  5212. if( (p=party_search(sd->status.party_id))==NULL )
  5213. return 0;
  5214. WFIFOHEAD(fd,packet_len_table[0xfe]);
  5215. WFIFOW(fd,0)=0xfe;
  5216. WFIFOL(fd,2)=sd->status.account_id;
  5217. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5218. WFIFOSET(fd,packet_len_table[0xfe]);
  5219. return 0;
  5220. }
  5221. /*==========================================
  5222. * パーティ勧誘結果
  5223. *------------------------------------------
  5224. */
  5225. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5226. {
  5227. int fd;
  5228. nullpo_retr(0, sd);
  5229. fd=sd->fd;
  5230. WFIFOHEAD(fd,packet_len_table[0xfd]);
  5231. WFIFOW(fd,0)=0xfd;
  5232. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5233. WFIFOB(fd,26)=flag;
  5234. WFIFOSET(fd,packet_len_table[0xfd]);
  5235. return 0;
  5236. }
  5237. /*==========================================
  5238. * パーティ設定送信
  5239. * flag & 0x001=exp変更ミス
  5240. * 0x010=item変更ミス
  5241. * 0x100=一人にのみ送信
  5242. *------------------------------------------
  5243. */
  5244. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5245. {
  5246. unsigned char buf[16];
  5247. nullpo_retr(0, p);
  5248. // if(battle_config.etc_log)
  5249. // printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
  5250. if(sd==NULL && flag==0){
  5251. int i;
  5252. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5253. if (i < MAX_PARTY)
  5254. sd = p->data[i].sd;
  5255. }
  5256. if(sd==NULL)
  5257. return 0;
  5258. WBUFW(buf,0)=0x101;
  5259. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5260. WBUFW(buf,4)=0; //NOTE: We don't know yet what this is for, it is NOT for item share rules, though. [Skotlex]
  5261. if(flag==0)
  5262. clif_send(buf,packet_len_table[0x101],&sd->bl,PARTY);
  5263. else {
  5264. WFIFOHEAD(sd->fd,packet_len_table[0x101]);
  5265. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x101]);
  5266. WFIFOSET(sd->fd,packet_len_table[0x101]);
  5267. }
  5268. return 0;
  5269. }
  5270. /*==========================================
  5271. * パーティ脱退(脱退前に呼ぶこと)
  5272. *------------------------------------------
  5273. */
  5274. int clif_party_leaved(struct party_data *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5275. {
  5276. unsigned char buf[64];
  5277. int i;
  5278. nullpo_retr(0, p);
  5279. WBUFW(buf,0)=0x105;
  5280. WBUFL(buf,2)=account_id;
  5281. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5282. WBUFB(buf,30)=flag&0x0f;
  5283. if((flag&0xf0)==0){
  5284. if(sd==NULL) {
  5285. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5286. if (i < MAX_PARTY)
  5287. sd = p->data[i].sd;
  5288. }
  5289. if (sd)
  5290. clif_send(buf,packet_len_table[0x105],&sd->bl,PARTY);
  5291. } else if (sd!=NULL) {
  5292. WFIFOHEAD(sd->fd,packet_len_table[0x105]);
  5293. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x105]);
  5294. WFIFOSET(sd->fd,packet_len_table[0x105]);
  5295. }
  5296. return 0;
  5297. }
  5298. /*==========================================
  5299. * パーティメッセージ送信
  5300. *------------------------------------------
  5301. */
  5302. int clif_party_message(struct party_data *p,int account_id,char *mes,int len)
  5303. {
  5304. struct map_session_data *sd;
  5305. int i;
  5306. nullpo_retr(0, p);
  5307. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5308. if(i < MAX_PARTY){
  5309. unsigned char buf[1024];
  5310. sd = p->data[i].sd;
  5311. WBUFW(buf,0)=0x109;
  5312. WBUFW(buf,2)=len+8;
  5313. WBUFL(buf,4)=account_id;
  5314. memcpy(WBUFP(buf,8),mes,len);
  5315. clif_send(buf,len+8,&sd->bl,PARTY);
  5316. }
  5317. return 0;
  5318. }
  5319. /*==========================================
  5320. * パーティ座標通知
  5321. *------------------------------------------
  5322. */
  5323. int clif_party_xy(struct map_session_data *sd)
  5324. {
  5325. unsigned char buf[16];
  5326. nullpo_retr(0, sd);
  5327. WBUFW(buf,0)=0x107;
  5328. WBUFL(buf,2)=sd->status.account_id;
  5329. WBUFW(buf,6)=sd->bl.x;
  5330. WBUFW(buf,8)=sd->bl.y;
  5331. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  5332. return 0;
  5333. }
  5334. /*==========================================
  5335. * Sends x/y dot to a single fd. [Skotlex]
  5336. *------------------------------------------
  5337. */
  5338. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5339. {
  5340. WFIFOHEAD(fd,packet_len_table[0x107]);
  5341. WFIFOW(fd,0)=0x107;
  5342. WFIFOL(fd,2)=sd->status.account_id;
  5343. WFIFOW(fd,6)=sd->bl.x;
  5344. WFIFOW(fd,8)=sd->bl.y;
  5345. WFIFOSET(fd,packet_len_table[0x107]);
  5346. return 0;
  5347. }
  5348. /*==========================================
  5349. * パーティHP通知
  5350. *------------------------------------------
  5351. */
  5352. int clif_party_hp(struct map_session_data *sd)
  5353. {
  5354. unsigned char buf[16];
  5355. nullpo_retr(0, sd);
  5356. WBUFW(buf,0)=0x106;
  5357. WBUFL(buf,2)=sd->status.account_id;
  5358. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5359. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5360. WBUFW(buf,8) = 100;
  5361. } else {
  5362. WBUFW(buf,6) = sd->battle_status.hp;
  5363. WBUFW(buf,8) = sd->battle_status.max_hp;
  5364. }
  5365. clif_send(buf,packet_len_table[0x106],&sd->bl,PARTY_AREA_WOS);
  5366. return 0;
  5367. }
  5368. /*==========================================
  5369. * Sends HP bar to a single fd. [Skotlex]
  5370. *------------------------------------------
  5371. */
  5372. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5373. {
  5374. WFIFOHEAD(fd,packet_len_table[0x106]);
  5375. WFIFOW(fd,0) = 0x106;
  5376. WFIFOL(fd,2) = sd->status.account_id;
  5377. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5378. WFIFOW(fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5379. WFIFOW(fd,8) = 100;
  5380. } else {
  5381. WFIFOW(fd,6) = sd->battle_status.hp;
  5382. WFIFOW(fd,8) = sd->battle_status.max_hp;
  5383. }
  5384. WFIFOSET (fd, packet_len_table[0x106]);
  5385. }
  5386. /*==========================================
  5387. * GMへ場所とHP通知
  5388. *------------------------------------------
  5389. */
  5390. int clif_hpmeter(struct map_session_data *sd)
  5391. {
  5392. struct map_session_data *sd2;
  5393. unsigned char buf[16];
  5394. int i, x0, y0, x1, y1;
  5395. int level;
  5396. nullpo_retr(0, sd);
  5397. x0 = sd->bl.x - AREA_SIZE;
  5398. y0 = sd->bl.y - AREA_SIZE;
  5399. x1 = sd->bl.x + AREA_SIZE;
  5400. y1 = sd->bl.y + AREA_SIZE;
  5401. WBUFW(buf,0) = 0x106;
  5402. WBUFL(buf,2) = sd->status.account_id;
  5403. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5404. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5405. WBUFW(buf,8) = 100;
  5406. } else {
  5407. WBUFW(buf,6) = sd->battle_status.hp;
  5408. WBUFW(buf,8) = sd->battle_status.max_hp;
  5409. }
  5410. for (i = 0; i < fd_max; i++) {
  5411. if (session[i] && session[i]->func_parse == clif_parse &&
  5412. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5413. sd != sd2 && sd2->state.auth) {
  5414. if (sd2->bl.m != sd->bl.m ||
  5415. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5416. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5417. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5418. level < pc_isGM(sd))
  5419. continue;
  5420. WFIFOHEAD (i, packet_len_table[0x106]);
  5421. memcpy (WFIFOP(i,0), buf, packet_len_table[0x106]);
  5422. WFIFOSET (i, packet_len_table[0x106]);
  5423. }
  5424. }
  5425. return 0;
  5426. }
  5427. /*==========================================
  5428. * パーティ場所移動(未使用)
  5429. *------------------------------------------
  5430. */
  5431. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5432. {
  5433. unsigned char buf[128];
  5434. nullpo_retr(0, sd);
  5435. nullpo_retr(0, p);
  5436. WBUFW(buf, 0)=0x104;
  5437. WBUFL(buf, 2)=sd->status.account_id;
  5438. WBUFL(buf, 6)=0;
  5439. WBUFW(buf,10)=sd->bl.x;
  5440. WBUFW(buf,12)=sd->bl.y;
  5441. WBUFB(buf,14)=!online;
  5442. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5443. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5444. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5445. clif_send(buf,packet_len_table[0x104],&sd->bl,PARTY);
  5446. return 0;
  5447. }
  5448. /*==========================================
  5449. * 攻撃するために移動が必要
  5450. *------------------------------------------
  5451. */
  5452. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5453. {
  5454. int fd;
  5455. nullpo_retr(0, sd);
  5456. nullpo_retr(0, bl);
  5457. fd=sd->fd;
  5458. WFIFOHEAD(fd,packet_len_table[0x139]);
  5459. WFIFOW(fd, 0)=0x139;
  5460. WFIFOL(fd, 2)=bl->id;
  5461. WFIFOW(fd, 6)=bl->x;
  5462. WFIFOW(fd, 8)=bl->y;
  5463. WFIFOW(fd,10)=sd->bl.x;
  5464. WFIFOW(fd,12)=sd->bl.y;
  5465. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5466. WFIFOSET(fd,packet_len_table[0x139]);
  5467. return 0;
  5468. }
  5469. /*==========================================
  5470. * 製造エフェクト
  5471. *------------------------------------------
  5472. */
  5473. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5474. {
  5475. int view,fd;
  5476. nullpo_retr(0, sd);
  5477. fd=sd->fd;
  5478. // 名前の登録と送信を先にしておく
  5479. if( map_charid2nick(sd->status.char_id)==NULL )
  5480. map_addchariddb(sd->status.char_id,sd->status.name);
  5481. clif_solved_charname(sd,sd->status.char_id);
  5482. WFIFOHEAD(fd,packet_len_table[0x18f]);
  5483. WFIFOW(fd, 0)=0x18f;
  5484. WFIFOW(fd, 2)=flag;
  5485. if((view = itemdb_viewid(nameid)) > 0)
  5486. WFIFOW(fd, 4)=view;
  5487. else
  5488. WFIFOW(fd, 4)=nameid;
  5489. WFIFOSET(fd,packet_len_table[0x18f]);
  5490. return 0;
  5491. }
  5492. // pet
  5493. int clif_catch_process(struct map_session_data *sd)
  5494. {
  5495. int fd;
  5496. nullpo_retr(0, sd);
  5497. fd=sd->fd;
  5498. WFIFOHEAD(fd,packet_len_table[0x19e]);
  5499. WFIFOW(fd,0)=0x19e;
  5500. WFIFOSET(fd,packet_len_table[0x19e]);
  5501. sd->menuskill_id = SA_TAMINGMONSTER;
  5502. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5503. sd->menuskill_lv = 0; //Free catch
  5504. else
  5505. sd->menuskill_lv = sd->itemid; //Consume catch
  5506. return 0;
  5507. }
  5508. int clif_pet_rulet(struct map_session_data *sd,int data)
  5509. {
  5510. int fd;
  5511. nullpo_retr(0, sd);
  5512. fd=sd->fd;
  5513. WFIFOHEAD(fd,packet_len_table[0x1a0]);
  5514. WFIFOW(fd,0)=0x1a0;
  5515. WFIFOB(fd,2)=data;
  5516. WFIFOSET(fd,packet_len_table[0x1a0]);
  5517. return 0;
  5518. }
  5519. /*==========================================
  5520. * pet卵リスト作成
  5521. *------------------------------------------
  5522. */
  5523. int clif_sendegg(struct map_session_data *sd)
  5524. {
  5525. //R 01a6 <len>.w <index>.w*
  5526. int i,n=0,fd;
  5527. nullpo_retr(0, sd);
  5528. fd=sd->fd;
  5529. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5530. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5531. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5532. return 0;
  5533. }
  5534. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5535. WFIFOW(fd,0)=0x1a6;
  5536. if(sd->status.pet_id <= 0) {
  5537. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5538. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5539. sd->inventory_data[i]->type!=IT_PETEGG ||
  5540. sd->status.inventory[i].amount<=0)
  5541. continue;
  5542. WFIFOW(fd,n*2+4)=i+2;
  5543. n++;
  5544. }
  5545. }
  5546. WFIFOW(fd,2)=4+n*2;
  5547. WFIFOSET(fd,WFIFOW(fd,2));
  5548. sd->menuskill_id = SA_TAMINGMONSTER;
  5549. sd->menuskill_lv = -1;
  5550. return 0;
  5551. }
  5552. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5553. {
  5554. int fd;
  5555. nullpo_retr(0, sd);
  5556. nullpo_retr(0, sd->pd);
  5557. fd=sd->fd;
  5558. WFIFOHEAD(fd,packet_len_table[0x1a4]);
  5559. WFIFOW(fd,0)=0x1a4;
  5560. WFIFOB(fd,2)=type;
  5561. WFIFOL(fd,3)=sd->pd->bl.id;
  5562. WFIFOL(fd,7)=param;
  5563. WFIFOSET(fd,packet_len_table[0x1a4]);
  5564. return 0;
  5565. }
  5566. int clif_send_petstatus(struct map_session_data *sd)
  5567. {
  5568. int fd;
  5569. struct s_pet *pet;
  5570. nullpo_retr(0, sd);
  5571. nullpo_retr(0, sd->pd);
  5572. fd=sd->fd;
  5573. pet = &sd->pd->pet;
  5574. WFIFOHEAD(fd,packet_len_table[0x1a2]);
  5575. WFIFOW(fd,0)=0x1a2;
  5576. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5577. WFIFOB(fd,26)=(battle_config.pet_rename == 1)? 0:pet->rename_flag;
  5578. WFIFOW(fd,27)=pet->level;
  5579. WFIFOW(fd,29)=pet->hungry;
  5580. WFIFOW(fd,31)=pet->intimate;
  5581. WFIFOW(fd,33)=pet->equip;
  5582. WFIFOSET(fd,packet_len_table[0x1a2]);
  5583. return 0;
  5584. }
  5585. /*==========================================
  5586. *
  5587. *------------------------------------------
  5588. */
  5589. int clif_pet_emotion(struct pet_data *pd,int param)
  5590. {
  5591. unsigned char buf[16];
  5592. nullpo_retr(0, pd);
  5593. malloc_set(buf,0,packet_len_table[0x1aa]);
  5594. WBUFW(buf,0)=0x1aa;
  5595. WBUFL(buf,2)=pd->bl.id;
  5596. if(param >= 100 && pd->petDB->talk_convert_class) {
  5597. if(pd->petDB->talk_convert_class < 0)
  5598. return 0;
  5599. else if(pd->petDB->talk_convert_class > 0) {
  5600. param -= (pd->pet.class_ - 100)*100;
  5601. param += (pd->petDB->talk_convert_class - 100)*100;
  5602. }
  5603. }
  5604. WBUFL(buf,6)=param;
  5605. clif_send(buf,packet_len_table[0x1aa],&pd->bl,AREA);
  5606. return 0;
  5607. }
  5608. int clif_pet_performance(struct block_list *bl,int param)
  5609. {
  5610. unsigned char buf[16];
  5611. nullpo_retr(0, bl);
  5612. malloc_set(buf,0,packet_len_table[0x1a4]);
  5613. WBUFW(buf,0)=0x1a4;
  5614. WBUFB(buf,2)=4;
  5615. WBUFL(buf,3)=bl->id;
  5616. WBUFL(buf,7)=param;
  5617. clif_send(buf,packet_len_table[0x1a4],bl,AREA);
  5618. return 0;
  5619. }
  5620. int clif_pet_equip(struct pet_data *pd)
  5621. {
  5622. unsigned char buf[16];
  5623. nullpo_retr(0, pd);
  5624. malloc_set(buf,0,packet_len_table[0x1a4]);
  5625. WBUFW(buf,0)=0x1a4;
  5626. WBUFB(buf,2)=3;
  5627. WBUFL(buf,3)=pd->bl.id;
  5628. WBUFL(buf,7)=pd->vd.shield;
  5629. clif_send(buf,packet_len_table[0x1a4],&pd->bl,AREA);
  5630. return 0;
  5631. }
  5632. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5633. {
  5634. int fd;
  5635. nullpo_retr(0, sd);
  5636. fd=sd->fd;
  5637. WFIFOHEAD(fd,packet_len_table[0x1a3]);
  5638. WFIFOW(fd,0)=0x1a3;
  5639. WFIFOB(fd,2)=fail;
  5640. WFIFOW(fd,3)=foodid;
  5641. WFIFOSET(fd,packet_len_table[0x1a3]);
  5642. return 0;
  5643. }
  5644. /*==========================================
  5645. * オートスペル リスト送信
  5646. *------------------------------------------
  5647. */
  5648. int clif_autospell(struct map_session_data *sd,int skilllv)
  5649. {
  5650. int fd;
  5651. nullpo_retr(0, sd);
  5652. fd=sd->fd;
  5653. WFIFOHEAD(fd,packet_len_table[0x1cd]);
  5654. WFIFOW(fd, 0)=0x1cd;
  5655. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5656. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5657. else
  5658. WFIFOL(fd,2)= 0x00000000;
  5659. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5660. WFIFOL(fd,6)= MG_COLDBOLT;
  5661. else
  5662. WFIFOL(fd,6)= 0x00000000;
  5663. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5664. WFIFOL(fd,10)= MG_FIREBOLT;
  5665. else
  5666. WFIFOL(fd,10)= 0x00000000;
  5667. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5668. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5669. else
  5670. WFIFOL(fd,14)= 0x00000000;
  5671. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5672. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5673. else
  5674. WFIFOL(fd,18)= 0x00000000;
  5675. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5676. WFIFOL(fd,22)= MG_FIREBALL;
  5677. else
  5678. WFIFOL(fd,22)= 0x00000000;
  5679. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5680. WFIFOL(fd,26)= MG_FROSTDIVER;
  5681. else
  5682. WFIFOL(fd,26)= 0x00000000;
  5683. WFIFOSET(fd,packet_len_table[0x1cd]);
  5684. sd->menuskill_id = SA_AUTOSPELL;
  5685. sd->menuskill_lv = skilllv;
  5686. return 0;
  5687. }
  5688. /*==========================================
  5689. * ディボーションの青い糸
  5690. *------------------------------------------
  5691. */
  5692. int clif_devotion(struct map_session_data *sd)
  5693. {
  5694. unsigned char buf[56];
  5695. int i,n;
  5696. nullpo_retr(0, sd);
  5697. WBUFW(buf,0)=0x1cf;
  5698. WBUFL(buf,2)=sd->bl.id;
  5699. for(i=0,n=0;i<5;i++) {
  5700. if (!sd->devotion[i])
  5701. continue;
  5702. WBUFL(buf,6+4*n)=sd->devotion[i];
  5703. n++;
  5704. }
  5705. for(;n<5;n++)
  5706. WBUFL(buf,6+4*n)=0;
  5707. WBUFB(buf,26)=8;
  5708. WBUFB(buf,27)=0;
  5709. clif_send(buf,packet_len_table[0x1cf],&sd->bl,AREA);
  5710. return 0;
  5711. }
  5712. int clif_marionette(struct block_list *src, struct block_list *target)
  5713. {
  5714. unsigned char buf[56];
  5715. int n;
  5716. WBUFW(buf,0)=0x1cf;
  5717. WBUFL(buf,2)=src->id;
  5718. for(n=0;n<5;n++)
  5719. WBUFL(buf,6+4*n)=0;
  5720. if (target) //The target goes on the second slot.
  5721. WBUFL(buf,6+4) = target->id;
  5722. WBUFB(buf,26)=8;
  5723. WBUFB(buf,27)=0;
  5724. clif_send(buf,packet_len_table[0x1cf],src,AREA);
  5725. return 0;
  5726. }
  5727. /*==========================================
  5728. * 氣球
  5729. *------------------------------------------
  5730. */
  5731. int clif_spiritball(struct map_session_data *sd)
  5732. {
  5733. unsigned char buf[16];
  5734. nullpo_retr(0, sd);
  5735. WBUFW(buf,0)=0x1d0;
  5736. WBUFL(buf,2)=sd->bl.id;
  5737. WBUFW(buf,6)=sd->spiritball;
  5738. clif_send(buf,packet_len_table[0x1d0],&sd->bl,AREA);
  5739. return 0;
  5740. }
  5741. /*==========================================
  5742. *
  5743. *------------------------------------------
  5744. */
  5745. int clif_combo_delay(struct block_list *bl,int wait)
  5746. {
  5747. unsigned char buf[32];
  5748. nullpo_retr(0, bl);
  5749. WBUFW(buf,0)=0x1d2;
  5750. WBUFL(buf,2)=bl->id;
  5751. WBUFL(buf,6)=wait;
  5752. clif_send(buf,packet_len_table[0x1d2],bl,AREA);
  5753. return 0;
  5754. }
  5755. /*==========================================
  5756. *白刃取り
  5757. *------------------------------------------
  5758. */
  5759. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5760. int _bool)
  5761. {
  5762. unsigned char buf[32];
  5763. nullpo_retr(0, src);
  5764. nullpo_retr(0, dst);
  5765. WBUFW(buf,0)=0x1d1;
  5766. WBUFL(buf,2)=src->id;
  5767. WBUFL(buf,6)=dst->id;
  5768. WBUFL(buf,10)=_bool;
  5769. clif_send(buf,packet_len_table[0x1d1],src,AREA);
  5770. return 0;
  5771. }
  5772. /*==========================================
  5773. *
  5774. *------------------------------------------
  5775. */
  5776. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5777. {
  5778. struct block_list bl;
  5779. unsigned char buf[32];
  5780. bl.type = BL_NUL;
  5781. bl.m = m;
  5782. bl.x = x;
  5783. bl.y = y;
  5784. WBUFW(buf,0) = 0x192;
  5785. WBUFW(buf,2) = x;
  5786. WBUFW(buf,4) = y;
  5787. WBUFW(buf,6) = cell_type;
  5788. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  5789. if(!type)
  5790. clif_send(buf,packet_len_table[0x192],&bl,AREA);
  5791. else
  5792. clif_send(buf,packet_len_table[0x192],&bl,ALL_SAMEMAP);
  5793. return 0;
  5794. }
  5795. /*==========================================
  5796. * MVPエフェクト
  5797. *------------------------------------------
  5798. */
  5799. int clif_mvp_effect(struct map_session_data *sd)
  5800. {
  5801. unsigned char buf[16];
  5802. nullpo_retr(0, sd);
  5803. WBUFW(buf,0)=0x10c;
  5804. WBUFL(buf,2)=sd->bl.id;
  5805. clif_send(buf,packet_len_table[0x10c],&sd->bl,AREA);
  5806. return 0;
  5807. }
  5808. /*==========================================
  5809. * MVPアイテム所得
  5810. *------------------------------------------
  5811. */
  5812. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5813. {
  5814. int view,fd;
  5815. nullpo_retr(0, sd);
  5816. fd=sd->fd;
  5817. WFIFOHEAD(fd,packet_len_table[0x10a]);
  5818. WFIFOW(fd,0)=0x10a;
  5819. if((view = itemdb_viewid(nameid)) > 0)
  5820. WFIFOW(fd,2)=view;
  5821. else
  5822. WFIFOW(fd,2)=nameid;
  5823. WFIFOSET(fd,packet_len_table[0x10a]);
  5824. return 0;
  5825. }
  5826. /*==========================================
  5827. * MVP経験値所得
  5828. *------------------------------------------
  5829. */
  5830. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5831. {
  5832. int fd;
  5833. nullpo_retr(0, sd);
  5834. fd=sd->fd;
  5835. WFIFOHEAD(fd,packet_len_table[0x10b]);
  5836. WFIFOW(fd,0)=0x10b;
  5837. WFIFOL(fd,2)=exp;
  5838. WFIFOSET(fd,packet_len_table[0x10b]);
  5839. return 0;
  5840. }
  5841. /*==========================================
  5842. * ギルド作成可否通知
  5843. *------------------------------------------
  5844. */
  5845. int clif_guild_created(struct map_session_data *sd,int flag)
  5846. {
  5847. int fd;
  5848. nullpo_retr(0, sd);
  5849. fd=sd->fd;
  5850. WFIFOHEAD(fd,packet_len_table[0x167]);
  5851. WFIFOW(fd,0)=0x167;
  5852. WFIFOB(fd,2)=flag;
  5853. WFIFOSET(fd,packet_len_table[0x167]);
  5854. return 0;
  5855. }
  5856. /*==========================================
  5857. * ギルド所属通知
  5858. *------------------------------------------
  5859. */
  5860. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5861. {
  5862. int ps,fd;
  5863. nullpo_retr(0, sd);
  5864. nullpo_retr(0, g);
  5865. fd=sd->fd;
  5866. ps=guild_getposition(sd,g);
  5867. WFIFOHEAD(fd,packet_len_table[0x16c]);
  5868. malloc_set(WFIFOP(fd,0),0,packet_len_table[0x16c]);
  5869. WFIFOW(fd,0)=0x16c;
  5870. WFIFOL(fd,2)=g->guild_id;
  5871. WFIFOL(fd,6)=g->emblem_id;
  5872. WFIFOL(fd,10)=g->position[ps].mode;
  5873. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5874. WFIFOSET(fd,packet_len_table[0x16c]);
  5875. return 0;
  5876. }
  5877. /*==========================================
  5878. * ギルドメンバログイン通知
  5879. *------------------------------------------
  5880. */
  5881. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5882. {
  5883. unsigned char buf[64];
  5884. nullpo_retr(0, g);
  5885. WBUFW(buf, 0)=0x16d;
  5886. WBUFL(buf, 2)=g->member[idx].account_id;
  5887. WBUFL(buf, 6)=g->member[idx].char_id;
  5888. WBUFL(buf,10)=flag;
  5889. if(g->member[idx].sd==NULL){
  5890. struct map_session_data *sd=guild_getavailablesd(g);
  5891. if(sd!=NULL)
  5892. clif_send(buf,packet_len_table[0x16d],&sd->bl,GUILD);
  5893. }else
  5894. clif_send(buf,packet_len_table[0x16d],&g->member[idx].sd->bl,GUILD_WOS);
  5895. return 0;
  5896. }
  5897. // Function `clif_guild_memberlogin_notice` sends info about
  5898. // logins and logouts of a guild member to the rest members.
  5899. // But at the 1st time (after a player login or map changing)
  5900. // the client won't show the message.
  5901. // So I suggest use this function for sending "first-time-info"
  5902. // to some player on entering the game or changing location.
  5903. // At next time the client would always show the message.
  5904. // The function sends all the statuses in the single packet
  5905. // to economize traffic. [LuzZza]
  5906. int clif_guild_send_onlineinfo(struct map_session_data *sd) {
  5907. struct guild *g;
  5908. char buf[14*128];
  5909. int i, count=0, p_len;
  5910. nullpo_retr(0, sd);
  5911. p_len = packet_len_table[0x16d];
  5912. if(!(g = guild_search(sd->status.guild_id)))
  5913. return 0;
  5914. for(i=0; i<g->max_member; i++) {
  5915. if(g->member[i].account_id > 0 &&
  5916. g->member[i].account_id != sd->status.account_id) {
  5917. WBUFW(buf,count*p_len) = 0x16d;
  5918. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5919. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5920. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5921. count++;
  5922. }
  5923. }
  5924. clif_send(buf,p_len*count,&sd->bl,SELF);
  5925. return 0;
  5926. }
  5927. /*==========================================
  5928. * ギルドマスター通知(14dへの応答)
  5929. *------------------------------------------
  5930. */
  5931. int clif_guild_masterormember(struct map_session_data *sd)
  5932. {
  5933. int type=0x57,fd;
  5934. nullpo_retr(0, sd);
  5935. fd=sd->fd;
  5936. if(sd->state.gmaster_flag)
  5937. type=0xd7;
  5938. WFIFOHEAD(fd,packet_len_table[0x14e]);
  5939. WFIFOW(fd,0)=0x14e;
  5940. WFIFOL(fd,2)=type;
  5941. WFIFOSET(fd,packet_len_table[0x14e]);
  5942. return 0;
  5943. }
  5944. /*==========================================
  5945. * Basic Info (Territories [Valaris])
  5946. *------------------------------------------
  5947. */
  5948. int clif_guild_basicinfo(struct map_session_data *sd)
  5949. {
  5950. int fd,i,t=0;
  5951. struct guild *g;
  5952. struct guild_castle *gc=NULL;
  5953. nullpo_retr(0, sd);
  5954. fd=sd->fd;
  5955. g=guild_search(sd->status.guild_id);
  5956. if(g==NULL)
  5957. return 0;
  5958. WFIFOHEAD(fd,packet_len_table[0x1b6]);
  5959. WFIFOW(fd, 0)=0x1b6;//0x150;
  5960. WFIFOL(fd, 2)=g->guild_id;
  5961. WFIFOL(fd, 6)=g->guild_lv;
  5962. WFIFOL(fd,10)=g->connect_member;
  5963. WFIFOL(fd,14)=g->max_member;
  5964. WFIFOL(fd,18)=g->average_lv;
  5965. WFIFOL(fd,22)=g->exp;
  5966. WFIFOL(fd,26)=g->next_exp;
  5967. WFIFOL(fd,30)=0; // 上納
  5968. WFIFOL(fd,34)=0; // VW(性格の悪さ?:性向グラフ左右)
  5969. WFIFOL(fd,38)=0; // RF(正義の度合い?:性向グラフ上下)
  5970. WFIFOL(fd,42)=0; // 人数?
  5971. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5972. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5973. for(i=0;i<MAX_GUILDCASTLE;i++){
  5974. gc=guild_castle_search(i);
  5975. if(!gc) continue;
  5976. if(g->guild_id == gc->guild_id) t++;
  5977. }
  5978. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  5979. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  5980. else
  5981. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  5982. WFIFOSET(fd,packet_len_table[WFIFOW(fd,0)]);
  5983. clif_guild_emblem(sd,g); // Guild emblem vanish fix [Valaris]
  5984. return 0;
  5985. }
  5986. /*==========================================
  5987. * ギルド同盟/敵対情報
  5988. *------------------------------------------
  5989. */
  5990. int clif_guild_allianceinfo(struct map_session_data *sd)
  5991. {
  5992. int fd,i,c;
  5993. struct guild *g;
  5994. nullpo_retr(0, sd);
  5995. fd=sd->fd;
  5996. g=guild_search(sd->status.guild_id);
  5997. if(g==NULL)
  5998. return 0;
  5999. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6000. WFIFOW(fd, 0)=0x14c;
  6001. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6002. struct guild_alliance *a=&g->alliance[i];
  6003. if(a->guild_id>0){
  6004. WFIFOL(fd,c*32+4)=a->opposition;
  6005. WFIFOL(fd,c*32+8)=a->guild_id;
  6006. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6007. c++;
  6008. }
  6009. }
  6010. WFIFOW(fd, 2)=c*32+4;
  6011. WFIFOSET(fd,WFIFOW(fd,2));
  6012. return 0;
  6013. }
  6014. /*==========================================
  6015. * ギルドメンバーリスト
  6016. *------------------------------------------
  6017. */
  6018. int clif_guild_memberlist(struct map_session_data *sd)
  6019. {
  6020. int fd;
  6021. int i,c;
  6022. struct guild *g;
  6023. nullpo_retr(0, sd);
  6024. fd=sd->fd;
  6025. if (!fd)
  6026. return 0;
  6027. g=guild_search(sd->status.guild_id);
  6028. if(g==NULL)
  6029. return 0;
  6030. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6031. WFIFOW(fd, 0)=0x154;
  6032. for(i=0,c=0;i<g->max_member;i++){
  6033. struct guild_member *m=&g->member[i];
  6034. if(m->account_id==0)
  6035. continue;
  6036. WFIFOL(fd,c*104+ 4)=m->account_id;
  6037. WFIFOL(fd,c*104+ 8)=m->char_id;
  6038. WFIFOW(fd,c*104+12)=m->hair;
  6039. WFIFOW(fd,c*104+14)=m->hair_color;
  6040. WFIFOW(fd,c*104+16)=m->gender;
  6041. WFIFOW(fd,c*104+18)=m->class_;
  6042. WFIFOW(fd,c*104+20)=m->lv;
  6043. WFIFOL(fd,c*104+22)=m->exp;
  6044. WFIFOL(fd,c*104+26)=m->online;
  6045. WFIFOL(fd,c*104+30)=m->position;
  6046. malloc_tsetword(WFIFOP(fd,c*104+34),0,50); // メモ?
  6047. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6048. c++;
  6049. }
  6050. WFIFOW(fd, 2)=c*104+4;
  6051. WFIFOSET(fd,WFIFOW(fd,2));
  6052. return 0;
  6053. }
  6054. /*==========================================
  6055. * ギルド役職名リスト
  6056. *------------------------------------------
  6057. */
  6058. int clif_guild_positionnamelist(struct map_session_data *sd)
  6059. {
  6060. int i,fd;
  6061. struct guild *g;
  6062. nullpo_retr(0, sd);
  6063. fd=sd->fd;
  6064. g=guild_search(sd->status.guild_id);
  6065. if(g==NULL)
  6066. return 0;
  6067. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6068. WFIFOW(fd, 0)=0x166;
  6069. for(i=0;i<MAX_GUILDPOSITION;i++){
  6070. WFIFOL(fd,i*28+4)=i;
  6071. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6072. }
  6073. WFIFOW(fd,2)=i*28+4;
  6074. WFIFOSET(fd,WFIFOW(fd,2));
  6075. return 0;
  6076. }
  6077. /*==========================================
  6078. * ギルド役職情報リスト
  6079. *------------------------------------------
  6080. */
  6081. int clif_guild_positioninfolist(struct map_session_data *sd)
  6082. {
  6083. int i,fd;
  6084. struct guild *g;
  6085. nullpo_retr(0, sd);
  6086. fd=sd->fd;
  6087. g=guild_search(sd->status.guild_id);
  6088. if(g==NULL)
  6089. return 0;
  6090. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6091. WFIFOW(fd, 0)=0x160;
  6092. for(i=0;i<MAX_GUILDPOSITION;i++){
  6093. struct guild_position *p=&g->position[i];
  6094. WFIFOL(fd,i*16+ 4)=i;
  6095. WFIFOL(fd,i*16+ 8)=p->mode;
  6096. WFIFOL(fd,i*16+12)=i;
  6097. WFIFOL(fd,i*16+16)=p->exp_mode;
  6098. }
  6099. WFIFOW(fd, 2)=i*16+4;
  6100. WFIFOSET(fd,WFIFOW(fd,2));
  6101. return 0;
  6102. }
  6103. /*==========================================
  6104. * ギルド役職変更通知
  6105. *------------------------------------------
  6106. */
  6107. int clif_guild_positionchanged(struct guild *g,int idx)
  6108. {
  6109. struct map_session_data *sd;
  6110. unsigned char buf[128];
  6111. nullpo_retr(0, g);
  6112. WBUFW(buf, 0)=0x174;
  6113. WBUFW(buf, 2)=44;
  6114. WBUFL(buf, 4)=idx;
  6115. WBUFL(buf, 8)=g->position[idx].mode;
  6116. WBUFL(buf,12)=idx;
  6117. WBUFL(buf,16)=g->position[idx].exp_mode;
  6118. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6119. if( (sd=guild_getavailablesd(g))!=NULL )
  6120. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6121. return 0;
  6122. }
  6123. /*==========================================
  6124. * ギルドメンバ変更通知
  6125. *------------------------------------------
  6126. */
  6127. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6128. {
  6129. struct map_session_data *sd;
  6130. unsigned char buf[64];
  6131. nullpo_retr(0, g);
  6132. WBUFW(buf, 0)=0x156;
  6133. WBUFW(buf, 2)=16;
  6134. WBUFL(buf, 4)=g->member[idx].account_id;
  6135. WBUFL(buf, 8)=g->member[idx].char_id;
  6136. WBUFL(buf,12)=g->member[idx].position;
  6137. if( (sd=guild_getavailablesd(g))!=NULL )
  6138. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6139. return 0;
  6140. }
  6141. /*==========================================
  6142. * ギルドエンブレム送信
  6143. *------------------------------------------
  6144. */
  6145. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6146. {
  6147. int fd;
  6148. nullpo_retr(0, sd);
  6149. nullpo_retr(0, g);
  6150. fd=sd->fd;
  6151. if(g->emblem_len<=0)
  6152. return 0;
  6153. WFIFOHEAD(fd,g->emblem_len+12);
  6154. WFIFOW(fd,0)=0x152;
  6155. WFIFOW(fd,2)=g->emblem_len+12;
  6156. WFIFOL(fd,4)=g->guild_id;
  6157. WFIFOL(fd,8)=g->emblem_id;
  6158. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6159. WFIFOSET(fd,WFIFOW(fd,2));
  6160. return 0;
  6161. }
  6162. /*==========================================
  6163. * ギルドスキル送信
  6164. *------------------------------------------
  6165. */
  6166. int clif_guild_skillinfo(struct map_session_data *sd)
  6167. {
  6168. int fd;
  6169. int i,id,c,up=1;
  6170. struct guild *g;
  6171. nullpo_retr(0, sd);
  6172. fd=sd->fd;
  6173. g=guild_search(sd->status.guild_id);
  6174. if(g==NULL)
  6175. return 0;
  6176. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6177. WFIFOW(fd,0)=0x0162;
  6178. WFIFOW(fd,4)=g->skill_point;
  6179. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6180. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6181. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6182. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  6183. WFIFOW(fd,c*37+10) = 0;
  6184. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6185. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6186. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6187. malloc_tsetdword(WFIFOP(fd,c*37+18),0,24);
  6188. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6189. up = 1;
  6190. else
  6191. up = 0;
  6192. WFIFOB(fd,c*37+42)= up;
  6193. c++;
  6194. }
  6195. }
  6196. WFIFOW(fd,2)=c*37+6;
  6197. WFIFOSET(fd,WFIFOW(fd,2));
  6198. return 0;
  6199. }
  6200. /*==========================================
  6201. * ギルド告知送信
  6202. *------------------------------------------
  6203. */
  6204. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6205. {
  6206. int fd;
  6207. nullpo_retr(0, sd);
  6208. nullpo_retr(0, g);
  6209. fd = sd->fd;
  6210. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6211. return 0;
  6212. if (fd <= 0)
  6213. return 0;
  6214. if(*g->mes1==0 && *g->mes2==0)
  6215. return 0;
  6216. WFIFOHEAD(fd,packet_len_table[0x16f]);
  6217. WFIFOW(fd,0)=0x16f;
  6218. memcpy(WFIFOP(fd,2),g->mes1,60);
  6219. memcpy(WFIFOP(fd,62),g->mes2,120);
  6220. WFIFOSET(fd,packet_len_table[0x16f]);
  6221. return 0;
  6222. }
  6223. /*==========================================
  6224. * ギルドメンバ勧誘
  6225. *------------------------------------------
  6226. */
  6227. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6228. {
  6229. int fd;
  6230. nullpo_retr(0, sd);
  6231. nullpo_retr(0, g);
  6232. fd=sd->fd;
  6233. WFIFOHEAD(fd,packet_len_table[0x16a]);
  6234. WFIFOW(fd,0)=0x16a;
  6235. WFIFOL(fd,2)=g->guild_id;
  6236. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6237. WFIFOSET(fd,packet_len_table[0x16a]);
  6238. return 0;
  6239. }
  6240. /*==========================================
  6241. * ギルドメンバ勧誘結果
  6242. *------------------------------------------
  6243. */
  6244. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6245. {
  6246. int fd;
  6247. nullpo_retr(0, sd);
  6248. fd=sd->fd;
  6249. WFIFOHEAD(fd,packet_len_table[0x169]);
  6250. WFIFOW(fd,0)=0x169;
  6251. WFIFOB(fd,2)=flag;
  6252. WFIFOSET(fd,packet_len_table[0x169]);
  6253. return 0;
  6254. }
  6255. /*==========================================
  6256. * ギルドメンバ脱退通知
  6257. *------------------------------------------
  6258. */
  6259. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6260. {
  6261. unsigned char buf[128];
  6262. nullpo_retr(0, sd);
  6263. WBUFW(buf, 0)=0x15a;
  6264. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6265. memcpy(WBUFP(buf,26),mes,40);
  6266. clif_send(buf,packet_len_table[0x15a],&sd->bl,GUILD);
  6267. return 0;
  6268. }
  6269. /*==========================================
  6270. * ギルドメンバ追放通知
  6271. *------------------------------------------
  6272. */
  6273. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  6274. int account_id)
  6275. {
  6276. unsigned char buf[128];
  6277. nullpo_retr(0, sd);
  6278. WBUFW(buf, 0)=0x15c;
  6279. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6280. memcpy(WBUFP(buf,26),mes,40);
  6281. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6282. clif_send(buf,packet_len_table[0x15c],&sd->bl,GUILD);
  6283. return 0;
  6284. }
  6285. /*==========================================
  6286. * ギルド追放メンバリスト
  6287. *------------------------------------------
  6288. */
  6289. int clif_guild_expulsionlist(struct map_session_data *sd)
  6290. {
  6291. int fd;
  6292. int i,c;
  6293. struct guild *g;
  6294. nullpo_retr(0, sd);
  6295. fd=sd->fd;
  6296. g=guild_search(sd->status.guild_id);
  6297. if(g==NULL)
  6298. return 0;
  6299. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  6300. WFIFOW(fd,0)=0x163;
  6301. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  6302. struct guild_expulsion *e=&g->expulsion[i];
  6303. if(e->account_id>0){
  6304. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6305. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6306. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6307. c++;
  6308. }
  6309. }
  6310. WFIFOW(fd,2)=c*88+4;
  6311. WFIFOSET(fd,WFIFOW(fd,2));
  6312. return 0;
  6313. }
  6314. /*==========================================
  6315. * ギルド会話
  6316. *------------------------------------------
  6317. */
  6318. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6319. {
  6320. struct map_session_data *sd;
  6321. unsigned char *buf;
  6322. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6323. WBUFW(buf, 0) = 0x17f;
  6324. WBUFW(buf, 2) = len + 4;
  6325. memcpy(WBUFP(buf,4), mes, len);
  6326. if ((sd = guild_getavailablesd(g)) != NULL)
  6327. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6328. if(buf) aFree(buf);
  6329. return 0;
  6330. }
  6331. /*==========================================
  6332. * ギルドスキル割り振り通知
  6333. *------------------------------------------
  6334. */
  6335. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6336. {
  6337. int fd;
  6338. nullpo_retr(0, sd);
  6339. fd=sd->fd;
  6340. WFIFOHEAD(fd,11);
  6341. WFIFOW(fd,0) = 0x10e;
  6342. WFIFOW(fd,2) = skill_num;
  6343. WFIFOW(fd,4) = lv;
  6344. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6345. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6346. WFIFOB(fd,10) = 1;
  6347. WFIFOSET(fd,11);
  6348. return 0;
  6349. }
  6350. /*==========================================
  6351. * ギルド同盟要請
  6352. *------------------------------------------
  6353. */
  6354. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6355. {
  6356. int fd;
  6357. nullpo_retr(0, sd);
  6358. fd=sd->fd;
  6359. WFIFOHEAD(fd,packet_len_table[0x171]);
  6360. WFIFOW(fd,0)=0x171;
  6361. WFIFOL(fd,2)=account_id;
  6362. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6363. WFIFOSET(fd,packet_len_table[0x171]);
  6364. return 0;
  6365. }
  6366. /*==========================================
  6367. * ギルド同盟結果
  6368. *------------------------------------------
  6369. */
  6370. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6371. {
  6372. int fd;
  6373. nullpo_retr(0, sd);
  6374. fd=sd->fd;
  6375. WFIFOHEAD(fd,packet_len_table[0x173]);
  6376. WFIFOW(fd,0)=0x173;
  6377. WFIFOL(fd,2)=flag;
  6378. WFIFOSET(fd,packet_len_table[0x173]);
  6379. return 0;
  6380. }
  6381. /*==========================================
  6382. * ギルド関係解消通知
  6383. *------------------------------------------
  6384. */
  6385. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6386. {
  6387. int fd;
  6388. nullpo_retr(0, sd);
  6389. fd = sd->fd;
  6390. if (fd <= 0)
  6391. return 0;
  6392. WFIFOHEAD(fd,packet_len_table[0x184]);
  6393. WFIFOW(fd,0)=0x184;
  6394. WFIFOL(fd,2)=guild_id;
  6395. WFIFOL(fd,6)=flag;
  6396. WFIFOSET(fd,packet_len_table[0x184]);
  6397. return 0;
  6398. }
  6399. /*==========================================
  6400. * ギルド敵対結果
  6401. *------------------------------------------
  6402. */
  6403. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6404. {
  6405. int fd;
  6406. nullpo_retr(0, sd);
  6407. fd=sd->fd;
  6408. WFIFOHEAD(fd,packet_len_table[0x181]);
  6409. WFIFOW(fd,0)=0x181;
  6410. WFIFOB(fd,2)=flag;
  6411. WFIFOSET(fd,packet_len_table[0x181]);
  6412. return 0;
  6413. }
  6414. /*==========================================
  6415. * ギルド関係追加
  6416. *------------------------------------------
  6417. */
  6418. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6419. {
  6420. unsigned char buf[64];
  6421. WBUFW(fd,0)=0x185;
  6422. WBUFL(fd,2)=g->alliance[idx].opposition;
  6423. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6424. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6425. clif_send(buf,packet_len_table[0x185],guild_getavailablesd(g),GUILD);
  6426. return 0;
  6427. }*/
  6428. /*==========================================
  6429. * ギルド解散通知
  6430. *------------------------------------------
  6431. */
  6432. int clif_guild_broken(struct map_session_data *sd,int flag)
  6433. {
  6434. int fd;
  6435. nullpo_retr(0, sd);
  6436. fd=sd->fd;
  6437. WFIFOHEAD(fd,packet_len_table[0x15e]);
  6438. WFIFOW(fd,0)=0x15e;
  6439. WFIFOL(fd,2)=flag;
  6440. WFIFOSET(fd,packet_len_table[0x15e]);
  6441. return 0;
  6442. }
  6443. /*==========================================
  6444. * エモーション
  6445. *------------------------------------------
  6446. */
  6447. void clif_emotion(struct block_list *bl,int type)
  6448. {
  6449. unsigned char buf[8];
  6450. nullpo_retv(bl);
  6451. WBUFW(buf,0)=0xc0;
  6452. WBUFL(buf,2)=bl->id;
  6453. WBUFB(buf,6)=type;
  6454. clif_send(buf,packet_len_table[0xc0],bl,AREA);
  6455. }
  6456. /*==========================================
  6457. * トーキーボックス
  6458. *------------------------------------------
  6459. */
  6460. void clif_talkiebox(struct block_list *bl,char* talkie)
  6461. {
  6462. unsigned char buf[86];
  6463. nullpo_retv(bl);
  6464. WBUFW(buf,0)=0x191;
  6465. WBUFL(buf,2)=bl->id;
  6466. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6467. clif_send(buf,packet_len_table[0x191],bl,AREA);
  6468. }
  6469. /*==========================================
  6470. * 結婚エフェクト
  6471. *------------------------------------------
  6472. */
  6473. void clif_wedding_effect(struct block_list *bl) {
  6474. unsigned char buf[6];
  6475. nullpo_retv(bl);
  6476. WBUFW(buf,0) = 0x1ea;
  6477. WBUFL(buf,2) = bl->id;
  6478. clif_send(buf, packet_len_table[0x1ea], bl, AREA);
  6479. }
  6480. /*==========================================
  6481. * あなたに逢いたい使用時名前叫び
  6482. *------------------------------------------
  6483. void clif_callpartner(struct map_session_data *sd)
  6484. {
  6485. unsigned char buf[26];
  6486. char *p;
  6487. nullpo_retv(sd);
  6488. if(sd->status.partner_id){
  6489. WBUFW(buf,0)=0x1e6;
  6490. p = map_charid2nick(sd->status.partner_id);
  6491. if(p){
  6492. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6493. }else{
  6494. map_reqchariddb(sd,sd->status.partner_id);
  6495. chrif_searchcharid(sd->status.partner_id);
  6496. WBUFB(buf,2) = 0;
  6497. }
  6498. clif_send(buf,packet_len_table[0x1e6],&sd->bl,AREA);
  6499. }
  6500. return;
  6501. }
  6502. */
  6503. /*==========================================
  6504. * Adopt baby [Celest]
  6505. *------------------------------------------
  6506. */
  6507. void clif_adopt_process(struct map_session_data *sd)
  6508. {
  6509. int fd;
  6510. nullpo_retv(sd);
  6511. fd=sd->fd;
  6512. WFIFOHEAD(fd,packet_len_table[0x1f8]);
  6513. WFIFOW(fd,0)=0x1f8;
  6514. WFIFOSET(fd,packet_len_table[0x1f8]);
  6515. }
  6516. /*==========================================
  6517. * Marry [DracoRPG]
  6518. *------------------------------------------
  6519. */
  6520. void clif_marriage_process(struct map_session_data *sd)
  6521. {
  6522. int fd;
  6523. nullpo_retv(sd);
  6524. fd=sd->fd;
  6525. WFIFOHEAD(fd,packet_len_table[0x1e4]);
  6526. WFIFOW(fd,0)=0x1e4;
  6527. WFIFOSET(fd,packet_len_table[0x1e4]);
  6528. }
  6529. /*==========================================
  6530. * Notice of divorce
  6531. *------------------------------------------
  6532. */
  6533. void clif_divorced(struct map_session_data *sd, char *name)
  6534. {
  6535. int fd;
  6536. nullpo_retv(sd);
  6537. fd=sd->fd;
  6538. WFIFOHEAD(fd,packet_len_table[0x205]);
  6539. WFIFOW(fd,0)=0x205;
  6540. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6541. WFIFOSET(fd, packet_len_table[0x205]);
  6542. }
  6543. /*==========================================
  6544. *
  6545. *------------------------------------------
  6546. */
  6547. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6548. nullpo_retv(sd);
  6549. WFIFOHEAD(fd,packet_len_table[0x1f6]);
  6550. WFIFOW(fd,0)=0x1f6;
  6551. WFIFOSET(fd, packet_len_table[0x1f6]);
  6552. }
  6553. /*==========================================
  6554. *
  6555. *------------------------------------------
  6556. */
  6557. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6558. nullpo_retv(sd);
  6559. WFIFOHEAD(fd,packet_len_table[0x1e2]);
  6560. WFIFOW(fd,0)=0x1e2;
  6561. WFIFOSET(fd, packet_len_table[0x1e2]);
  6562. }
  6563. /*==========================================
  6564. * 座る
  6565. *------------------------------------------
  6566. */
  6567. void clif_sitting(struct map_session_data *sd)
  6568. {
  6569. unsigned char buf[64];
  6570. nullpo_retv(sd);
  6571. WBUFW(buf, 0) = 0x8a;
  6572. WBUFL(buf, 2) = sd->bl.id;
  6573. WBUFB(buf,26) = 2;
  6574. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  6575. }
  6576. /*==========================================
  6577. *
  6578. *------------------------------------------
  6579. */
  6580. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  6581. {
  6582. int fd;
  6583. nullpo_retr(0, sd);
  6584. fd = sd->fd;
  6585. if (!fd || !len) return 0; //Disconnected player.
  6586. WFIFOHEAD(fd, len+5);
  6587. WFIFOW(fd, 0) = 0x17f;
  6588. WFIFOW(fd, 2) = len + 5;
  6589. memcpy(WFIFOP(fd,4), mes, len);
  6590. WFIFOSET(fd, WFIFOW(fd,2));
  6591. return 1;
  6592. }
  6593. /*==========================================
  6594. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6595. *------------------------------------------
  6596. */
  6597. void clif_disp_message(struct block_list *src, char *mes, int len, int type)
  6598. {
  6599. unsigned char buf[1024];
  6600. if (!len) return;
  6601. WBUFW(buf, 0) = 0x17f;
  6602. WBUFW(buf, 2) = len + 5;
  6603. memcpy(WBUFP(buf,4), mes, len);
  6604. clif_send(buf, WBUFW(buf,2), src, type);
  6605. return;
  6606. }
  6607. /*==========================================
  6608. *
  6609. *------------------------------------------
  6610. */
  6611. int clif_GM_kickack(struct map_session_data *sd, int id)
  6612. {
  6613. int fd;
  6614. nullpo_retr(0, sd);
  6615. fd = sd->fd;
  6616. WFIFOHEAD(fd,packet_len_table[0xcd]);
  6617. WFIFOW(fd,0) = 0xcd;
  6618. WFIFOL(fd,2) = id;
  6619. WFIFOSET(fd, packet_len_table[0xcd]);
  6620. return 0;
  6621. }
  6622. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6623. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6624. {
  6625. nullpo_retr(0, tsd);
  6626. if(type)
  6627. clif_GM_kickack(sd,tsd->status.account_id);
  6628. WFIFOHEAD(tsd->fd,packet_len_table[0x18b]);
  6629. WFIFOW(tsd->fd,0) = 0x18b;
  6630. WFIFOW(tsd->fd,2) = 0;
  6631. WFIFOSET(tsd->fd,packet_len_table[0x18b]);
  6632. if (tsd->fd)
  6633. {
  6634. ShowDebug("clif_GM_kick: Disconnecting session #%d\n", tsd->fd);
  6635. clif_setwaitclose(tsd->fd);
  6636. } else { //Player has no session attached, delete it right away. [Skotlex]
  6637. map_quit(tsd);
  6638. }
  6639. return 0;
  6640. }
  6641. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6642. {
  6643. int fd;
  6644. nullpo_retr(0, sd);
  6645. nullpo_retr(0, tsd);
  6646. fd = tsd->fd;
  6647. if (fd <= 0)
  6648. return 0;
  6649. WFIFOHEAD(fd,packet_len_table[0x14b]);
  6650. WFIFOW(fd,0) = 0x14b;
  6651. WFIFOB(fd,2) = 0;
  6652. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6653. WFIFOSET(fd, packet_len_table[0x14b]);
  6654. return 0;
  6655. }
  6656. /*==========================================
  6657. *
  6658. *------------------------------------------
  6659. */
  6660. int clif_timedout(struct map_session_data *sd)
  6661. {
  6662. nullpo_retr(0, sd);
  6663. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6664. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6665. clif_setwaitclose(sd->fd); // Set session to EOF
  6666. return 0;
  6667. }
  6668. /*==========================================
  6669. * Wis拒否許可応答
  6670. *------------------------------------------
  6671. */
  6672. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6673. {
  6674. int fd;
  6675. nullpo_retr(0, sd);
  6676. fd=sd->fd;
  6677. WFIFOHEAD(fd,packet_len_table[0xd1]);
  6678. WFIFOW(fd,0)=0xd1;
  6679. WFIFOB(fd,2)=type;
  6680. WFIFOB(fd,3)=flag;
  6681. WFIFOSET(fd,packet_len_table[0xd1]);
  6682. return 0;
  6683. }
  6684. /*==========================================
  6685. * Wis全拒否許可応答
  6686. *------------------------------------------
  6687. */
  6688. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6689. {
  6690. int fd;
  6691. nullpo_retr(0, sd);
  6692. fd=sd->fd;
  6693. WFIFOHEAD(fd,packet_len_table[0xd2]);
  6694. WFIFOW(fd,0)=0xd2;
  6695. WFIFOB(fd,2)=type;
  6696. WFIFOB(fd,3)=flag;
  6697. WFIFOSET(fd,packet_len_table[0xd2]);
  6698. return 0;
  6699. }
  6700. /*==========================================
  6701. * サウンドエフェクト
  6702. *------------------------------------------
  6703. */
  6704. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  6705. {
  6706. int fd;
  6707. nullpo_retv(sd);
  6708. nullpo_retv(bl);
  6709. fd=sd->fd;
  6710. WFIFOHEAD(fd,packet_len_table[0x1d3]);
  6711. WFIFOW(fd,0)=0x1d3;
  6712. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6713. WFIFOB(fd,26)=type;
  6714. WFIFOL(fd,27)=0;
  6715. WFIFOL(fd,31)=bl->id;
  6716. WFIFOSET(fd,packet_len_table[0x1d3]);
  6717. return;
  6718. }
  6719. int clif_soundeffectall(struct block_list *bl, char *name, int type, int coverage)
  6720. {
  6721. unsigned char buf[40];
  6722. malloc_set(buf, 0, packet_len_table[0x1d3]);
  6723. if(coverage < 0 || coverage > 22){
  6724. ShowError("clif_soundeffectall: undefined coverage.\n");
  6725. return 0;
  6726. }
  6727. nullpo_retr(0, bl);
  6728. WBUFW(buf,0)=0x1d3;
  6729. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6730. WBUFB(buf,26)=type;
  6731. WBUFL(buf,27)=0;
  6732. WBUFL(buf,31)=bl->id;
  6733. clif_send(buf, packet_len_table[0x1d3], bl, coverage);
  6734. return 0;
  6735. }
  6736. // displaying special effects (npcs, weather, etc) [Valaris]
  6737. int clif_specialeffect(struct block_list *bl, int type, int flag)
  6738. {
  6739. unsigned char buf[24];
  6740. nullpo_retr(0, bl);
  6741. malloc_set(buf, 0, packet_len_table[0x1f3]);
  6742. WBUFW(buf,0) = 0x1f3;
  6743. WBUFL(buf,2) = bl->id;
  6744. WBUFL(buf,6) = type;
  6745. clif_send(buf, packet_len_table[0x1f3], bl, flag);
  6746. if (disguised(bl)) {
  6747. WBUFL(buf,2) = -bl->id;
  6748. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  6749. }
  6750. return 0;
  6751. }
  6752. // refresh the client's screen, getting rid of any effects
  6753. int clif_refresh(struct map_session_data *sd) {
  6754. nullpo_retr(-1, sd);
  6755. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6756. clif_inventorylist(sd);
  6757. if(pc_iscarton(sd)){
  6758. clif_cartlist(sd);
  6759. clif_updatestatus(sd,SP_CARTINFO);
  6760. }
  6761. clif_updatestatus(sd,SP_MAXWEIGHT);
  6762. clif_updatestatus(sd,SP_WEIGHT);
  6763. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6764. clif_weather_check(sd);
  6765. return 0;
  6766. }
  6767. // updates the object's (bl) name on client
  6768. int clif_charnameack (int fd, struct block_list *bl)
  6769. {
  6770. unsigned char buf[103];
  6771. int cmd = 0x95;
  6772. nullpo_retr(0, bl);
  6773. WBUFW(buf,0) = cmd;
  6774. WBUFL(buf,2) = bl->id;
  6775. switch(bl->type) {
  6776. case BL_PC:
  6777. {
  6778. struct map_session_data *ssd = (struct map_session_data *)bl;
  6779. struct party_data *p = NULL;
  6780. struct guild *g = NULL;
  6781. //Requesting your own "shadow" name. [Skotlex]
  6782. if (ssd->fd == fd && ssd->disguise)
  6783. WBUFL(buf,2) = -bl->id;
  6784. if (strlen(ssd->fakename)>1) {
  6785. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6786. break;
  6787. }
  6788. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6789. if (ssd->status.party_id > 0)
  6790. p = party_search(ssd->status.party_id);
  6791. if (ssd->status.guild_id > 0)
  6792. g = guild_search(ssd->status.guild_id);
  6793. if (p == NULL && g == NULL)
  6794. break;
  6795. WBUFW(buf, 0) = cmd = 0x195;
  6796. if (p)
  6797. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6798. else
  6799. WBUFB(buf,30) = 0;
  6800. if (g)
  6801. {
  6802. int i, ps = -1;
  6803. for(i = 0; i < g->max_member; i++) {
  6804. if (g->member[i].account_id == ssd->status.account_id &&
  6805. g->member[i].char_id == ssd->status.char_id )
  6806. {
  6807. ps = g->member[i].position;
  6808. break;
  6809. }
  6810. }
  6811. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6812. {
  6813. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6814. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6815. } else { //Assume no guild.
  6816. WBUFB(buf,54) = 0;
  6817. WBUFB(buf,78) = 0;
  6818. }
  6819. } else {
  6820. WBUFB(buf,54) = 0;
  6821. WBUFB(buf,78) = 0;
  6822. }
  6823. }
  6824. break;
  6825. //[blackhole89]
  6826. case BL_HOM:
  6827. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6828. break;
  6829. case BL_PET:
  6830. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6831. break;
  6832. case BL_NPC:
  6833. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6834. break;
  6835. case BL_MOB:
  6836. {
  6837. struct mob_data *md = (struct mob_data *)bl;
  6838. nullpo_retr(0, md);
  6839. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6840. if (md->guardian_data && md->guardian_data->guild_id) {
  6841. WBUFW(buf, 0) = cmd = 0x195;
  6842. WBUFB(buf,30) = 0;
  6843. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6844. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6845. } else if (battle_config.show_mob_info) {
  6846. char mobhp[50], *str_p = mobhp;
  6847. WBUFW(buf, 0) = cmd = 0x195;
  6848. if (battle_config.show_mob_info&4)
  6849. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6850. if (battle_config.show_mob_info&1)
  6851. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6852. if (battle_config.show_mob_info&2)
  6853. str_p += sprintf(str_p, "HP: %d%% | ",
  6854. md->status.max_hp > 10000?
  6855. md->status.hp/(md->status.max_hp/100):
  6856. 100*md->status.hp/md->status.max_hp);
  6857. //Even thought mobhp ain't a name, we send it as one so the client
  6858. //can parse it. [Skotlex]
  6859. if (str_p != mobhp) {
  6860. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6861. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6862. WBUFB(buf,54) = 0;
  6863. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6864. }
  6865. }
  6866. }
  6867. break;
  6868. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6869. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6870. // break;
  6871. return 0;
  6872. default:
  6873. if (battle_config.error_log)
  6874. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6875. return 0;
  6876. }
  6877. // if no receipient specified just update nearby clients
  6878. if (fd == 0)
  6879. clif_send(buf, packet_len_table[cmd], bl, AREA);
  6880. else {
  6881. WFIFOHEAD(fd, packet_len_table[cmd]);
  6882. memcpy(WFIFOP(fd, 0), buf, packet_len_table[cmd]);
  6883. WFIFOSET(fd, packet_len_table[cmd]);
  6884. }
  6885. return 0;
  6886. }
  6887. //Used to update when a char leaves a party/guild. [Skotlex]
  6888. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6889. int clif_charnameupdate (struct map_session_data *ssd)
  6890. {
  6891. unsigned char buf[103];
  6892. int cmd = 0x195;
  6893. struct party_data *p = NULL;
  6894. struct guild *g = NULL;
  6895. nullpo_retr(0, ssd);
  6896. if (strlen(ssd->fakename)>1)
  6897. return 0; //No need to update as the party/guild was not displayed anyway.
  6898. WBUFW(buf,0) = cmd;
  6899. WBUFL(buf,2) = ssd->bl.id;
  6900. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6901. if (ssd->status.party_id > 0)
  6902. p = party_search(ssd->status.party_id);
  6903. if (ssd->status.guild_id > 0)
  6904. g = guild_search(ssd->status.guild_id);
  6905. if (p)
  6906. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6907. else
  6908. WBUFB(buf,30) = 0;
  6909. if (g)
  6910. {
  6911. int i, ps = -1;
  6912. for(i = 0; i < g->max_member; i++) {
  6913. if (g->member[i].account_id == ssd->status.account_id &&
  6914. g->member[i].char_id == ssd->status.char_id )
  6915. {
  6916. ps = g->member[i].position;
  6917. break;
  6918. }
  6919. }
  6920. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6921. {
  6922. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6923. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6924. } else { //Assume no guild.
  6925. WBUFB(buf,54) = 0;
  6926. WBUFB(buf,78) = 0;
  6927. }
  6928. } else {
  6929. WBUFB(buf,54) = 0;
  6930. WBUFB(buf,78) = 0;
  6931. }
  6932. // Update nearby clients
  6933. clif_send(buf, packet_len_table[cmd], &ssd->bl, AREA);
  6934. return 0;
  6935. }
  6936. int clif_slide(struct block_list *bl, int x, int y){
  6937. unsigned char buf[10];
  6938. nullpo_retr(0, bl);
  6939. WBUFW(buf, 0) = 0x01ff;
  6940. WBUFL(buf, 2) = bl->id;
  6941. WBUFW(buf, 6) = x;
  6942. WBUFW(buf, 8) = y;
  6943. clif_send(buf, packet_len_table[0x1ff], bl, AREA);
  6944. return 0;
  6945. }
  6946. /*------------------------------------------
  6947. * @me command by lordalfa, rewritten implementation by Skotlex
  6948. *------------------------------------------
  6949. */
  6950. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  6951. {
  6952. unsigned char buf[256]; //This should be more than sufficient, the theorical max is MESSAGE_SIZE+NAME_LENGTH + 8 (pads and extra inserted crap)
  6953. int len_mes = strlen(mes)+1; //Account for \0
  6954. if (len_mes + 8 >= 256) {
  6955. if (battle_config.error_log)
  6956. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6957. len_mes = 247; //Trunk it to avoid problems.
  6958. }
  6959. // send message to others
  6960. WBUFW(buf,0) = 0x8d;
  6961. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6962. WBUFL(buf,4) = sd->bl.id;
  6963. memcpy(WBUFP(buf,8), mes, len_mes);
  6964. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6965. // send back message to the speaker
  6966. WBUFW(buf,0) = 0x8e;
  6967. WBUFW(buf, 2) = len_mes + 4;
  6968. memcpy(WBUFP(buf,4), mes, len_mes);
  6969. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6970. return 0;
  6971. }
  6972. /*==========================
  6973. * Minimap fix [Kevin]
  6974. * Remove dot from minimap
  6975. *--------------------------
  6976. */
  6977. int clif_party_xy_remove(struct map_session_data *sd)
  6978. {
  6979. unsigned char buf[16];
  6980. nullpo_retr(0, sd);
  6981. WBUFW(buf,0)=0x107;
  6982. WBUFL(buf,2)=sd->status.account_id;
  6983. WBUFW(buf,6)=-1;
  6984. WBUFW(buf,8)=-1;
  6985. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  6986. return 0;
  6987. }
  6988. /*==========================================
  6989. * Info about Star Glaldiator save map [Komurka]
  6990. * type: 1: Information, 0: Map registered
  6991. *------------------------------------------
  6992. */
  6993. void clif_feel_info(struct map_session_data *sd, unsigned char feel_level, unsigned char type)
  6994. {
  6995. int fd=sd->fd;
  6996. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6997. WFIFOW(fd,0)=0x20e;
  6998. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  6999. WFIFOL(fd,26)=sd->bl.id;
  7000. WFIFOB(fd,30)=feel_level;
  7001. WFIFOB(fd,31)=type?1:0;
  7002. WFIFOSET(fd, packet_len_table[0x20e]);
  7003. }
  7004. /*==========================================
  7005. * Info about Star Glaldiator hate mob [Komurka]
  7006. * type: 1: Register mob, 0: Information.
  7007. *------------------------------------------
  7008. */
  7009. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7010. {
  7011. int fd=sd->fd;
  7012. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7013. WFIFOW(fd,0)=0x20e;
  7014. if (pcdb_checkid(class_))
  7015. strncpy(WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  7016. else if (mobdb_checkid(class_))
  7017. strncpy(WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  7018. else //Really shouldn't happen...
  7019. malloc_tsetdword(WFIFOP(fd,2), 0, NAME_LENGTH);
  7020. WFIFOL(fd,26)=sd->bl.id;
  7021. WFIFOB(fd,30)=hate_level;
  7022. WFIFOB(fd,31)=type?10:11; //Register/Info
  7023. WFIFOSET(fd, packet_len_table[0x20e]);
  7024. }
  7025. /*==========================================
  7026. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7027. *------------------------------------------
  7028. */
  7029. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7030. {
  7031. int fd=sd->fd;
  7032. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7033. WFIFOW(fd,0)=0x20e;
  7034. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  7035. WFIFOL(fd,26)=mob_id;
  7036. WFIFOB(fd,30)=progress; //Message to display
  7037. WFIFOB(fd,31)=20;
  7038. WFIFOSET(fd, packet_len_table[0x20e]);
  7039. }
  7040. /*==========================================
  7041. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7042. *------------------------------------------
  7043. */
  7044. void clif_feel_hate_reset(struct map_session_data *sd)
  7045. {
  7046. int fd=sd->fd;
  7047. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7048. WFIFOW(fd,0)=0x20e;
  7049. malloc_tsetdword(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  7050. WFIFOL(fd,26)=sd->bl.id;
  7051. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  7052. WFIFOB(fd,31)=30;
  7053. WFIFOSET(fd, packet_len_table[0x20e]);
  7054. }
  7055. // ---------------------
  7056. // clif_guess_PacketVer
  7057. // ---------------------
  7058. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7059. static int clif_guess_PacketVer(int fd, int get_previous)
  7060. {
  7061. static int packet_ver = -1;
  7062. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7063. RFIFOHEAD(fd);
  7064. if (get_previous) //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]
  7065. return packet_ver;
  7066. //By default, start searching on the default one.
  7067. packet_ver = clif_config.packet_db_ver;
  7068. cmd = RFIFOW(fd,0);
  7069. packet_len = RFIFOREST(fd);
  7070. if (
  7071. cmd == clif_config.connect_cmd[packet_ver] &&
  7072. packet_len == packet_db[packet_ver][cmd].len &&
  7073. ((value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) == 0 || value == 1) &&
  7074. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) > 700000 && //Account ID is valid
  7075. value <= max_account_id &&
  7076. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) > 0 && //Char ID is valid
  7077. value <= max_char_id &&
  7078. (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) > 0 //Login 1 is a positive value (?)
  7079. )
  7080. return clif_config.packet_db_ver; //Default packet version found.
  7081. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7082. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7083. if (cmd != clif_config.connect_cmd[packet_ver] || //it is not a wanttoconnection for this version.
  7084. packet_len != packet_db[packet_ver][cmd].len) //The size of the wantoconnection packet does not matches.
  7085. continue;
  7086. if (
  7087. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < 700000 || value > max_account_id
  7088. || (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) < 1 || value > max_char_id
  7089. //What is login 1? In my tests it is a very very high value.
  7090. || (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) < 1
  7091. //This check seems redundant, all wanttoconnection packets have the gender on the very
  7092. //last byte of the packet.
  7093. || (value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) < 0 || value > 1
  7094. )
  7095. continue;
  7096. return packet_ver; //This is our best guess.
  7097. }
  7098. packet_ver = -1;
  7099. return -1;
  7100. }
  7101. // ------------
  7102. // clif_parse_*
  7103. // ------------
  7104. // パケット読み取って色々操作
  7105. /*==========================================
  7106. *
  7107. *------------------------------------------
  7108. */
  7109. void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
  7110. {
  7111. struct map_session_data *old_sd;
  7112. int cmd, account_id, char_id, login_id1, sex;
  7113. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7114. 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])
  7115. RFIFOHEAD(fd);
  7116. if (sd) {
  7117. if (battle_config.error_log)
  7118. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  7119. return;
  7120. }
  7121. packet_ver = clif_guess_PacketVer(fd, 1);
  7122. cmd = RFIFOW(fd,0);
  7123. if (packet_ver > 0)
  7124. {
  7125. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7126. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7127. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7128. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7129. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7130. if ((old_sd = map_id2sd(account_id)) != NULL)
  7131. { // if same account already connected, we disconnect the 2 sessions
  7132. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  7133. if (old_sd->state.finalsave)
  7134. ; //Ack has not arrived yet from char-server, be patient!
  7135. else if (old_sd->fd)
  7136. clif_authfail_fd(old_sd->fd, 2); // same id
  7137. else
  7138. map_quit(old_sd);
  7139. clif_authfail_fd(fd, 8); // still recognizes last connection
  7140. } else {
  7141. sd = (struct map_session_data*)aCalloc(1, sizeof(struct map_session_data));
  7142. sd->fd = fd;
  7143. sd->packet_ver = packet_ver;
  7144. session[fd]->session_data = sd;
  7145. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7146. WFIFOHEAD(fd,4);
  7147. WFIFOL(fd,0) = sd->bl.id;
  7148. WFIFOSET(fd,4);
  7149. chrif_authreq(sd);
  7150. }
  7151. }
  7152. return;
  7153. }
  7154. static int clif_nighttimer(int tid, unsigned int tick, int id, int data)
  7155. {
  7156. TBL_PC *sd;
  7157. sd=map_id2sd(id);
  7158. if (!sd) return 0;
  7159. //Check if character didn't instant-warped after logging in.
  7160. if (sd->bl.prev!=NULL) {
  7161. sd->state.night = 1;
  7162. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7163. }
  7164. return 0;
  7165. }
  7166. /*==========================================
  7167. * 007d クライアント側マップ読み込み完了
  7168. * map侵入時に必要なデータを全て送りつける
  7169. *------------------------------------------
  7170. */
  7171. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7172. {
  7173. int i;
  7174. if(sd->bl.prev != NULL)
  7175. return;
  7176. if (sd->state.rewarp)
  7177. { //Rewarp player.
  7178. sd->state.rewarp = 0;
  7179. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7180. return;
  7181. }
  7182. if(sd->npc_id) npc_event_dequeue(sd);
  7183. if(sd->state.connect_new) {
  7184. if (sd->sc.option&OPTION_FALCON)
  7185. clif_status_load(&sd->bl, SI_FALCON, 1);
  7186. if (sd->sc.option&OPTION_RIDING)
  7187. clif_status_load(&sd->bl, SI_RIDING, 1);
  7188. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7189. if ((i = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7190. if(sd->bl.m == sd->feel_map[0].m
  7191. || sd->bl.m == sd->feel_map[1].m
  7192. || sd->bl.m == sd->feel_map[2].m)
  7193. sc_start(&sd->bl, SC_KNOWLEDGE, 100, i, skill_get_time(SG_KNOWLEDGE, i));
  7194. }
  7195. clif_skillinfoblock(sd);
  7196. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7197. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7198. clif_updatestatus(sd,SP_SKILLPOINT);
  7199. clif_initialstatus(sd);
  7200. //Removed, for some reason chars get stuck on map-change when you send this packet!? [Skotlex]
  7201. //[LuzZza]
  7202. //clif_guild_send_onlineinfo(sd);
  7203. } else {
  7204. //For some reason the client "loses" these on map-change.
  7205. clif_updatestatus(sd,SP_STR);
  7206. clif_updatestatus(sd,SP_AGI);
  7207. clif_updatestatus(sd,SP_VIT);
  7208. clif_updatestatus(sd,SP_INT);
  7209. clif_updatestatus(sd,SP_DEX);
  7210. clif_updatestatus(sd,SP_LUK);
  7211. }
  7212. // item
  7213. pc_checkitem(sd);
  7214. clif_inventorylist(sd);
  7215. // cart
  7216. if(pc_iscarton(sd)){
  7217. clif_cartlist(sd);
  7218. clif_updatestatus(sd,SP_CARTINFO);
  7219. }
  7220. // weight max , now
  7221. clif_updatestatus(sd,SP_MAXWEIGHT);
  7222. clif_updatestatus(sd,SP_WEIGHT);
  7223. if(battle_config.pc_invincible_time > 0) {
  7224. if(map_flag_gvg(sd->bl.m))
  7225. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7226. else
  7227. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7228. }
  7229. map_addblock(&sd->bl); // ブロック登録
  7230. clif_spawn(&sd->bl); // spawn
  7231. // party
  7232. party_send_movemap(sd);
  7233. // guild
  7234. guild_send_memberinfoshort(sd,1);
  7235. // Show hp after displacement [LuzZza]
  7236. if(sd->status.party_id)
  7237. clif_party_hp(sd);
  7238. sd->state.using_fake_npc = 0;
  7239. // pvp
  7240. //if(sd->pvp_timer!=-1 && !battle_config.pk_mode) /PVP Client crash fix* Removed timer deletion
  7241. // delete_timer(sd->pvp_timer,pc_calc_pvprank_timer);
  7242. if(map[sd->bl.m].flag.pvp){
  7243. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7244. if (sd->pvp_timer == -1)
  7245. sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
  7246. sd->pvp_rank=0;
  7247. sd->pvp_lastusers=0;
  7248. sd->pvp_point=5;
  7249. sd->pvp_won=0;
  7250. sd->pvp_lost=0;
  7251. }
  7252. clif_set0199(fd,1);
  7253. } else {
  7254. sd->pvp_timer=-1;
  7255. // set flag, if it's a duel [LuzZza]
  7256. if(sd->duel_group)
  7257. clif_set0199(fd, 1);
  7258. }
  7259. if(map_flag_gvg(sd->bl.m))
  7260. clif_set0199(fd,3);
  7261. // pet
  7262. if(sd->status.pet_id > 0 && sd->pd) {
  7263. map_addblock(&sd->pd->bl);
  7264. clif_spawn(&sd->pd->bl);
  7265. clif_send_petdata(sd,0,0);
  7266. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7267. clif_send_petstatus(sd);
  7268. if(sd->state.connect_new && sd->pd->pet.intimate > 900)
  7269. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7270. }
  7271. //homunculus [blackhole89]
  7272. if(merc_is_hom_active(sd->hd)) {
  7273. map_addblock(&sd->hd->bl);
  7274. clif_spawn(&sd->hd->bl);
  7275. clif_hominfo(sd,sd->hd,1);
  7276. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7277. clif_send_homdata(sd,0,0);
  7278. clif_homskillinfoblock(sd);
  7279. //Homunc mimic their master's speed on each map change. [Skotlex]
  7280. if (battle_config.slaves_inherit_speed)
  7281. status_calc_bl(&sd->hd->bl, SCB_SPEED);
  7282. }
  7283. // view equipment item
  7284. #if PACKETVER < 4
  7285. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7286. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7287. #else
  7288. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7289. #endif
  7290. if(sd->vd.cloth_color)
  7291. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7292. if(sd->status.manner < 0)
  7293. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7294. if(sd->state.connect_new) {
  7295. sd->state.connect_new = 0;
  7296. //Delayed night effect on log-on fix for the glow-issue. Thanks to Larry.
  7297. if (night_flag) {
  7298. char tmpstr[1024];
  7299. strcpy(tmpstr, msg_txt(500)); // Actually, it's the night...
  7300. clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
  7301. if (map[sd->bl.m].flag.nightenabled)
  7302. add_timer(gettick()+1000,clif_nighttimer,sd->bl.id,0);
  7303. }
  7304. //On Login Script.
  7305. npc_script_event(sd, NPCE_LOGIN);
  7306. } else
  7307. //New 'night' effect by dynamix [Skotlex]
  7308. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7309. { //Display night.
  7310. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  7311. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7312. else
  7313. sd->state.night = 1;
  7314. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7315. } else if (sd->state.night) { //Clear night display.
  7316. sd->state.night = 0;
  7317. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7318. }
  7319. // Lance
  7320. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  7321. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  7322. npc_script_event(sd, NPCE_LOADMAP);
  7323. }
  7324. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7325. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7326. clif_weather_check(sd);
  7327. map_foreachinarea(clif_getareachar,sd->bl.m,
  7328. sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,
  7329. BL_ALL,sd);
  7330. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7331. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7332. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7333. else
  7334. sd->areanpc_id = 0;
  7335. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7336. if(pc_isdead(sd))
  7337. clif_clearchar_area(&sd->bl,1);
  7338. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7339. // else
  7340. // clif_changed_dir(&sd->bl, SELF);
  7341. }
  7342. /*==========================================
  7343. *
  7344. *------------------------------------------
  7345. */
  7346. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7347. RFIFOHEAD(fd);
  7348. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7349. WFIFOHEAD(fd, packet_len_table[0x7f]);
  7350. WFIFOW(fd,0)=0x7f;
  7351. WFIFOL(fd,2)=gettick();
  7352. WFIFOSET(fd,packet_len_table[0x7f]);
  7353. return;
  7354. }
  7355. static int clif_walktoxy_timer(int tid, unsigned int tick, int id, int data)
  7356. {
  7357. struct map_session_data *sd;
  7358. short x,y;
  7359. if (!session[id] || (sd = session[id]->session_data) == NULL)
  7360. return 0;
  7361. if (!unit_can_move(&sd->bl))
  7362. return 0;
  7363. x = data>>16;
  7364. y = data&0xffff;
  7365. unit_walktoxy(&sd->bl, x, y, 0);
  7366. return 1;
  7367. }
  7368. /*==========================================
  7369. *
  7370. *------------------------------------------
  7371. */
  7372. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7373. int x, y;
  7374. int cmd;
  7375. unsigned int tick;
  7376. RFIFOHEAD(fd);
  7377. if (pc_isdead(sd)) {
  7378. clif_clearchar_area(&sd->bl, 1);
  7379. return;
  7380. }
  7381. if (clif_cant_act(sd) && sd->sc.opt1 != OPT1_STONEWAIT)
  7382. return;
  7383. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7384. return;
  7385. pc_stop_attack(sd);
  7386. if (sd->invincible_timer != -1)
  7387. pc_delinvincibletimer(sd);
  7388. cmd = RFIFOW(fd,0);
  7389. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7390. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7391. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7392. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7393. //Set last idle time... [Skotlex]
  7394. sd->idletime = last_tick;
  7395. tick = gettick();
  7396. if (DIFF_TICK(sd->ud.canmove_tick, tick) > 0 &&
  7397. DIFF_TICK(sd->ud.canmove_tick, tick) < 2000)
  7398. { // Delay walking command. [Skotlex]
  7399. add_timer(sd->ud.canmove_tick+1, clif_walktoxy_timer, fd, (x<<16)|y);
  7400. return;
  7401. }
  7402. if (!unit_can_move(&sd->bl))
  7403. return;
  7404. unit_walktoxy(&sd->bl, x, y, 0);
  7405. }
  7406. /*==========================================
  7407. *
  7408. *------------------------------------------
  7409. */
  7410. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7411. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7412. WFIFOW(fd,0) = 0x18b;
  7413. /* Rovert's prevent logout option fixed [Valaris] */
  7414. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7415. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7416. ) {
  7417. clif_setwaitclose(fd);
  7418. WFIFOW(fd,2)=0;
  7419. } else {
  7420. WFIFOW(fd,2)=1;
  7421. }
  7422. WFIFOSET(fd,packet_len_table[0x18b]);
  7423. }
  7424. /*==========================================
  7425. *
  7426. *------------------------------------------
  7427. */
  7428. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7429. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7430. /* if (target_id == server_char_id) {
  7431. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7432. 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).
  7433. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7434. // if we block people
  7435. if (battle_config.ban_bot < 0) {
  7436. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7437. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7438. // message about the ban
  7439. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7440. // if we ban people
  7441. } else if (battle_config.ban_bot > 0) {
  7442. 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)
  7443. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7444. // message about the ban
  7445. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7446. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7447. // message about the ban
  7448. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7449. }
  7450. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7451. // send this info cause the bot ask until get an answer, damn spam
  7452. malloc_tsetdword(WPACKETP(0), 0, packet_len_table[0x95]);
  7453. WPACKETW(0) = 0x95;
  7454. WPACKETL(2) = server_char_id;
  7455. strncpy(WPACKETP(6), sd->status.name, 24);
  7456. SENDPACKET(fd, packet_len_table[0x95]);
  7457. // take fake player out of screen
  7458. WPACKETW(0) = 0x80;
  7459. WPACKETL(2) = server_char_id;
  7460. WPACKETB(6) = 0;
  7461. SENDPACKET(fd, packet_len_table[0x80]);
  7462. // take fake mob out of screen
  7463. WPACKETW(0) = 0x80;
  7464. WPACKETL(2) = server_fake_mob_id;
  7465. WPACKETB(6) = 0;
  7466. SENDPACKET(fd, packet_len_table[0x80]);
  7467. }
  7468. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7469. if (target_id == server_fake_mob_id) {
  7470. int fake_mob;
  7471. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7472. 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).
  7473. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7474. // if we block people
  7475. if (battle_config.ban_bot < 0) {
  7476. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7477. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7478. // message about the ban
  7479. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7480. // if we ban people
  7481. } else if (battle_config.ban_bot > 0) {
  7482. 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)
  7483. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7484. // message about the ban
  7485. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7486. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7487. // message about the ban
  7488. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7489. }
  7490. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7491. // send this info cause the bot ask until get an answer, damn spam
  7492. malloc_tsetdword(WPACKETP(0), 0, packet_len_table[0x95]);
  7493. WPACKETW(0) = 0x95;
  7494. WPACKETL(2) = server_fake_mob_id;
  7495. 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
  7496. if (!mobdb_checkid(fake_mob))
  7497. fake_mob = 1002; // poring (default)
  7498. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7499. SENDPACKET(fd, packet_len_table[0x95]);
  7500. // take fake mob out of screen
  7501. WPACKETW(0) = 0x80;
  7502. WPACKETL(2) = server_fake_mob_id;
  7503. WPACKETB(6) = 0;
  7504. SENDPACKET(fd, packet_len_table[0x80]);
  7505. // take fake player out of screen
  7506. WPACKETW(0) = 0x80;
  7507. WPACKETL(2) = server_char_id;
  7508. WPACKETB(6) = 0;
  7509. SENDPACKET(fd, packet_len_table[0x80]);
  7510. }
  7511. */
  7512. return;
  7513. }
  7514. /*==========================================
  7515. *
  7516. *------------------------------------------
  7517. */
  7518. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7519. int account_id;
  7520. struct block_list* bl;
  7521. struct status_change *sc;
  7522. RFIFOHEAD(fd);
  7523. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7524. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7525. account_id= sd->bl.id;
  7526. bl = map_id2bl(account_id);
  7527. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7528. if (!bl) return;
  7529. sc = status_get_sc(bl);
  7530. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) && pc_isGM(sd) < battle_config.hack_info_GM_level)
  7531. {
  7532. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7533. //Asked name of invisible player, this shouldn't be possible!
  7534. //Possible bot? Thanks to veider and qspirit
  7535. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7536. unsigned char gm_msg[256];
  7537. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requests name of invisible chars.", sd->status.name, sd->status.account_id);
  7538. ShowWarning(gm_msg);
  7539. // information is sended to all online GM
  7540. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7541. return;
  7542. }
  7543. clif_charnameack(fd, bl);
  7544. }
  7545. /*==========================================
  7546. *
  7547. *------------------------------------------
  7548. */
  7549. void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
  7550. char *message, *buf, buf2[128];
  7551. RFIFOHEAD(fd);
  7552. WFIFOHEAD(fd, RFIFOW(fd,2) + 4);
  7553. message = (unsigned char*)RFIFOP(fd,4);
  7554. if (strlen(message) < strlen(sd->status.name) || //If the incoming string is too short...
  7555. strncmp(message, sd->status.name, strlen(sd->status.name)) != 0) //Or the name does not matches...
  7556. {
  7557. //Hacked message, or infamous "client desynch" issue where they pick
  7558. //one char while loading another. Just kick them out to correct it.
  7559. clif_setwaitclose(fd);
  7560. return;
  7561. }
  7562. if ((is_atcommand(fd, sd, message, 0) != AtCommand_None) ||
  7563. (is_charcommand(fd, sd, message,0) != CharCommand_None))
  7564. return;
  7565. if (sd->sc.count &&
  7566. (sd->sc.data[SC_BERSERK].timer != -1 ||
  7567. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)))
  7568. return;
  7569. if (battle_config.min_chat_delay)
  7570. { //[Skotlex]
  7571. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7572. return;
  7573. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7574. }
  7575. if (RFIFOW(fd,2)+4 < 128)
  7576. buf = buf2; //Use a static buffer.
  7577. else
  7578. buf = (unsigned char*)aMallocA((RFIFOW(fd,2) + 4)*sizeof(char));
  7579. // send message to others
  7580. WBUFW(buf,0) = 0x8d;
  7581. WBUFW(buf,2) = RFIFOW(fd,2) + 4; // len of message - 4 + 8
  7582. WBUFL(buf,4) = sd->bl.id;
  7583. memcpy(WBUFP(buf,8), message, RFIFOW(fd,2) - 4);
  7584. clif_send(buf, WBUFW(buf,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7585. if(buf != buf2) aFree(buf);
  7586. // send back message to the speaker
  7587. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7588. WFIFOW(fd,0) = 0x8e;
  7589. WFIFOSET(fd, WFIFOW(fd,2));
  7590. #ifdef PCRE_SUPPORT
  7591. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7592. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7593. #endif
  7594. // Celest
  7595. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7596. int next = pc_nextbaseexp(sd);
  7597. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7598. switch (sd->state.snovice_flag) {
  7599. case 0:
  7600. if (strstr(message, msg_txt(504)))
  7601. sd->state.snovice_flag++;
  7602. break;
  7603. case 1:
  7604. sprintf(buf2, msg_txt(505), sd->status.name);
  7605. if (strstr(message, buf2))
  7606. sd->state.snovice_flag++;
  7607. break;
  7608. case 2:
  7609. if (strstr(message, msg_txt(506)))
  7610. sd->state.snovice_flag++;
  7611. break;
  7612. case 3:
  7613. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7614. break; //Do not override the noskill mapflag. [Skotlex]
  7615. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7616. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7617. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7618. sd->state.snovice_flag = 0;
  7619. break;
  7620. }
  7621. }
  7622. }
  7623. return;
  7624. }
  7625. int clif_message(struct block_list *bl, char* msg)
  7626. {
  7627. unsigned short msg_len = strlen(msg) + 1;
  7628. unsigned char buf[256];
  7629. nullpo_retr(0, bl);
  7630. WBUFW(buf, 0) = 0x8d;
  7631. WBUFW(buf, 2) = msg_len + 8;
  7632. WBUFL(buf, 4) = bl->id;
  7633. memcpy(WBUFP(buf, 8), msg, msg_len);
  7634. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7635. return 0;
  7636. }
  7637. /*==========================================
  7638. *
  7639. *------------------------------------------
  7640. */
  7641. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7642. // /m /mapmove (as @rura GM command)
  7643. char output[30]; // 17+4+4=26, 30 max.
  7644. char map_name[MAP_NAME_LENGTH]; //Err... map names are 15+'\0' in size, not 16+'\0' [Skotlex]
  7645. RFIFOHEAD(fd);
  7646. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7647. (pc_isGM(sd) >= get_atcommand_level(AtCommand_MapMove))) {
  7648. memcpy(map_name, RFIFOP(fd,2), MAP_NAME_LENGTH-1);
  7649. map_name[MAP_NAME_LENGTH-1]='\0';
  7650. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7651. atcommand_rura(fd, sd, "@rura", output);
  7652. }
  7653. return;
  7654. }
  7655. /*==========================================
  7656. *
  7657. *------------------------------------------
  7658. */
  7659. void clif_changed_dir(struct block_list *bl, int type) {
  7660. unsigned char buf[64];
  7661. WBUFW(buf,0) = 0x9c;
  7662. WBUFL(buf,2) = bl->id;
  7663. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7664. WBUFB(buf,8) = unit_getdir(bl);
  7665. clif_send(buf, packet_len_table[0x9c], bl, type);
  7666. if (disguised(bl)) {
  7667. WBUFL(buf,2) = -bl->id;
  7668. WBUFW(buf,6) = 0;
  7669. clif_send(buf, packet_len_table[0x9c], bl, SELF);
  7670. }
  7671. return;
  7672. }
  7673. /*==========================================
  7674. *
  7675. *------------------------------------------
  7676. */
  7677. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7678. unsigned char headdir, dir;
  7679. RFIFOHEAD(fd);
  7680. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7681. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7682. pc_setdir(sd, dir, headdir);
  7683. clif_changed_dir(&sd->bl, AREA_WOS);
  7684. return;
  7685. }
  7686. /*==========================================
  7687. *
  7688. *------------------------------------------
  7689. */
  7690. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7691. unsigned char buf[64];
  7692. RFIFOHEAD(fd);
  7693. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7694. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7695. clif_skill_fail(sd, 1, 0, 1);
  7696. return;
  7697. }
  7698. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7699. if (sd->emotionlasttime >= time(NULL)) {
  7700. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7701. clif_skill_fail(sd, 1, 0, 1);
  7702. return;
  7703. }
  7704. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7705. WBUFW(buf,0) = 0xc0;
  7706. WBUFL(buf,2) = sd->bl.id;
  7707. WBUFB(buf,6) = RFIFOB(fd,2);
  7708. clif_send(buf, packet_len_table[0xc0], &sd->bl, AREA);
  7709. } else
  7710. clif_skill_fail(sd, 1, 0, 1);
  7711. }
  7712. /*==========================================
  7713. *
  7714. *------------------------------------------
  7715. */
  7716. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7717. WFIFOHEAD(fd,packet_len_table[0xc2]);
  7718. WFIFOW(fd,0) = 0xc2;
  7719. WFIFOL(fd,2) = map_getusers();
  7720. WFIFOSET(fd,packet_len_table[0xc2]);
  7721. }
  7722. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7723. {
  7724. unsigned char buf[64];
  7725. if (pc_isdead(sd)) {
  7726. clif_clearchar_area(&sd->bl, 1);
  7727. return;
  7728. }
  7729. if (sd->sc.count &&
  7730. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7731. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7732. sd->sc.data[SC_BLADESTOP].timer != -1))
  7733. return;
  7734. pc_stop_walking(sd, 1);
  7735. pc_stop_attack(sd);
  7736. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7737. target_id = sd->bl.id;
  7738. switch(action_type) {
  7739. case 0x00: // once attack
  7740. case 0x07: // continuous attack
  7741. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7742. return;
  7743. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  7744. return;
  7745. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7746. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7747. clif_skill_fail(sd, 1, 4, 0);
  7748. return;
  7749. }
  7750. }
  7751. if (sd->invincible_timer != -1)
  7752. pc_delinvincibletimer(sd);
  7753. sd->idletime = last_tick;
  7754. unit_attack(&sd->bl, target_id, action_type != 0);
  7755. break;
  7756. case 0x02: // sitdown
  7757. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7758. clif_skill_fail(sd, 1, 0, 2);
  7759. break;
  7760. }
  7761. if(pc_issit(sd)) {
  7762. //Bugged client? Just refresh them.
  7763. WBUFW(buf, 0) = 0x8a;
  7764. WBUFL(buf, 2) = sd->bl.id;
  7765. WBUFB(buf,26) = 2;
  7766. clif_send(buf, packet_len_table[0x8a], &sd->bl, SELF);
  7767. return;
  7768. }
  7769. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7770. break;
  7771. if (sd->sc.count && (
  7772. sd->sc.data[SC_DANCING].timer != -1 ||
  7773. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7774. )) //No sitting during these states neither.
  7775. break;
  7776. pc_setsit(sd);
  7777. skill_sit(sd, 1);
  7778. clif_sitting(sd);
  7779. break;
  7780. case 0x03: // standup
  7781. if (!pc_issit(sd)) {
  7782. //Bugged client? Just refresh them.
  7783. WBUFW(buf, 0) = 0x8a;
  7784. WBUFL(buf, 2) = sd->bl.id;
  7785. WBUFB(buf,26) = 3;
  7786. clif_send(buf, packet_len_table[0x8a], &sd->bl, SELF);
  7787. return;
  7788. }
  7789. pc_setstand(sd);
  7790. skill_sit(sd, 0);
  7791. WBUFW(buf, 0) = 0x8a;
  7792. WBUFL(buf, 2) = sd->bl.id;
  7793. WBUFB(buf,26) = 3;
  7794. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  7795. break;
  7796. }
  7797. }
  7798. /*==========================================
  7799. *
  7800. *------------------------------------------
  7801. */
  7802. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  7803. clif_parse_ActionRequest_sub(sd,
  7804. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7805. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7806. gettick()
  7807. );
  7808. }
  7809. /*==========================================
  7810. *
  7811. *------------------------------------------
  7812. */
  7813. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  7814. RFIFOHEAD(fd);
  7815. switch(RFIFOB(fd,2)) {
  7816. case 0x00:
  7817. if (pc_isdead(sd)) {
  7818. pc_setstand(sd);
  7819. pc_setrestartvalue(sd, 3);
  7820. if (sd->sc.count && battle_config.debuff_on_logout&2) {
  7821. //For some reason food buffs are removed when you respawn.
  7822. if(sd->sc.data[SC_STRFOOD].timer!=-1)
  7823. status_change_end(&sd->bl,SC_STRFOOD,-1);
  7824. if(sd->sc.data[SC_AGIFOOD].timer!=-1)
  7825. status_change_end(&sd->bl,SC_AGIFOOD,-1);
  7826. if(sd->sc.data[SC_VITFOOD].timer!=-1)
  7827. status_change_end(&sd->bl,SC_VITFOOD,-1);
  7828. if(sd->sc.data[SC_INTFOOD].timer!=-1)
  7829. status_change_end(&sd->bl,SC_INTFOOD,-1);
  7830. if(sd->sc.data[SC_DEXFOOD].timer!=-1)
  7831. status_change_end(&sd->bl,SC_DEXFOOD,-1);
  7832. if(sd->sc.data[SC_LUKFOOD].timer!=-1)
  7833. status_change_end(&sd->bl,SC_LUKFOOD,-1);
  7834. if(sd->sc.data[SC_HITFOOD].timer!=-1)
  7835. status_change_end(&sd->bl,SC_HITFOOD,-1);
  7836. if(sd->sc.data[SC_FLEEFOOD].timer!=-1)
  7837. status_change_end(&sd->bl,SC_FLEEFOOD,-1);
  7838. if(sd->sc.data[SC_BATKFOOD].timer!=-1)
  7839. status_change_end(&sd->bl,SC_BATKFOOD,-1);
  7840. if(sd->sc.data[SC_WATKFOOD].timer!=-1)
  7841. status_change_end(&sd->bl,SC_WATKFOOD,-1);
  7842. if(sd->sc.data[SC_MATKFOOD].timer!=-1)
  7843. status_change_end(&sd->bl,SC_MATKFOOD,-1);
  7844. }
  7845. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  7846. }
  7847. // in case the player's status somehow wasn't updated yet [Celest]
  7848. else if (sd->battle_status.hp <= 0)
  7849. pc_setdead(sd);
  7850. break;
  7851. case 0x01:
  7852. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7853. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7854. { //Send to char-server for character selection.
  7855. chrif_charselectreq(sd, session[fd]->client_addr.sin_addr.s_addr);
  7856. } else {
  7857. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7858. WFIFOW(fd,0)=0x18b;
  7859. WFIFOW(fd,2)=1;
  7860. WFIFOSET(fd,packet_len_table[0x018b]);
  7861. }
  7862. break;
  7863. }
  7864. }
  7865. /*==========================================
  7866. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7867. *------------------------------------------
  7868. */
  7869. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  7870. char *gm_command;
  7871. struct map_session_data *dstsd;
  7872. int i=0;
  7873. struct npc_data *npc;
  7874. char split_data[10][50];
  7875. int j=0,k=0;
  7876. char target[NAME_LENGTH+1];
  7877. char output[256];
  7878. RFIFOHEAD(fd);
  7879. //printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28));
  7880. gm_command = (char*)aMallocA((strlen((const char*)RFIFOP(fd,28)) + 28)*sizeof(char)); // 24+3+(RFIFOW(fd,2)-28)+1 or 24+3+(strlen(RFIFOP(fd,28))+1 (size can be wrong with hacker)
  7881. sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28));
  7882. if ((is_charcommand(fd, sd, gm_command, 0) != CharCommand_None) ||
  7883. (is_atcommand(fd, sd, gm_command, 0) != AtCommand_None)) {
  7884. if(gm_command) aFree(gm_command);
  7885. return;
  7886. }
  7887. if(gm_command) aFree(gm_command);
  7888. if (sd->sc.count &&
  7889. (sd->sc.data[SC_BERSERK].timer!=-1 ||
  7890. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)))
  7891. return;
  7892. if (battle_config.min_chat_delay)
  7893. { //[Skotlex]
  7894. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7895. return;
  7896. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7897. }
  7898. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7899. target[NAME_LENGTH]='\0';
  7900. //Chat Logging type 'W' / Whisper
  7901. if(log_config.chat&1 //we log everything then
  7902. || ( log_config.chat&2 //if Whisper bit is on
  7903. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  7904. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, (char*)RFIFOP(fd, 28));
  7905. //-------------------------------------------------------//
  7906. // Lordalfa - Paperboy - To whisper NPC commands //
  7907. //-------------------------------------------------------//
  7908. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7909. char *whisper_tmp = target+4; //Skip the NPC: string part.
  7910. if ((npc = npc_name2id(whisper_tmp)))
  7911. {
  7912. whisper_tmp=(char *)aMallocA((strlen((char *)(RFIFOP(fd,28)))+1)*sizeof(char));
  7913. sprintf(whisper_tmp, "%s", (const char*)RFIFOP(fd,28));
  7914. for( j=0;whisper_tmp[j]!='\0';j++)
  7915. {
  7916. if(whisper_tmp[j]!='#')
  7917. {
  7918. split_data[i][j-k]=whisper_tmp[j];
  7919. }
  7920. else
  7921. {
  7922. split_data[i][j-k]='\0';
  7923. k=j+1;
  7924. i++;
  7925. }
  7926. } // Splits the message using '#' as separators
  7927. split_data[i][j-k]='\0';
  7928. aFree(whisper_tmp);
  7929. whisper_tmp=(char *)aMallocA(15*sizeof(char));
  7930. for (j=0;j<=10;j++)
  7931. {
  7932. sprintf(whisper_tmp, "@whispervar%d$", j);
  7933. set_var(sd,whisper_tmp,(char *) split_data[j]);
  7934. }//You don't need to zero them, just reset them [Kevin]
  7935. aFree(whisper_tmp);
  7936. whisper_tmp=(char *)aMallocA((strlen(npc->name)+18)*sizeof(char));
  7937. sprintf(whisper_tmp, "%s::OnWhisperGlobal", npc->name);
  7938. npc_event(sd,whisper_tmp,0); // Calls the NPC label
  7939. aFree(whisper_tmp); //I rewrote it a little to use memory allocation, a bit more stable =P [Kevin]
  7940. return;
  7941. } //should have just removed the one below that was a my bad =P
  7942. }
  7943. // Main chat [LuzZza]
  7944. if(strcmpi(target, main_chat_nick) == 0) {
  7945. if(!sd->state.mainchat) {
  7946. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7947. return;
  7948. }
  7949. sprintf(output, msg_txt(386), sd->status.name, (char *)RFIFOP(fd,28));
  7950. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7951. return;
  7952. }
  7953. // searching destination character
  7954. dstsd = map_nick2sd(target);
  7955. // player is not on this map-server
  7956. if (dstsd == NULL ||
  7957. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7958. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7959. // and if we ask for 'Test', we must not contact 'test' player
  7960. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7961. strcmp(dstsd->status.name, target) != 0) // not exactly same name
  7962. // send message to inter-server
  7963. intif_wis_message(sd, target, (char*)RFIFOP(fd,28), RFIFOW(fd,2)-28);
  7964. // player is on this map-server
  7965. else {
  7966. // if you send to your self, don't send anything to others
  7967. if (dstsd->fd == fd) // but, normaly, it's impossible!
  7968. clif_wis_message(fd, wisp_server_name, "You can not page yourself. Sorry.", strlen("You can not page yourself. Sorry.") + 1);
  7969. // otherwise, send message and answer immediatly
  7970. else {
  7971. if (dstsd->ignoreAll == 1) {
  7972. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7973. clif_wis_end(fd, 1); // 1: target character is not loged in
  7974. else
  7975. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7976. } else {
  7977. // if player ignore the source character
  7978. for(i = 0; i < MAX_IGNORE_LIST; i++)
  7979. if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0) {
  7980. clif_wis_end(fd, 2); // 2: ignored by target
  7981. break;
  7982. }
  7983. // if source player not found in ignore list
  7984. if (i == MAX_IGNORE_LIST) {
  7985. if(strlen(dstsd->away_message) > 0) { // Send away automessage [LuzZza]
  7986. //(Automessage has been sent)
  7987. sprintf(output, "%s %s", (char*)RFIFOP(fd,28),msg_txt(543));
  7988. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7989. clif_wis_end(fd, 0); // 0: success to send wisper
  7990. if(dstsd->state.autotrade)
  7991. //"Away [AT] - \"%s\""
  7992. sprintf(output, msg_txt(544), dstsd->away_message);
  7993. else
  7994. //"Away - \"%s\""
  7995. sprintf(output, msg_txt(545), dstsd->away_message);
  7996. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7997. } else { // Normal message
  7998. clif_wis_message(dstsd->fd, sd->status.name, (char*)RFIFOP(fd,28), RFIFOW(fd,2) - 28);
  7999. clif_wis_end(fd, 0); // 0: success to send wisper
  8000. }
  8001. }
  8002. }
  8003. }
  8004. }
  8005. return;
  8006. }
  8007. /*==========================================
  8008. *
  8009. *------------------------------------------
  8010. */
  8011. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  8012. // /b
  8013. RFIFOHEAD(fd);
  8014. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8015. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast)))
  8016. intif_GMmessage((char*)RFIFOP(fd,4), RFIFOW(fd,2)-4, 0);
  8017. }
  8018. /*==========================================
  8019. *
  8020. *------------------------------------------
  8021. */
  8022. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  8023. struct flooritem_data *fitem;
  8024. int map_object_id;
  8025. RFIFOHEAD(fd);
  8026. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8027. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8028. do {
  8029. if (pc_isdead(sd)) {
  8030. clif_clearchar_area(&sd->bl, 1);
  8031. break;
  8032. }
  8033. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8034. break;
  8035. if (clif_cant_act(sd))
  8036. break;
  8037. //Disable cloaking/chasewalking characters from looting [Skotlex]
  8038. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  8039. break;
  8040. if(sd->sc.count && (
  8041. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  8042. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  8043. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  8044. )
  8045. break;
  8046. if (!pc_takeitem(sd, fitem))
  8047. break;
  8048. return;
  8049. } while (0);
  8050. // Client REQUIRES a fail packet or you can no longer pick items.
  8051. clif_additem(sd,0,0,6);
  8052. }
  8053. /*==========================================
  8054. *
  8055. *------------------------------------------
  8056. */
  8057. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  8058. int item_index, item_amount;
  8059. RFIFOHEAD(fd);
  8060. if (pc_isdead(sd)) {
  8061. clif_clearchar_area(&sd->bl, 1);
  8062. return;
  8063. }
  8064. if (clif_cant_act(sd))
  8065. return;
  8066. if (sd->sc.count && (
  8067. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  8068. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  8069. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  8070. ))
  8071. return;
  8072. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8073. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8074. if (!pc_dropitem(sd, item_index, item_amount))
  8075. //Because the client does not likes being ignored.
  8076. clif_delitem(sd, item_index,0);
  8077. }
  8078. /*==========================================
  8079. *
  8080. *------------------------------------------
  8081. */
  8082. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  8083. int n;
  8084. RFIFOHEAD(fd);
  8085. if (pc_isdead(sd)) {
  8086. clif_clearchar_area(&sd->bl, 1);
  8087. return;
  8088. }
  8089. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8090. return;
  8091. //This flag enables you to use items while in an NPC. [Skotlex]
  8092. if (sd->npc_id) {
  8093. if (sd->npc_id != sd->npc_item_flag)
  8094. return;
  8095. } else
  8096. if (clif_trading(sd))
  8097. return;
  8098. if (sd->invincible_timer != -1)
  8099. pc_delinvincibletimer(sd);
  8100. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8101. sd->idletime = last_tick;
  8102. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8103. if(n <0 || n >= MAX_INVENTORY)
  8104. return;
  8105. if (!pc_useitem(sd,n))
  8106. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8107. }
  8108. /*==========================================
  8109. *
  8110. *------------------------------------------
  8111. */
  8112. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8113. {
  8114. int index;
  8115. RFIFOHEAD(fd);
  8116. if(pc_isdead(sd)) {
  8117. clif_clearchar_area(&sd->bl,1);
  8118. return;
  8119. }
  8120. index = RFIFOW(fd,2)-2;
  8121. if (index < 0 || index >= MAX_INVENTORY)
  8122. return; //Out of bounds check.
  8123. if(sd->npc_id) {
  8124. if (sd->npc_id != sd->npc_item_flag)
  8125. return;
  8126. } else if (sd->state.storage_flag || sd->sc.opt1)
  8127. ; //You can equip/unequip stuff while storage is open/under status changes
  8128. else if (clif_cant_act(sd))
  8129. return;
  8130. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  8131. return;
  8132. if(!sd->status.inventory[index].identify) { // 未鑑定
  8133. clif_equipitemack(sd,index,0,0); // fail
  8134. return;
  8135. }
  8136. //ペット用装備であるかないか
  8137. if(sd->inventory_data[index]) {
  8138. if(sd->inventory_data[index]->type != IT_PETARMOR){
  8139. if(sd->inventory_data[index]->type == IT_AMMO)
  8140. pc_equipitem(sd,index,EQP_AMMO); //Client doesn't sends the position.
  8141. else
  8142. pc_equipitem(sd,index,RFIFOW(fd,4));
  8143. } else
  8144. pet_equipitem(sd,index);
  8145. }
  8146. }
  8147. /*==========================================
  8148. *
  8149. *------------------------------------------
  8150. */
  8151. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8152. {
  8153. int index;
  8154. RFIFOHEAD(fd);
  8155. if(pc_isdead(sd)) {
  8156. clif_clearchar_area(&sd->bl,1);
  8157. return;
  8158. }
  8159. if (sd->state.storage_flag)
  8160. ; //You can equip/unequip stuff while storage is open.
  8161. else if (clif_cant_act(sd))
  8162. return;
  8163. index = RFIFOW(fd,2)-2;
  8164. pc_unequipitem(sd,index,1);
  8165. }
  8166. /*==========================================
  8167. *
  8168. *------------------------------------------
  8169. */
  8170. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8171. {
  8172. struct block_list *bl;
  8173. RFIFOHEAD(fd);
  8174. if(pc_isdead(sd)) {
  8175. clif_clearchar_area(&sd->bl,1);
  8176. return;
  8177. }
  8178. if (clif_cant_act(sd))
  8179. return;
  8180. bl = map_id2bl(RFIFOL(fd,2));
  8181. if (!bl) return;
  8182. switch (bl->type) {
  8183. case BL_MOB:
  8184. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  8185. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8186. break;
  8187. case BL_PC:
  8188. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8189. break;
  8190. case BL_NPC:
  8191. npc_click(sd,(TBL_NPC*)bl);
  8192. break;
  8193. }
  8194. return;
  8195. }
  8196. /*==========================================
  8197. *
  8198. *------------------------------------------
  8199. */
  8200. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8201. {
  8202. RFIFOHEAD(fd);
  8203. if (sd->state.trading)
  8204. return;
  8205. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8206. }
  8207. /*==========================================
  8208. *
  8209. *------------------------------------------
  8210. */
  8211. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8212. {
  8213. int fail=0,n;
  8214. unsigned short *item_list;
  8215. RFIFOHEAD(fd);
  8216. n = (RFIFOW(fd,2)-4) /4;
  8217. item_list = (unsigned short*)RFIFOP(fd,4);
  8218. if (sd->state.trading|| !sd->npc_shopid)
  8219. fail = 1;
  8220. else
  8221. fail = npc_buylist(sd,n,item_list);
  8222. sd->npc_shopid = 0; //Clear shop data.
  8223. WFIFOHEAD(fd,packet_len_table[0xca]);
  8224. WFIFOW(fd,0)=0xca;
  8225. WFIFOB(fd,2)=fail;
  8226. WFIFOSET(fd,packet_len_table[0xca]);
  8227. }
  8228. /*==========================================
  8229. *
  8230. *------------------------------------------
  8231. */
  8232. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8233. {
  8234. int fail=0,n;
  8235. unsigned short *item_list;
  8236. RFIFOHEAD(fd);
  8237. n = (RFIFOW(fd,2)-4) /4;
  8238. item_list = (unsigned short*)RFIFOP(fd,4);
  8239. if (sd->state.trading || !sd->npc_shopid)
  8240. fail = 1;
  8241. else
  8242. fail = npc_selllist(sd,n,item_list);
  8243. sd->npc_shopid = 0; //Clear shop data.
  8244. WFIFOHEAD(fd,packet_len_table[0xcb]);
  8245. WFIFOW(fd,0)=0xcb;
  8246. WFIFOB(fd,2)=fail;
  8247. WFIFOSET(fd,packet_len_table[0xcb]);
  8248. }
  8249. /*==========================================
  8250. *
  8251. *------------------------------------------
  8252. */
  8253. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8254. {
  8255. RFIFOHEAD(fd);
  8256. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8257. return;
  8258. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8259. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8260. } else
  8261. clif_skill_fail(sd,1,0,3);
  8262. }
  8263. /*==========================================
  8264. *
  8265. *------------------------------------------
  8266. */
  8267. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8268. {
  8269. RFIFOHEAD(fd);
  8270. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8271. }
  8272. /*==========================================
  8273. *
  8274. *------------------------------------------
  8275. */
  8276. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8277. {
  8278. RFIFOHEAD(fd);
  8279. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8280. }
  8281. /*==========================================
  8282. *
  8283. *------------------------------------------
  8284. */
  8285. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8286. {
  8287. RFIFOHEAD(fd);
  8288. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8289. }
  8290. /*==========================================
  8291. *
  8292. *------------------------------------------
  8293. */
  8294. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8295. {
  8296. RFIFOHEAD(fd);
  8297. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8298. }
  8299. /*==========================================
  8300. *
  8301. *------------------------------------------
  8302. */
  8303. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8304. {
  8305. chat_leavechat(sd);
  8306. }
  8307. //Handles notifying asker and rejecter of what has just ocurred.
  8308. //Type is used to determine the correct msg_txt to use:
  8309. //0:
  8310. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8311. {
  8312. char *msg, output[256];
  8313. // Your request has been rejected by autoreject option.
  8314. msg = msg_txt(392);
  8315. clif_disp_onlyself(src, msg, strlen(msg));
  8316. //Notice that a request was rejected.
  8317. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8318. clif_disp_onlyself(target, output, strlen(output));
  8319. }
  8320. /*==========================================
  8321. * 取引要請を相手に送る
  8322. *------------------------------------------
  8323. */
  8324. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8325. {
  8326. struct map_session_data *t_sd;
  8327. RFIFOHEAD(fd);
  8328. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  8329. if(!sd->chatID && clif_cant_act(sd))
  8330. return; //You can trade while in a chatroom.
  8331. // @noask [LuzZza]
  8332. if(t_sd) {
  8333. if (t_sd->state.noask) {
  8334. clif_noask_sub(sd, t_sd, 0);
  8335. return;
  8336. }
  8337. if(!t_sd->chatID && clif_cant_act(t_sd))
  8338. return;
  8339. }
  8340. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8341. trade_traderequest(sd,t_sd);
  8342. } else
  8343. clif_skill_fail(sd,1,0,0);
  8344. }
  8345. /*==========================================
  8346. * 取引要請
  8347. *------------------------------------------
  8348. */
  8349. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8350. {
  8351. RFIFOHEAD(fd);
  8352. trade_tradeack(sd,RFIFOB(sd->fd,2));
  8353. }
  8354. /*==========================================
  8355. * アイテム追加
  8356. *------------------------------------------
  8357. */
  8358. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8359. {
  8360. RFIFOHEAD(fd);
  8361. trade_tradeadditem(sd,RFIFOW(sd->fd,2),RFIFOL(sd->fd,4));
  8362. }
  8363. /*==========================================
  8364. * アイテム追加完了(ok押し)
  8365. *------------------------------------------
  8366. */
  8367. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8368. {
  8369. trade_tradeok(sd);
  8370. }
  8371. /*==========================================
  8372. * 取引キャンセル
  8373. *------------------------------------------
  8374. */
  8375. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8376. {
  8377. trade_tradecancel(sd);
  8378. }
  8379. /*==========================================
  8380. * 取引許諾(trade押し)
  8381. *------------------------------------------
  8382. */
  8383. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8384. {
  8385. trade_tradecommit(sd);
  8386. }
  8387. /*==========================================
  8388. *
  8389. *------------------------------------------
  8390. */
  8391. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8392. {
  8393. pc_stop_attack(sd);
  8394. }
  8395. /*==========================================
  8396. * カートへアイテムを移す
  8397. *------------------------------------------
  8398. */
  8399. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8400. {
  8401. RFIFOHEAD(fd);
  8402. if (clif_trading(sd))
  8403. return;
  8404. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8405. }
  8406. /*==========================================
  8407. * カートからアイテムを出す
  8408. *------------------------------------------
  8409. */
  8410. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8411. {
  8412. RFIFOHEAD(fd);
  8413. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8414. }
  8415. /*==========================================
  8416. * 付属品(鷹,ペコ,カート)をはずす
  8417. *------------------------------------------
  8418. */
  8419. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8420. {
  8421. //Can only remove Cart/Riding/Falcon.
  8422. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8423. }
  8424. /*==========================================
  8425. * チェンジカート
  8426. *------------------------------------------
  8427. */
  8428. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8429. {
  8430. RFIFOHEAD(fd);
  8431. pc_setcart(sd,RFIFOW(fd,2));
  8432. }
  8433. /*==========================================
  8434. * ステータスアップ
  8435. *------------------------------------------
  8436. */
  8437. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8438. {
  8439. RFIFOHEAD(fd);
  8440. pc_statusup(sd,RFIFOW(fd,2));
  8441. }
  8442. /*==========================================
  8443. * スキルレベルアップ
  8444. *------------------------------------------
  8445. */
  8446. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8447. {
  8448. RFIFOHEAD(fd);
  8449. pc_skillup(sd,RFIFOW(fd,2));
  8450. }
  8451. 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)
  8452. {
  8453. int lv;
  8454. if (!hd)
  8455. return;
  8456. if (skillnotok_hom(skillnum, hd)) //[orn]
  8457. return;
  8458. if (hd->bl.id != target_id &&
  8459. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8460. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8461. if (hd->ud.skilltimer != -1) {
  8462. if (skillnum != SA_CASTCANCEL)
  8463. return;
  8464. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8465. return;
  8466. lv = merc_hom_checkskill(hd, skillnum);
  8467. if (skilllv > lv)
  8468. skilllv = lv;
  8469. if (skilllv)
  8470. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8471. }
  8472. /*==========================================
  8473. * スキル使用(ID指定)
  8474. *------------------------------------------
  8475. */
  8476. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8477. int skillnum, skilllv, tmp, target_id;
  8478. unsigned int tick = gettick();
  8479. RFIFOHEAD(fd);
  8480. if (clif_cant_act(sd))
  8481. return;
  8482. if (pc_issit(sd))
  8483. return;
  8484. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8485. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8486. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8487. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8488. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8489. sd->idletime = last_tick;
  8490. tmp = skill_get_inf(skillnum);
  8491. if (tmp&INF_GROUND_SKILL)
  8492. return; //Using a ground skill on a target? WRONG.
  8493. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8494. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8495. return;
  8496. }
  8497. if (skillnotok(skillnum, sd))
  8498. return;
  8499. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8500. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8501. if (sd->ud.skilltimer != -1) {
  8502. if (skillnum != SA_CASTCANCEL)
  8503. return;
  8504. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8505. clif_skill_fail(sd, skillnum, 4, 0);
  8506. return;
  8507. }
  8508. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8509. return;
  8510. if (sd->invincible_timer != -1)
  8511. pc_delinvincibletimer(sd);
  8512. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8513. target_id = sd->bl.id;
  8514. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8515. if (skilllv != sd->skillitemlv)
  8516. skilllv = sd->skillitemlv;
  8517. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8518. return;
  8519. }
  8520. sd->skillitem = sd->skillitemlv = -1;
  8521. if (skillnum == MO_EXTREMITYFIST) {
  8522. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8523. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8524. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8525. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8526. if (!sd->state.skill_flag ) {
  8527. sd->state.skill_flag = 1;
  8528. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8529. return;
  8530. } else if (sd->bl.id == target_id) {
  8531. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8532. return;
  8533. }
  8534. }
  8535. }
  8536. if (skillnum == TK_JUMPKICK) {
  8537. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8538. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8539. if (!sd->state.skill_flag ) {
  8540. sd->state.skill_flag = 1;
  8541. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8542. return;
  8543. } else if (sd->bl.id == target_id) {
  8544. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8545. return;
  8546. }
  8547. }
  8548. }
  8549. if (skillnum >= GD_SKILLBASE) {
  8550. if (sd->state.gmaster_flag)
  8551. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8552. else
  8553. skilllv = 0;
  8554. } else {
  8555. tmp = pc_checkskill(sd, skillnum);
  8556. if (skilllv > tmp)
  8557. skilllv = tmp;
  8558. }
  8559. if (skilllv)
  8560. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8561. if (sd->state.skill_flag)
  8562. sd->state.skill_flag = 0;
  8563. }
  8564. /*==========================================
  8565. * スキル使用(場所指定)
  8566. *------------------------------------------
  8567. */
  8568. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8569. {
  8570. int lv;
  8571. unsigned int tick = gettick();
  8572. RFIFOHEAD(fd);
  8573. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8574. sd->idletime = last_tick;
  8575. if (skillnotok(skillnum, sd))
  8576. return;
  8577. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8578. return; //Using a target skill on the ground? WRONG.
  8579. if (skillmoreinfo != -1) {
  8580. if (pc_issit(sd)) {
  8581. clif_skill_fail(sd, skillnum, 0, 0);
  8582. return;
  8583. }
  8584. memcpy(talkie_mes, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8585. talkie_mes[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8586. }
  8587. if (sd->ud.skilltimer != -1)
  8588. return;
  8589. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8590. {
  8591. clif_skill_fail(sd, skillnum, 4, 0);
  8592. return;
  8593. }
  8594. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8595. return;
  8596. if (sd->invincible_timer != -1)
  8597. pc_delinvincibletimer(sd);
  8598. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8599. if (skilllv != sd->skillitemlv)
  8600. skilllv = sd->skillitemlv;
  8601. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8602. } else {
  8603. sd->skillitem = sd->skillitemlv = -1;
  8604. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8605. if (skilllv > lv)
  8606. skilllv = lv;
  8607. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8608. }
  8609. }
  8610. }
  8611. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8612. RFIFOHEAD(fd);
  8613. if (clif_cant_act(sd))
  8614. return;
  8615. if (pc_issit(sd))
  8616. return;
  8617. clif_parse_UseSkillToPosSub(fd, sd,
  8618. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8619. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8620. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8621. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8622. -1 //Skill more info.
  8623. );
  8624. }
  8625. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8626. RFIFOHEAD(fd);
  8627. if (clif_cant_act(sd))
  8628. return;
  8629. if (pc_issit(sd))
  8630. return;
  8631. clif_parse_UseSkillToPosSub(fd, sd,
  8632. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8633. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8634. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8635. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8636. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8637. );
  8638. }
  8639. /*==========================================
  8640. * スキル使用(map指定)
  8641. *------------------------------------------
  8642. */
  8643. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8644. {
  8645. RFIFOHEAD(fd);
  8646. if (clif_cant_act(sd))
  8647. return;
  8648. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8649. return;
  8650. if(sd->invincible_timer != -1)
  8651. pc_delinvincibletimer(sd);
  8652. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8653. }
  8654. /*==========================================
  8655. * メモ要求
  8656. *------------------------------------------
  8657. */
  8658. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8659. {
  8660. if (!pc_isdead(sd))
  8661. pc_memo(sd,-1);
  8662. }
  8663. /*==========================================
  8664. * アイテム合成
  8665. *------------------------------------------
  8666. */
  8667. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8668. {
  8669. RFIFOHEAD(fd);
  8670. if (sd->menuskill_id != AM_PHARMACY)
  8671. return;
  8672. if (clif_trading(sd)) {
  8673. //Make it fail to avoid shop exploits where you sell something different than you see.
  8674. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8675. sd->menuskill_lv = sd->menuskill_id = 0;
  8676. return;
  8677. }
  8678. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8679. sd->menuskill_lv = sd->menuskill_id = 0;
  8680. }
  8681. /*==========================================
  8682. * 武器修理
  8683. *------------------------------------------
  8684. */
  8685. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8686. {
  8687. RFIFOHEAD(fd);
  8688. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8689. return;
  8690. if (clif_trading(sd)) {
  8691. //Make it fail to avoid shop exploits where you sell something different than you see.
  8692. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8693. sd->menuskill_lv = sd->menuskill_id = 0;
  8694. return;
  8695. }
  8696. skill_repairweapon(sd,RFIFOW(fd,2));
  8697. sd->menuskill_lv = sd->menuskill_id = 0;
  8698. }
  8699. /*==========================================
  8700. *
  8701. *------------------------------------------
  8702. */
  8703. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8704. int idx;
  8705. RFIFOHEAD(fd);
  8706. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8707. return;
  8708. if (clif_trading(sd)) {
  8709. //Make it fail to avoid shop exploits where you sell something different than you see.
  8710. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8711. sd->menuskill_lv = sd->menuskill_id = 0;
  8712. return;
  8713. }
  8714. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8715. skill_weaponrefine(sd, idx-2);
  8716. sd->menuskill_lv = sd->menuskill_id = 0;
  8717. }
  8718. /*==========================================
  8719. *
  8720. *------------------------------------------
  8721. */
  8722. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8723. {
  8724. RFIFOHEAD(fd);
  8725. sd->npc_menu=RFIFOB(fd,6);
  8726. npc_scriptcont(sd,RFIFOL(fd,2));
  8727. }
  8728. /*==========================================
  8729. *
  8730. *------------------------------------------
  8731. */
  8732. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8733. {
  8734. RFIFOHEAD(fd);
  8735. #ifdef __WIN32
  8736. //For some extraordinarily eerie reason that noone has figured out yet,
  8737. //windows native compiles NEED this nullpo_retv or the function is not found!
  8738. nullpo_retv(sd);
  8739. #endif
  8740. npc_scriptcont(sd,RFIFOL(fd,2));
  8741. }
  8742. /*==========================================
  8743. *
  8744. *------------------------------------------
  8745. */
  8746. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8747. {
  8748. RFIFOHEAD(fd);
  8749. #define RFIFOL_(fd,pos) (*(int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos)))
  8750. //Input Value overflow Exploit FIX
  8751. sd->npc_amount=RFIFOL_(fd,6); //fixed by Lupus. npc_amount is (int) but was RFIFOL changing it to (unsigned int)
  8752. #undef RFIFOL_
  8753. npc_scriptcont(sd,RFIFOL(fd,2));
  8754. }
  8755. /*==========================================
  8756. *
  8757. *------------------------------------------
  8758. */
  8759. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8760. {
  8761. unsigned short message_len = RFIFOW(fd,2)-7;
  8762. RFIFOHEAD(fd);
  8763. if(message_len >= sizeof(sd->npc_str)){
  8764. ShowWarning("clif: input string too long !\n");
  8765. message_len = sizeof(sd->npc_str);
  8766. }
  8767. // Exploit prevention if crafted packets (without null) is being sent. [Lance]
  8768. memcpy(sd->npc_str,RFIFOP(fd,8),message_len);
  8769. sd->npc_str[message_len-1]=0;
  8770. npc_scriptcont(sd,RFIFOL(fd,4));
  8771. }
  8772. /*==========================================
  8773. *
  8774. *------------------------------------------
  8775. */
  8776. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8777. {
  8778. RFIFOHEAD(fd);
  8779. if (sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8780. npc_scriptcont(sd,RFIFOL(fd,2));
  8781. }
  8782. /*==========================================
  8783. * アイテム鑑定
  8784. *------------------------------------------
  8785. */
  8786. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8787. {
  8788. RFIFOHEAD(fd);
  8789. if (sd->menuskill_id != MC_IDENTIFY)
  8790. return;
  8791. skill_identify(sd,RFIFOW(fd,2)-2);
  8792. sd->menuskill_lv = sd->menuskill_id = 0;
  8793. }
  8794. /*==========================================
  8795. * 矢作成
  8796. *------------------------------------------
  8797. */
  8798. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8799. {
  8800. RFIFOHEAD(fd);
  8801. if (sd->menuskill_id != AC_MAKINGARROW)
  8802. return;
  8803. if (clif_trading(sd)) {
  8804. //Make it fail to avoid shop exploits where you sell something different than you see.
  8805. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8806. sd->menuskill_lv = sd->menuskill_id = 0;
  8807. return;
  8808. }
  8809. skill_arrow_create(sd,RFIFOW(fd,2));
  8810. sd->menuskill_lv = sd->menuskill_id = 0;
  8811. }
  8812. /*==========================================
  8813. * オートスペル受信
  8814. *------------------------------------------
  8815. */
  8816. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8817. {
  8818. RFIFOHEAD(fd);
  8819. if (sd->menuskill_id != SA_AUTOSPELL)
  8820. return;
  8821. skill_autospell(sd,RFIFOW(fd,2));
  8822. sd->menuskill_lv = sd->menuskill_id = 0;
  8823. }
  8824. /*==========================================
  8825. * カード使用
  8826. *------------------------------------------
  8827. */
  8828. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8829. {
  8830. RFIFOHEAD(fd);
  8831. if (sd->state.trading!= 0)
  8832. return;
  8833. clif_use_card(sd,RFIFOW(fd,2)-2);
  8834. }
  8835. /*==========================================
  8836. * カード挿入装備選択
  8837. *------------------------------------------
  8838. */
  8839. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8840. {
  8841. RFIFOHEAD(fd);
  8842. if (sd->state.trading!= 0)
  8843. return;
  8844. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8845. }
  8846. /*==========================================
  8847. * 0193 キャラID名前引き
  8848. *------------------------------------------
  8849. */
  8850. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8851. int char_id;
  8852. RFIFOHEAD(fd);
  8853. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8854. clif_solved_charname(sd, char_id);
  8855. }
  8856. /*==========================================
  8857. * 0197 /resetskill /resetstate
  8858. *------------------------------------------
  8859. */
  8860. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8861. RFIFOHEAD(fd);
  8862. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8863. pc_isGM(sd) >= get_atcommand_level(AtCommand_ResetState)) {
  8864. switch(RFIFOW(fd,2)){
  8865. case 0:
  8866. pc_resetstate(sd);
  8867. break;
  8868. case 1:
  8869. pc_resetskill(sd,1);
  8870. break;
  8871. }
  8872. }
  8873. }
  8874. /*==========================================
  8875. * 019c /lb等
  8876. *------------------------------------------
  8877. */
  8878. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  8879. unsigned char buf[512];
  8880. RFIFOHEAD(fd);
  8881. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8882. (pc_isGM(sd) >= get_atcommand_level(AtCommand_LocalBroadcast))) {
  8883. WBUFW(buf,0) = 0x9a;
  8884. WBUFW(buf,2) = RFIFOW(fd,2);
  8885. memcpy(WBUFP(buf,4), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  8886. clif_send(buf, RFIFOW(fd,2), &sd->bl, ALL_SAMEMAP);
  8887. }
  8888. }
  8889. /*==========================================
  8890. * カプラ倉庫へ入れる
  8891. *------------------------------------------
  8892. */
  8893. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  8894. int item_index, item_amount;
  8895. RFIFOHEAD(fd);
  8896. if (clif_trading(sd))
  8897. return;
  8898. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8899. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8900. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8901. return;
  8902. if (sd->state.storage_flag == 1)
  8903. storage_storageadd(sd, item_index, item_amount);
  8904. else if (sd->state.storage_flag == 2)
  8905. storage_guild_storageadd(sd, item_index, item_amount);
  8906. }
  8907. /*==========================================
  8908. * カプラ倉庫から出す
  8909. *------------------------------------------
  8910. */
  8911. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  8912. int item_index, item_amount;
  8913. RFIFOHEAD(fd);
  8914. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8915. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8916. if (sd->state.storage_flag == 1)
  8917. storage_storageget(sd, item_index, item_amount);
  8918. else if(sd->state.storage_flag == 2)
  8919. storage_guild_storageget(sd, item_index, item_amount);
  8920. }
  8921. /*==========================================
  8922. * カプラ倉庫へカートから入れる
  8923. *------------------------------------------
  8924. */
  8925. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  8926. RFIFOHEAD(fd);
  8927. if(sd->vender_id)
  8928. return;
  8929. if (sd->state.storage_flag == 1)
  8930. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8931. else if (sd->state.storage_flag == 2)
  8932. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8933. }
  8934. /*==========================================
  8935. * カプラ倉庫から出す
  8936. *------------------------------------------
  8937. */
  8938. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  8939. RFIFOHEAD(fd);
  8940. if (sd->vender_id)
  8941. return;
  8942. if (sd->state.storage_flag == 1)
  8943. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8944. else if (sd->state.storage_flag == 2)
  8945. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8946. }
  8947. /*==========================================
  8948. * カプラ倉庫を閉じる
  8949. *------------------------------------------
  8950. */
  8951. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  8952. if (sd->state.storage_flag == 1)
  8953. storage_storageclose(sd);
  8954. else if (sd->state.storage_flag == 2)
  8955. storage_guild_storageclose(sd);
  8956. }
  8957. /*==========================================
  8958. * パーティを作る
  8959. *------------------------------------------
  8960. */
  8961. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  8962. RFIFOHEAD(fd);
  8963. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8964. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8965. } else
  8966. clif_skill_fail(sd,1,0,4);
  8967. }
  8968. /*==========================================
  8969. * パーティを作る
  8970. *------------------------------------------
  8971. */
  8972. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  8973. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  8974. RFIFOHEAD(fd);
  8975. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8976. } else
  8977. clif_skill_fail(sd,1,0,4);
  8978. }
  8979. /*==========================================
  8980. * パーティに勧誘
  8981. *------------------------------------------
  8982. */
  8983. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  8984. struct map_session_data *t_sd;
  8985. RFIFOHEAD(fd);
  8986. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  8987. // @noask [LuzZza]
  8988. if(t_sd && t_sd->state.noask) {
  8989. clif_noask_sub(sd, t_sd, 1);
  8990. return;
  8991. }
  8992. party_invite(sd, t_sd);
  8993. }
  8994. /*==========================================
  8995. * パーティ勧誘返答
  8996. *------------------------------------------
  8997. */
  8998. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  8999. RFIFOHEAD(fd);
  9000. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  9001. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9002. } else {
  9003. party_reply_invite(sd,RFIFOL(fd,2),-1);
  9004. clif_skill_fail(sd,1,0,4);
  9005. }
  9006. }
  9007. /*==========================================
  9008. * パーティ脱退要求
  9009. *------------------------------------------
  9010. */
  9011. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  9012. party_leave(sd);
  9013. }
  9014. /*==========================================
  9015. * パーティ除名要求
  9016. *------------------------------------------
  9017. */
  9018. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  9019. RFIFOHEAD(fd);
  9020. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9021. }
  9022. /*==========================================
  9023. * パーティ設定変更要求
  9024. *------------------------------------------
  9025. */
  9026. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  9027. struct party_data *p;
  9028. RFIFOHEAD(fd);
  9029. if(!sd->status.party_id)
  9030. return;
  9031. p = party_search(sd->status.party_id);
  9032. if (!p) return;
  9033. //The client no longer can change the item-field, therefore it always
  9034. //comes as zero. Here, resend the item data as it is.
  9035. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  9036. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  9037. }
  9038. /*==========================================
  9039. * パーティメッセージ送信要求
  9040. *------------------------------------------
  9041. */
  9042. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  9043. RFIFOHEAD(fd);
  9044. if (is_charcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != CharCommand_None ||
  9045. is_atcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != AtCommand_None)
  9046. return;
  9047. if (sd->sc.count && (
  9048. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9049. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9050. ))
  9051. return;
  9052. if (battle_config.min_chat_delay)
  9053. { //[Skotlex]
  9054. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9055. return;
  9056. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9057. }
  9058. party_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9059. }
  9060. /*==========================================
  9061. * 露店閉鎖
  9062. *------------------------------------------
  9063. */
  9064. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  9065. vending_closevending(sd);
  9066. }
  9067. /*==========================================
  9068. * 露店アイテムリスト要求
  9069. *------------------------------------------
  9070. */
  9071. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  9072. RFIFOHEAD(fd);
  9073. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9074. if(sd->npc_id)
  9075. npc_event_dequeue(sd);
  9076. }
  9077. /*==========================================
  9078. * 露店アイテム購入
  9079. *------------------------------------------
  9080. */
  9081. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  9082. RFIFOHEAD(fd);
  9083. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  9084. }
  9085. /*==========================================
  9086. * 露店開設
  9087. *------------------------------------------
  9088. */
  9089. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  9090. RFIFOHEAD(fd);
  9091. if (clif_trading(sd))
  9092. return;
  9093. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  9094. return;
  9095. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  9096. }
  9097. /*==========================================
  9098. * ギルドを作る
  9099. *------------------------------------------
  9100. */
  9101. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  9102. RFIFOHEAD(fd);
  9103. guild_create(sd, (char*)RFIFOP(fd,6));
  9104. }
  9105. /*==========================================
  9106. * ギルドマスターかどうか確認
  9107. *------------------------------------------
  9108. */
  9109. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  9110. clif_guild_masterormember(sd);
  9111. }
  9112. /*==========================================
  9113. * ギルド情報要求
  9114. *------------------------------------------
  9115. */
  9116. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  9117. RFIFOHEAD(fd);
  9118. switch(RFIFOL(fd,2)){
  9119. case 0: // ギルド基本情報、同盟敵対情報
  9120. clif_guild_basicinfo(sd);
  9121. clif_guild_allianceinfo(sd);
  9122. break;
  9123. case 1: // メンバーリスト、役職名リスト
  9124. clif_guild_positionnamelist(sd);
  9125. clif_guild_memberlist(sd);
  9126. break;
  9127. case 2: // 役職名リスト、役職情報リスト
  9128. clif_guild_positionnamelist(sd);
  9129. clif_guild_positioninfolist(sd);
  9130. break;
  9131. case 3: // スキルリスト
  9132. clif_guild_skillinfo(sd);
  9133. break;
  9134. case 4: // 追放リスト
  9135. clif_guild_expulsionlist(sd);
  9136. break;
  9137. default:
  9138. if (battle_config.error_log)
  9139. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9140. break;
  9141. }
  9142. }
  9143. /*==========================================
  9144. * ギルド役職変更
  9145. *------------------------------------------
  9146. */
  9147. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  9148. int i;
  9149. RFIFOHEAD(fd);
  9150. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9151. guild_change_position(sd, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9152. }
  9153. }
  9154. /*==========================================
  9155. * ギルドメンバ役職変更
  9156. *------------------------------------------
  9157. */
  9158. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  9159. int i;
  9160. RFIFOHEAD(fd);
  9161. for(i=4;i<RFIFOW(fd,2);i+=12){
  9162. guild_change_memberposition(sd->status.guild_id,
  9163. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9164. }
  9165. }
  9166. /*==========================================
  9167. * ギルドエンブレム要求
  9168. *------------------------------------------
  9169. */
  9170. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  9171. struct guild *g;
  9172. RFIFOHEAD(fd);
  9173. g=guild_search(RFIFOL(fd,2));
  9174. if(g!=NULL)
  9175. clif_guild_emblem(sd,g);
  9176. }
  9177. /*==========================================
  9178. * ギルドエンブレム変更
  9179. *------------------------------------------
  9180. */
  9181. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  9182. RFIFOHEAD(fd);
  9183. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9184. }
  9185. /*==========================================
  9186. * ギルド告知変更
  9187. *------------------------------------------
  9188. */
  9189. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  9190. RFIFOHEAD(fd);
  9191. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  9192. }
  9193. /*==========================================
  9194. * ギルド勧誘
  9195. *------------------------------------------
  9196. */
  9197. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  9198. struct map_session_data *t_sd;
  9199. RFIFOHEAD(fd);
  9200. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  9201. // @noask [LuzZza]
  9202. if(t_sd && t_sd->state.noask) {
  9203. clif_noask_sub(sd, t_sd, 2);
  9204. return;
  9205. }
  9206. guild_invite(sd,t_sd);
  9207. }
  9208. /*==========================================
  9209. * ギルド勧誘返信
  9210. *------------------------------------------
  9211. */
  9212. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9213. RFIFOHEAD(fd);
  9214. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9215. }
  9216. /*==========================================
  9217. * ギルド脱退
  9218. *------------------------------------------
  9219. */
  9220. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9221. RFIFOHEAD(fd);
  9222. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9223. }
  9224. /*==========================================
  9225. * ギルド追放
  9226. *------------------------------------------
  9227. */
  9228. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd) {
  9229. RFIFOHEAD(fd);
  9230. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9231. }
  9232. /*==========================================
  9233. * ギルド会話
  9234. *------------------------------------------
  9235. */
  9236. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9237. RFIFOHEAD(fd);
  9238. if (is_charcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != CharCommand_None ||
  9239. is_atcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != AtCommand_None)
  9240. return;
  9241. if (sd->sc.count && (
  9242. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9243. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9244. ))
  9245. return;
  9246. if (battle_config.min_chat_delay)
  9247. { //[Skotlex]
  9248. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9249. return;
  9250. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9251. }
  9252. guild_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9253. }
  9254. /*==========================================
  9255. * ギルド同盟要求
  9256. *------------------------------------------
  9257. */
  9258. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9259. struct map_session_data *t_sd;
  9260. RFIFOHEAD(fd);
  9261. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  9262. // @noask [LuzZza]
  9263. if(t_sd && t_sd->state.noask) {
  9264. clif_noask_sub(sd, t_sd, 3);
  9265. return;
  9266. }
  9267. guild_reqalliance(sd,t_sd);
  9268. }
  9269. /*==========================================
  9270. * ギルド同盟要求返信
  9271. *------------------------------------------
  9272. */
  9273. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9274. RFIFOHEAD(fd);
  9275. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9276. }
  9277. /*==========================================
  9278. * ギルド関係解消
  9279. *------------------------------------------
  9280. */
  9281. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9282. RFIFOHEAD(fd);
  9283. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9284. }
  9285. /*==========================================
  9286. * ギルド敵対
  9287. *------------------------------------------
  9288. */
  9289. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9290. struct map_session_data *t_sd;
  9291. RFIFOHEAD(fd);
  9292. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  9293. // @noask [LuzZza]
  9294. if(t_sd && t_sd->state.noask) {
  9295. clif_noask_sub(sd, t_sd, 4);
  9296. return;
  9297. }
  9298. guild_opposition(sd,t_sd);
  9299. }
  9300. /*==========================================
  9301. * ギルド解散
  9302. *------------------------------------------
  9303. */
  9304. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9305. RFIFOHEAD(fd);
  9306. guild_break(sd,(char*)RFIFOP(fd,2));
  9307. }
  9308. // pet
  9309. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9310. RFIFOHEAD(fd);
  9311. pet_menu(sd,RFIFOB(fd,2));
  9312. }
  9313. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9314. RFIFOHEAD(fd);
  9315. pet_catch_process2(sd,RFIFOL(fd,2));
  9316. }
  9317. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9318. RFIFOHEAD(fd);
  9319. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  9320. return;
  9321. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9322. sd->menuskill_lv = sd->menuskill_id = 0;
  9323. }
  9324. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9325. if(sd->pd) {
  9326. RFIFOHEAD(fd);
  9327. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9328. }
  9329. }
  9330. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9331. RFIFOHEAD(fd);
  9332. pet_change_name(sd,(char*)RFIFOP(fd,2), 0);
  9333. }
  9334. // Kick (right click menu for GM "(name) force to quit")
  9335. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9336. struct block_list *target;
  9337. int tid;
  9338. RFIFOHEAD(fd);
  9339. tid = RFIFOL(fd,2);
  9340. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9341. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Kick))) {
  9342. target = map_id2bl(tid);
  9343. if (target) {
  9344. if (target->type == BL_PC) {
  9345. struct map_session_data *tsd = (struct map_session_data *)target;
  9346. if (pc_isGM(sd) > pc_isGM(tsd))
  9347. clif_GM_kick(sd, tsd, 1);
  9348. else
  9349. clif_GM_kickack(sd, 0);
  9350. } else if (target->type == BL_MOB) {
  9351. status_percent_damage(&sd->bl, target, 100, 0);
  9352. } else
  9353. clif_GM_kickack(sd, 0);
  9354. } else
  9355. clif_GM_kickack(sd, 0);
  9356. }
  9357. }
  9358. /*==========================================
  9359. * /shift
  9360. *------------------------------------------
  9361. */
  9362. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9363. char player_name[NAME_LENGTH];
  9364. malloc_tsetdword(player_name, '\0', sizeof(player_name));
  9365. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9366. (pc_isGM(sd) >= get_atcommand_level(AtCommand_JumpTo))) {
  9367. RFIFOHEAD(fd);
  9368. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9369. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9370. }
  9371. return;
  9372. }
  9373. /*==========================================
  9374. * /recall
  9375. *------------------------------------------
  9376. */
  9377. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9378. char player_name[NAME_LENGTH];
  9379. malloc_tsetdword(player_name, '\0', sizeof(player_name));
  9380. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9381. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Recall))) {
  9382. RFIFOHEAD(fd);
  9383. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9384. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9385. }
  9386. return;
  9387. }
  9388. /*==========================================
  9389. * /monster /item rewriten by [Yor]
  9390. *------------------------------------------
  9391. */
  9392. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9393. char monster_item_name[NAME_LENGTH+10]; //Additional space is for logging, eg: "@monster Poring"
  9394. int level;
  9395. malloc_tsetdword(monster_item_name, '\0', sizeof(monster_item_name));
  9396. if (battle_config.atc_gmonly == 0 || pc_isGM(sd)) {
  9397. RFIFOHEAD(fd);
  9398. memcpy(monster_item_name, RFIFOP(fd,2), NAME_LENGTH);
  9399. if (mobdb_searchname(monster_item_name) != 0) {
  9400. if (pc_isGM(sd) >= (level =get_atcommand_level(AtCommand_Spawn))) // changed from AtCommand_Monster for Skots [Reddozen]
  9401. {
  9402. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9403. if(log_config.gm && level >= log_config.gm)
  9404. { //Log action. [Skotlex]
  9405. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@spawn %s", RFIFOP(fd,2));
  9406. log_atcommand(sd, monster_item_name);
  9407. }
  9408. }
  9409. } else if (itemdb_searchname(monster_item_name) != NULL) {
  9410. if (pc_isGM(sd) >= (level = get_atcommand_level(AtCommand_Item)))
  9411. {
  9412. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9413. if(log_config.gm && level >= log_config.gm)
  9414. { //Log action. [Skotlex]
  9415. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@item %s", RFIFOP(fd,2));
  9416. log_atcommand(sd, monster_item_name);
  9417. }
  9418. }
  9419. }
  9420. }
  9421. }
  9422. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9423. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9424. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) {
  9425. if (sd->sc.option & OPTION_INVISIBLE) {
  9426. sd->sc.option &= ~OPTION_INVISIBLE;
  9427. if (sd->disguise)
  9428. status_set_viewdata(&sd->bl, sd->disguise);
  9429. else
  9430. status_set_viewdata(&sd->bl, sd->status.class_);
  9431. clif_displaymessage(fd, "Invisible: Off.");
  9432. } else {
  9433. sd->sc.option |= OPTION_INVISIBLE;
  9434. //Experimental hidden mode, changes your view class to invisible [Skotlex]
  9435. sd->vd.class_ = INVISIBLE_CLASS;
  9436. clif_displaymessage(fd, "Invisible: On.");
  9437. }
  9438. clif_changeoption(&sd->bl);
  9439. }
  9440. }
  9441. /*==========================================
  9442. * GMによるチャット禁止時間付与
  9443. *------------------------------------------
  9444. */
  9445. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9446. {
  9447. int type, limit, level;
  9448. struct block_list *bl;
  9449. struct map_session_data *dstsd;
  9450. RFIFOHEAD(fd);
  9451. bl = map_id2bl(RFIFOL(fd,2));
  9452. if (!bl || bl->type != BL_PC)
  9453. return;
  9454. nullpo_retv(dstsd =(struct map_session_data *)bl);
  9455. type = RFIFOB(fd,6);
  9456. limit = RFIFOW(fd,7);
  9457. if (type == 0)
  9458. limit = 0 - limit;
  9459. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9460. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9461. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9462. return;
  9463. if (
  9464. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9465. || (type == 2 && !level)) {
  9466. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9467. dstsd->status.manner -= limit;
  9468. if(dstsd->status.manner < 0)
  9469. sc_start(bl,SC_NOCHAT,100,0,0);
  9470. else
  9471. {
  9472. dstsd->status.manner = 0;
  9473. status_change_end(bl,SC_NOCHAT,-1);
  9474. }
  9475. }
  9476. return;
  9477. }
  9478. /*==========================================
  9479. * GMによるチャット禁止時間参照(?)
  9480. *------------------------------------------
  9481. */
  9482. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9483. {
  9484. int tid;
  9485. RFIFOHEAD(fd);
  9486. tid = RFIFOL(fd,2);
  9487. WFIFOHEAD(fd,packet_len_table[0x1e0]);
  9488. WFIFOW(fd,0) = 0x1e0;
  9489. WFIFOL(fd,2) = tid;
  9490. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9491. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9492. WFIFOSET(fd, packet_len_table[0x1e0]);
  9493. return;
  9494. }
  9495. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9496. char output[512];
  9497. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9498. int i, pos;
  9499. RFIFOHEAD(fd);
  9500. malloc_tsetdword(output, '\0', sizeof(output));
  9501. nick = (char*)RFIFOP(fd,2); // speed up
  9502. RFIFOB(fd,NAME_LENGTH+1) = '\0'; // to be sure that the player name have at maximum 23 characters (nick range: [2]->[26])
  9503. //printf("Ignore: char '%s' state: %d\n", nick, RFIFOB(fd,26));
  9504. WFIFOHEAD(fd,packet_len_table[0xd1]);
  9505. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9506. WFIFOB(fd,2) = RFIFOB(fd,26);
  9507. // do nothing only if nick can not exist
  9508. if (strlen(nick) < 4) {
  9509. WFIFOB(fd,3) = 1; // fail
  9510. WFIFOSET(fd, packet_len_table[0x0d1]);
  9511. if (RFIFOB(fd,26) == 0) // type
  9512. clif_wis_message(fd, wisp_server_name, "It's impossible to block this player.", strlen("It's impossible to block this player.") + 1);
  9513. else
  9514. clif_wis_message(fd, wisp_server_name, "It's impossible to unblock this player.", strlen("It's impossible to unblock this player.") + 1);
  9515. return;
  9516. // name can exist
  9517. } else {
  9518. // deny action (we add nick only if it's not already exist
  9519. if (RFIFOB(fd,26) == 0) { // type
  9520. pos = -1;
  9521. for(i = 0; i < MAX_IGNORE_LIST; i++) {
  9522. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9523. WFIFOB(fd,3) = 1; // fail
  9524. WFIFOSET(fd, packet_len_table[0x0d1]);
  9525. clif_wis_message(fd, wisp_server_name, "This player is already blocked.", strlen("This player is already blocked.") + 1);
  9526. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9527. 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);
  9528. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9529. }
  9530. return;
  9531. } else if (pos == -1 && sd->ignore[i].name[0] == '\0')
  9532. pos = i;
  9533. }
  9534. // if a position is found and name not found, we add it in the list
  9535. if (pos != -1) {
  9536. memcpy(sd->ignore[pos].name, nick, NAME_LENGTH-1);
  9537. WFIFOB(fd,3) = 0; // success
  9538. WFIFOSET(fd, packet_len_table[0x0d1]);
  9539. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9540. 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);
  9541. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9542. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9543. clif_wis_message(fd, wisp_server_name, "Add me in your ignore list, doesn't block my wisps.", strlen("Add me in your ignore list, doesn't block my wisps.") + 1);
  9544. }
  9545. } else {
  9546. WFIFOB(fd,3) = 1; // fail
  9547. WFIFOSET(fd, packet_len_table[0x0d1]);
  9548. clif_wis_message(fd, wisp_server_name, "You can not block more people.", strlen("You can not block more people.") + 1);
  9549. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9550. 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);
  9551. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9552. }
  9553. }
  9554. // allow action (we remove all same nicks if they exist)
  9555. } else {
  9556. pos = -1;
  9557. for(i = 0; i < MAX_IGNORE_LIST; i++)
  9558. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9559. malloc_tsetdword(sd->ignore[i].name, 0, sizeof(sd->ignore[i].name));
  9560. if (pos == -1) {
  9561. WFIFOB(fd,3) = 0; // success
  9562. WFIFOSET(fd, packet_len_table[0x0d1]);
  9563. pos = i; // don't break, to remove ALL same nick
  9564. }
  9565. }
  9566. if (pos == -1) {
  9567. WFIFOB(fd,3) = 1; // fail
  9568. WFIFOSET(fd, packet_len_table[0x0d1]);
  9569. clif_wis_message(fd, wisp_server_name, "This player is not blocked by you.", strlen("This player is not blocked by you.") + 1);
  9570. }
  9571. }
  9572. }
  9573. // for(i = 0; i < MAX_IGNORE_LIST; i++) // for debug only
  9574. // if (sd->ignore[i].name[0] != '\0')
  9575. // printf("Ignored player: '%s'\n", sd->ignore[i].name);
  9576. return;
  9577. }
  9578. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9579. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9580. RFIFOHEAD(fd);
  9581. if (RFIFOB(fd,2) == 0) {// S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9582. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9583. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9584. WFIFOB(fd,2) = 0;
  9585. if (sd->ignoreAll == 0) {
  9586. sd->ignoreAll = 1;
  9587. WFIFOB(fd,3) = 0; // success
  9588. WFIFOSET(fd, packet_len_table[0x0d2]);
  9589. } else {
  9590. WFIFOB(fd,3) = 1; // fail
  9591. WFIFOSET(fd, packet_len_table[0x0d2]);
  9592. clif_wis_message(fd, wisp_server_name, "You already block everyone.", strlen("You already block everyone.") + 1);
  9593. }
  9594. } else {
  9595. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9596. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9597. WFIFOB(fd,2) = 1;
  9598. if (sd->ignoreAll == 1) {
  9599. sd->ignoreAll = 0;
  9600. WFIFOB(fd,3) = 0; // success
  9601. WFIFOSET(fd, packet_len_table[0x0d2]);
  9602. } else {
  9603. WFIFOB(fd,3) = 1; // fail
  9604. WFIFOSET(fd, packet_len_table[0x0d2]);
  9605. clif_wis_message(fd, wisp_server_name, "You already allow everyone.", strlen("You already allow everyone.") + 1);
  9606. }
  9607. }
  9608. return;
  9609. }
  9610. /*==========================================
  9611. * Wis拒否リスト
  9612. *------------------------------------------
  9613. */
  9614. int pstrcmp(const void *a, const void *b)
  9615. {
  9616. return strcmp((char *)a, (char *)b);
  9617. }
  9618. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9619. {
  9620. int i,j=0,count=0;
  9621. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9622. for(i = 0; i < MAX_IGNORE_LIST; i++){ //中身があるのを数える
  9623. if(sd->ignore[i].name[0] != 0)
  9624. count++;
  9625. }
  9626. WFIFOHEAD(fd, 4 + (NAME_LENGTH * count));
  9627. WFIFOW(fd,0) = 0xd4;
  9628. WFIFOW(fd,2) = 4 + (NAME_LENGTH * count);
  9629. for(i = 0; i < MAX_IGNORE_LIST; i++){
  9630. if(sd->ignore[i].name[0] != 0){
  9631. memcpy(WFIFOP(fd, 4 + j * 24),sd->ignore[i].name, NAME_LENGTH);
  9632. j++;
  9633. }
  9634. }
  9635. WFIFOSET(fd, WFIFOW(fd,2));
  9636. if(count >= MAX_IGNORE_LIST) //満タンなら最後の1個を消す
  9637. sd->ignore[MAX_IGNORE_LIST - 1].name[0] = 0;
  9638. return;
  9639. }
  9640. /*==========================================
  9641. * スパノビの/doridoriによるSPR2倍
  9642. *------------------------------------------
  9643. */
  9644. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9645. if (sd->state.doridori) return;
  9646. switch (sd->class_&MAPID_UPPERMASK)
  9647. {
  9648. case MAPID_SOUL_LINKER:
  9649. case MAPID_STAR_GLADIATOR:
  9650. case MAPID_TAEKWON:
  9651. if (!sd->state.rest)
  9652. break;
  9653. case MAPID_SUPER_NOVICE:
  9654. sd->state.doridori=1;
  9655. break;
  9656. }
  9657. return;
  9658. }
  9659. /*==========================================
  9660. * スパノビの爆裂波動
  9661. *------------------------------------------
  9662. */
  9663. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9664. {
  9665. if(sd){
  9666. int nextbaseexp=pc_nextbaseexp(sd);
  9667. if (battle_config.etc_log){
  9668. if(nextbaseexp != 0)
  9669. 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));
  9670. else
  9671. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9672. }
  9673. 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){
  9674. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9675. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9676. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9677. }
  9678. }
  9679. return;
  9680. }
  9681. // random notes:
  9682. // 0x214: monster/player info ?
  9683. /*==========================================
  9684. * Friends List
  9685. *------------------------------------------
  9686. */
  9687. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9688. { //Toggles a single friend online/offline [Skotlex]
  9689. int i;
  9690. //Seek friend.
  9691. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9692. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9693. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9694. return; //Not found
  9695. WFIFOHEAD(sd->fd,packet_len_table[0x206]);
  9696. WFIFOW(sd->fd, 0) = 0x206;
  9697. WFIFOL(sd->fd, 2) = sd->status.friends[i].account_id;
  9698. WFIFOL(sd->fd, 6) = sd->status.friends[i].char_id;
  9699. WFIFOB(sd->fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9700. WFIFOSET(sd->fd, packet_len_table[0x206]);
  9701. }
  9702. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9703. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9704. {
  9705. int account_id, char_id, online;
  9706. account_id = va_arg(ap, int);
  9707. char_id = va_arg(ap, int);
  9708. online = va_arg(ap, int);
  9709. clif_friendslist_toggle(sd, account_id, char_id, online);
  9710. return 0;
  9711. }
  9712. //For sending the whole friends list.
  9713. void clif_friendslist_send(struct map_session_data *sd) {
  9714. int i = 0, n;
  9715. // Send friends list
  9716. WFIFOHEAD(sd->fd, MAX_FRIENDS * 32 + 4);
  9717. WFIFOW(sd->fd, 0) = 0x201;
  9718. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9719. {
  9720. WFIFOL(sd->fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9721. WFIFOL(sd->fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9722. memcpy(WFIFOP(sd->fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9723. }
  9724. if (i) {
  9725. WFIFOW(sd->fd,2) = 4 + 32 * i;
  9726. WFIFOSET(sd->fd, WFIFOW(sd->fd,2));
  9727. }
  9728. for (n = 0; n < i; n++)
  9729. { //Sending the online players
  9730. if (map_charid2sd(sd->status.friends[n].char_id))
  9731. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9732. }
  9733. }
  9734. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9735. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9736. {
  9737. int fd;
  9738. nullpo_retv(sd);
  9739. fd = sd->fd;
  9740. WFIFOHEAD(fd,packet_len_table[0x209]);
  9741. WFIFOW(fd,0) = 0x209;
  9742. WFIFOW(fd,2) = type;
  9743. if (f_sd)
  9744. {
  9745. WFIFOW(fd,4) = f_sd->status.account_id;
  9746. WFIFOW(fd,8) = f_sd->status.char_id;
  9747. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9748. }
  9749. WFIFOSET(fd, packet_len_table[0x209]);
  9750. }
  9751. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9752. struct map_session_data *f_sd;
  9753. int i, f_fd;
  9754. RFIFOHEAD(fd);
  9755. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9756. // Friend doesn't exist (no player with this name)
  9757. if (f_sd == NULL) {
  9758. clif_displaymessage(fd, msg_txt(3));
  9759. return;
  9760. }
  9761. // @noask [LuzZza]
  9762. if(f_sd->state.noask) {
  9763. clif_noask_sub(sd, f_sd, 5);
  9764. return;
  9765. }
  9766. // Friend already exists
  9767. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9768. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9769. clif_displaymessage(fd, "Friend already exists.");
  9770. return;
  9771. }
  9772. }
  9773. if (i == MAX_FRIENDS) {
  9774. //No space, list full.
  9775. clif_friendslist_reqack(sd, f_sd, 2);
  9776. return;
  9777. }
  9778. f_fd = f_sd->fd;
  9779. WFIFOHEAD(f_fd,packet_len_table[0x207]);
  9780. WFIFOW(f_fd,0) = 0x207;
  9781. WFIFOL(f_fd,2) = sd->status.account_id;
  9782. WFIFOL(f_fd,6) = sd->status.char_id;
  9783. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9784. WFIFOSET(f_fd, packet_len_table[0x207]);
  9785. return;
  9786. }
  9787. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9788. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9789. struct map_session_data *f_sd;
  9790. int char_id, account_id;
  9791. char reply;
  9792. RFIFOHEAD(fd);
  9793. account_id = RFIFOL(fd,2);
  9794. char_id = RFIFOL(fd,6);
  9795. reply = RFIFOB(fd,10);
  9796. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9797. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9798. if (f_sd == NULL)
  9799. return;
  9800. if (reply == 0)
  9801. clif_friendslist_reqack(f_sd, sd, 1);
  9802. else {
  9803. int i;
  9804. // Find an empty slot
  9805. for (i = 0; i < MAX_FRIENDS; i++)
  9806. if (f_sd->status.friends[i].char_id == 0)
  9807. break;
  9808. if (i == MAX_FRIENDS) {
  9809. clif_friendslist_reqack(f_sd, sd, 2);
  9810. return;
  9811. }
  9812. f_sd->status.friends[i].account_id = sd->status.account_id;
  9813. f_sd->status.friends[i].char_id = sd->status.char_id;
  9814. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9815. clif_friendslist_reqack(f_sd, sd, 0);
  9816. if (battle_config.friend_auto_add) {
  9817. // Also add f_sd to sd's friendlist.
  9818. for (i = 0; i < MAX_FRIENDS; i++) {
  9819. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9820. return; //No need to add anything.
  9821. if (sd->status.friends[i].char_id == 0)
  9822. break;
  9823. }
  9824. if (i == MAX_FRIENDS) {
  9825. clif_friendslist_reqack(sd, f_sd, 2);
  9826. return;
  9827. }
  9828. sd->status.friends[i].account_id = f_sd->status.account_id;
  9829. sd->status.friends[i].char_id = f_sd->status.char_id;
  9830. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9831. clif_friendslist_reqack(sd, f_sd, 0);
  9832. }
  9833. }
  9834. return;
  9835. }
  9836. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9837. // 0x203 </o> <ID to be removed W 4B>
  9838. int account_id, char_id;
  9839. int i, j;
  9840. RFIFOHEAD(fd);
  9841. account_id = RFIFOL(fd,2);
  9842. char_id = RFIFOL(fd,6);
  9843. // Search friend
  9844. for (i = 0; i < MAX_FRIENDS &&
  9845. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9846. if (i == MAX_FRIENDS) {
  9847. clif_displaymessage(fd, "Name not found in list.");
  9848. return;
  9849. }
  9850. // move all chars down
  9851. for(j = i + 1; j < MAX_FRIENDS; j++)
  9852. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9853. malloc_set(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9854. clif_displaymessage(fd, "Friend removed");
  9855. WFIFOHEAD(fd,packet_len_table[0x20a]);
  9856. WFIFOW(fd,0) = 0x20a;
  9857. WFIFOL(fd,2) = account_id;
  9858. WFIFOL(fd,6) = char_id;
  9859. WFIFOSET(fd, packet_len_table[0x20a]);
  9860. // clif_friendslist_send(sd); //This is not needed anymore.
  9861. return;
  9862. }
  9863. /*==========================================
  9864. * /killall
  9865. *------------------------------------------
  9866. */
  9867. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  9868. {
  9869. char message[50];
  9870. strncpy(message,sd->status.name, NAME_LENGTH);
  9871. is_atcommand(fd, sd, strcat(message," : @kickall"),0);
  9872. return;
  9873. }
  9874. /*==========================================
  9875. * /pvpinfo
  9876. *------------------------------------------
  9877. */
  9878. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9879. {
  9880. WFIFOHEAD(fd,packet_len_table[0x210]);
  9881. WFIFOW(fd,0) = 0x210;
  9882. //WFIFOL(fd,2) = 0; // not sure what for yet
  9883. //WFIFOL(fd,6) = 0;
  9884. WFIFOL(fd,10) = sd->pvp_won; // times won
  9885. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9886. WFIFOL(fd,18) = sd->pvp_point;
  9887. WFIFOSET(fd, packet_len_table[0x210]);
  9888. return;
  9889. }
  9890. /*==========================================
  9891. * /blacksmith
  9892. *------------------------------------------
  9893. */
  9894. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9895. {
  9896. int i;
  9897. char *name;
  9898. WFIFOHEAD(fd,packet_len_table[0x219]);
  9899. WFIFOW(fd,0) = 0x219;
  9900. //Packet size limits this list to 10 elements. [Skotlex]
  9901. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9902. if (smith_fame_list[i].id > 0) {
  9903. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9904. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9905. {
  9906. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9907. } else
  9908. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9909. } else
  9910. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9911. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9912. }
  9913. for(;i < 10; i++) { //In case the MAX is less than 10.
  9914. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9915. WFIFOL(fd, 242 + i * 4) = 0;
  9916. }
  9917. WFIFOSET(fd, packet_len_table[0x219]);
  9918. }
  9919. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9920. {
  9921. int fd = sd->fd;
  9922. WFIFOHEAD(fd,packet_len_table[0x21b]);
  9923. WFIFOW(fd,0) = 0x21b;
  9924. WFIFOL(fd,2) = points;
  9925. WFIFOL(fd,6) = sd->status.fame;
  9926. WFIFOSET(fd, packet_len_table[0x21b]);
  9927. return 0;
  9928. }
  9929. /*==========================================
  9930. * /alchemist
  9931. *------------------------------------------
  9932. */
  9933. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9934. {
  9935. int i;
  9936. char *name;
  9937. WFIFOHEAD(fd,packet_len_table[0x21a]);
  9938. WFIFOW(fd,0) = 0x21a;
  9939. //Packet size limits this list to 10 elements. [Skotlex]
  9940. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9941. if (chemist_fame_list[i].id > 0) {
  9942. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9943. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9944. {
  9945. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9946. } else
  9947. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9948. } else
  9949. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9950. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9951. }
  9952. for(;i < 10; i++) { //In case the MAX is less than 10.
  9953. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9954. WFIFOL(fd, 242 + i * 4) = 0;
  9955. }
  9956. WFIFOSET(fd, packet_len_table[0x21a]);
  9957. }
  9958. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9959. {
  9960. int fd = sd->fd;
  9961. WFIFOHEAD(fd,packet_len_table[0x21c]);
  9962. WFIFOW(fd,0) = 0x21c;
  9963. WFIFOL(fd,2) = points;
  9964. WFIFOL(fd,6) = sd->status.fame;
  9965. WFIFOSET(fd, packet_len_table[0x21c]);
  9966. return 0;
  9967. }
  9968. /*==========================================
  9969. * /taekwon
  9970. *------------------------------------------
  9971. */
  9972. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9973. {
  9974. int i;
  9975. char *name;
  9976. WFIFOHEAD(fd,packet_len_table[0x226]);
  9977. WFIFOW(fd,0) = 0x226;
  9978. //Packet size limits this list to 10 elements. [Skotlex]
  9979. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9980. if (taekwon_fame_list[i].id > 0) {
  9981. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9982. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9983. {
  9984. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9985. } else
  9986. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9987. } else
  9988. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9989. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9990. }
  9991. for(;i < 10; i++) { //In case the MAX is less than 10.
  9992. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9993. WFIFOL(fd, 242 + i * 4) = 0;
  9994. }
  9995. WFIFOSET(fd, packet_len_table[0x226]);
  9996. }
  9997. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9998. {
  9999. int fd = sd->fd;
  10000. WFIFOHEAD(fd,packet_len_table[0x224]);
  10001. WFIFOW(fd,0) = 0x224;
  10002. WFIFOL(fd,2) = points;
  10003. WFIFOL(fd,6) = sd->status.fame;
  10004. WFIFOSET(fd, packet_len_table[0x224]);
  10005. return 0;
  10006. }
  10007. /*==========================================
  10008. * PK Ranking table?
  10009. *------------------------------------------
  10010. */
  10011. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10012. {
  10013. int i;
  10014. WFIFOHEAD(fd,packet_len_table[0x238]);
  10015. WFIFOW(fd,0) = 0x238;
  10016. for(i=0;i<10;i++){
  10017. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10018. WFIFOL(fd,i*4+242) = 0;
  10019. }
  10020. WFIFOSET(fd, packet_len_table[0x238]);
  10021. return;
  10022. }
  10023. /*==========================================
  10024. * SG Feel save OK [Komurka]
  10025. *------------------------------------------
  10026. */
  10027. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10028. {
  10029. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  10030. int i;
  10031. if (sd->menuskill_id != SG_FEEL)
  10032. return;
  10033. i = sd->menuskill_lv-1;
  10034. if (i<0 || i > 2) return; //Bug?
  10035. sd->feel_map[i].index = map[sd->bl.m].index;
  10036. sd->feel_map[i].m = sd->bl.m;
  10037. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  10038. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10039. // clif_misceffect2(&sd->bl, 0x1b0);
  10040. // clif_misceffect2(&sd->bl, 0x21f);
  10041. clif_feel_info(sd, i, 0);
  10042. sd->menuskill_lv = sd->menuskill_id = 0;
  10043. }
  10044. /*==========================================
  10045. * Question about Star Glaldiator save map [Komurka]
  10046. *------------------------------------------
  10047. */
  10048. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  10049. WFIFOHEAD(fd,packet_len_table[0x253]);
  10050. WFIFOW(fd,0)=0x253;
  10051. WFIFOSET(fd, packet_len_table[0x253]);
  10052. sd->menuskill_id=SG_FEEL;
  10053. sd->menuskill_lv=skilllv;
  10054. }
  10055. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd) {
  10056. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  10057. //Missing packets are the client's reply packets to the adopt request one.
  10058. //[Skotlex]
  10059. int account_id;
  10060. struct map_session_data *sd2;
  10061. RFIFOHEAD(fd);
  10062. account_id = RFIFOL(fd,2);
  10063. sd2 = map_id2sd(account_id);
  10064. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  10065. fd = sd2->fd;
  10066. WFIFOHEAD(fd,packet_len_table[0x1f9]);
  10067. WFIFOW(fd,0)=0x1f9;
  10068. WFIFOSET(fd, packet_len_table[0x1f9]);
  10069. }
  10070. }
  10071. /*==========================================
  10072. * パケットデバッグ
  10073. *------------------------------------------
  10074. */
  10075. void clif_parse_debug(int fd,struct map_session_data *sd)
  10076. {
  10077. int i, cmd, len;
  10078. RFIFOHEAD(fd);
  10079. cmd = RFIFOW(fd,0);
  10080. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10081. ShowDebug("packet debug 0x%4X\n",cmd);
  10082. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10083. for(i=0;i<len;i++){
  10084. if((i&15)==0)
  10085. printf("\n%04X ",i);
  10086. printf("%02X ",RFIFOB(fd,i));
  10087. }
  10088. printf("\n");
  10089. }
  10090. /*==========================================
  10091. * クライアントからのパケット解析
  10092. * socket.cのdo_parsepacketから呼び出される
  10093. *------------------------------------------
  10094. */
  10095. int clif_parse(int fd) {
  10096. int packet_len = 0, cmd, packet_ver, dump = 0;
  10097. struct map_session_data *sd;
  10098. RFIFOHEAD(fd);
  10099. if (fd <= 0)
  10100. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  10101. ShowError("clif_parse: Received invalid session %d\n", fd);
  10102. return 0;
  10103. }
  10104. sd = (struct map_session_data*)session[fd]->session_data;
  10105. /* This behaviour has been deprecated due to actually causing trouble instead
  10106. * of helping against exploits ~.~ [Skotlex]
  10107. if (!chrif_isconnect())
  10108. {
  10109. ShowInfo("Closing session #%d (Not connected to Char server)\n", fd);
  10110. if (sd && sd->state.auth)
  10111. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  10112. do_close(fd);
  10113. return 0;
  10114. } else
  10115. */
  10116. if (session[fd]->eof) {
  10117. if (sd && sd->state.autotrade) {
  10118. //Disassociate character from the socket connection.
  10119. session[fd]->session_data = NULL;
  10120. sd->fd = 0;
  10121. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  10122. } else if (sd && sd->state.auth) {
  10123. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  10124. if (sd->status.name != NULL)
  10125. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  10126. else
  10127. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id); // Player logout display [Yor]
  10128. } else {
  10129. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  10130. ShowInfo("Player not identified with IP '"CL_WHITE"%d.%d.%d.%d"CL_RESET"' logged off.\n", ip[0],ip[1],ip[2],ip[3]);
  10131. }
  10132. do_close(fd);
  10133. return 0;
  10134. }
  10135. if (RFIFOREST(fd) < 2)
  10136. return 0;
  10137. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  10138. cmd = RFIFOW(fd,0);
  10139. // 管理用パケット処理
  10140. if (cmd >= 30000) {
  10141. switch(cmd) {
  10142. case 0x7530: { //Why are we letting people know which version we are running?
  10143. WFIFOHEAD(fd, 10);
  10144. WFIFOW(fd,0) = 0x7531;
  10145. WFIFOB(fd,2) = ATHENA_MAJOR_VERSION;
  10146. WFIFOB(fd,3) = ATHENA_MINOR_VERSION;
  10147. WFIFOB(fd,4) = ATHENA_REVISION;
  10148. WFIFOB(fd,5) = ATHENA_RELEASE_FLAG;
  10149. WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG;
  10150. WFIFOB(fd,7) = ATHENA_SERVER_MAP;
  10151. WFIFOW(fd,8) = ATHENA_MOD_VERSION;
  10152. WFIFOSET(fd,10);
  10153. RFIFOSKIP(fd,2);
  10154. break;
  10155. }
  10156. case 0x7532: // 接続の切断
  10157. ShowWarning("clif_parse: session #%d disconnected for sending packet 0x04%x\n", fd, cmd);
  10158. session[fd]->eof=1;
  10159. break;
  10160. default:
  10161. ShowWarning("Unknown incoming packet (command: 0x%04x, session: %d), disconnecting.\n", cmd, fd);
  10162. session[fd]->eof=1;
  10163. break;
  10164. }
  10165. return 0;
  10166. }
  10167. // get packet version before to parse
  10168. packet_ver = 0;
  10169. if (sd) {
  10170. packet_ver = sd->packet_ver;
  10171. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  10172. session[fd]->eof = 1;
  10173. return 0;
  10174. }
  10175. } else {
  10176. // check authentification packet to know packet version
  10177. packet_ver = clif_guess_PacketVer(fd, 0);
  10178. // check if version is accepted
  10179. if (packet_ver < 5 || // reject really old client versions
  10180. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  10181. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
  10182. packet_ver > MAX_PACKET_VER) // no packet version support yet
  10183. {
  10184. ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
  10185. WFIFOHEAD(fd, 23);
  10186. WFIFOW(fd,0) = 0x6a;
  10187. WFIFOB(fd,2) = 5; // 05 = Game's EXE is not the latest version
  10188. WFIFOSET(fd,23);
  10189. packet_len = RFIFOREST(fd);
  10190. RFIFOSKIP(fd, packet_len);
  10191. clif_setwaitclose(fd);
  10192. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  10193. session[fd]->func_send(fd);
  10194. return 0;
  10195. }
  10196. }
  10197. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  10198. 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
  10199. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10200. session[fd]->eof = 1;
  10201. return 0;
  10202. }
  10203. // パケット長を計算
  10204. packet_len = packet_db[packet_ver][cmd].len;
  10205. if (packet_len == -1) {
  10206. if (RFIFOREST(fd) < 4)
  10207. return 0; // 可変長パケットで長さの所までデータが来てない
  10208. packet_len = RFIFOW(fd,2);
  10209. if (packet_len < 4 || packet_len > 32768) {
  10210. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10211. session[fd]->eof =1;
  10212. return 0;
  10213. }
  10214. }
  10215. if ((int)RFIFOREST(fd) < packet_len)
  10216. return 0; // まだ1パケット分データが揃ってない
  10217. #if DUMP_ALL_PACKETS
  10218. {
  10219. int i;
  10220. FILE *fp;
  10221. char packet_txt[256] = "save/packet.txt";
  10222. time_t now;
  10223. dump = 1;
  10224. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10225. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10226. return 1;
  10227. } else {
  10228. time(&now);
  10229. if (sd && sd->state.auth) {
  10230. if (sd->status.name != NULL)
  10231. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent packet:\n",
  10232. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10233. else
  10234. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10235. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10236. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10237. fprintf(fp, "\tsession #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10238. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10239. for(i = 0; i < packet_len; i++) {
  10240. if ((i & 15) == 0)
  10241. fprintf(fp, "\n\t%04X ", i);
  10242. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10243. }
  10244. fprintf(fp, "\n\n");
  10245. fclose(fp);
  10246. }
  10247. }
  10248. #endif
  10249. if (sd && sd->state.auth == 1 && sd->state.waitingdisconnect == 1) { // 切断待ちの場合パケットを処理しない
  10250. } else if (packet_db[packet_ver][cmd].func) {
  10251. if (sd && sd->bl.prev == NULL &&
  10252. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10253. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10254. else
  10255. if (sd
  10256. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10257. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10258. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10259. packet_db[packet_ver][cmd].func(fd, sd);
  10260. } else {
  10261. // 不明なパケット
  10262. if (battle_config.error_log) {
  10263. #if DUMP_UNKNOWN_PACKET
  10264. {
  10265. int i;
  10266. FILE *fp;
  10267. char packet_txt[256] = "save/packet.txt";
  10268. time_t now;
  10269. dump = 1;
  10270. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10271. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10272. return 1;
  10273. } else {
  10274. time(&now);
  10275. if (sd && sd->state.auth) {
  10276. if (sd->status.name != NULL)
  10277. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10278. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10279. else
  10280. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10281. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10282. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10283. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10284. for(i = 0; i < packet_len; i++) {
  10285. if ((i & 15) == 0)
  10286. fprintf(fp, "\n\t%04X ", i);
  10287. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10288. }
  10289. fprintf(fp, "\n\n");
  10290. fclose(fp);
  10291. }
  10292. }
  10293. #endif
  10294. }
  10295. }
  10296. if (dump) {
  10297. int i;
  10298. if (fd)
  10299. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10300. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10301. for(i = 0; i < packet_len; i++) {
  10302. if ((i & 15) == 0)
  10303. printf("\n%04X ",i);
  10304. printf("%02X ", RFIFOB(fd,i));
  10305. }
  10306. printf("\n");
  10307. if (sd && sd->state.auth) {
  10308. if (sd->status.name != NULL)
  10309. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10310. sd->status.account_id, sd->status.char_id, sd->status.name);
  10311. else
  10312. printf("\nAccount ID %d.\n", sd->bl.id);
  10313. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10314. printf("\nAccount ID %d.\n", sd->bl.id);
  10315. }
  10316. RFIFOSKIP(fd, packet_len);
  10317. return 0;
  10318. }
  10319. /*==========================================
  10320. * パケットデータベース読み込み
  10321. *------------------------------------------
  10322. */
  10323. static int packetdb_readdb(void)
  10324. {
  10325. FILE *fp;
  10326. char line[1024];
  10327. int ln=0;
  10328. int cmd,i,j,k,packet_ver;
  10329. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10330. struct {
  10331. void (*func)(int, struct map_session_data *);
  10332. char *name;
  10333. } clif_parse_func[]={
  10334. {clif_parse_WantToConnection,"wanttoconnection"},
  10335. {clif_parse_LoadEndAck,"loadendack"},
  10336. {clif_parse_TickSend,"ticksend"},
  10337. {clif_parse_WalkToXY,"walktoxy"},
  10338. {clif_parse_QuitGame,"quitgame"},
  10339. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10340. {clif_parse_GlobalMessage,"globalmessage"},
  10341. {clif_parse_MapMove,"mapmove"},
  10342. {clif_parse_ChangeDir,"changedir"},
  10343. {clif_parse_Emotion,"emotion"},
  10344. {clif_parse_HowManyConnections,"howmanyconnections"},
  10345. {clif_parse_ActionRequest,"actionrequest"},
  10346. {clif_parse_Restart,"restart"},
  10347. {clif_parse_Wis,"wis"},
  10348. {clif_parse_GMmessage,"gmmessage"},
  10349. {clif_parse_TakeItem,"takeitem"},
  10350. {clif_parse_DropItem,"dropitem"},
  10351. {clif_parse_UseItem,"useitem"},
  10352. {clif_parse_EquipItem,"equipitem"},
  10353. {clif_parse_UnequipItem,"unequipitem"},
  10354. {clif_parse_NpcClicked,"npcclicked"},
  10355. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10356. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10357. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10358. {clif_parse_CreateChatRoom,"createchatroom"},
  10359. {clif_parse_ChatAddMember,"chataddmember"},
  10360. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10361. {clif_parse_ChangeChatOwner,"changechatowner"},
  10362. {clif_parse_KickFromChat,"kickfromchat"},
  10363. {clif_parse_ChatLeave,"chatleave"},
  10364. {clif_parse_TradeRequest,"traderequest"},
  10365. {clif_parse_TradeAck,"tradeack"},
  10366. {clif_parse_TradeAddItem,"tradeadditem"},
  10367. {clif_parse_TradeOk,"tradeok"},
  10368. {clif_parse_TradeCancel,"tradecancel"},
  10369. {clif_parse_TradeCommit,"tradecommit"},
  10370. {clif_parse_StopAttack,"stopattack"},
  10371. {clif_parse_PutItemToCart,"putitemtocart"},
  10372. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10373. {clif_parse_RemoveOption,"removeoption"},
  10374. {clif_parse_ChangeCart,"changecart"},
  10375. {clif_parse_StatusUp,"statusup"},
  10376. {clif_parse_SkillUp,"skillup"},
  10377. {clif_parse_UseSkillToId,"useskilltoid"},
  10378. {clif_parse_UseSkillToPos,"useskilltopos"},
  10379. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10380. {clif_parse_UseSkillMap,"useskillmap"},
  10381. {clif_parse_RequestMemo,"requestmemo"},
  10382. {clif_parse_ProduceMix,"producemix"},
  10383. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10384. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10385. {clif_parse_NpcAmountInput,"npcamountinput"},
  10386. {clif_parse_NpcStringInput,"npcstringinput"},
  10387. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10388. {clif_parse_ItemIdentify,"itemidentify"},
  10389. {clif_parse_SelectArrow,"selectarrow"},
  10390. {clif_parse_AutoSpell,"autospell"},
  10391. {clif_parse_UseCard,"usecard"},
  10392. {clif_parse_InsertCard,"insertcard"},
  10393. {clif_parse_RepairItem,"repairitem"},
  10394. {clif_parse_WeaponRefine,"weaponrefine"},
  10395. {clif_parse_SolveCharName,"solvecharname"},
  10396. {clif_parse_ResetChar,"resetchar"},
  10397. {clif_parse_LGMmessage,"lgmmessage"},
  10398. {clif_parse_MoveToKafra,"movetokafra"},
  10399. {clif_parse_MoveFromKafra,"movefromkafra"},
  10400. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10401. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10402. {clif_parse_CloseKafra,"closekafra"},
  10403. {clif_parse_CreateParty,"createparty"},
  10404. {clif_parse_CreateParty2,"createparty2"},
  10405. {clif_parse_PartyInvite,"partyinvite"},
  10406. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10407. {clif_parse_LeaveParty,"leaveparty"},
  10408. {clif_parse_RemovePartyMember,"removepartymember"},
  10409. {clif_parse_PartyChangeOption,"partychangeoption"},
  10410. {clif_parse_PartyMessage,"partymessage"},
  10411. {clif_parse_CloseVending,"closevending"},
  10412. {clif_parse_VendingListReq,"vendinglistreq"},
  10413. {clif_parse_PurchaseReq,"purchasereq"},
  10414. {clif_parse_OpenVending,"openvending"},
  10415. {clif_parse_CreateGuild,"createguild"},
  10416. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10417. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10418. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10419. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10420. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10421. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10422. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10423. {clif_parse_GuildInvite,"guildinvite"},
  10424. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10425. {clif_parse_GuildLeave,"guildleave"},
  10426. {clif_parse_GuildExpulsion,"guildexplusion"},
  10427. {clif_parse_GuildMessage,"guildmessage"},
  10428. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10429. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10430. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10431. {clif_parse_GuildOpposition,"guildopposition"},
  10432. {clif_parse_GuildBreak,"guildbreak"},
  10433. {clif_parse_PetMenu,"petmenu"},
  10434. {clif_parse_CatchPet,"catchpet"},
  10435. {clif_parse_SelectEgg,"selectegg"},
  10436. {clif_parse_SendEmotion,"sendemotion"},
  10437. {clif_parse_ChangePetName,"changepetname"},
  10438. {clif_parse_GMKick,"gmkick"},
  10439. {clif_parse_GMHide,"gmhide"},
  10440. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10441. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10442. {clif_parse_NoviceDoriDori,"sndoridori"},
  10443. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10444. {clif_parse_PMIgnore,"wisexin"},
  10445. {clif_parse_PMIgnoreList,"wisexlist"},
  10446. {clif_parse_PMIgnoreAll,"wisall"},
  10447. {clif_parse_FriendsListAdd,"friendslistadd"},
  10448. {clif_parse_FriendsListRemove,"friendslistremove"},
  10449. {clif_parse_FriendsListReply,"friendslistreply"},
  10450. {clif_parse_GMKillAll,"killall"},
  10451. {clif_parse_Recall,"summon"},
  10452. {clif_parse_GM_Monster_Item,"itemmonster"},
  10453. {clif_parse_Shift,"shift"},
  10454. {clif_parse_Blacksmith,"blacksmith"},
  10455. {clif_parse_Alchemist,"alchemist"},
  10456. {clif_parse_Taekwon,"taekwon"},
  10457. {clif_parse_RankingPk,"rankingpk"},
  10458. {clif_parse_FeelSaveOk,"feelsaveok"},
  10459. {clif_parse_AdoptRequest,"adopt"},
  10460. {clif_parse_debug,"debug"},
  10461. //[blackhole89] //[orn]
  10462. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10463. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10464. {clif_parse_HomMoveTo,"hommoveto"},
  10465. {clif_parse_HomAttack,"homattack"},
  10466. {clif_parse_HomMenu,"hommenu"},
  10467. {NULL,NULL}
  10468. };
  10469. sprintf(line, "%s/packet_db.txt", db_path);
  10470. if( (fp=fopen(line,"r"))==NULL ){
  10471. ShowFatalError("can't read %s\n", line);
  10472. exit(1);
  10473. }
  10474. clif_config.packet_db_ver = MAX_PACKET_VER;
  10475. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10476. while(fgets(line,1020,fp)){
  10477. if(line[0]=='/' && line[1]=='/')
  10478. continue;
  10479. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10480. if(strcmpi(w1,"packet_ver")==0) {
  10481. int prev_ver = packet_ver;
  10482. packet_ver = atoi(w2);
  10483. if (packet_ver > MAX_PACKET_VER)
  10484. { //Check to avoid overflowing. [Skotlex]
  10485. ShowWarning("The packet_db table only has support up to version %d\n", MAX_PACKET_VER);
  10486. break;
  10487. }
  10488. // copy from previous version into new version and continue
  10489. // - indicating all following packets should be read into the newer version
  10490. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10491. continue;
  10492. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10493. //This is the preferred version.
  10494. if(strcmpi(w2,"default")==0)
  10495. clif_config.packet_db_ver = MAX_PACKET_VER;
  10496. else {
  10497. // to manually set the packet DB version
  10498. clif_config.packet_db_ver = atoi(w2);
  10499. // check for invalid version
  10500. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10501. clif_config.packet_db_ver < 0)
  10502. clif_config.packet_db_ver = MAX_PACKET_VER;
  10503. }
  10504. continue;
  10505. }
  10506. }
  10507. malloc_tsetdword(str,0,sizeof(str));
  10508. for(j=0,p=line;j<4 && p;j++){
  10509. str[j]=p;
  10510. p=strchr(p,',');
  10511. if(p) *p++=0;
  10512. }
  10513. if(str[0]==NULL)
  10514. continue;
  10515. cmd=strtol(str[0],(char **)NULL,0);
  10516. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10517. continue;
  10518. if(str[1]==NULL){
  10519. ShowError("packet_db: packet len error\n");
  10520. continue;
  10521. }
  10522. k = atoi(str[1]);
  10523. packet_db[packet_ver][cmd].len = k;
  10524. if(str[2]==NULL){
  10525. packet_db[packet_ver][cmd].func = NULL;
  10526. ln++;
  10527. continue;
  10528. }
  10529. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10530. if(clif_parse_func[j].name != NULL &&
  10531. strcmp(str[2],clif_parse_func[j].name)==0)
  10532. {
  10533. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10534. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10535. for(i=0;i<MAX_PACKET_DB;i++){
  10536. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10537. {
  10538. malloc_tsetword(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10539. break;
  10540. }
  10541. }
  10542. }
  10543. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10544. break;
  10545. }
  10546. }
  10547. // set the identifying cmd for the packet_db version
  10548. if (strcmp(str[2],"wanttoconnection")==0)
  10549. clif_config.connect_cmd[packet_ver] = cmd;
  10550. if(str[3]==NULL){
  10551. ShowError("packet_db: packet error\n");
  10552. exit(1);
  10553. }
  10554. for(j=0,p2=str[3];p2;j++){
  10555. str2[j]=p2;
  10556. p2=strchr(p2,':');
  10557. if(p2) *p2++=0;
  10558. k = atoi(str2[j]);
  10559. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10560. packet_db[packet_ver][cmd].pos[j] = k;
  10561. }
  10562. ln++;
  10563. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10564. // 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);
  10565. }
  10566. fclose(fp);
  10567. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10568. { //Locate the nearest version that we still support. [Skotlex]
  10569. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10570. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10571. }
  10572. 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);
  10573. return 0;
  10574. }
  10575. /*==========================================
  10576. *
  10577. *------------------------------------------
  10578. */
  10579. int do_init_clif(void) {
  10580. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10581. malloc_tsetdword(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10582. malloc_tsetword(packet_db,0,sizeof(packet_db));
  10583. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10584. packetdb_readdb();
  10585. set_defaultparse(clif_parse);
  10586. if (!make_listen_bind(bind_ip,map_port)) {
  10587. ShowFatalError("cant bind game port\n");
  10588. exit(1);
  10589. }
  10590. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10591. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10592. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10593. add_timer_func_list(clif_nighttimer, "clif_nighttimer");
  10594. add_timer_func_list(clif_walktoxy_timer, "clif_walktoxy_timer");
  10595. return 0;
  10596. }