clif.c 321 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841
  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. #ifdef __WIN32
  12. #define __USE_W32_SOCKETS
  13. #include <windows.h>
  14. #else
  15. #include <unistd.h>
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #include <netinet/in.h>
  19. #include <arpa/inet.h>
  20. #endif
  21. #include <time.h>
  22. #include "../common/socket.h"
  23. #include "../common/timer.h"
  24. #include "../common/malloc.h"
  25. #include "../common/version.h"
  26. #include "../common/nullpo.h"
  27. #include "../common/showmsg.h"
  28. #include "map.h"
  29. #include "chrif.h"
  30. #include "clif.h"
  31. #include "pc.h"
  32. #include "status.h"
  33. #include "npc.h"
  34. #include "itemdb.h"
  35. #include "chat.h"
  36. #include "trade.h"
  37. #include "storage.h"
  38. #include "script.h"
  39. #include "skill.h"
  40. #include "atcommand.h"
  41. #include "charcommand.h"
  42. #include "intif.h"
  43. #include "battle.h"
  44. #include "mob.h"
  45. #include "party.h"
  46. #include "unit.h"
  47. #include "guild.h"
  48. #include "vending.h"
  49. #include "pet.h"
  50. #include "log.h"
  51. #include "irc.h"
  52. struct Clif_Config {
  53. int packet_db_ver; //Preferred packet version.
  54. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  55. } clif_config;
  56. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
  57. static const int packet_len_table[MAX_PACKET_DB] = {
  58. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  59. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  60. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  61. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  62. //#0x0040
  63. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  64. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  65. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  66. #if PACKETVER < 2
  67. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  68. #else // 78-7b 亀島以降 lv99エフェクト用
  69. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  70. #endif
  71. //#0x0080
  72. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  73. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  74. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  75. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  76. //#0x00C0
  77. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  78. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  79. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  80. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  81. //#0x0100
  82. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  83. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  84. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  85. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  86. //#0x0140
  87. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  88. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  89. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  90. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  91. //#0x0180
  92. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  93. #if PACKETVER < 1
  94. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  95. #else // 196 comodo以降 状態表示アイコン用
  96. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  97. #endif
  98. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  99. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  100. //#0x01C0, Set 0x1d5=-1
  101. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  102. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  103. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  104. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  105. //#0x200
  106. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  107. 22, 0, 26, 26, 42, -1, -1, 2, 2,282,282,10, 10, -1, -1, 66,
  108. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 69, 5,
  109. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  110. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  111. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4
  112. };
  113. // local define
  114. enum {
  115. ALL_CLIENT,
  116. ALL_SAMEMAP,
  117. AREA,
  118. AREA_WOS,
  119. AREA_WOC,
  120. AREA_WOSC,
  121. AREA_CHAT_WOC,
  122. CHAT,
  123. CHAT_WOS,
  124. CHAT_MAINCHAT,
  125. PARTY,
  126. PARTY_WOS,
  127. PARTY_SAMEMAP,
  128. PARTY_SAMEMAP_WOS,
  129. PARTY_AREA,
  130. PARTY_AREA_WOS,
  131. GUILD,
  132. GUILD_WOS,
  133. GUILD_SAMEMAP, // [Valaris]
  134. GUILD_SAMEMAP_WOS,
  135. GUILD_AREA,
  136. GUILD_AREA_WOS, // end additions [Valaris]
  137. SELF
  138. };
  139. //Converts item type in case of pet eggs.
  140. #define itemtype(a) (a == 7)?4:a
  141. #define WBUFPOS(p,pos,x,y) { unsigned char *__p = (p); __p+=(pos); __p[0] = (x)>>2; __p[1] = ((x)<<6) | (((y)>>4)&0x3f); __p[2] = (y)<<4; }
  142. #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); }
  143. #define WFIFOPOS(fd,pos,x,y) { WBUFPOS (WFIFOP(fd,pos),0,x,y); }
  144. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1) { WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1); }
  145. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  146. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  147. //Removed sd->npc_shopid because there is no packet sent from the client when you cancel a buy!
  148. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  149. #define clif_cant_act(sd) (sd->npc_id || sd->vender_id || sd->chatID || sd->sc.opt1 || sd->state.trading || sd->state.storage_flag)
  150. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  151. #define clif_trading(sd) (sd->npc_id || sd->vender_id || sd->state.trading )
  152. //To idenfity disguised characters.
  153. #define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
  154. static char map_ip_str[16];
  155. static in_addr_t map_ip;
  156. static in_addr_t bind_ip = INADDR_ANY;
  157. static int map_port = 5121;
  158. int map_fd;
  159. char talkie_mes[MESSAGE_SIZE];
  160. //These two will be used to verify the incoming player's validity.
  161. //It helps identify their client packet version correctly. [Skotlex]
  162. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  163. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  164. int clif_parse (int fd);
  165. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  166. /*==========================================
  167. * map鯖のip設定
  168. *------------------------------------------
  169. */
  170. void clif_setip(char *ip)
  171. {
  172. memcpy(map_ip_str, ip, 16);
  173. map_ip = inet_addr(map_ip_str);
  174. }
  175. void clif_setbindip(char *ip)
  176. {
  177. bind_ip = inet_addr(ip);
  178. }
  179. /*==========================================
  180. * map鯖のport設定
  181. *------------------------------------------
  182. */
  183. void clif_setport(int port)
  184. {
  185. map_port = port;
  186. }
  187. /*==========================================
  188. * map鯖のip読み出し
  189. *------------------------------------------
  190. */
  191. in_addr_t clif_getip(void)
  192. {
  193. return map_ip;
  194. }
  195. /*==========================================
  196. * map鯖のport読み出し
  197. *------------------------------------------
  198. */
  199. int clif_getport(void)
  200. {
  201. return map_port;
  202. }
  203. /*==========================================
  204. * Counts connected players.
  205. *------------------------------------------
  206. */
  207. int clif_countusers(void)
  208. {
  209. int users = 0, i;
  210. struct map_session_data *sd;
  211. for(i = 0; i < fd_max; i++) {
  212. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) && sd->state.auth &&
  213. !(battle_config.hide_GM_session && pc_isGM(sd)))
  214. users++;
  215. }
  216. return users;
  217. }
  218. /*==========================================
  219. * 全てのclientに対してfunc()実行
  220. *------------------------------------------
  221. */
  222. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  223. {
  224. int i;
  225. va_list ap;
  226. struct map_session_data *sd;
  227. va_start(ap,func);
  228. for(i = 0; i < fd_max; i++) {
  229. if ( session[i] ) {
  230. sd = (struct map_session_data*)session[i]->session_data;
  231. if ( sd && session[i]->func_parse == clif_parse &&
  232. sd->state.auth && !sd->state.waitingdisconnect )
  233. func(sd, ap);
  234. }
  235. }
  236. va_end(ap);
  237. return 0;
  238. }
  239. /*==========================================
  240. * clif_sendでAREA*指定時用
  241. *------------------------------------------
  242. */
  243. int clif_send_sub(struct block_list *bl, va_list ap)
  244. {
  245. struct block_list *src_bl;
  246. struct map_session_data *sd;
  247. unsigned char *buf;
  248. int len, type;
  249. nullpo_retr(0, bl);
  250. nullpo_retr(0, ap);
  251. nullpo_retr(0, sd = (struct map_session_data *)bl);
  252. if (!sd->fd) //Avoid attempting to send to disconnected chars (may prevent buffer overrun errors?) [Skotlex]
  253. return 0;
  254. buf = va_arg(ap,unsigned char*);
  255. len = va_arg(ap,int);
  256. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  257. type = va_arg(ap,int);
  258. switch(type) {
  259. case AREA_WOS:
  260. if (bl == src_bl)
  261. return 0;
  262. break;
  263. case AREA_WOC:
  264. if (sd->chatID || bl == src_bl)
  265. return 0;
  266. break;
  267. case AREA_WOSC:
  268. {
  269. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  270. if ((ssd != 0) && (src_bl->type == BL_PC) && (sd->chatID != 0) && (sd->chatID == ssd->chatID))
  271. return 0;
  272. }
  273. break;
  274. }
  275. if (session[sd->fd] != NULL) {
  276. WFIFOHEAD(sd->fd, len);
  277. if (WFIFOP(sd->fd,0) == buf) {
  278. printf("WARNING: Invalid use of clif_send function\n");
  279. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  280. printf(" Please correct your code.\n");
  281. // don't send to not move the pointer of the packet for next sessions in the loop
  282. } else {
  283. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  284. memcpy(WFIFOP(sd->fd,0), buf, len);
  285. //Check if hidden, better to modify the char's buffer than the
  286. //given buffer to prevent intravision affecting the packet as
  287. //it's being received by everyone. [Skotlex]
  288. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 )
  289. && bl != src_bl && WFIFOW(sd->fd,0) == 0x0196)
  290. { //New intravision method, just modify the status change/start packet. [Skotlex]
  291. switch (WFIFOW(sd->fd,2)) {
  292. case SI_HIDING:
  293. case SI_CLOAKING:
  294. case SI_CHASEWALK:
  295. WFIFOW(sd->fd,2) = SI_INTRAVISION;
  296. }
  297. }
  298. /* Previous implementation.
  299. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 ) && bl != src_bl) {
  300. struct status_change *sc = status_get_sc(src_bl);
  301. if(sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK)))
  302. { //optionの修正
  303. switch(((unsigned short*)buf)[0])
  304. {
  305. case 0x119:
  306. WFIFOW(sd->fd,10) &= ~(OPTION_HIDE|OPTION_CLOAK);
  307. break;
  308. #if PACKETVER < 4
  309. case 0x78:
  310. #else
  311. case 0x1da:
  312. #endif
  313. case 0x7b:
  314. case 0x7c:
  315. case 0x1d8:
  316. WFIFOW(sd->fd,12) &=~(OPTION_HIDE|OPTION_CLOAK);
  317. break;
  318. }
  319. }
  320. }
  321. */
  322. WFIFOSET(sd->fd,len);
  323. }
  324. }
  325. }
  326. return 0;
  327. }
  328. /*==========================================
  329. *
  330. *------------------------------------------
  331. */
  332. int clif_send (unsigned char *buf, int len, struct block_list *bl, int type) {
  333. int i;
  334. struct map_session_data *sd = NULL;
  335. struct party *p = NULL;
  336. struct guild *g = NULL;
  337. int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
  338. if (type != ALL_CLIENT &&
  339. type != CHAT_MAINCHAT) {
  340. nullpo_retr(0, bl);
  341. if (bl->type == BL_PC) {
  342. sd = (struct map_session_data *)bl;
  343. }
  344. }
  345. switch(type) {
  346. case ALL_CLIENT: // 全クライアントに送信
  347. for (i = 0; i < fd_max; i++) {
  348. if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL && sd->state.auth) {
  349. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  350. WFIFOHEAD(i, len);
  351. memcpy(WFIFOP(i,0), buf, len);
  352. WFIFOSET(i,len);
  353. }
  354. }
  355. }
  356. break;
  357. case ALL_SAMEMAP: // 同じマップの全クライアントに送信
  358. for(i = 0; i < fd_max; i++) {
  359. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  360. sd->state.auth && sd->bl.m == bl->m) {
  361. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  362. WFIFOHEAD(i,len);
  363. memcpy(WFIFOP(i,0), buf, len);
  364. WFIFOSET(i,len);
  365. }
  366. }
  367. }
  368. break;
  369. case AREA:
  370. case AREA_WOS:
  371. case AREA_WOC:
  372. case AREA_WOSC:
  373. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  374. BL_PC, buf, len, bl, type);
  375. break;
  376. case AREA_CHAT_WOC:
  377. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  378. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  379. break;
  380. case CHAT:
  381. case CHAT_WOS:
  382. {
  383. struct chat_data *cd;
  384. if (sd) {
  385. cd = (struct chat_data*)map_id2bl(sd->chatID);
  386. } else if (bl->type == BL_CHAT) {
  387. cd = (struct chat_data*)bl;
  388. } else break;
  389. if (cd == NULL)
  390. break;
  391. for(i = 0; i < cd->users; i++) {
  392. if (type == CHAT_WOS && cd->usersd[i] == sd)
  393. continue;
  394. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  395. if (cd->usersd[i]->fd >0 && session[cd->usersd[i]->fd]) // Added check to see if session exists [PoW]
  396. {
  397. WFIFOHEAD(cd->usersd[i]->fd,len);
  398. memcpy(WFIFOP(cd->usersd[i]->fd,0), buf, len);
  399. WFIFOSET(cd->usersd[i]->fd,len);
  400. }
  401. }
  402. }
  403. }
  404. break;
  405. case CHAT_MAINCHAT: //[LuzZza]
  406. for(i=1; i<fd_max; i++) {
  407. if(session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  408. sd->state.mainchat && sd->fd) {
  409. WFIFOHEAD(sd->fd, len);
  410. memcpy(WFIFOP(sd->fd,0), buf, len);
  411. WFIFOSET(sd->fd, len);
  412. }
  413. }
  414. break;
  415. case PARTY_AREA: // 同じ画面内の全パーティーメンバに送信
  416. case PARTY_AREA_WOS: // 自分以外の同じ画面内の全パーティーメンバに送信
  417. x0 = bl->x - AREA_SIZE;
  418. y0 = bl->y - AREA_SIZE;
  419. x1 = bl->x + AREA_SIZE;
  420. y1 = bl->y + AREA_SIZE;
  421. case PARTY: // 全パーティーメンバに送信
  422. case PARTY_WOS: // 自分以外の全パーティーメンバに送信
  423. case PARTY_SAMEMAP: // 同じマップの全パーティーメンバに送信
  424. case PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信
  425. if (sd && sd->status.party_id)
  426. p = party_search(sd->status.party_id);
  427. if (p) {
  428. for(i=0;i<MAX_PARTY;i++){
  429. if ((sd = p->member[i].sd) != NULL) {
  430. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  431. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  432. continue;
  433. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  434. continue;
  435. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m) // マップチェック
  436. continue;
  437. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  438. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  439. continue;
  440. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  441. WFIFOHEAD(sd->fd,len);
  442. memcpy(WFIFOP(sd->fd,0), buf, len);
  443. WFIFOSET(sd->fd,len);
  444. }
  445. }
  446. }
  447. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  448. break;
  449. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  450. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL && sd->state.auth && sd->fd && sd->partyspy) {
  451. if (sd->partyspy == p->party_id) {
  452. if (sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  453. WFIFOHEAD(sd->fd,len);
  454. memcpy(WFIFOP(sd->fd,0), buf, len);
  455. WFIFOSET(sd->fd,len);
  456. }
  457. }
  458. }
  459. }
  460. }
  461. break;
  462. case SELF:
  463. if (sd && sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  464. WFIFOHEAD(sd->fd,len);
  465. memcpy(WFIFOP(sd->fd,0), buf, len);
  466. WFIFOSET(sd->fd,len);
  467. }
  468. break;
  469. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  470. case GUILD_AREA:
  471. case GUILD_AREA_WOS:
  472. x0 = bl->x - AREA_SIZE;
  473. y0 = bl->y - AREA_SIZE;
  474. x1 = bl->x + AREA_SIZE;
  475. y1 = bl->y + AREA_SIZE;
  476. case GUILD_SAMEMAP:
  477. case GUILD_SAMEMAP_WOS:
  478. case GUILD:
  479. case GUILD_WOS:
  480. if (sd && sd->status.guild_id)
  481. g = guild_search(sd->status.guild_id);
  482. if (g) {
  483. for(i = 0; i < g->max_member; i++) {
  484. if ((sd = g->member[i].sd) != NULL) {
  485. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  486. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  487. continue;
  488. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  489. continue;
  490. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  491. continue;
  492. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  493. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  494. continue;
  495. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  496. WFIFOHEAD(sd->fd,len);
  497. memcpy(WFIFOP(sd->fd,0), buf, len);
  498. WFIFOSET(sd->fd,len);
  499. }
  500. }
  501. }
  502. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  503. break;
  504. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  505. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL && sd->state.auth && sd->fd && sd->guildspy) {
  506. if (sd->guildspy == g->guild_id) {
  507. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  508. WFIFOHEAD(sd->fd,len);
  509. memcpy(WFIFOP(sd->fd,0), buf, len);
  510. WFIFOSET(sd->fd,len);
  511. }
  512. }
  513. }
  514. }
  515. }
  516. break;
  517. /* End [Valaris] */
  518. default:
  519. if (battle_config.error_log)
  520. ShowError("clif_send: Unrecognized type %d\n",type);
  521. return -1;
  522. }
  523. return 0;
  524. }
  525. //
  526. // パケット作って送信
  527. //
  528. /*==========================================
  529. *
  530. *------------------------------------------
  531. */
  532. int clif_authok(struct map_session_data *sd) {
  533. int fd;
  534. if (!sd->fd)
  535. return 0;
  536. fd = sd->fd;
  537. WFIFOHEAD(fd, packet_len_table[0x73]);
  538. WFIFOW(fd, 0) = 0x73;
  539. WFIFOL(fd, 2) = gettick();
  540. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y);
  541. WFIFOB(fd, 9) = 5;
  542. WFIFOB(fd,10) = 5;
  543. WFIFOSET(fd,packet_len_table[0x73]);
  544. return 0;
  545. }
  546. /*==========================================
  547. *
  548. *------------------------------------------
  549. */
  550. int clif_authfail_fd(int fd, int type) {
  551. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  552. return 0;
  553. WFIFOHEAD(fd, packet_len_table[0x81]);
  554. WFIFOW(fd,0) = 0x81;
  555. WFIFOB(fd,2) = type;
  556. WFIFOSET(fd,packet_len_table[0x81]);
  557. clif_setwaitclose(fd);
  558. return 0;
  559. }
  560. /*==========================================
  561. * Used to know which is the max valid account/char id [Skotlex]
  562. *------------------------------------------
  563. */
  564. void clif_updatemaxid(int account_id, int char_id)
  565. {
  566. max_account_id = account_id;
  567. max_char_id = char_id;
  568. }
  569. /*==========================================
  570. *
  571. *------------------------------------------
  572. */
  573. int clif_charselectok(int id) {
  574. struct map_session_data *sd;
  575. int fd;
  576. if ((sd = map_id2sd(id)) == NULL)
  577. return 1;
  578. if (!sd->fd)
  579. return 1;
  580. fd = sd->fd;
  581. WFIFOHEAD(fd, packet_len_table[0xb3]);
  582. WFIFOW(fd,0) = 0xb3;
  583. WFIFOB(fd,2) = 1;
  584. WFIFOSET(fd,packet_len_table[0xb3]);
  585. return 0;
  586. }
  587. /*==========================================
  588. *
  589. *------------------------------------------
  590. */
  591. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  592. int view;
  593. nullpo_retr(0, fitem);
  594. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  595. WBUFW(buf, 0) = 0x9e;
  596. WBUFL(buf, 2) = fitem->bl.id;
  597. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  598. WBUFW(buf, 6) = view;
  599. else
  600. WBUFW(buf, 6) = fitem->item_data.nameid;
  601. WBUFB(buf, 8) = fitem->item_data.identify;
  602. WBUFW(buf, 9) = fitem->bl.x;
  603. WBUFW(buf,11) = fitem->bl.y;
  604. WBUFB(buf,13) = fitem->subx;
  605. WBUFB(buf,14) = fitem->suby;
  606. WBUFW(buf,15) = fitem->item_data.amount;
  607. return packet_len_table[0x9e];
  608. }
  609. /*==========================================
  610. *
  611. *------------------------------------------
  612. */
  613. int clif_dropflooritem(struct flooritem_data *fitem) {
  614. unsigned char buf[64];
  615. nullpo_retr(0, fitem);
  616. if (fitem->item_data.nameid <= 0)
  617. return 0;
  618. clif_set009e(fitem, buf);
  619. clif_send(buf, packet_len_table[0x9e], &fitem->bl, AREA);
  620. return 0;
  621. }
  622. /*==========================================
  623. *
  624. *------------------------------------------
  625. */
  626. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  627. unsigned char buf[16];
  628. nullpo_retr(0, fitem);
  629. WBUFW(buf,0) = 0xa1;
  630. WBUFL(buf,2) = fitem->bl.id;
  631. if (fd == 0) {
  632. clif_send(buf, packet_len_table[0xa1], &fitem->bl, AREA);
  633. } else {
  634. WFIFOHEAD(fd,packet_len_table[0xa1]);
  635. memcpy(WFIFOP(fd,0), buf, 6);
  636. WFIFOSET(fd,packet_len_table[0xa1]);
  637. }
  638. return 0;
  639. }
  640. /*==========================================
  641. *
  642. *------------------------------------------
  643. */
  644. int clif_clearchar(struct block_list *bl, int type) {
  645. unsigned char buf[16];
  646. nullpo_retr(0, bl);
  647. WBUFW(buf,0) = 0x80;
  648. WBUFL(buf,2) = bl->id;
  649. WBUFB(buf,6) = type;
  650. clif_send(buf, packet_len_table[0x80], bl, type == 1 ? AREA : AREA_WOS);
  651. if(disguised(bl)) {
  652. WBUFL(buf,2) = -bl->id;
  653. clif_send(buf, packet_len_table[0x80], bl, SELF);
  654. }
  655. return 0;
  656. }
  657. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  658. struct block_list *bl = (struct block_list *)id;
  659. clif_clearchar(bl,data);
  660. aFree(bl);
  661. return 0;
  662. }
  663. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  664. struct block_list *tbl;
  665. tbl = aMalloc(sizeof (struct block_list));
  666. memcpy (tbl, bl, sizeof (struct block_list));
  667. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  668. return 0;
  669. }
  670. /*==========================================
  671. *
  672. *------------------------------------------
  673. */
  674. int clif_clearchar_id(int id, int type, int fd) {
  675. WFIFOHEAD(fd, packet_len_table[0x80]);
  676. WFIFOW(fd,0) = 0x80;
  677. WFIFOL(fd,2) = id;
  678. WFIFOB(fd,6) = (char)type; // Why use int for a char in the first place?
  679. WFIFOSET(fd, packet_len_table[0x80]);
  680. return 0;
  681. }
  682. void clif_get_weapon_view(TBL_PC* sd, unsigned short *rhand, unsigned short *lhand)
  683. {
  684. #if PACKETVER > 3
  685. struct item_data *id;
  686. #endif
  687. if(sd->sc.option&OPTION_WEDDING || sd->vd.class_ == JOB_XMAS)
  688. {
  689. *rhand = *lhand = 0;
  690. return;
  691. }
  692. #if PACKETVER < 4
  693. *rhand = sd->status.weapon;
  694. *lhand = sd->status.shield;
  695. #else
  696. if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]])
  697. {
  698. id = sd->inventory_data[sd->equip_index[9]];
  699. if (id->view_id > 0)
  700. *rhand = id->view_id;
  701. else
  702. *rhand = id->nameid;
  703. } else
  704. *rhand = 0;
  705. if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
  706. && sd->inventory_data[sd->equip_index[8]])
  707. {
  708. id = sd->inventory_data[sd->equip_index[8]];
  709. if (id->view_id > 0)
  710. *lhand = id->view_id;
  711. else
  712. *lhand = id->nameid;
  713. } else
  714. *lhand = 0;
  715. #endif
  716. }
  717. static void clif_get_guild_data(struct block_list *bl, long *guild_id, short *emblem_id)
  718. {
  719. //TODO: There has to be a way to clean this up.
  720. switch (bl->type) {
  721. case BL_PC:
  722. *guild_id = ((TBL_PC*)bl)->status.guild_id;
  723. *emblem_id = ((TBL_PC*)bl)->guild_emblem_id;
  724. break;
  725. case BL_MOB:
  726. if (((TBL_MOB*)bl)->guardian_data) {
  727. *guild_id =((TBL_MOB*)bl)->guardian_data->guild_id;
  728. *emblem_id =((TBL_MOB*)bl)->guardian_data->emblem_id;
  729. }
  730. break;
  731. case BL_NPC:
  732. if (bl->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) {
  733. struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id);
  734. if (g) {
  735. *guild_id =g->guild_id;
  736. *emblem_id =g->emblem_id;
  737. }
  738. }
  739. break;
  740. default:
  741. *guild_id = status_get_guild_id(bl);
  742. }
  743. return;
  744. }
  745. /*==========================================
  746. *
  747. *------------------------------------------
  748. */
  749. static int clif_set0078(struct block_list *bl, struct view_data *vd, unsigned char *buf) {
  750. struct status_change *sc;
  751. struct map_session_data *sd;
  752. long guild_id=0;
  753. unsigned short emblem_id=0, lv;
  754. unsigned short dir;
  755. nullpo_retr(0, bl);
  756. BL_CAST(BL_PC, bl, sd);
  757. sc = status_get_sc(bl);
  758. clif_get_guild_data(bl, &guild_id, &emblem_id);
  759. dir = unit_getdir(bl);
  760. lv = status_get_lv(bl);
  761. if(pcdb_checkid(vd->class_)) {
  762. #if PACKETVER > 3
  763. memset(buf,0,packet_len_table[0x1d8]);
  764. WBUFW(buf,0)=0x1d8;
  765. WBUFL(buf,2)=bl->id;
  766. WBUFW(buf,6)=status_get_speed(bl);
  767. if (sc) {
  768. WBUFW(buf,8)=sc->opt1;
  769. WBUFW(buf,10)=sc->opt2;
  770. WBUFW(buf,12)=sc->option;
  771. WBUFW(buf,42)=sc->opt3;
  772. }
  773. WBUFW(buf,14)=vd->class_;
  774. WBUFW(buf,16)=vd->hair_style;
  775. WBUFW(buf,18)=vd->weapon;
  776. WBUFW(buf,20)=vd->shield;
  777. WBUFW(buf,22)=vd->head_bottom;
  778. WBUFW(buf,24)=vd->head_top;
  779. WBUFW(buf,26)=vd->head_mid;
  780. WBUFW(buf,28)=vd->hair_color;
  781. WBUFW(buf,30)=vd->cloth_color;
  782. WBUFW(buf,32)=sd?sd->head_dir:dir;
  783. WBUFL(buf,34)=guild_id;
  784. WBUFW(buf,38)=emblem_id;
  785. if (sd) {
  786. WBUFW(buf,40)=sd->status.manner;
  787. WBUFB(buf,44)=sd->status.karma;
  788. }
  789. WBUFB(buf,45)=vd->sex;
  790. WBUFPOS(buf,46,bl->x,bl->y);
  791. WBUFB(buf,48)|=dir & 0x0f;
  792. WBUFB(buf,49)=5;
  793. WBUFB(buf,50)=5;
  794. WBUFB(buf,51)=vd->dead_sit;
  795. WBUFW(buf,52)=clif_setlevel(lv);
  796. return packet_len_table[0x1d8];
  797. #else
  798. memset(buf,0,packet_len_table[0x78]);
  799. WBUFW(buf,0)=0x78;
  800. WBUFL(buf,2)=bl->id;
  801. WBUFW(buf,6)=status_get_speed(bl);
  802. if (sc) {
  803. WBUFW(buf,8)=sc->opt1;
  804. WBUFW(buf,10)=sc->opt2;
  805. WBUFW(buf,12)=sc->option;
  806. WBUFW(buf,42)=sc->opt3;
  807. }
  808. WBUFW(buf,14)=vd->class_;
  809. WBUFW(buf,16)=vd->hair_style;
  810. WBUFW(buf,18)=vd->weapon;
  811. WBUFW(buf,20)=vd->head_bottom;
  812. WBUFW(buf,22)=vd->shield;
  813. WBUFW(buf,24)=vd->head_top;
  814. WBUFW(buf,26)=vd->head_mid;
  815. WBUFW(buf,28)=vd->hair_color;
  816. WBUFW(buf,30)=vd->cloth_color;
  817. WBUFW(buf,32)=sd?sd->head_dir:dir;
  818. WBUFL(buf,34)=guild_id;
  819. WBUFL(buf,38)=emblem_id;
  820. if (sd)
  821. WBUFB(buf,44)=sd->status.karma;
  822. WBUFB(buf,45)=vd->sex;
  823. WBUFPOS(buf,46,bl->x,bl->y);
  824. WBUFB(buf,48)|=dir&0x0f;
  825. WBUFB(buf,49)=5;
  826. WBUFB(buf,50)=5;
  827. WBUFB(buf,51)=vd->dead_sit;
  828. WBUFW(buf,52)=clif_setlevel(lv);
  829. return packet_len_table[0x78];
  830. #endif
  831. }
  832. //Non-player sprites need just a few fields filled.
  833. memset(buf,0,packet_len_table[0x78]);
  834. WBUFW(buf,0)=0x78;
  835. WBUFL(buf,2)=bl->id;
  836. WBUFW(buf,6)=status_get_speed(bl);
  837. if (sc) {
  838. WBUFW(buf,8)=sc->opt1;
  839. WBUFW(buf,10)=sc->opt2;
  840. WBUFW(buf,12)=sc->option;
  841. WBUFW(buf,42)=sc->opt3;
  842. }
  843. WBUFW(buf,14)=vd->class_;
  844. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  845. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  846. if (bl->type == BL_NPC && vd->class_ == 722)
  847. { //The hell, why flags work like this?
  848. WBUFL(buf,22)=emblem_id;
  849. WBUFL(buf,26)=guild_id;
  850. }
  851. WBUFW(buf,32)=dir;
  852. WBUFL(buf,34)=guild_id;
  853. WBUFL(buf,38)=emblem_id;
  854. WBUFPOS(buf,46,bl->x,bl->y);
  855. WBUFB(buf,48)|=dir&0x0f;
  856. WBUFB(buf,49)=5;
  857. WBUFB(buf,50)=5;
  858. WBUFW(buf,52)=clif_setlevel(lv);
  859. return packet_len_table[0x78];
  860. }
  861. /*==========================================
  862. *
  863. *------------------------------------------
  864. */
  865. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf) {
  866. struct status_change *sc;
  867. struct map_session_data *sd;
  868. long guild_id=0;
  869. unsigned short emblem_id=0, lv;
  870. nullpo_retr(0, bl);
  871. BL_CAST(BL_PC, bl, sd);
  872. sc = status_get_sc(bl);
  873. clif_get_guild_data(bl, &guild_id, &emblem_id);
  874. lv = status_get_lv(bl);
  875. if(pcdb_checkid(vd->class_)) {
  876. #if PACKETVER > 6
  877. memset(buf,0,packet_len_table[0x22c]);
  878. WBUFW(buf,0)=0x22c;
  879. WBUFL(buf,2)=bl->id;
  880. WBUFW(buf,6)=status_get_speed(bl);
  881. if (sc) {
  882. WBUFW(buf,8)= sc->opt1;
  883. WBUFW(buf,10)= sc->opt2;
  884. WBUFL(buf,12)= sc->option;
  885. WBUFL(buf,48)= sc->opt3;
  886. }
  887. WBUFW(buf,16)=vd->class_;
  888. WBUFW(buf,18)=vd->hair_style;
  889. WBUFW(buf,20)=vd->weapon;
  890. WBUFW(buf,22)=vd->shield;
  891. WBUFW(buf,24)=vd->head_bottom;
  892. WBUFL(buf,26)=gettick();
  893. WBUFW(buf,30)=vd->head_top;
  894. WBUFW(buf,32)=vd->head_mid;
  895. WBUFW(buf,34)=vd->hair_color;
  896. WBUFW(buf,36)=vd->cloth_color;
  897. WBUFW(buf,38)=sd?sd->head_dir:unit_getdir(bl);
  898. WBUFL(buf,40)=guild_id;
  899. WBUFW(buf,44)=emblem_id;
  900. if (sd) {
  901. WBUFW(buf,46)=sd->status.manner;
  902. WBUFB(buf,52)=sd->status.karma;
  903. }
  904. WBUFB(buf,53)=vd->sex;
  905. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  906. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  907. WBUFB(buf,60)=0;
  908. WBUFB(buf,61)=0;
  909. WBUFW(buf,62)=clif_setlevel(lv);
  910. return packet_len_table[0x22c];
  911. #elif PACKETVER > 3
  912. memset(buf,0,packet_len_table[0x1da]);
  913. WBUFW(buf,0)=0x1da;
  914. WBUFL(buf,2)=bl->id;
  915. WBUFW(buf,6)=status_get_speed(bl);
  916. if (sc) {
  917. WBUFW(buf,8)=sc->opt1;
  918. WBUFW(buf,10)=sc->opt2;
  919. WBUFW(buf,12)=sc->option;
  920. WBUFW(buf,46)=sc->opt3;
  921. }
  922. WBUFW(buf,14)=vd->class_;
  923. WBUFW(buf,16)=vd->hair_style;
  924. WBUFW(buf,18)=vd->weapon;
  925. WBUFW(buf,20)=vd->shield;
  926. WBUFW(buf,22)=vd->head_bottom;
  927. WBUFL(buf,24)=gettick();
  928. WBUFW(buf,28)=vd->head_top;
  929. WBUFW(buf,30)=vd->head_mid;
  930. WBUFW(buf,32)=vd->hair_color;
  931. WBUFW(buf,34)=vd->cloth_color;
  932. WBUFW(buf,36)=sd?sd->head_dir:unit_getdir(bl);
  933. WBUFL(buf,38)=guild_id;
  934. WBUFW(buf,42)=emblem_id;
  935. if (sd) {
  936. WBUFW(buf,44)=sd->status.manner;
  937. WBUFB(buf,48)=sd->status.karma;
  938. }
  939. WBUFB(buf,49)=vd->sex;
  940. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  941. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  942. WBUFB(buf,56)=5;
  943. WBUFB(buf,57)=5;
  944. WBUFW(buf,58)=clif_setlevel(lv);
  945. return packet_len_table[0x1da];
  946. #else
  947. memset(buf,0,packet_len_table[0x7b]);
  948. WBUFW(buf,0)=0x7b;
  949. WBUFL(buf,2)=bl->id;
  950. WBUFW(buf,6)=status_get_speed(bl);
  951. if (sc) {
  952. WBUFW(buf,8)=sc->opt1;
  953. WBUFW(buf,10)=sc->opt2;
  954. WBUFW(buf,12)=sc->option;
  955. WBUFW(buf,46)=sc->opt3;
  956. }
  957. WBUFW(buf,14)=vd->class_;
  958. WBUFW(buf,16)=vd->hair_style;
  959. WBUFW(buf,18)=vd->weapon;
  960. WBUFW(buf,20)=vd->head_bottom;
  961. WBUFL(buf,22)=gettick();
  962. WBUFW(buf,26)=vd->shield;
  963. WBUFW(buf,28)=vd->head_top;
  964. WBUFW(buf,30)=vd->head_mid;
  965. WBUFW(buf,32)=vd->hair_color;
  966. WBUFW(buf,34)=vd->cloth_color;
  967. WBUFW(buf,36)=sd?sd->head_dir:unit_getdir(bl);
  968. WBUFL(buf,38)=guild_id;
  969. WBUFL(buf,42)=emblem_id;
  970. if (sd)
  971. WBUFB(buf,48)=sd->status.karma;
  972. WBUFB(buf,49)=vd->sex;
  973. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  974. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  975. WBUFB(buf,56)=5;
  976. WBUFB(buf,57)=5;
  977. WBUFW(buf,58)=clif_setlevel(lv);
  978. return packet_len_table[0x7b];
  979. #endif
  980. }
  981. //Non-player sprites only require a few fields.
  982. #if PACKETVER > 6
  983. memset(buf,0,packet_len_table[0x22c]);
  984. WBUFW(buf,0)=0x22c;
  985. WBUFL(buf,2)=bl->id;
  986. WBUFW(buf,6)=status_get_speed(bl);
  987. if (sc) {
  988. WBUFW(buf,8)=sc->opt1;
  989. WBUFW(buf,10)=sc->opt2;
  990. WBUFL(buf,12)=sc->option;
  991. WBUFL(buf,48)=sc->opt3;
  992. }
  993. WBUFW(buf,16)=vd->class_;
  994. WBUFW(buf,18)=vd->hair_style; //For pets
  995. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  996. WBUFL(buf,26)=gettick();
  997. WBUFW(buf,38)=unit_getdir(bl);
  998. WBUFL(buf,40)=guild_id;
  999. WBUFL(buf,44)=emblem_id;
  1000. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  1001. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  1002. WBUFB(buf,60)=0;
  1003. WBUFB(buf,61)=0;
  1004. WBUFW(buf,62)=clif_setlevel(lv);
  1005. return packet_len_table[0x22c];
  1006. #else
  1007. memset(buf,0,packet_len_table[0x7b]);
  1008. WBUFW(buf,0)=0x7b;
  1009. WBUFL(buf,2)=bl->id;
  1010. WBUFW(buf,6)=status_get_speed(bl);
  1011. if (sc) {
  1012. WBUFW(buf,8)=sc->opt1;
  1013. WBUFW(buf,10)=sc->opt2;
  1014. WBUFW(buf,12)=sc->option;
  1015. WBUFW(buf,46)=sc->opt3;
  1016. }
  1017. WBUFW(buf,14)=vd->class_;
  1018. WBUFW(buf,16)=vd->hair_style; //For pets
  1019. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  1020. WBUFL(buf,22)=gettick();
  1021. WBUFW(buf,36)=unit_getdir(bl);
  1022. WBUFL(buf,38)=guild_id;
  1023. WBUFL(buf,42)=emblem_id;
  1024. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1025. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1026. WBUFB(buf,56)=5;
  1027. WBUFB(buf,57)=5;
  1028. WBUFW(buf,58)=clif_setlevel(lv);
  1029. return packet_len_table[0x7b];
  1030. #endif
  1031. }
  1032. //Modifies the buffer for disguise characters and sends it to self.
  1033. //Flag = 0: change id to negative, buf will have disguise data.
  1034. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1035. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1036. //But no longer holds true for packet 0x22c
  1037. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag) {
  1038. if (flag) {
  1039. #if PACKETVER > 6
  1040. if (WBUFW(buf,0)==0x22c) {
  1041. WBUFL(buf,12)=OPTION_INVISIBLE;
  1042. WBUFW(buf,16)=sd->status.class_;
  1043. } else {
  1044. #endif
  1045. WBUFL(buf,2)=sd->bl.id;
  1046. WBUFW(buf,12)=OPTION_INVISIBLE;
  1047. WBUFW(buf,14)=sd->status.class_;
  1048. #if PACKETVER > 6
  1049. }
  1050. #endif
  1051. } else {
  1052. WBUFL(buf,2)=-sd->bl.id;
  1053. }
  1054. clif_send(buf, len, &sd->bl, SELF);
  1055. }
  1056. /*==========================================
  1057. * クラスチェンジ typeはMobの場合は1で他は0?
  1058. *------------------------------------------
  1059. */
  1060. int clif_class_change(struct block_list *bl,int class_,int type)
  1061. {
  1062. unsigned char buf[16];
  1063. nullpo_retr(0, bl);
  1064. if(!pcdb_checkid(class_)) {
  1065. WBUFW(buf,0)=0x1b0;
  1066. WBUFL(buf,2)=bl->id;
  1067. WBUFB(buf,6)=type;
  1068. WBUFL(buf,7)=class_;
  1069. clif_send(buf,packet_len_table[0x1b0],bl,AREA);
  1070. }
  1071. return 0;
  1072. }
  1073. /*==========================================
  1074. *
  1075. *------------------------------------------
  1076. */
  1077. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1078. {
  1079. WFIFOHEAD(fd, packet_len_table[0x1e1]);
  1080. WFIFOW(fd,0)=0x1e1;
  1081. WFIFOL(fd,2)=sd->bl.id;
  1082. WFIFOW(fd,6)=sd->spiritball;
  1083. WFIFOSET(fd, packet_len_table[0x1e1]);
  1084. }
  1085. /*==========================================
  1086. *
  1087. *------------------------------------------
  1088. */
  1089. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1090. WFIFOHEAD(fd, packet_len_table[0x192]);
  1091. WFIFOW(fd,0) = 0x192;
  1092. WFIFOW(fd,2) = x;
  1093. WFIFOW(fd,4) = y;
  1094. WFIFOW(fd,6) = type;
  1095. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1096. WFIFOSET(fd,packet_len_table[0x192]);
  1097. return 0;
  1098. }
  1099. /*==========================================
  1100. *
  1101. *------------------------------------------
  1102. */
  1103. static void clif_weather_check(struct map_session_data *sd) {
  1104. int m = sd->bl.m, fd = sd->fd;
  1105. if (map[m].flag.snow
  1106. || map[m].flag.clouds
  1107. || map[m].flag.fog
  1108. || map[m].flag.fireworks
  1109. || map[m].flag.sakura
  1110. || map[m].flag.leaves
  1111. || map[m].flag.rain
  1112. || map[m].flag.clouds2)
  1113. {
  1114. WFIFOHEAD(fd, packet_len_table[0x7c]);
  1115. WFIFOW(fd,0)=0x7c;
  1116. WFIFOL(fd,2)=-10;
  1117. WFIFOW(fd,6)=0;
  1118. WFIFOW(fd,8)=0;
  1119. WFIFOW(fd,10)=0;
  1120. WFIFOW(fd,12)=OPTION_INVISIBLE;
  1121. WFIFOW(fd,20)=100;
  1122. WFIFOPOS(fd,36,sd->bl.x,sd->bl.y);
  1123. WFIFOSET(fd,packet_len_table[0x7c]);
  1124. if (map[m].flag.snow)
  1125. clif_weather_sub(fd, 162);
  1126. if (map[m].flag.clouds)
  1127. clif_weather_sub(fd, 233);
  1128. if (map[m].flag.clouds2)
  1129. clif_weather_sub(fd, 516);
  1130. if (map[m].flag.fog)
  1131. clif_weather_sub(fd, 515);
  1132. if (map[m].flag.fireworks) {
  1133. clif_weather_sub(fd, 297);
  1134. clif_weather_sub(fd, 299);
  1135. clif_weather_sub(fd, 301);
  1136. }
  1137. if (map[m].flag.sakura)
  1138. clif_weather_sub(fd, 163);
  1139. if (map[m].flag.leaves)
  1140. clif_weather_sub(fd, 333);
  1141. if (map[m].flag.rain)
  1142. clif_weather_sub(fd, 161);
  1143. }
  1144. }
  1145. // new and improved weather display [Valaris]
  1146. int clif_weather_sub(int fd, int type) {
  1147. WFIFOHEAD(fd, packet_len_table[0x1f3]);
  1148. WFIFOW(fd,0) = 0x1f3;
  1149. WFIFOL(fd,2) = -10;
  1150. WFIFOL(fd,6) = type;
  1151. WFIFOSET(fd,packet_len_table[0x1f3]);
  1152. return 0;
  1153. }
  1154. int clif_weather(int m) {
  1155. int i;
  1156. struct map_session_data *sd=NULL;
  1157. for(i = 0; i < fd_max; i++) {
  1158. if (session[i] && (sd = session[i]->session_data) != NULL && sd->state.auth && sd->bl.m == m) {
  1159. WFIFOHEAD(sd->fd, packet_len_table[0x80]);
  1160. WFIFOW(sd->fd,0) = 0x80;
  1161. WFIFOL(sd->fd,2) = -10;
  1162. WFIFOB(sd->fd,6) = 0;
  1163. WFIFOSET(sd->fd,packet_len_table[0x80]);
  1164. clif_weather_check(sd);
  1165. }
  1166. }
  1167. return 0;
  1168. }
  1169. int clif_spawn(struct block_list *bl)
  1170. {
  1171. unsigned char buf[128];
  1172. struct view_data *vd;
  1173. nullpo_retr(0, bl);
  1174. vd = status_get_viewdata(bl);
  1175. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1176. return 0;
  1177. if (pcdb_checkid(vd->class_))
  1178. { //Player spawn packet.
  1179. if(((TBL_PC *)bl)->status.option & OPTION_INVISIBLE)
  1180. return 0;
  1181. clif_set0078(bl, vd, buf);
  1182. #if PACKETVER > 3
  1183. if (WBUFW(buf,0)==0x78) {
  1184. WBUFW(buf, 0) = 0x79;
  1185. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1186. clif_send(buf, packet_len_table[0x79], bl, AREA_WOS);
  1187. if (disguised(bl))
  1188. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x79], 0);
  1189. } else {
  1190. #endif
  1191. WBUFW(buf, 0) = 0x1d9;
  1192. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1193. clif_send(buf, packet_len_table[0x1d9], bl, AREA_WOS);
  1194. if (disguised(bl))
  1195. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x1d9], 0);
  1196. #if PACKETVER > 3
  1197. }
  1198. #endif
  1199. } else { //Mob spawn packet.
  1200. struct status_change *sc = status_get_sc(bl);
  1201. memset(buf,0,sizeof(buf));
  1202. WBUFW(buf,0)=0x7c;
  1203. WBUFL(buf,2)=bl->id;
  1204. WBUFW(buf,6)=status_get_speed(bl);
  1205. if (sc) {
  1206. WBUFW(buf,8)=sc->opt1;
  1207. WBUFW(buf,10)=sc->opt2;
  1208. WBUFW(buf,12)=sc->option;
  1209. }
  1210. WBUFW(buf,20)=vd->class_;
  1211. WBUFW(buf,22)=vd->hair_style; //Required for pets.
  1212. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  1213. WBUFPOS(buf,36,bl->x,bl->y);
  1214. clif_send(buf,packet_len_table[0x7c],bl,AREA_WOS);
  1215. if (disguised(bl)) {
  1216. WBUFL(buf,2)=-bl->id;
  1217. clif_send(buf,packet_len_table[0x7c],bl,SELF);
  1218. }
  1219. }
  1220. if (vd->cloth_color)
  1221. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1222. switch (bl->type)
  1223. {
  1224. case BL_PC:
  1225. {
  1226. TBL_PC *sd = ((TBL_PC*)bl);
  1227. if (sd->spiritball > 0)
  1228. clif_spiritball(sd);
  1229. if(sd->state.size==2) // tiny/big players [Valaris]
  1230. clif_specialeffect(bl,423,0);
  1231. else if(sd->state.size==1)
  1232. clif_specialeffect(bl,421,0);
  1233. }
  1234. break;
  1235. case BL_MOB:
  1236. {
  1237. TBL_MOB *md = ((TBL_MOB*)bl);
  1238. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1239. clif_specialeffect(&md->bl,423,0);
  1240. else if(md->special_state.size==1)
  1241. clif_specialeffect(&md->bl,421,0);
  1242. }
  1243. break;
  1244. }
  1245. return 0;
  1246. }
  1247. /*==========================================
  1248. *
  1249. *------------------------------------------
  1250. */
  1251. int clif_servertick(struct map_session_data *sd)
  1252. {
  1253. int fd;
  1254. nullpo_retr(0, sd);
  1255. fd=sd->fd;
  1256. WFIFOHEAD(fd, packet_len_table[0x7f]);
  1257. WFIFOW(fd,0)=0x7f;
  1258. WFIFOL(fd,2)=sd->server_tick;
  1259. WFIFOSET(fd,packet_len_table[0x7f]);
  1260. return 0;
  1261. }
  1262. /*==========================================
  1263. *
  1264. *------------------------------------------
  1265. */
  1266. int clif_walkok(struct map_session_data *sd)
  1267. {
  1268. int fd;
  1269. nullpo_retr(0, sd);
  1270. fd=sd->fd;
  1271. WFIFOHEAD(fd, packet_len_table[0x87]);
  1272. WFIFOW(fd,0)=0x87;
  1273. WFIFOL(fd,2)=gettick();
  1274. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1275. WFIFOB(fd,11)=0x88;
  1276. WFIFOSET(fd,packet_len_table[0x87]);
  1277. return 0;
  1278. }
  1279. /*==========================================
  1280. *
  1281. *------------------------------------------
  1282. */
  1283. int clif_movepc(struct map_session_data *sd) {
  1284. unsigned char buf[256];
  1285. nullpo_retr(0, sd);
  1286. if (map[sd->bl.m].flag.snow
  1287. || map[sd->bl.m].flag.clouds
  1288. || map[sd->bl.m].flag.fog
  1289. || map[sd->bl.m].flag.fireworks
  1290. || map[sd->bl.m].flag.sakura
  1291. || map[sd->bl.m].flag.leaves
  1292. || map[sd->bl.m].flag.rain
  1293. || map[sd->bl.m].flag.clouds2
  1294. ) {
  1295. memset(buf,0,packet_len_table[0x7b]);
  1296. WBUFW(buf,0)=0x7b;
  1297. WBUFL(buf,2)=-10;
  1298. WBUFW(buf,6)=sd->speed;
  1299. WBUFW(buf,8)=0;
  1300. WBUFW(buf,10)=0;
  1301. WBUFW(buf,12)=OPTION_INVISIBLE;
  1302. WBUFW(buf,14)=100;
  1303. WBUFL(buf,22)=gettick();
  1304. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1305. WBUFB(buf,56)=5;
  1306. WBUFB(buf,57)=5;
  1307. clif_send(buf, packet_len_table[0x7b], &sd->bl, SELF);
  1308. }
  1309. return 0;
  1310. }
  1311. /*==========================================
  1312. *
  1313. *------------------------------------------
  1314. */
  1315. int clif_move(struct block_list *bl) {
  1316. struct view_data *vd;
  1317. struct unit_data *ud;
  1318. unsigned char buf[256];
  1319. int len;
  1320. nullpo_retr(0, bl);
  1321. vd = status_get_viewdata(bl);
  1322. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1323. return 0;
  1324. ud = unit_bl2ud(bl);
  1325. nullpo_retr(0, ud);
  1326. len = clif_set007b(bl,vd,ud,buf);
  1327. clif_send(buf,len,bl,AREA_WOS);
  1328. if (disguised(bl)){
  1329. if(((TBL_PC *)bl)->status.option & OPTION_INVISIBLE)
  1330. return 0;
  1331. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1332. }
  1333. //Stupid client that needs this resent every time someone walks :X
  1334. if(vd->cloth_color)
  1335. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1336. switch(bl->type)
  1337. {
  1338. case BL_PC:
  1339. {
  1340. TBL_PC *sd = ((TBL_PC*)bl);
  1341. clif_movepc(sd);
  1342. if(sd->state.size==2) // tiny/big players [Valaris]
  1343. clif_specialeffect(&sd->bl,423,0);
  1344. else if(sd->state.size==1)
  1345. clif_specialeffect(&sd->bl,421,0);
  1346. }
  1347. break;
  1348. case BL_MOB:
  1349. {
  1350. TBL_MOB *md = ((TBL_MOB*)bl);
  1351. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1352. clif_specialeffect(&md->bl,423,0);
  1353. else if(md->special_state.size==1)
  1354. clif_specialeffect(&md->bl,421,0);
  1355. }
  1356. break;
  1357. }
  1358. return 0;
  1359. }
  1360. /*==========================================
  1361. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1362. *------------------------------------------
  1363. */
  1364. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1365. struct map_session_data *sd = NULL;
  1366. if (chrif_isconnect())
  1367. { //Remove player from map server
  1368. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1369. map_quit(sd);
  1370. } else //Save later.
  1371. add_timer(tick + 10000, clif_delayquit, id, 0);
  1372. return 0;
  1373. }
  1374. /*==========================================
  1375. *
  1376. *------------------------------------------
  1377. */
  1378. void clif_quitsave(int fd,struct map_session_data *sd)
  1379. {
  1380. if (chrif_isconnect() && (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1381. !battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout))
  1382. map_quit(sd);
  1383. else if (sd->fd)
  1384. { //Disassociate session from player (session is deleted after this function was called)
  1385. //And set a timer to delete this player later.
  1386. session[fd]->session_data = NULL;
  1387. sd->fd = 0;
  1388. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1389. }
  1390. }
  1391. /*==========================================
  1392. *
  1393. *------------------------------------------
  1394. */
  1395. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1396. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1397. session[id]->eof = 1;
  1398. return 0;
  1399. }
  1400. /*==========================================
  1401. *
  1402. *------------------------------------------
  1403. */
  1404. void clif_setwaitclose(int fd) {
  1405. struct map_session_data *sd;
  1406. // if player is not already in the game (double connection probably)
  1407. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1408. // limited timer, just to send information.
  1409. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1410. } else
  1411. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1412. }
  1413. /*==========================================
  1414. *
  1415. *------------------------------------------
  1416. */
  1417. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1418. int fd;
  1419. nullpo_retr(0, sd);
  1420. fd = sd->fd;
  1421. WFIFOHEAD(fd, packet_len_table[0x91]);
  1422. WFIFOW(fd,0) = 0x91;
  1423. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1424. WFIFOW(fd,18) = x;
  1425. WFIFOW(fd,20) = y;
  1426. WFIFOSET(fd, packet_len_table[0x91]);
  1427. if(pc_isdead(sd)) // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  1428. clif_clearchar_area(&sd->bl,1);
  1429. return 0;
  1430. }
  1431. /*==========================================
  1432. *
  1433. *------------------------------------------
  1434. */
  1435. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1436. int fd;
  1437. nullpo_retr(0, sd);
  1438. fd = sd->fd;
  1439. WFIFOHEAD(fd, packet_len_table[0x92]);
  1440. WFIFOW(fd,0) = 0x92;
  1441. //Better not trust the null-terminator is there. [Skotlex]
  1442. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1443. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1444. WFIFOW(fd,18) = x;
  1445. WFIFOW(fd,20) = y;
  1446. WFIFOL(fd,22) = ip;
  1447. WFIFOW(fd,26) = port;
  1448. WFIFOSET(fd, packet_len_table[0x92]);
  1449. return 0;
  1450. }
  1451. int clif_blown(struct block_list *bl) {
  1452. //Previous Aegis versions simply used clif_fixpos, but it seems clif_slide works better on current clients.
  1453. // return clif_fixpos(bl);
  1454. return clif_slide(bl, bl->x, bl->y);
  1455. }
  1456. /*==========================================
  1457. *
  1458. *------------------------------------------
  1459. */
  1460. int clif_fixpos(struct block_list *bl) {
  1461. unsigned char buf[16];
  1462. nullpo_retr(0, bl);
  1463. WBUFW(buf,0)=0x88;
  1464. WBUFL(buf,2)=bl->id;
  1465. WBUFW(buf,6)=bl->x;
  1466. WBUFW(buf,8)=bl->y;
  1467. clif_send(buf, packet_len_table[0x88], bl, AREA);
  1468. if (disguised(bl)) {
  1469. WBUFL(buf,2)=-bl->id;
  1470. clif_send(buf, packet_len_table[0x88], bl, SELF);
  1471. }
  1472. return 0;
  1473. }
  1474. /*==========================================
  1475. *
  1476. *------------------------------------------
  1477. */
  1478. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1479. int fd;
  1480. nullpo_retr(0, sd);
  1481. fd=sd->fd;
  1482. WFIFOHEAD(fd, packet_len_table[0xc4]);
  1483. WFIFOW(fd,0)=0xc4;
  1484. WFIFOL(fd,2)=id;
  1485. WFIFOSET(fd,packet_len_table[0xc4]);
  1486. return 0;
  1487. }
  1488. /*==========================================
  1489. *
  1490. *------------------------------------------
  1491. */
  1492. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1493. struct item_data *id;
  1494. int fd,i,val;
  1495. nullpo_retr(0, sd);
  1496. nullpo_retr(0, nd);
  1497. fd=sd->fd;
  1498. WFIFOHEAD(fd, 200 * 11 + 4);
  1499. WFIFOW(fd,0)=0xc6;
  1500. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1501. id = itemdb_search(nd->u.shop_item[i].nameid);
  1502. val=nd->u.shop_item[i].value;
  1503. WFIFOL(fd,4+i*11)=val;
  1504. if (!id->flag.value_notdc)
  1505. val=pc_modifybuyvalue(sd,val);
  1506. WFIFOL(fd,8+i*11)=val;
  1507. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1508. if (id->view_id > 0)
  1509. WFIFOW(fd,13+i*11)=id->view_id;
  1510. else
  1511. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1512. }
  1513. WFIFOW(fd,2)=i*11+4;
  1514. WFIFOSET(fd,WFIFOW(fd,2));
  1515. return 0;
  1516. }
  1517. /*==========================================
  1518. *
  1519. *------------------------------------------
  1520. */
  1521. int clif_selllist(struct map_session_data *sd) {
  1522. int fd,i,c=0,val;
  1523. nullpo_retr(0, sd);
  1524. fd=sd->fd;
  1525. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1526. WFIFOW(fd,0)=0xc7;
  1527. for(i=0;i<MAX_INVENTORY;i++) {
  1528. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1529. if (!itemdb_cansell(sd->status.inventory[i].nameid, pc_isGM(sd)))
  1530. continue;
  1531. val=sd->inventory_data[i]->value_sell;
  1532. if (val < 0)
  1533. continue;
  1534. WFIFOW(fd,4+c*10)=i+2;
  1535. WFIFOL(fd,6+c*10)=val;
  1536. if (!sd->inventory_data[i]->flag.value_notoc)
  1537. val=pc_modifysellvalue(sd,val);
  1538. WFIFOL(fd,10+c*10)=val;
  1539. c++;
  1540. }
  1541. }
  1542. WFIFOW(fd,2)=c*10+4;
  1543. WFIFOSET(fd,WFIFOW(fd,2));
  1544. return 0;
  1545. }
  1546. /*==========================================
  1547. *
  1548. *------------------------------------------
  1549. */
  1550. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  1551. int fd;
  1552. int slen = strlen(mes) + 9;
  1553. WFIFOHEAD(fd, slen);
  1554. nullpo_retr(0, sd);
  1555. fd=sd->fd;
  1556. WFIFOW(fd,0)=0xb4;
  1557. WFIFOW(fd,2)=slen;
  1558. WFIFOL(fd,4)=npcid;
  1559. strcpy((char*)WFIFOP(fd,8),mes);
  1560. WFIFOSET(fd,WFIFOW(fd,2));
  1561. return 0;
  1562. }
  1563. /*==========================================
  1564. *
  1565. *------------------------------------------
  1566. */
  1567. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  1568. int fd;
  1569. nullpo_retr(0, sd);
  1570. fd=sd->fd;
  1571. WFIFOHEAD(fd, packet_len_table[0xb5]);
  1572. WFIFOW(fd,0)=0xb5;
  1573. WFIFOL(fd,2)=npcid;
  1574. WFIFOSET(fd,packet_len_table[0xb5]);
  1575. return 0;
  1576. }
  1577. /*==========================================
  1578. *
  1579. *------------------------------------------
  1580. */
  1581. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  1582. int fd;
  1583. nullpo_retr(0, sd);
  1584. fd=sd->fd;
  1585. WFIFOHEAD(fd, packet_len_table[0xb6]);
  1586. WFIFOW(fd,0)=0xb6;
  1587. WFIFOL(fd,2)=npcid;
  1588. WFIFOSET(fd,packet_len_table[0xb6]);
  1589. return 0;
  1590. }
  1591. /*==========================================
  1592. *
  1593. *------------------------------------------
  1594. */
  1595. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1596. int fd = sd->fd;
  1597. sd->npc_id = npcid;
  1598. sd->state.using_fake_npc = 1;
  1599. memset(WFIFOP(fd,0), 0, packet_len_table[0x78]);
  1600. WFIFOW(fd,0)=0x78;
  1601. WFIFOL(fd,2)=npcid;
  1602. WFIFOW(fd,14)=111;
  1603. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y);
  1604. WFIFOB(fd,49)=5;
  1605. WFIFOB(fd,50)=5;
  1606. WFIFOSET(fd, packet_len_table[0x78]);
  1607. return;
  1608. }
  1609. /*==========================================
  1610. *
  1611. *------------------------------------------
  1612. */
  1613. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  1614. int fd;
  1615. int slen = strlen(mes) + 8;
  1616. struct block_list *bl = NULL;
  1617. WFIFOHEAD(fd, slen);
  1618. nullpo_retr(0, sd);
  1619. if (!sd->state.using_fake_npc && (npcid == fake_npc_id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1620. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1621. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1622. clif_sendfakenpc(sd, npcid);
  1623. fd=sd->fd;
  1624. WFIFOW(fd,0)=0xb7;
  1625. WFIFOW(fd,2)=slen;
  1626. WFIFOL(fd,4)=npcid;
  1627. strcpy((char*)WFIFOP(fd,8),mes);
  1628. WFIFOSET(fd,WFIFOW(fd,2));
  1629. return 0;
  1630. }
  1631. /*==========================================
  1632. *
  1633. *------------------------------------------
  1634. */
  1635. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  1636. int fd;
  1637. struct block_list *bl = NULL;
  1638. nullpo_retr(0, sd);
  1639. if (!sd->state.using_fake_npc && (npcid == fake_npc_id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1640. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1641. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1642. clif_sendfakenpc(sd, npcid);
  1643. fd=sd->fd;
  1644. WFIFOHEAD(fd, packet_len_table[0x142]);
  1645. WFIFOW(fd,0)=0x142;
  1646. WFIFOL(fd,2)=npcid;
  1647. WFIFOSET(fd,packet_len_table[0x142]);
  1648. return 0;
  1649. }
  1650. /*==========================================
  1651. *
  1652. *------------------------------------------
  1653. */
  1654. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1655. int fd;
  1656. struct block_list *bl = NULL;
  1657. nullpo_retr(0, sd);
  1658. if (!sd->state.using_fake_npc && (npcid == fake_npc_id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1659. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1660. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1661. clif_sendfakenpc(sd, npcid);
  1662. fd=sd->fd;
  1663. WFIFOHEAD(fd, packet_len_table[0x1d4]);
  1664. WFIFOW(fd,0)=0x1d4;
  1665. WFIFOL(fd,2)=npcid;
  1666. WFIFOSET(fd,packet_len_table[0x1d4]);
  1667. return 0;
  1668. }
  1669. /*==========================================
  1670. *
  1671. *------------------------------------------
  1672. */
  1673. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  1674. int fd;
  1675. nullpo_retr(0, sd);
  1676. fd=sd->fd;
  1677. WFIFOHEAD(fd, packet_len_table[0x144]);
  1678. WFIFOW(fd,0)=0x144;
  1679. WFIFOL(fd,2)=npc_id;
  1680. WFIFOL(fd,6)=type;
  1681. WFIFOL(fd,10)=x;
  1682. WFIFOL(fd,14)=y;
  1683. WFIFOB(fd,18)=id;
  1684. WFIFOL(fd,19)=color;
  1685. WFIFOSET(fd,packet_len_table[0x144]);
  1686. return 0;
  1687. }
  1688. /*==========================================
  1689. *
  1690. *------------------------------------------
  1691. */
  1692. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  1693. int fd;
  1694. nullpo_retr(0, sd);
  1695. fd=sd->fd;
  1696. WFIFOHEAD(fd, packet_len_table[0x1b3]);
  1697. WFIFOW(fd,0)=0x1b3;
  1698. strncpy((char*)WFIFOP(fd,2),image,64);
  1699. WFIFOB(fd,66)=type;
  1700. WFIFOSET(fd,packet_len_table[0x1b3]);
  1701. return 0;
  1702. }
  1703. /*==========================================
  1704. * Fills in card data from the given item and into the buffer. [Skotlex]
  1705. *------------------------------------------
  1706. */
  1707. static void clif_addcards(unsigned char* buf, struct item* item)
  1708. {
  1709. int i=0,j;
  1710. if (item == NULL) { //Blank data
  1711. WBUFW(buf,0)=0;
  1712. WBUFW(buf,2)=0;
  1713. WBUFW(buf,4)=0;
  1714. WBUFW(buf,6)=0;
  1715. return;
  1716. }
  1717. if(item->card[0]==(short)0xff00) { //pet eggs
  1718. WBUFW(buf,0)=0;
  1719. WBUFW(buf,2)=0;
  1720. WBUFW(buf,4)=0;
  1721. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1722. return;
  1723. }
  1724. if(item->card[0]==0x00ff || item->card[0]==0x00fe) { //Forged/created items
  1725. WBUFW(buf,0)=item->card[0];
  1726. WBUFW(buf,2)=item->card[1];
  1727. WBUFW(buf,4)=item->card[2];
  1728. WBUFW(buf,6)=item->card[3];
  1729. return;
  1730. }
  1731. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1732. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1733. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1734. //Normal items.
  1735. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1736. WBUFW(buf,0)=j;
  1737. else
  1738. WBUFW(buf,0)= item->card[i];
  1739. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1740. WBUFW(buf,2)=j;
  1741. else
  1742. WBUFW(buf,2)=item->card[i];
  1743. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1744. WBUFW(buf,4)=j;
  1745. else
  1746. WBUFW(buf,4)=item->card[i];
  1747. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1748. WBUFW(buf,6)=j;
  1749. else
  1750. WBUFW(buf,6)=item->card[i];
  1751. }
  1752. /*==========================================
  1753. *
  1754. *------------------------------------------
  1755. */
  1756. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  1757. int fd;
  1758. unsigned char *buf;
  1759. nullpo_retr(0, sd);
  1760. fd = sd->fd;
  1761. if (!session_isActive(fd)) //Sasuke-
  1762. return 0;
  1763. WFIFOHEAD(fd,packet_len_table[0xa0]);
  1764. buf = WFIFOP(fd,0);
  1765. if(fail) {
  1766. WBUFW(buf,0)=0xa0;
  1767. WBUFW(buf,2)=n+2;
  1768. WBUFW(buf,4)=amount;
  1769. WBUFW(buf,6)=0;
  1770. WBUFB(buf,8)=0;
  1771. WBUFB(buf,9)=0;
  1772. WBUFB(buf,10)=0;
  1773. WBUFW(buf,11)=0;
  1774. WBUFW(buf,13)=0;
  1775. WBUFW(buf,15)=0;
  1776. WBUFW(buf,17)=0;
  1777. WBUFW(buf,19)=0;
  1778. WBUFB(buf,21)=0;
  1779. WBUFB(buf,22)=fail;
  1780. } else {
  1781. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1782. return 1;
  1783. WBUFW(buf,0)=0xa0;
  1784. WBUFW(buf,2)=n+2;
  1785. WBUFW(buf,4)=amount;
  1786. if (sd->inventory_data[n]->view_id > 0)
  1787. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  1788. else
  1789. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  1790. WBUFB(buf,8)=sd->status.inventory[n].identify;
  1791. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  1792. WBUFB(buf,10)=sd->status.inventory[n].refine;
  1793. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  1794. WBUFW(buf,19)=pc_equippoint(sd,n);
  1795. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  1796. WBUFB(buf,22)=fail;
  1797. }
  1798. WFIFOSET(fd,packet_len_table[0xa0]);
  1799. return 0;
  1800. }
  1801. /*==========================================
  1802. *
  1803. *------------------------------------------
  1804. */
  1805. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1806. {
  1807. int fd;
  1808. nullpo_retr(0, sd);
  1809. fd=sd->fd;
  1810. WFIFOHEAD(fd, packet_len_table[0xaf]);
  1811. WFIFOW(fd,0)=0xaf;
  1812. WFIFOW(fd,2)=n+2;
  1813. WFIFOW(fd,4)=amount;
  1814. WFIFOSET(fd,packet_len_table[0xaf]);
  1815. return 0;
  1816. }
  1817. /*==========================================
  1818. *
  1819. *------------------------------------------
  1820. */
  1821. int clif_itemlist(struct map_session_data *sd)
  1822. {
  1823. int i,n,fd,arrow=-1;
  1824. unsigned char *buf;
  1825. nullpo_retr(0, sd);
  1826. fd=sd->fd;
  1827. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1828. buf = WFIFOP(fd,0);
  1829. #if PACKETVER < 5
  1830. WBUFW(buf,0)=0xa3;
  1831. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1832. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  1833. continue;
  1834. WBUFW(buf,n*10+4)=i+2;
  1835. if (sd->inventory_data[i]->view_id > 0)
  1836. WBUFW(buf,n*10+6)=sd->inventory_data[i]->view_id;
  1837. else
  1838. WBUFW(buf,n*10+6)=sd->status.inventory[i].nameid;
  1839. WBUFB(buf,n*10+8)=itemtype(sd->inventory_data[i]->type);
  1840. WBUFB(buf,n*10+9)=sd->status.inventory[i].identify;
  1841. WBUFW(buf,n*10+10)=sd->status.inventory[i].amount;
  1842. if (sd->inventory_data[i]->equip == 0x8000) {
  1843. WBUFW(buf,n*10+12)=0x8000;
  1844. if (sd->status.inventory[i].equip)
  1845. arrow=i; // ついでに矢装備チェック
  1846. } else
  1847. WBUFW(buf,n*10+12)=0;
  1848. n++;
  1849. }
  1850. if (n) {
  1851. WBUFW(buf,2)=4+n*10;
  1852. WFIFOSET(fd,WFIFOW(fd,2));
  1853. }
  1854. #else
  1855. WBUFW(buf,0)=0x1ee;
  1856. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1857. if(sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  1858. continue;
  1859. WBUFW(buf,n*18+4)=i+2;
  1860. if(sd->inventory_data[i]->view_id > 0)
  1861. WBUFW(buf,n*18+6)=sd->inventory_data[i]->view_id;
  1862. else
  1863. WBUFW(buf,n*18+6)=sd->status.inventory[i].nameid;
  1864. WBUFB(buf,n*18+8)=itemtype(sd->inventory_data[i]->type);
  1865. WBUFB(buf,n*18+9)=sd->status.inventory[i].identify;
  1866. WBUFW(buf,n*18+10)=sd->status.inventory[i].amount;
  1867. if (sd->inventory_data[i]->equip == 0x8000) {
  1868. WBUFW(buf,n*18+12)=0x8000;
  1869. if(sd->status.inventory[i].equip)
  1870. arrow=i; // ついでに矢装備チェック
  1871. } else
  1872. WBUFW(buf,n*18+12)=0;
  1873. clif_addcards(WBUFP(buf, n*18+14), &sd->status.inventory[i]);
  1874. n++;
  1875. }
  1876. if (n) {
  1877. WBUFW(buf,2)=4+n*18;
  1878. WFIFOSET(fd,WFIFOW(fd,2));
  1879. }
  1880. #endif
  1881. if(arrow >= 0)
  1882. clif_arrowequip(sd,arrow);
  1883. return 0;
  1884. }
  1885. /*==========================================
  1886. *
  1887. *------------------------------------------
  1888. */
  1889. int clif_equiplist(struct map_session_data *sd)
  1890. {
  1891. int i,n,fd;
  1892. nullpo_retr(0, sd);
  1893. fd=sd->fd;
  1894. if (!session_isActive(fd))
  1895. return 0;
  1896. WFIFOHEAD(fd, 4 + MAX_INVENTORY * 20);
  1897. WFIFOW(fd,0)=0xa4;
  1898. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1899. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL || !itemdb_isequip2(sd->inventory_data[i]))
  1900. continue;
  1901. WFIFOW(fd,n*20+4)=i+2;
  1902. if(sd->inventory_data[i]->view_id > 0)
  1903. WFIFOW(fd,n*20+6)=sd->inventory_data[i]->view_id;
  1904. else
  1905. WFIFOW(fd,n*20+6)=sd->status.inventory[i].nameid;
  1906. WFIFOB(fd,n*20+8)=itemtype(sd->inventory_data[i]->type);
  1907. WFIFOB(fd,n*20+9)=sd->status.inventory[i].identify;
  1908. WFIFOW(fd,n*20+10)=pc_equippoint(sd,i);
  1909. WFIFOW(fd,n*20+12)=sd->status.inventory[i].equip;
  1910. WFIFOB(fd,n*20+14)=sd->status.inventory[i].attribute;
  1911. WFIFOB(fd,n*20+15)=sd->status.inventory[i].refine;
  1912. clif_addcards(WFIFOP(fd, n*20+16), &sd->status.inventory[i]);
  1913. n++;
  1914. }
  1915. if(n){
  1916. WFIFOW(fd,2)=4+n*20;
  1917. WFIFOSET(fd,WFIFOW(fd,2));
  1918. }
  1919. return 0;
  1920. }
  1921. /*==========================================
  1922. * カプラさんに預けてある消耗品&収集品リスト
  1923. *------------------------------------------
  1924. */
  1925. int clif_storageitemlist(struct map_session_data *sd,struct storage *stor)
  1926. {
  1927. struct item_data *id;
  1928. int i,n,fd;
  1929. unsigned char *buf;
  1930. nullpo_retr(0, sd);
  1931. nullpo_retr(0, stor);
  1932. fd=sd->fd;
  1933. WFIFOHEAD(fd,MAX_STORAGE * 18 + 4);
  1934. buf = WFIFOP(fd,0);
  1935. #if PACKETVER < 5
  1936. WBUFW(buf,0)=0xa5;
  1937. for(i=0,n=0;i<MAX_STORAGE;i++){
  1938. if(stor->storage_[i].nameid<=0)
  1939. continue;
  1940. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1941. if(itemdb_isequip2(id))
  1942. continue;
  1943. WBUFW(buf,n*10+4)=i+1;
  1944. if(id->view_id > 0)
  1945. WBUFW(buf,n*10+6)=id->view_id;
  1946. else
  1947. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  1948. WBUFB(buf,n*10+8)=itemtype(id->type);
  1949. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  1950. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  1951. WBUFW(buf,n*10+12)=0;
  1952. n++;
  1953. }
  1954. if(n){
  1955. WBUFW(buf,2)=4+n*10;
  1956. WFIFOSET(fd,WFIFOW(fd,2));
  1957. }
  1958. #else
  1959. WBUFW(buf,0)=0x1f0;
  1960. for(i=0,n=0;i<MAX_STORAGE;i++){
  1961. if(stor->storage_[i].nameid<=0)
  1962. continue;
  1963. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1964. if(itemdb_isequip2(id))
  1965. continue;
  1966. WBUFW(buf,n*18+4)=i+1;
  1967. if(id->view_id > 0)
  1968. WBUFW(buf,n*18+6)=id->view_id;
  1969. else
  1970. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  1971. WBUFB(buf,n*18+8)=itemtype(id->type);
  1972. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  1973. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  1974. WBUFW(buf,n*18+12)=0;
  1975. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  1976. n++;
  1977. }
  1978. if(n){
  1979. WBUFW(buf,2)=4+n*18;
  1980. WFIFOSET(fd,WFIFOW(fd,2));
  1981. }
  1982. #endif
  1983. return 0;
  1984. }
  1985. /*==========================================
  1986. * カプラさんに預けてある装備リスト
  1987. *------------------------------------------
  1988. */
  1989. int clif_storageequiplist(struct map_session_data *sd,struct storage *stor)
  1990. {
  1991. struct item_data *id;
  1992. int i,n,fd;
  1993. unsigned char *buf;
  1994. nullpo_retr(0, sd);
  1995. nullpo_retr(0, stor);
  1996. fd=sd->fd;
  1997. WFIFOHEAD(fd,MAX_STORAGE * 20 + 4);
  1998. buf = WFIFOP(fd,0);
  1999. WBUFW(buf,0)=0xa6;
  2000. for(i=0,n=0;i<MAX_STORAGE;i++){
  2001. if(stor->storage_[i].nameid<=0)
  2002. continue;
  2003. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2004. if(!itemdb_isequip2(id))
  2005. continue;
  2006. WBUFW(buf,n*20+4)=i+1;
  2007. if(id->view_id > 0)
  2008. WBUFW(buf,n*20+6)=id->view_id;
  2009. else
  2010. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2011. WBUFB(buf,n*20+8)=itemtype(id->type);
  2012. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2013. WBUFW(buf,n*20+10)=id->equip;
  2014. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2015. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2016. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2017. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2018. n++;
  2019. }
  2020. if(n){
  2021. WBUFW(buf,2)=4+n*20;
  2022. WFIFOSET(fd,WFIFOW(fd,2));
  2023. }
  2024. return 0;
  2025. }
  2026. /*==========================================
  2027. *
  2028. *------------------------------------------
  2029. */
  2030. int clif_guildstorageitemlist(struct map_session_data *sd,struct guild_storage *stor)
  2031. {
  2032. struct item_data *id;
  2033. int i,n,fd;
  2034. unsigned char *buf;
  2035. nullpo_retr(0, sd);
  2036. nullpo_retr(0, stor);
  2037. fd=sd->fd;
  2038. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 18 + 4);
  2039. buf=WFIFOP(fd,0);
  2040. #if PACKETVER < 5
  2041. WBUFW(buf,0)=0xa5;
  2042. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2043. if(stor->storage_[i].nameid<=0)
  2044. continue;
  2045. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2046. if(itemdb_isequip2(id))
  2047. continue;
  2048. WBUFW(buf,n*10+4)=i+1;
  2049. if(id->view_id > 0)
  2050. WBUFW(buf,n*10+6)=id->view_id;
  2051. else
  2052. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  2053. WBUFB(buf,n*10+8)=itemtype(id->type);
  2054. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  2055. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  2056. WBUFW(buf,n*10+12)=0;
  2057. n++;
  2058. }
  2059. if(n){
  2060. WBUFW(buf,2)=4+n*10;
  2061. WFIFOSET(fd,WFIFOW(fd,2));
  2062. }
  2063. #else
  2064. WBUFW(buf,0)=0x1f0;
  2065. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2066. if(stor->storage_[i].nameid<=0)
  2067. continue;
  2068. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2069. if(itemdb_isequip2(id))
  2070. continue;
  2071. WBUFW(buf,n*18+4)=i+1;
  2072. if(id->view_id > 0)
  2073. WBUFW(buf,n*18+6)=id->view_id;
  2074. else
  2075. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  2076. WBUFB(buf,n*18+8)=itemtype(id->type);
  2077. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  2078. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  2079. WBUFW(buf,n*18+12)=0;
  2080. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  2081. n++;
  2082. }
  2083. if(n){
  2084. WBUFW(buf,2)=4+n*18;
  2085. WFIFOSET(fd,WFIFOW(fd,2));
  2086. }
  2087. #endif
  2088. return 0;
  2089. }
  2090. /*==========================================
  2091. *
  2092. *------------------------------------------
  2093. */
  2094. int clif_guildstorageequiplist(struct map_session_data *sd,struct guild_storage *stor)
  2095. {
  2096. struct item_data *id;
  2097. int i,n,fd;
  2098. unsigned char *buf;
  2099. nullpo_retr(0, sd);
  2100. fd=sd->fd;
  2101. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 20 + 4);
  2102. buf=WFIFOP(fd,0);
  2103. WBUFW(buf,0)=0xa6;
  2104. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2105. if(stor->storage_[i].nameid<=0)
  2106. continue;
  2107. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2108. if(!itemdb_isequip2(id))
  2109. continue;
  2110. WBUFW(buf,n*20+4)=i+1;
  2111. if(id->view_id > 0)
  2112. WBUFW(buf,n*20+6)=id->view_id;
  2113. else
  2114. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2115. WBUFB(buf,n*20+8)=itemtype(id->type);
  2116. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2117. WBUFW(buf,n*20+10)=id->equip;
  2118. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2119. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2120. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2121. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2122. n++;
  2123. }
  2124. if(n){
  2125. WBUFW(buf,2)=4+n*20;
  2126. WFIFOSET(fd,WFIFOW(fd,2));
  2127. }
  2128. return 0;
  2129. }
  2130. // Guild XY locators [Valaris]
  2131. int clif_guild_xy(struct map_session_data *sd)
  2132. {
  2133. unsigned char buf[10];
  2134. nullpo_retr(0, sd);
  2135. WBUFW(buf,0)=0x1eb;
  2136. WBUFL(buf,2)=sd->status.account_id;
  2137. WBUFW(buf,6)=sd->bl.x;
  2138. WBUFW(buf,8)=sd->bl.y;
  2139. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2140. return 0;
  2141. }
  2142. /*==========================================
  2143. * Sends x/y dot to a single fd. [Skotlex]
  2144. *------------------------------------------
  2145. */
  2146. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2147. {
  2148. WFIFOHEAD(fd,packet_len_table[0x1eb]);
  2149. WFIFOW(fd,0)=0x1eb;
  2150. WFIFOL(fd,2)=sd->status.account_id;
  2151. WFIFOW(fd,6)=sd->bl.x;
  2152. WFIFOW(fd,8)=sd->bl.y;
  2153. WFIFOSET(fd,packet_len_table[0x1eb]);
  2154. return 0;
  2155. }
  2156. // Guild XY locators [Valaris]
  2157. int clif_guild_xy_remove(struct map_session_data *sd)
  2158. {
  2159. unsigned char buf[10];
  2160. nullpo_retr(0, sd);
  2161. WBUFW(buf,0)=0x1eb;
  2162. WBUFL(buf,2)=sd->status.account_id;
  2163. WBUFW(buf,6)=-1;
  2164. WBUFW(buf,8)=-1;
  2165. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2166. return 0;
  2167. }
  2168. /*==========================================
  2169. * ステータスを送りつける
  2170. * 表示専用数字はこの中で計算して送る
  2171. *------------------------------------------
  2172. */
  2173. int clif_updatestatus(struct map_session_data *sd,int type)
  2174. {
  2175. int fd,len=8;
  2176. nullpo_retr(0, sd);
  2177. fd=sd->fd;
  2178. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2179. return 0;
  2180. WFIFOHEAD(fd, 14);
  2181. WFIFOW(fd,0)=0xb0;
  2182. WFIFOW(fd,2)=type;
  2183. switch(type){
  2184. // 00b0
  2185. case SP_WEIGHT:
  2186. pc_checkweighticon(sd);
  2187. WFIFOW(fd,0)=0xb0;
  2188. WFIFOW(fd,2)=type; //Added this packet back, Temp fix to the slow motion [Lupus]
  2189. WFIFOL(fd,4)=sd->weight;
  2190. break;
  2191. case SP_MAXWEIGHT:
  2192. WFIFOL(fd,4)=sd->max_weight;
  2193. break;
  2194. case SP_SPEED:
  2195. WFIFOL(fd,4)=sd->speed;
  2196. break;
  2197. case SP_BASELEVEL:
  2198. WFIFOL(fd,4)=sd->status.base_level;
  2199. break;
  2200. case SP_JOBLEVEL:
  2201. WFIFOL(fd,4)=sd->status.job_level;
  2202. break;
  2203. case SP_MANNER:
  2204. WFIFOL(fd,4)=sd->status.manner;
  2205. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2206. break;
  2207. case SP_STATUSPOINT:
  2208. WFIFOL(fd,4)=sd->status.status_point;
  2209. break;
  2210. case SP_SKILLPOINT:
  2211. WFIFOL(fd,4)=sd->status.skill_point;
  2212. break;
  2213. case SP_HIT:
  2214. WFIFOL(fd,4)=sd->hit;
  2215. break;
  2216. case SP_FLEE1:
  2217. WFIFOL(fd,4)=sd->flee;
  2218. break;
  2219. case SP_FLEE2:
  2220. WFIFOL(fd,4)=sd->flee2/10;
  2221. break;
  2222. case SP_MAXHP:
  2223. WFIFOL(fd,4)=sd->status.max_hp;
  2224. break;
  2225. case SP_MAXSP:
  2226. WFIFOL(fd,4)=sd->status.max_sp;
  2227. break;
  2228. case SP_HP:
  2229. WFIFOL(fd,4)=sd->status.hp;
  2230. if (sd->status.party_id)
  2231. clif_party_hp(sd);
  2232. if (battle_config.disp_hpmeter)
  2233. clif_hpmeter(sd);
  2234. break;
  2235. case SP_SP:
  2236. WFIFOL(fd,4)=sd->status.sp;
  2237. break;
  2238. case SP_ASPD:
  2239. WFIFOL(fd,4)=sd->aspd;
  2240. break;
  2241. case SP_ATK1:
  2242. WFIFOL(fd,4)=sd->base_atk+sd->right_weapon.watk+sd->left_weapon.watk;
  2243. break;
  2244. case SP_DEF1:
  2245. WFIFOL(fd,4)=sd->def;
  2246. break;
  2247. case SP_MDEF1:
  2248. WFIFOL(fd,4)=sd->mdef;
  2249. break;
  2250. case SP_ATK2:
  2251. WFIFOL(fd,4)=sd->right_weapon.watk2 + sd->left_weapon.watk2;
  2252. break;
  2253. case SP_DEF2:
  2254. WFIFOL(fd,4)=sd->def2;
  2255. break;
  2256. case SP_MDEF2:
  2257. WFIFOL(fd,4)=sd->mdef2;
  2258. break;
  2259. case SP_CRITICAL:
  2260. WFIFOL(fd,4)=sd->critical/10;
  2261. break;
  2262. case SP_MATK1:
  2263. WFIFOL(fd,4)=sd->matk1;
  2264. break;
  2265. case SP_MATK2:
  2266. WFIFOL(fd,4)=sd->matk2;
  2267. break;
  2268. case SP_ZENY:
  2269. WFIFOW(fd,0)=0xb1;
  2270. if(sd->status.zeny < 0)
  2271. sd->status.zeny = 0;
  2272. WFIFOL(fd,4)=sd->status.zeny;
  2273. break;
  2274. case SP_BASEEXP:
  2275. WFIFOW(fd,0)=0xb1;
  2276. WFIFOL(fd,4)=sd->status.base_exp;
  2277. break;
  2278. case SP_JOBEXP:
  2279. WFIFOW(fd,0)=0xb1;
  2280. WFIFOL(fd,4)=sd->status.job_exp;
  2281. break;
  2282. case SP_NEXTBASEEXP:
  2283. WFIFOW(fd,0)=0xb1;
  2284. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2285. break;
  2286. case SP_NEXTJOBEXP:
  2287. WFIFOW(fd,0)=0xb1;
  2288. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2289. break;
  2290. // 00be 終了
  2291. case SP_USTR:
  2292. case SP_UAGI:
  2293. case SP_UVIT:
  2294. case SP_UINT:
  2295. case SP_UDEX:
  2296. case SP_ULUK:
  2297. WFIFOW(fd,0)=0xbe;
  2298. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2299. len=5;
  2300. break;
  2301. // 013a 終了
  2302. case SP_ATTACKRANGE:
  2303. WFIFOW(fd,0)=0x13a;
  2304. WFIFOW(fd,2)=sd->attackrange;
  2305. len=4;
  2306. break;
  2307. // 0141 終了
  2308. case SP_STR:
  2309. WFIFOW(fd,0)=0x141;
  2310. WFIFOL(fd,2)=type;
  2311. WFIFOL(fd,6)=sd->status.str;
  2312. WFIFOL(fd,10)=sd->paramb[0] + sd->parame[0];
  2313. len=14;
  2314. break;
  2315. case SP_AGI:
  2316. WFIFOW(fd,0)=0x141;
  2317. WFIFOL(fd,2)=type;
  2318. WFIFOL(fd,6)=sd->status.agi;
  2319. WFIFOL(fd,10)=sd->paramb[1] + sd->parame[1];
  2320. len=14;
  2321. break;
  2322. case SP_VIT:
  2323. WFIFOW(fd,0)=0x141;
  2324. WFIFOL(fd,2)=type;
  2325. WFIFOL(fd,6)=sd->status.vit;
  2326. WFIFOL(fd,10)=sd->paramb[2] + sd->parame[2];
  2327. len=14;
  2328. break;
  2329. case SP_INT:
  2330. WFIFOW(fd,0)=0x141;
  2331. WFIFOL(fd,2)=type;
  2332. WFIFOL(fd,6)=sd->status.int_;
  2333. WFIFOL(fd,10)=sd->paramb[3] + sd->parame[3];
  2334. len=14;
  2335. break;
  2336. case SP_DEX:
  2337. WFIFOW(fd,0)=0x141;
  2338. WFIFOL(fd,2)=type;
  2339. WFIFOL(fd,6)=sd->status.dex;
  2340. WFIFOL(fd,10)=sd->paramb[4] + sd->parame[4];
  2341. len=14;
  2342. break;
  2343. case SP_LUK:
  2344. WFIFOW(fd,0)=0x141;
  2345. WFIFOL(fd,2)=type;
  2346. WFIFOL(fd,6)=sd->status.luk;
  2347. WFIFOL(fd,10)=sd->paramb[5] + sd->parame[5];
  2348. len=14;
  2349. break;
  2350. case SP_CARTINFO:
  2351. WFIFOW(fd,0)=0x121;
  2352. WFIFOW(fd,2)=sd->cart_num;
  2353. WFIFOW(fd,4)=sd->cart_max_num;
  2354. WFIFOL(fd,6)=sd->cart_weight;
  2355. WFIFOL(fd,10)=sd->cart_max_weight;
  2356. len=14;
  2357. break;
  2358. default:
  2359. if(battle_config.error_log)
  2360. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2361. return 1;
  2362. }
  2363. WFIFOSET(fd,len);
  2364. return 0;
  2365. }
  2366. int clif_changestatus(struct block_list *bl,int type,int val)
  2367. {
  2368. unsigned char buf[12];
  2369. struct map_session_data *sd = NULL;
  2370. nullpo_retr(0, bl);
  2371. if(bl->type == BL_PC)
  2372. sd = (struct map_session_data *)bl;
  2373. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2374. if(sd){
  2375. WBUFW(buf,0)=0x1ab;
  2376. WBUFL(buf,2)=bl->id;
  2377. WBUFW(buf,6)=type;
  2378. switch(type){
  2379. case SP_MANNER:
  2380. WBUFL(buf,8)=val;
  2381. break;
  2382. default:
  2383. if(battle_config.error_log)
  2384. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2385. return 1;
  2386. }
  2387. clif_send(buf,packet_len_table[0x1ab],bl,AREA_WOS);
  2388. }
  2389. return 0;
  2390. }
  2391. /*==========================================
  2392. *
  2393. *------------------------------------------
  2394. */
  2395. int clif_changelook(struct block_list *bl,int type,int val)
  2396. {
  2397. unsigned char buf[32];
  2398. struct map_session_data *sd = NULL;
  2399. struct view_data *vd;
  2400. vd = status_get_viewdata(bl);
  2401. nullpo_retr(0, vd);
  2402. if(bl->type == BL_PC)
  2403. sd = (struct map_session_data *)bl;
  2404. switch(type) {
  2405. case LOOK_WEAPON:
  2406. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2407. else vd->weapon = val;
  2408. break;
  2409. case LOOK_SHIELD:
  2410. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2411. else vd->shield = val;
  2412. break;
  2413. case LOOK_BASE:
  2414. vd->class_ = val;
  2415. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2416. vd->weapon = vd->shield = 0;
  2417. if (
  2418. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2419. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2420. )
  2421. vd->cloth_color = 0;
  2422. break;
  2423. case LOOK_HAIR:
  2424. vd->hair_style = val;
  2425. break;
  2426. case LOOK_HEAD_BOTTOM:
  2427. vd->head_bottom = val;
  2428. break;
  2429. case LOOK_HEAD_TOP:
  2430. vd->head_top = val;
  2431. break;
  2432. case LOOK_HEAD_MID:
  2433. vd->head_mid = val;
  2434. break;
  2435. case LOOK_HAIR_COLOR:
  2436. vd->hair_color = val;
  2437. break;
  2438. case LOOK_CLOTHES_COLOR:
  2439. if (
  2440. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2441. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2442. )
  2443. val = 0;
  2444. vd->cloth_color = val;
  2445. break;
  2446. case LOOK_SHOES:
  2447. #if PACKETVER > 3
  2448. if (sd) {
  2449. int n;
  2450. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2451. if(sd->inventory_data[n]->view_id > 0)
  2452. val = sd->inventory_data[n]->view_id;
  2453. else
  2454. val = sd->status.inventory[n].nameid;
  2455. }
  2456. val = 0;
  2457. }
  2458. #endif
  2459. //Shoes? No packet uses this....
  2460. break;
  2461. }
  2462. #if PACKETVER < 4
  2463. WBUFW(buf,0)=0xc3;
  2464. WBUFL(buf,2)=bl->id;
  2465. WBUFB(buf,6)=type;
  2466. WBUFB(buf,7)=val;
  2467. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2468. #else
  2469. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2470. WBUFW(buf,0)=0x1d7;
  2471. WBUFL(buf,2)=bl->id;
  2472. WBUFB(buf,6)=LOOK_WEAPON;
  2473. WBUFW(buf,7)=vd->weapon;
  2474. WBUFW(buf,9)=vd->shield;
  2475. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2476. }
  2477. else if(type == LOOK_BASE && val > 255)
  2478. {
  2479. WBUFW(buf,0)=0x1d7;
  2480. WBUFL(buf,2)=bl->id;
  2481. WBUFB(buf,6)=type;
  2482. WBUFW(buf,7)=val;
  2483. WBUFW(buf,9)=0;
  2484. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2485. } else {
  2486. WBUFW(buf,0)=0xc3;
  2487. WBUFL(buf,2)=bl->id;
  2488. WBUFB(buf,6)=type;
  2489. WBUFB(buf,7)=val;
  2490. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2491. }
  2492. #endif
  2493. return 0;
  2494. }
  2495. //Sends a change-base-look packet required for traps as they are triggered.
  2496. void clif_changetraplook(struct block_list *bl,int val)
  2497. {
  2498. unsigned char buf[32];
  2499. #if PACKETVER < 4
  2500. WBUFW(buf,0)=0xc3;
  2501. WBUFL(buf,2)=bl->id;
  2502. WBUFB(buf,6)=LOOK_BASE;
  2503. WBUFB(buf,7)=val;
  2504. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2505. #else
  2506. if (val > 255)
  2507. {
  2508. WBUFW(buf,0)=0x1d7;
  2509. WBUFL(buf,2)=bl->id;
  2510. WBUFB(buf,6)=LOOK_BASE;
  2511. WBUFW(buf,7)=val;
  2512. WBUFW(buf,9)=0;
  2513. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2514. } else {
  2515. WBUFW(buf,0)=0xc3;
  2516. WBUFL(buf,2)=bl->id;
  2517. WBUFB(buf,6)=LOOK_BASE;
  2518. WBUFB(buf,7)=val;
  2519. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2520. }
  2521. #endif
  2522. }
  2523. //For the stupid cloth-dye bug. Resends the given view data
  2524. //to the area specified by bl.
  2525. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2526. {
  2527. unsigned char buf[32];
  2528. #if PACKETVER < 4
  2529. WBUFW(buf,0)=0xc3;
  2530. WBUFL(buf,2)=id;
  2531. WBUFB(buf,6)=type;
  2532. WBUFB(buf,7)=val;
  2533. clif_send(buf,packet_len_table[0xc3],bl,area);
  2534. #else
  2535. if(type == LOOK_BASE && val > 255)
  2536. {
  2537. WBUFW(buf,0)=0x1d7;
  2538. WBUFL(buf,2)=id;
  2539. WBUFB(buf,6)=type;
  2540. WBUFW(buf,7)=val;
  2541. WBUFW(buf,9)=0;
  2542. clif_send(buf,packet_len_table[0x1d7],bl,area);
  2543. } else {
  2544. WBUFW(buf,0)=0xc3;
  2545. WBUFL(buf,2)=id;
  2546. WBUFB(buf,6)=type;
  2547. WBUFB(buf,7)=val;
  2548. clif_send(buf,packet_len_table[0xc3],bl,area);
  2549. }
  2550. #endif
  2551. return;
  2552. }
  2553. /*==========================================
  2554. *
  2555. *------------------------------------------
  2556. */
  2557. int clif_initialstatus(struct map_session_data *sd)
  2558. {
  2559. int fd;
  2560. unsigned char *buf;
  2561. nullpo_retr(0, sd);
  2562. fd=sd->fd;
  2563. WFIFOHEAD(fd,packet_len_table[0xbd]);
  2564. buf=WFIFOP(fd,0);
  2565. WBUFW(buf,0)=0xbd;
  2566. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2567. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2568. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2569. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2570. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2571. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2572. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2573. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2574. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2575. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2576. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2577. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2578. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2579. WBUFW(buf,16) = sd->base_atk + sd->right_weapon.watk + sd->left_weapon.watk;
  2580. WBUFW(buf,18) = sd->right_weapon.watk2 + sd->left_weapon.watk2; //atk bonus
  2581. WBUFW(buf,20) = sd->matk1;
  2582. WBUFW(buf,22) = sd->matk2;
  2583. WBUFW(buf,24) = sd->def; // def
  2584. WBUFW(buf,26) = sd->def2;
  2585. WBUFW(buf,28) = sd->mdef; // mdef
  2586. WBUFW(buf,30) = sd->mdef2;
  2587. WBUFW(buf,32) = sd->hit;
  2588. WBUFW(buf,34) = sd->flee;
  2589. WBUFW(buf,36) = sd->flee2/10;
  2590. WBUFW(buf,38) = sd->critical/10;
  2591. WBUFW(buf,40) = sd->status.karma;
  2592. WBUFW(buf,42) = sd->status.manner;
  2593. WFIFOSET(fd,packet_len_table[0xbd]);
  2594. clif_updatestatus(sd,SP_STR);
  2595. clif_updatestatus(sd,SP_AGI);
  2596. clif_updatestatus(sd,SP_VIT);
  2597. clif_updatestatus(sd,SP_INT);
  2598. clif_updatestatus(sd,SP_DEX);
  2599. clif_updatestatus(sd,SP_LUK);
  2600. clif_updatestatus(sd,SP_ATTACKRANGE);
  2601. clif_updatestatus(sd,SP_ASPD);
  2602. return 0;
  2603. }
  2604. /*==========================================
  2605. *矢装備
  2606. *------------------------------------------
  2607. */
  2608. int clif_arrowequip(struct map_session_data *sd,int val)
  2609. {
  2610. int fd;
  2611. nullpo_retr(0, sd);
  2612. pc_stop_attack(sd); // [Valaris]
  2613. fd=sd->fd;
  2614. WFIFOHEAD(fd, packet_len_table[0x013c]);
  2615. WFIFOW(fd,0)=0x013c;
  2616. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2617. WFIFOSET(fd,packet_len_table[0x013c]);
  2618. return 0;
  2619. }
  2620. /*==========================================
  2621. *
  2622. *------------------------------------------
  2623. */
  2624. int clif_arrow_fail(struct map_session_data *sd,int type)
  2625. {
  2626. int fd;
  2627. nullpo_retr(0, sd);
  2628. fd=sd->fd;
  2629. WFIFOHEAD(fd, packet_len_table[0x013b]);
  2630. WFIFOW(fd,0)=0x013b;
  2631. WFIFOW(fd,2)=type;
  2632. WFIFOSET(fd,packet_len_table[0x013b]);
  2633. return 0;
  2634. }
  2635. /*==========================================
  2636. * 作成可能 矢リスト送信
  2637. *------------------------------------------
  2638. */
  2639. int clif_arrow_create_list(struct map_session_data *sd)
  2640. {
  2641. int i, c, j;
  2642. int fd;
  2643. nullpo_retr(0, sd);
  2644. fd = sd->fd;
  2645. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2646. WFIFOW(fd,0) = 0x1ad;
  2647. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2648. if (skill_arrow_db[i].nameid > 0 &&
  2649. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2650. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2651. {
  2652. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2653. WFIFOW(fd,c*2+4) = j;
  2654. else
  2655. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2656. c++;
  2657. }
  2658. }
  2659. WFIFOW(fd,2) = c*2+4;
  2660. WFIFOSET(fd, WFIFOW(fd,2));
  2661. if (c > 0) {
  2662. sd->menuskill_id = AC_MAKINGARROW;
  2663. sd->menuskill_lv = c;
  2664. }
  2665. return 0;
  2666. }
  2667. /*==========================================
  2668. *
  2669. *------------------------------------------
  2670. */
  2671. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2672. {
  2673. int fd;
  2674. nullpo_retr(0, sd);
  2675. fd=sd->fd;
  2676. WFIFOHEAD(fd,packet_len_table[0xbc]);
  2677. WFIFOW(fd,0)=0xbc;
  2678. WFIFOW(fd,2)=type;
  2679. WFIFOB(fd,4)=ok;
  2680. WFIFOB(fd,5)=val;
  2681. WFIFOSET(fd,packet_len_table[0xbc]);
  2682. return 0;
  2683. }
  2684. /*==========================================
  2685. *
  2686. *------------------------------------------
  2687. */
  2688. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2689. {
  2690. int fd;
  2691. nullpo_retr(0, sd);
  2692. fd=sd->fd;
  2693. WFIFOHEAD(fd,packet_len_table[0xaa]);
  2694. WFIFOW(fd,0)=0xaa;
  2695. WFIFOW(fd,2)=n+2;
  2696. WFIFOW(fd,4)=pos;
  2697. WFIFOB(fd,6)=ok;
  2698. WFIFOSET(fd,packet_len_table[0xaa]);
  2699. return 0;
  2700. }
  2701. /*==========================================
  2702. *
  2703. *------------------------------------------
  2704. */
  2705. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2706. {
  2707. int fd;
  2708. nullpo_retr(0, sd);
  2709. fd=sd->fd;
  2710. WFIFOHEAD(fd,packet_len_table[0xac]);
  2711. WFIFOW(fd,0)=0xac;
  2712. WFIFOW(fd,2)=n+2;
  2713. WFIFOW(fd,4)=pos;
  2714. WFIFOB(fd,6)=ok;
  2715. WFIFOSET(fd,packet_len_table[0xac]);
  2716. return 0;
  2717. }
  2718. /*==========================================
  2719. *
  2720. *------------------------------------------
  2721. */
  2722. int clif_misceffect(struct block_list* bl,int type)
  2723. {
  2724. unsigned char buf[32];
  2725. nullpo_retr(0, bl);
  2726. WBUFW(buf,0) = 0x19b;
  2727. WBUFL(buf,2) = bl->id;
  2728. WBUFL(buf,6) = type;
  2729. clif_send(buf,packet_len_table[0x19b],bl,AREA);
  2730. return 0;
  2731. }
  2732. int clif_misceffect2(struct block_list *bl, int type) {
  2733. unsigned char buf[24];
  2734. nullpo_retr(0, bl);
  2735. memset(buf, 0, packet_len_table[0x1f3]);
  2736. WBUFW(buf,0) = 0x1f3;
  2737. WBUFL(buf,2) = bl->id;
  2738. WBUFL(buf,6) = type;
  2739. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  2740. return 0;
  2741. }
  2742. /*==========================================
  2743. * 表示オプション変更
  2744. *------------------------------------------
  2745. */
  2746. int clif_changeoption(struct block_list* bl)
  2747. {
  2748. unsigned char buf[32];
  2749. struct status_change *sc;
  2750. nullpo_retr(0, bl);
  2751. sc = status_get_sc(bl);
  2752. if (!sc) return 0; //How can an option change if there's no sc?
  2753. #if PACKETVER > 6
  2754. WBUFW(buf,0) = 0x229;
  2755. WBUFL(buf,2) = bl->id;
  2756. WBUFW(buf,6) = sc->opt1;
  2757. WBUFW(buf,8) = sc->opt2;
  2758. WBUFL(buf,10) = sc->option;
  2759. WBUFB(buf,14) = 0; // ??
  2760. if(disguised(bl)) {
  2761. clif_send(buf,packet_len_table[0x229],bl,AREA_WOS);
  2762. WBUFL(buf,2) = -bl->id;
  2763. clif_send(buf,packet_len_table[0x229],bl,SELF);
  2764. WBUFL(buf,2) = bl->id;
  2765. WBUFL(buf,10) = OPTION_INVISIBLE;
  2766. clif_send(buf,packet_len_table[0x229],bl,SELF);
  2767. } else
  2768. clif_send(buf,packet_len_table[0x229],bl,AREA);
  2769. #else
  2770. WBUFW(buf,0) = 0x119;
  2771. WBUFL(buf,2) = bl->id;
  2772. WBUFW(buf,6) = sc->opt1;
  2773. WBUFW(buf,8) = sc->opt2;
  2774. WBUFW(buf,10) = sc->option;
  2775. WBUFB(buf,12) = 0; // ??
  2776. if(disguised(bl)) {
  2777. clif_send(buf,packet_len_table[0x119],bl,AREA_WOS);
  2778. WBUFL(buf,2) = -bl->id;
  2779. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2780. WBUFL(buf,2) = bl->id;
  2781. WBUFW(buf,10) = OPTION_INVISIBLE;
  2782. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2783. } else
  2784. clif_send(buf,packet_len_table[0x119],bl,AREA);
  2785. #endif
  2786. return 0;
  2787. }
  2788. /*==========================================
  2789. *
  2790. *------------------------------------------
  2791. */
  2792. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2793. {
  2794. nullpo_retr(0, sd);
  2795. if(!ok) {
  2796. int fd=sd->fd;
  2797. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2798. WFIFOW(fd,0)=0xa8;
  2799. WFIFOW(fd,2)=index+2;
  2800. WFIFOW(fd,4)=amount;
  2801. WFIFOB(fd,6)=ok;
  2802. WFIFOSET(fd,packet_len_table[0xa8]);
  2803. }
  2804. else {
  2805. #if PACKETVER < 3
  2806. int fd=sd->fd;
  2807. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2808. WFIFOW(fd,0)=0xa8;
  2809. WFIFOW(fd,2)=index+2;
  2810. WFIFOW(fd,4)=amount;
  2811. WFIFOB(fd,6)=ok;
  2812. WFIFOSET(fd,packet_len_table[0xa8]);
  2813. #else
  2814. unsigned char buf[32];
  2815. WBUFW(buf,0)=0x1c8;
  2816. WBUFW(buf,2)=index+2;
  2817. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2818. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2819. else
  2820. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2821. WBUFL(buf,6)=sd->bl.id;
  2822. WBUFW(buf,10)=amount;
  2823. WBUFB(buf,12)=ok;
  2824. clif_send(buf,packet_len_table[0x1c8],&sd->bl,AREA);
  2825. #endif
  2826. }
  2827. return 0;
  2828. }
  2829. /*==========================================
  2830. *
  2831. *------------------------------------------
  2832. */
  2833. int clif_createchat(struct map_session_data *sd,int fail)
  2834. {
  2835. int fd;
  2836. nullpo_retr(0, sd);
  2837. fd=sd->fd;
  2838. WFIFOHEAD(fd,packet_len_table[0xd6]);
  2839. WFIFOW(fd,0)=0xd6;
  2840. WFIFOB(fd,2)=fail;
  2841. WFIFOSET(fd,packet_len_table[0xd6]);
  2842. return 0;
  2843. }
  2844. /*==========================================
  2845. *
  2846. *------------------------------------------
  2847. */
  2848. int clif_dispchat(struct chat_data *cd,int fd)
  2849. {
  2850. unsigned char buf[128]; // 最大title(60バイト)+17
  2851. if(cd==NULL || *cd->owner==NULL)
  2852. return 1;
  2853. WBUFW(buf,0)=0xd7;
  2854. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  2855. WBUFL(buf,4)=(*cd->owner)->id;
  2856. WBUFL(buf,8)=cd->bl.id;
  2857. WBUFW(buf,12)=cd->limit;
  2858. WBUFW(buf,14)=cd->users;
  2859. WBUFB(buf,16)=cd->pub;
  2860. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2861. if(fd){
  2862. WFIFOHEAD(fd, WBUFW(buf,2));
  2863. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2864. WFIFOSET(fd,WBUFW(buf,2));
  2865. } else {
  2866. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  2867. }
  2868. return 0;
  2869. }
  2870. /*==========================================
  2871. * chatの状態変更成功
  2872. * 外部の人用と命令コード(d7->df)が違うだけ
  2873. *------------------------------------------
  2874. */
  2875. int clif_changechatstatus(struct chat_data *cd)
  2876. {
  2877. unsigned char buf[128]; // 最大title(60バイト)+17
  2878. if(cd==NULL || cd->usersd[0]==NULL)
  2879. return 1;
  2880. WBUFW(buf,0)=0xdf;
  2881. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  2882. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  2883. WBUFL(buf,8)=cd->bl.id;
  2884. WBUFW(buf,12)=cd->limit;
  2885. WBUFW(buf,14)=cd->users;
  2886. WBUFB(buf,16)=cd->pub;
  2887. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2888. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2889. return 0;
  2890. }
  2891. /*==========================================
  2892. *
  2893. *------------------------------------------
  2894. */
  2895. int clif_clearchat(struct chat_data *cd,int fd)
  2896. {
  2897. unsigned char buf[32];
  2898. nullpo_retr(0, cd);
  2899. WBUFW(buf,0)=0xd8;
  2900. WBUFL(buf,2)=cd->bl.id;
  2901. if(fd){
  2902. WFIFOHEAD(fd,packet_len_table[0xd8]);
  2903. memcpy(WFIFOP(fd,0),buf,packet_len_table[0xd8]);
  2904. WFIFOSET(fd,packet_len_table[0xd8]);
  2905. } else {
  2906. clif_send(buf,packet_len_table[0xd8],*cd->owner,AREA_WOSC);
  2907. }
  2908. return 0;
  2909. }
  2910. /*==========================================
  2911. *
  2912. *------------------------------------------
  2913. */
  2914. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2915. {
  2916. int fd;
  2917. nullpo_retr(0, sd);
  2918. fd=sd->fd;
  2919. WFIFOHEAD(fd,packet_len_table[0xda]);
  2920. WFIFOW(fd,0)=0xda;
  2921. WFIFOB(fd,2)=fail;
  2922. WFIFOSET(fd,packet_len_table[0xda]);
  2923. return 0;
  2924. }
  2925. /*==========================================
  2926. *
  2927. *------------------------------------------
  2928. */
  2929. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2930. {
  2931. int fd;
  2932. int i;
  2933. nullpo_retr(0, sd);
  2934. nullpo_retr(0, cd);
  2935. fd = sd->fd;
  2936. if (!session_isActive(fd))
  2937. return 0;
  2938. WFIFOHEAD(fd, 8 + (28*cd->users));
  2939. WFIFOW(fd, 0) = 0xdb;
  2940. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2941. WFIFOL(fd, 4) = cd->bl.id;
  2942. for (i = 0; i < cd->users; i++) {
  2943. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  2944. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2945. }
  2946. WFIFOSET(fd, WFIFOW(fd, 2));
  2947. return 0;
  2948. }
  2949. /*==========================================
  2950. *
  2951. *------------------------------------------
  2952. */
  2953. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2954. {
  2955. unsigned char buf[32];
  2956. nullpo_retr(0, sd);
  2957. nullpo_retr(0, cd);
  2958. WBUFW(buf, 0) = 0x0dc;
  2959. WBUFW(buf, 2) = cd->users;
  2960. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2961. clif_send(buf,packet_len_table[0xdc],&sd->bl,CHAT_WOS);
  2962. return 0;
  2963. }
  2964. /*==========================================
  2965. *
  2966. *------------------------------------------
  2967. */
  2968. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  2969. {
  2970. unsigned char buf[64];
  2971. nullpo_retr(0, sd);
  2972. nullpo_retr(0, cd);
  2973. WBUFW(buf, 0) = 0xe1;
  2974. WBUFL(buf, 2) = 1;
  2975. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2976. WBUFW(buf,30) = 0xe1;
  2977. WBUFL(buf,32) = 0;
  2978. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2979. clif_send(buf,packet_len_table[0xe1]*2,&sd->bl,CHAT);
  2980. return 0;
  2981. }
  2982. /*==========================================
  2983. *
  2984. *------------------------------------------
  2985. */
  2986. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  2987. {
  2988. unsigned char buf[32];
  2989. nullpo_retr(0, sd);
  2990. nullpo_retr(0, cd);
  2991. WBUFW(buf, 0) = 0xdd;
  2992. WBUFW(buf, 2) = cd->users-1;
  2993. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2994. WBUFB(buf,28) = 0;
  2995. clif_send(buf,packet_len_table[0xdd],&sd->bl,CHAT);
  2996. return 0;
  2997. }
  2998. /*==========================================
  2999. * 取り引き要請受け
  3000. *------------------------------------------
  3001. */
  3002. int clif_traderequest(struct map_session_data *sd,char *name)
  3003. {
  3004. int fd;
  3005. nullpo_retr(0, sd);
  3006. fd=sd->fd;
  3007. WFIFOHEAD(fd,packet_len_table[0xe5]);
  3008. WFIFOW(fd,0)=0xe5;
  3009. strcpy((char*)WFIFOP(fd,2),name);
  3010. WFIFOSET(fd,packet_len_table[0xe5]);
  3011. return 0;
  3012. }
  3013. /*==========================================
  3014. * 取り引き要求応答
  3015. *------------------------------------------
  3016. */
  3017. int clif_tradestart(struct map_session_data *sd,int type)
  3018. {
  3019. int fd;
  3020. nullpo_retr(0, sd);
  3021. fd=sd->fd;
  3022. WFIFOHEAD(fd,packet_len_table[0xe7]);
  3023. WFIFOW(fd,0)=0xe7;
  3024. WFIFOB(fd,2)=type;
  3025. WFIFOSET(fd,packet_len_table[0xe7]);
  3026. return 0;
  3027. }
  3028. /*==========================================
  3029. * 相手方からのアイテム追加
  3030. *------------------------------------------
  3031. */
  3032. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  3033. {
  3034. int fd;
  3035. nullpo_retr(0, sd);
  3036. nullpo_retr(0, tsd);
  3037. fd=tsd->fd;
  3038. WFIFOHEAD(fd,packet_len_table[0xe9]);
  3039. WFIFOW(fd,0)=0xe9;
  3040. WFIFOL(fd,2)=amount;
  3041. if(index==0){
  3042. WFIFOW(fd,6) = 0; // type id
  3043. WFIFOB(fd,8) = 0; //identify flag
  3044. WFIFOB(fd,9) = 0; // attribute
  3045. WFIFOB(fd,10)= 0; //refine
  3046. WFIFOW(fd,11)= 0; //card (4w)
  3047. WFIFOW(fd,13)= 0; //card (4w)
  3048. WFIFOW(fd,15)= 0; //card (4w)
  3049. WFIFOW(fd,17)= 0; //card (4w)
  3050. }
  3051. else{
  3052. index-=2; //index fix
  3053. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3054. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3055. else
  3056. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3057. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3058. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3059. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3060. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3061. }
  3062. WFIFOSET(fd,packet_len_table[0xe9]);
  3063. return 0;
  3064. }
  3065. /*==========================================
  3066. * アイテム追加成功/失敗
  3067. *------------------------------------------
  3068. */
  3069. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3070. {
  3071. int fd;
  3072. nullpo_retr(0, sd);
  3073. fd=sd->fd;
  3074. WFIFOHEAD(fd,packet_len_table[0xea]);
  3075. WFIFOW(fd,0)=0xea;
  3076. WFIFOW(fd,2)=index;
  3077. WFIFOB(fd,4)=fail;
  3078. WFIFOSET(fd,packet_len_table[0xea]);
  3079. return 0;
  3080. }
  3081. /*==========================================
  3082. * 取り引きok押し
  3083. *------------------------------------------
  3084. */
  3085. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3086. {
  3087. int fd;
  3088. nullpo_retr(0, sd);
  3089. fd=sd->fd;
  3090. WFIFOHEAD(fd,packet_len_table[0xec]);
  3091. WFIFOW(fd,0)=0xec;
  3092. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3093. WFIFOSET(fd,packet_len_table[0xec]);
  3094. return 0;
  3095. }
  3096. /*==========================================
  3097. * 取り引きがキャンセルされました
  3098. *------------------------------------------
  3099. */
  3100. int clif_tradecancelled(struct map_session_data *sd)
  3101. {
  3102. int fd;
  3103. nullpo_retr(0, sd);
  3104. fd=sd->fd;
  3105. WFIFOHEAD(fd,packet_len_table[0xee]);
  3106. WFIFOW(fd,0)=0xee;
  3107. WFIFOSET(fd,packet_len_table[0xee]);
  3108. return 0;
  3109. }
  3110. /*==========================================
  3111. * 取り引き完了
  3112. *------------------------------------------
  3113. */
  3114. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3115. {
  3116. int fd;
  3117. nullpo_retr(0, sd);
  3118. fd=sd->fd;
  3119. WFIFOHEAD(fd,packet_len_table[0xf0]);
  3120. WFIFOW(fd,0)=0xf0;
  3121. WFIFOB(fd,2)=fail;
  3122. WFIFOSET(fd,packet_len_table[0xf0]);
  3123. return 0;
  3124. }
  3125. /*==========================================
  3126. * カプラ倉庫のアイテム数を更新
  3127. *------------------------------------------
  3128. */
  3129. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3130. {
  3131. int fd;
  3132. nullpo_retr(0, sd);
  3133. nullpo_retr(0, stor);
  3134. fd=sd->fd;
  3135. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3136. WFIFOW(fd,0) = 0xf2; // update storage amount
  3137. WFIFOW(fd,2) = stor->storage_amount; //items
  3138. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3139. WFIFOSET(fd,packet_len_table[0xf2]);
  3140. return 0;
  3141. }
  3142. /*==========================================
  3143. * カプラ倉庫にアイテムを追加する
  3144. *------------------------------------------
  3145. */
  3146. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3147. {
  3148. int view,fd;
  3149. nullpo_retr(0, sd);
  3150. nullpo_retr(0, stor);
  3151. fd=sd->fd;
  3152. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3153. WFIFOW(fd,0) =0xf4; // Storage item added
  3154. WFIFOW(fd,2) =index+1; // index
  3155. WFIFOL(fd,4) =amount; // amount
  3156. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3157. WFIFOW(fd,8) =view;
  3158. else
  3159. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3160. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3161. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3162. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3163. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3164. WFIFOSET(fd,packet_len_table[0xf4]);
  3165. return 0;
  3166. }
  3167. /*==========================================
  3168. *
  3169. *------------------------------------------
  3170. */
  3171. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3172. {
  3173. int fd;
  3174. nullpo_retr(0, sd);
  3175. nullpo_retr(0, stor);
  3176. fd=sd->fd;
  3177. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3178. WFIFOW(fd,0) = 0xf2; // update storage amount
  3179. WFIFOW(fd,2) = stor->storage_amount; //items
  3180. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3181. WFIFOSET(fd,packet_len_table[0xf2]);
  3182. return 0;
  3183. }
  3184. /*==========================================
  3185. *
  3186. *------------------------------------------
  3187. */
  3188. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3189. {
  3190. int view,fd;
  3191. nullpo_retr(0, sd);
  3192. nullpo_retr(0, stor);
  3193. fd=sd->fd;
  3194. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3195. WFIFOW(fd,0) =0xf4; // Storage item added
  3196. WFIFOW(fd,2) =index+1; // index
  3197. WFIFOL(fd,4) =amount; // amount
  3198. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3199. WFIFOW(fd,8) =view;
  3200. else
  3201. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3202. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3203. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3204. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3205. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3206. WFIFOSET(fd,packet_len_table[0xf4]);
  3207. return 0;
  3208. }
  3209. /*==========================================
  3210. * カプラ倉庫からアイテムを取り去る
  3211. *------------------------------------------
  3212. */
  3213. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3214. {
  3215. int fd;
  3216. nullpo_retr(0, sd);
  3217. fd=sd->fd;
  3218. WFIFOHEAD(fd,packet_len_table[0xf6]);
  3219. WFIFOW(fd,0)=0xf6; // Storage item removed
  3220. WFIFOW(fd,2)=index+1;
  3221. WFIFOL(fd,4)=amount;
  3222. WFIFOSET(fd,packet_len_table[0xf6]);
  3223. return 0;
  3224. }
  3225. /*==========================================
  3226. * カプラ倉庫を閉じる
  3227. *------------------------------------------
  3228. */
  3229. int clif_storageclose(struct map_session_data *sd)
  3230. {
  3231. int fd;
  3232. nullpo_retr(0, sd);
  3233. fd=sd->fd;
  3234. WFIFOHEAD(fd,packet_len_table[0xf8]);
  3235. WFIFOW(fd,0)=0xf8; // Storage Closed
  3236. WFIFOSET(fd,packet_len_table[0xf8]);
  3237. return 0;
  3238. }
  3239. //
  3240. // callback系 ?
  3241. //
  3242. /*==========================================
  3243. * PC表示
  3244. *------------------------------------------
  3245. */
  3246. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3247. {
  3248. int len;
  3249. if(dstsd->chatID){
  3250. struct chat_data *cd;
  3251. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3252. if(cd && cd->usersd[0]==dstsd)
  3253. clif_dispchat(cd,sd->fd);
  3254. }
  3255. if(dstsd->vender_id)
  3256. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3257. if(dstsd->spiritball > 0)
  3258. clif_spiritball_single(sd->fd, dstsd);
  3259. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3260. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3261. )
  3262. clif_hpmeter_single(sd->fd, dstsd);
  3263. if(dstsd->status.manner < 0 && battle_config.manner_system)
  3264. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3265. // pvp circle for duel [LuzZza]
  3266. /*
  3267. if(dstsd->duel_group)
  3268. clif_specialeffect(&dstsd->bl, 159, 4);
  3269. */
  3270. }
  3271. void clif_getareachar_char(struct map_session_data* sd,struct block_list *bl)
  3272. {
  3273. struct unit_data *ud;
  3274. struct view_data *vd;
  3275. int len;
  3276. vd = status_get_viewdata(bl);
  3277. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3278. return;
  3279. if(bl->type == BL_PC && ((TBL_PC *)bl)->status.option & OPTION_INVISIBLE)
  3280. return;
  3281. ud = unit_bl2ud(bl);
  3282. if (ud && ud->walktimer != -1)
  3283. {
  3284. #if PACKETVER < 4
  3285. WFIFOHEAD(sd->fd, packet_len_table[0x7b]);
  3286. #else
  3287. WFIFOHEAD(sd->fd, packet_len_table[0x1da]);
  3288. #endif
  3289. len = clif_set007b(bl,vd,ud,WFIFOP(sd->fd,0));
  3290. WFIFOSET(sd->fd,len);
  3291. } else {
  3292. #if PACKETVER < 4
  3293. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3294. #else
  3295. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3296. #endif
  3297. len = clif_set0078(bl,vd,WFIFOP(sd->fd,0));
  3298. WFIFOSET(sd->fd,len);
  3299. }
  3300. if (vd->cloth_color)
  3301. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3302. switch (bl->type)
  3303. {
  3304. case BL_PC:
  3305. {
  3306. TBL_PC* tsd = (TBL_PC*)bl;
  3307. clif_getareachar_pc(sd, tsd);
  3308. if(tsd->state.size==2) // tiny/big players [Valaris]
  3309. clif_specialeffect(bl,423,0);
  3310. else if(tsd->state.size==1)
  3311. clif_specialeffect(bl,421,0);
  3312. }
  3313. break;
  3314. case BL_NPC:
  3315. {
  3316. if(((TBL_NPC*)bl)->chat_id)
  3317. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3318. }
  3319. break;
  3320. case BL_MOB:
  3321. {
  3322. TBL_MOB* md = (TBL_MOB*)bl;
  3323. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3324. clif_specialeffect(bl,423,0);
  3325. else if(md->special_state.size==1)
  3326. clif_specialeffect(bl,421,0);
  3327. }
  3328. break;
  3329. }
  3330. }
  3331. /*==========================================
  3332. * Older fix pos packet.
  3333. *------------------------------------------
  3334. */
  3335. int clif_fixpos2(struct block_list* bl)
  3336. {
  3337. struct unit_data *ud;
  3338. struct view_data *vd;
  3339. unsigned char buf[256];
  3340. int len;
  3341. nullpo_retr(0, bl);
  3342. ud = unit_bl2ud(bl);
  3343. vd = status_get_viewdata(bl);
  3344. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3345. return 0;
  3346. if(ud && ud->walktimer != -1)
  3347. len = clif_set007b(bl,vd,ud,buf);
  3348. else
  3349. len = clif_set0078(bl,vd,buf);
  3350. if (disguised(bl)) {
  3351. if(((TBL_PC *)bl)->status.option & OPTION_INVISIBLE)
  3352. return 0;
  3353. clif_send(buf,len,bl,AREA_WOS);
  3354. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  3355. clif_setdisguise((TBL_PC*)bl, buf, len, 1);
  3356. } else
  3357. clif_send(buf,len,bl,AREA);
  3358. return 0;
  3359. }
  3360. //Modifies the type of damage according to status changes [Skotlex]
  3361. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3362. /*==========================================
  3363. * Estimates walk delay based on the damage criteria. [Skotlex]
  3364. *------------------------------------------
  3365. */
  3366. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3367. if (type == 4 || type == 9 || damage <=0)
  3368. return 0;
  3369. if (bl->type == BL_PC) {
  3370. if (battle_config.pc_walk_delay_rate != 100)
  3371. delay = delay*battle_config.pc_walk_delay_rate/100;
  3372. } else
  3373. if (battle_config.walk_delay_rate != 100)
  3374. delay = delay*battle_config.walk_delay_rate/100;
  3375. if (div_ > 1) //Multi-hit skills mean higher delays.
  3376. delay += battle_config.multihit_delay*(div_-1);
  3377. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3378. }
  3379. /*==========================================
  3380. * 通常攻撃エフェクト&ダメージ
  3381. *------------------------------------------
  3382. */
  3383. 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)
  3384. {
  3385. unsigned char buf[256];
  3386. struct status_change *sc;
  3387. nullpo_retr(0, src);
  3388. nullpo_retr(0, dst);
  3389. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3390. sc = status_get_sc(dst);
  3391. if(sc && sc->count) {
  3392. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3393. if(damage > 0)
  3394. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3395. if(damage2 > 0)
  3396. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3397. }
  3398. }
  3399. WBUFW(buf,0)=0x8a;
  3400. WBUFL(buf,2)=src->id;
  3401. WBUFL(buf,6)=dst->id;
  3402. WBUFL(buf,10)=tick;
  3403. WBUFL(buf,14)=sdelay;
  3404. WBUFL(buf,18)=ddelay;
  3405. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3406. WBUFW(buf,22)=1;
  3407. WBUFW(buf,27)=1;
  3408. } else {
  3409. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3410. WBUFW(buf,27)=damage2;
  3411. }
  3412. WBUFW(buf,24)=div;
  3413. WBUFB(buf,26)=type;
  3414. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3415. if(disguised(src)) {
  3416. WBUFL(buf,2)=-src->id;
  3417. if(damage > 0)
  3418. WBUFW(buf,22)=-1;
  3419. if(damage2 > 0)
  3420. WBUFW(buf,27)=-1;
  3421. clif_send(buf,packet_len_table[0x8a],src,SELF);
  3422. }
  3423. if (disguised(dst)) {
  3424. WBUFL(buf,6)=-dst->id;
  3425. if (disguised(src))
  3426. WBUFL(buf,2)=src->id;
  3427. else {
  3428. if(damage > 0)
  3429. WBUFW(buf,22)=-1;
  3430. if(damage2 > 0)
  3431. WBUFW(buf,27)=-1;
  3432. }
  3433. clif_send(buf,packet_len_table[0x8a],dst,SELF);
  3434. }
  3435. //Return adjusted can't walk delay for further processing.
  3436. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3437. }
  3438. /*==========================================
  3439. *
  3440. *------------------------------------------
  3441. */
  3442. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3443. {
  3444. int view,fd;
  3445. fd=sd->fd;
  3446. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3447. WFIFOHEAD(fd,packet_len_table[0x9d]);
  3448. WFIFOW(fd,0)=0x9d;
  3449. WFIFOL(fd,2)=fitem->bl.id;
  3450. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3451. WFIFOW(fd,6)=view;
  3452. else
  3453. WFIFOW(fd,6)=fitem->item_data.nameid;
  3454. WFIFOB(fd,8)=fitem->item_data.identify;
  3455. WFIFOW(fd,9)=fitem->bl.x;
  3456. WFIFOW(fd,11)=fitem->bl.y;
  3457. WFIFOW(fd,13)=fitem->item_data.amount;
  3458. WFIFOB(fd,15)=fitem->subx;
  3459. WFIFOB(fd,16)=fitem->suby;
  3460. WFIFOSET(fd,packet_len_table[0x9d]);
  3461. }
  3462. /*==========================================
  3463. * 場所スキルエフェクトが視界に入る
  3464. *------------------------------------------
  3465. */
  3466. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3467. {
  3468. int fd;
  3469. struct block_list *bl;
  3470. fd=sd->fd;
  3471. bl=map_id2bl(unit->group->src_id);
  3472. #if PACKETVER >= 3
  3473. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3474. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3475. memset(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3476. WFIFOW(fd, 0)=0x1c9;
  3477. WFIFOL(fd, 2)=unit->bl.id;
  3478. WFIFOL(fd, 6)=unit->group->src_id;
  3479. WFIFOW(fd,10)=unit->bl.x;
  3480. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3481. WFIFOB(fd,14)=unit->group->unit_id;
  3482. WFIFOB(fd,15)=1;
  3483. WFIFOB(fd,16)=1;
  3484. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3485. WFIFOSET(fd,packet_len_table[0x1c9]);
  3486. return 0;
  3487. }
  3488. #endif
  3489. WFIFOHEAD(fd,packet_len_table[0x11f]);
  3490. memset(WFIFOP(fd,0),0,packet_len_table[0x11f]);
  3491. WFIFOW(fd, 0)=0x11f;
  3492. WFIFOL(fd, 2)=unit->bl.id;
  3493. WFIFOL(fd, 6)=unit->group->src_id;
  3494. WFIFOW(fd,10)=unit->bl.x;
  3495. WFIFOW(fd,12)=unit->bl.y;
  3496. //Use invisible unit id for traps.
  3497. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3498. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3499. else
  3500. WFIFOB(fd,14)=unit->group->unit_id;
  3501. WFIFOB(fd,15)=0;
  3502. WFIFOSET(fd,packet_len_table[0x11f]);
  3503. if(unit->group->skill_id == WZ_ICEWALL)
  3504. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3505. return 0;
  3506. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3507. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3508. memset(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3509. WFIFOW(fd, 0)=0x1c9;
  3510. WFIFOL(fd, 2)=unit->bl.id;
  3511. WFIFOL(fd, 6)=unit->group->src_id;
  3512. WFIFOW(fd,10)=unit->bl.x;
  3513. WFIFOW(fd,12)=unit->bl.y;
  3514. WFIFOB(fd,14)=unit->group->unit_id;
  3515. WFIFOB(fd,15)=1;
  3516. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3517. WFIFOB(fd,16)=1;
  3518. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3519. } else {
  3520. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3521. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3522. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3523. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3524. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3525. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3526. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3527. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3528. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3529. //37-39
  3530. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3531. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3532. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3533. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3534. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3535. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3536. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3537. //65-68
  3538. //69-72
  3539. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3540. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3541. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3542. }
  3543. WFIFOSET(fd,packet_len_table[0x1c9]);
  3544. #endif
  3545. if(unit->group->skill_id == WZ_ICEWALL)
  3546. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3547. return 0;
  3548. */
  3549. }
  3550. /*==========================================
  3551. * 場所スキルエフェクトが視界から消える
  3552. *------------------------------------------
  3553. */
  3554. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3555. {
  3556. nullpo_retr(0, unit);
  3557. WFIFOHEAD(fd,packet_len_table[0x120]);
  3558. WFIFOW(fd, 0)=0x120;
  3559. WFIFOL(fd, 2)=unit->bl.id;
  3560. WFIFOSET(fd,packet_len_table[0x120]);
  3561. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3562. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3563. return 0;
  3564. }
  3565. /*==========================================
  3566. *
  3567. *------------------------------------------
  3568. */
  3569. int clif_01ac(struct block_list *bl)
  3570. {
  3571. unsigned char buf[32];
  3572. nullpo_retr(0, bl);
  3573. WBUFW(buf, 0) = 0x1ac;
  3574. WBUFL(buf, 2) = bl->id;
  3575. clif_send(buf,packet_len_table[0x1ac],bl,AREA);
  3576. return 0;
  3577. }
  3578. /*==========================================
  3579. *
  3580. *------------------------------------------
  3581. */
  3582. int clif_getareachar(struct block_list* bl,va_list ap)
  3583. {
  3584. struct map_session_data *sd;
  3585. nullpo_retr(0, bl);
  3586. nullpo_retr(0, ap);
  3587. sd=va_arg(ap,struct map_session_data*);
  3588. if (sd == NULL || session[sd->fd] == NULL)
  3589. return 0;
  3590. switch(bl->type){
  3591. case BL_ITEM:
  3592. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3593. break;
  3594. case BL_SKILL:
  3595. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3596. break;
  3597. default:
  3598. if(&sd->bl == bl)
  3599. break;
  3600. clif_getareachar_char(sd,bl);
  3601. break;
  3602. }
  3603. return 0;
  3604. }
  3605. /*==========================================
  3606. * tbl has gone out of view-size of bl
  3607. *------------------------------------------
  3608. */
  3609. int clif_outsight(struct block_list *bl,va_list ap)
  3610. {
  3611. struct block_list *tbl;
  3612. struct view_data *vd;
  3613. TBL_PC *sd, *tsd;
  3614. tbl=va_arg(ap,struct block_list*);
  3615. if(bl == tbl) return 0;
  3616. BL_CAST(BL_PC, bl, sd);
  3617. BL_CAST(BL_PC, tbl, tsd);
  3618. if (tsd && tsd->fd)
  3619. { //tsd has lost sight of the bl object.
  3620. switch(bl->type){
  3621. case BL_PC:
  3622. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS || !(((TBL_PC*)bl)->status.option & OPTION_INVISIBLE))
  3623. clif_clearchar_id(bl->id,0,tsd->fd);
  3624. if(sd->chatID){
  3625. struct chat_data *cd;
  3626. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3627. if(cd->usersd[0]==sd)
  3628. clif_dispchat(cd,tsd->fd);
  3629. }
  3630. if(sd->vender_id)
  3631. clif_closevendingboard(bl,tsd->fd);
  3632. break;
  3633. case BL_ITEM:
  3634. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3635. break;
  3636. case BL_SKILL:
  3637. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3638. break;
  3639. default:
  3640. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3641. clif_clearchar_id(bl->id,0,tsd->fd);
  3642. break;
  3643. }
  3644. }
  3645. if (sd && sd->fd)
  3646. { //sd is watching tbl go out of view.
  3647. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3648. clif_clearchar_id(tbl->id,0,sd->fd);
  3649. }
  3650. return 0;
  3651. }
  3652. /*==========================================
  3653. * tbl has come into view of bl
  3654. *------------------------------------------
  3655. */
  3656. int clif_insight(struct block_list *bl,va_list ap)
  3657. {
  3658. struct block_list *tbl;
  3659. TBL_PC *sd, *tsd;
  3660. tbl=va_arg(ap,struct block_list*);
  3661. if (bl == tbl) return 0;
  3662. BL_CAST(BL_PC, bl, sd);
  3663. BL_CAST(BL_PC, tbl, tsd);
  3664. if (tsd && tsd->fd)
  3665. { //Tell tsd that bl entered into his view
  3666. switch(bl->type){
  3667. case BL_ITEM:
  3668. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3669. break;
  3670. case BL_SKILL:
  3671. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3672. break;
  3673. default:
  3674. clif_getareachar_char(tsd,bl);
  3675. break;
  3676. }
  3677. }
  3678. if (sd && sd->fd)
  3679. { //Tell sd that tbl walked into his view
  3680. clif_getareachar_char(sd,tbl);
  3681. }
  3682. return 0;
  3683. }
  3684. /*==========================================
  3685. *
  3686. *------------------------------------------
  3687. */
  3688. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3689. {
  3690. int fd,id, inf2;
  3691. nullpo_retr(0, sd);
  3692. fd=sd->fd;
  3693. if( (id=sd->status.skill[skillid].id) <= 0 )
  3694. return 0;
  3695. WFIFOHEAD(fd,packet_len_table[0x147]);
  3696. WFIFOW(fd,0)=0x147;
  3697. WFIFOW(fd,2) = id;
  3698. if(type < 0)
  3699. WFIFOW(fd,4) = skill_get_inf(id);
  3700. else
  3701. WFIFOW(fd,4) = type;
  3702. WFIFOW(fd,6) = 0;
  3703. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3704. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3705. if(range < 0)
  3706. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3707. WFIFOW(fd,12)= range;
  3708. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3709. inf2 = skill_get_inf2(id);
  3710. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3711. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3712. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill))
  3713. //WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_get_max(id) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3714. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3715. else
  3716. WFIFOB(fd,38) = 0;
  3717. WFIFOSET(fd,packet_len_table[0x147]);
  3718. return 0;
  3719. }
  3720. /*==========================================
  3721. * スキルリストを送信する
  3722. *------------------------------------------
  3723. */
  3724. int clif_skillinfoblock(struct map_session_data *sd)
  3725. {
  3726. int fd;
  3727. int i,c,len=4,id, inf2;
  3728. nullpo_retr(0, sd);
  3729. fd=sd->fd;
  3730. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3731. WFIFOW(fd,0)=0x10f;
  3732. for ( i = c = 0; i < MAX_SKILL; i++){
  3733. if( (id=sd->status.skill[i].id)!=0 ){
  3734. WFIFOW(fd,len ) = id;
  3735. WFIFOW(fd,len+2) = skill_get_inf(id);
  3736. WFIFOW(fd,len+4) = 0;
  3737. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3738. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3739. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3740. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3741. inf2 = skill_get_inf2(id);
  3742. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3743. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3744. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill) )
  3745. //WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_get_max(id) && sd->status.skill[i].flag ==0 )? 1:0;
  3746. 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;
  3747. else
  3748. WFIFOB(fd,len+36) = 0;
  3749. len+=37;
  3750. c++;
  3751. }
  3752. }
  3753. WFIFOW(fd,2)=len;
  3754. WFIFOSET(fd,len);
  3755. return 0;
  3756. }
  3757. /*==========================================
  3758. * スキル割り振り通知
  3759. *------------------------------------------
  3760. */
  3761. int clif_skillup(struct map_session_data *sd,int skill_num)
  3762. {
  3763. int fd;
  3764. nullpo_retr(0, sd);
  3765. fd=sd->fd;
  3766. WFIFOHEAD(fd,packet_len_table[0x10e]);
  3767. WFIFOW(fd,0) = 0x10e;
  3768. WFIFOW(fd,2) = skill_num;
  3769. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3770. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3771. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3772. //WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_get_max(sd->status.skill[skill_num].id)) ? 1 : 0;
  3773. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3774. WFIFOSET(fd,packet_len_table[0x10e]);
  3775. return 0;
  3776. }
  3777. /*==========================================
  3778. * スキル詠唱エフェクトを送信する
  3779. *------------------------------------------
  3780. */
  3781. int clif_skillcasting(struct block_list* bl,
  3782. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  3783. {
  3784. int pl = skill_get_pl(skill_num);
  3785. unsigned char buf[32];
  3786. WBUFW(buf,0) = 0x13e;
  3787. WBUFL(buf,2) = src_id;
  3788. WBUFL(buf,6) = dst_id;
  3789. WBUFW(buf,10) = dst_x;
  3790. WBUFW(buf,12) = dst_y;
  3791. WBUFW(buf,14) = skill_num;
  3792. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3793. WBUFL(buf,20) = casttime;
  3794. clif_send(buf,packet_len_table[0x13e], bl, AREA);
  3795. if (disguised(bl)) {
  3796. WBUFL(buf,2) = -src_id;
  3797. WBUFL(buf,20) = 0;
  3798. clif_send(buf,packet_len_table[0x13e], bl, SELF);
  3799. }
  3800. return 0;
  3801. }
  3802. /*==========================================
  3803. *
  3804. *------------------------------------------
  3805. */
  3806. int clif_skillcastcancel(struct block_list* bl)
  3807. {
  3808. unsigned char buf[16];
  3809. nullpo_retr(0, bl);
  3810. WBUFW(buf,0) = 0x1b9;
  3811. WBUFL(buf,2) = bl->id;
  3812. clif_send(buf,packet_len_table[0x1b9], bl, AREA);
  3813. return 0;
  3814. }
  3815. /*==========================================
  3816. * スキル詠唱失敗
  3817. *------------------------------------------
  3818. */
  3819. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3820. {
  3821. int fd;
  3822. if (!sd) { //Since this is the most common nullpo....
  3823. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3824. return 0;
  3825. }
  3826. fd=sd->fd;
  3827. // reset all variables [celest]
  3828. // Should be handled now by the unit_* code.
  3829. sd->skillitem = sd->skillitemlv = -1;
  3830. if(type==0x4 && !sd->state.showdelay)
  3831. return 0;
  3832. WFIFOHEAD(fd,packet_len_table[0x110]);
  3833. WFIFOW(fd,0) = 0x110;
  3834. WFIFOW(fd,2) = skill_id;
  3835. WFIFOW(fd,4) = btype;
  3836. WFIFOW(fd,6) = 0;
  3837. WFIFOB(fd,8) = 0;
  3838. WFIFOB(fd,9) = type;
  3839. WFIFOSET(fd,packet_len_table[0x110]);
  3840. return 0;
  3841. }
  3842. /*==========================================
  3843. * スキル攻撃エフェクト&ダメージ
  3844. *------------------------------------------
  3845. */
  3846. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  3847. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3848. {
  3849. unsigned char buf[64];
  3850. struct status_change *sc;
  3851. nullpo_retr(0, src);
  3852. nullpo_retr(0, dst);
  3853. type = (type>0)?type:skill_get_hit(skill_id);
  3854. type = clif_calc_delay(type, ddelay);
  3855. sc = status_get_sc(dst);
  3856. if(sc && sc->count) {
  3857. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3858. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3859. }
  3860. #if PACKETVER < 3
  3861. WBUFW(buf,0)=0x114;
  3862. WBUFW(buf,2)=skill_id;
  3863. WBUFL(buf,4)=src->id;
  3864. WBUFL(buf,8)=dst->id;
  3865. WBUFL(buf,12)=tick;
  3866. WBUFL(buf,16)=sdelay;
  3867. WBUFL(buf,20)=ddelay;
  3868. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3869. WBUFW(buf,24)=1;
  3870. } else {
  3871. WBUFW(buf,24)=damage;
  3872. }
  3873. WBUFW(buf,26)=skill_lv;
  3874. WBUFW(buf,28)=div;
  3875. WBUFB(buf,30)=type;
  3876. clif_send(buf,packet_len_table[0x114],src,AREA);
  3877. if(disguised(src)) {
  3878. WBUFL(buf,4)=-src->id;
  3879. if(damage > 0)
  3880. WBUFW(buf,24)=-1;
  3881. clif_send(buf,packet_len_table[0x114],src,SELF);
  3882. }
  3883. if (disguised(dst)) {
  3884. WBUFL(buf,8)=-dst->id;
  3885. if (disguised(src))
  3886. WBUFL(buf,4)=src->id;
  3887. else if(damage > 0)
  3888. WBUFW(buf,24)=-1;
  3889. clif_send(buf,packet_len_table[0x114],dst,SELF);
  3890. }
  3891. #else
  3892. WBUFW(buf,0)=0x1de;
  3893. WBUFW(buf,2)=skill_id;
  3894. WBUFL(buf,4)=src->id;
  3895. WBUFL(buf,8)=dst->id;
  3896. WBUFL(buf,12)=tick;
  3897. WBUFL(buf,16)=sdelay;
  3898. WBUFL(buf,20)=ddelay;
  3899. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3900. WBUFL(buf,24)=1;
  3901. } else {
  3902. WBUFL(buf,24)=damage;
  3903. }
  3904. WBUFW(buf,28)=skill_lv;
  3905. WBUFW(buf,30)=div;
  3906. WBUFB(buf,32)=type;
  3907. clif_send(buf,packet_len_table[0x1de],src,AREA);
  3908. if(disguised(src)) {
  3909. WBUFL(buf,4)=-src->id;
  3910. if(damage > 0)
  3911. WBUFW(buf,24)=-1;
  3912. clif_send(buf,packet_len_table[0x1de],src,SELF);
  3913. }
  3914. if (disguised(dst)) {
  3915. WBUFL(buf,8)=-dst->id;
  3916. if (disguised(src))
  3917. WBUFL(buf,4)=src->id;
  3918. else if(damage > 0)
  3919. WBUFW(buf,24)=-1;
  3920. clif_send(buf,packet_len_table[0x1de],dst,SELF);
  3921. }
  3922. #endif
  3923. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3924. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3925. }
  3926. /*==========================================
  3927. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3928. *------------------------------------------
  3929. */
  3930. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  3931. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3932. {
  3933. unsigned char buf[64];
  3934. struct status_change *sc;
  3935. nullpo_retr(0, src);
  3936. nullpo_retr(0, dst);
  3937. type = (type>0)?type:skill_get_hit(skill_id);
  3938. type = clif_calc_delay(type, ddelay);
  3939. sc = status_get_sc(dst);
  3940. if(sc && sc->count) {
  3941. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3942. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3943. }
  3944. WBUFW(buf,0)=0x115;
  3945. WBUFW(buf,2)=skill_id;
  3946. WBUFL(buf,4)=src->id;
  3947. WBUFL(buf,8)=dst->id;
  3948. WBUFL(buf,12)=tick;
  3949. WBUFL(buf,16)=sdelay;
  3950. WBUFL(buf,20)=ddelay;
  3951. WBUFW(buf,24)=dst->x;
  3952. WBUFW(buf,26)=dst->y;
  3953. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3954. WBUFW(buf,28)=1;
  3955. } else {
  3956. WBUFW(buf,28)=damage;
  3957. }
  3958. WBUFW(buf,30)=skill_lv;
  3959. WBUFW(buf,32)=div;
  3960. WBUFB(buf,34)=type;
  3961. clif_send(buf,packet_len_table[0x115],src,AREA);
  3962. if(disguised(src)) {
  3963. WBUFL(buf,4)=-src->id;
  3964. if(damage > 0)
  3965. WBUFW(buf,28)=-1;
  3966. clif_send(buf,packet_len_table[0x115],src,SELF);
  3967. }
  3968. if (disguised(dst)) {
  3969. WBUFL(buf,8)=-dst->id;
  3970. if (disguised(src))
  3971. WBUFL(buf,4)=src->id;
  3972. else if(damage > 0)
  3973. WBUFW(buf,28)=-1;
  3974. clif_send(buf,packet_len_table[0x115],dst,SELF);
  3975. }
  3976. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3977. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3978. }
  3979. /*==========================================
  3980. * 支援/回復スキルエフェクト
  3981. *------------------------------------------
  3982. */
  3983. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  3984. int skill_id,int heal,int fail)
  3985. {
  3986. unsigned char buf[32];
  3987. nullpo_retr(0, dst);
  3988. WBUFW(buf,0)=0x11a;
  3989. WBUFW(buf,2)=skill_id;
  3990. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  3991. WBUFL(buf,6)=dst->id;
  3992. WBUFL(buf,10)=src?src->id:0;
  3993. WBUFB(buf,14)=fail;
  3994. clif_send(buf,packet_len_table[0x11a],dst,AREA);
  3995. if (disguised(dst)) {
  3996. WBUFL(buf,6)=-dst->id;
  3997. clif_send(buf,packet_len_table[0x115],dst,SELF);
  3998. }
  3999. if(src && disguised(src)) {
  4000. WBUFL(buf,10)=-src->id;
  4001. if (disguised(dst))
  4002. WBUFL(buf,6)=dst->id;
  4003. clif_send(buf,packet_len_table[0x115],src,SELF);
  4004. }
  4005. return fail;
  4006. }
  4007. /*==========================================
  4008. * 場所スキルエフェクト
  4009. *------------------------------------------
  4010. */
  4011. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4012. {
  4013. unsigned char buf[32];
  4014. nullpo_retr(0, src);
  4015. WBUFW(buf,0)=0x117;
  4016. WBUFW(buf,2)=skill_id;
  4017. WBUFL(buf,4)=src->id;
  4018. WBUFW(buf,8)=val;
  4019. WBUFW(buf,10)=x;
  4020. WBUFW(buf,12)=y;
  4021. WBUFL(buf,14)=tick;
  4022. clif_send(buf,packet_len_table[0x117],src,AREA);
  4023. if(disguised(src)) {
  4024. WBUFL(buf,4)=-src->id;
  4025. clif_send(buf,packet_len_table[0x117],src,SELF);
  4026. }
  4027. return 0;
  4028. }
  4029. /*==========================================
  4030. * 場所スキルエフェクト表示
  4031. *------------------------------------------
  4032. */
  4033. int clif_skill_setunit(struct skill_unit *unit)
  4034. {
  4035. unsigned char buf[128];
  4036. struct block_list *bl;
  4037. nullpo_retr(0, unit);
  4038. bl=map_id2bl(unit->group->src_id);
  4039. // These are invisible client-side, but are necessary because
  4040. // otherwise the client will not know who caused the attack.
  4041. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  4042. // return 0;
  4043. #if PACKETVER >= 3
  4044. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4045. memset(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4046. WBUFW(buf, 0)=0x1c9;
  4047. WBUFL(buf, 2)=unit->bl.id;
  4048. WBUFL(buf, 6)=unit->group->src_id;
  4049. WBUFW(buf,10)=unit->bl.x;
  4050. WBUFW(buf,12)=unit->bl.y;
  4051. WBUFB(buf,14)=unit->group->unit_id;
  4052. WBUFB(buf,15)=1;
  4053. WBUFB(buf,16)=1;
  4054. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4055. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4056. return 0;
  4057. }
  4058. #endif
  4059. memset(WBUFP(buf, 0),0,packet_len_table[0x11f]);
  4060. WBUFW(buf, 0)=0x11f;
  4061. WBUFL(buf, 2)=unit->bl.id;
  4062. WBUFL(buf, 6)=unit->group->src_id;
  4063. WBUFW(buf,10)=unit->bl.x;
  4064. WBUFW(buf,12)=unit->bl.y;
  4065. WBUFB(buf,14)=unit->group->unit_id;
  4066. WBUFB(buf,15)=0;
  4067. clif_send(buf,packet_len_table[0x11f],&unit->bl,AREA);
  4068. return 0;
  4069. /* Previous mysterious implementation noone really understands. [Skotlex]
  4070. memset(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4071. WBUFW(buf, 0)=0x1c9;
  4072. WBUFL(buf, 2)=unit->bl.id;
  4073. WBUFL(buf, 6)=unit->group->src_id;
  4074. WBUFW(buf,10)=unit->bl.x;
  4075. WBUFW(buf,12)=unit->bl.y;
  4076. WBUFB(buf,14)=unit->group->unit_id;
  4077. WBUFB(buf,15)=1;
  4078. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4079. WBUFB(buf,16)=1;
  4080. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4081. } else {
  4082. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4083. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4084. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4085. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4086. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4087. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4088. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4089. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4090. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4091. //37-39
  4092. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4093. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4094. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4095. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4096. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4097. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4098. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4099. //65-68
  4100. //69-72
  4101. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4102. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4103. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4104. }
  4105. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4106. #endif
  4107. return 0;
  4108. */
  4109. }
  4110. /*==========================================
  4111. * 場所スキルエフェクト削除
  4112. *------------------------------------------
  4113. */
  4114. int clif_skill_delunit(struct skill_unit *unit)
  4115. {
  4116. unsigned char buf[16];
  4117. nullpo_retr(0, unit);
  4118. WBUFW(buf, 0)=0x120;
  4119. WBUFL(buf, 2)=unit->bl.id;
  4120. clif_send(buf,packet_len_table[0x120],&unit->bl,AREA);
  4121. return 0;
  4122. }
  4123. /*==========================================
  4124. * ワープ場所選択
  4125. *------------------------------------------
  4126. */
  4127. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4128. const char *map1,const char *map2,const char *map3,const char *map4)
  4129. {
  4130. int fd;
  4131. nullpo_retr(0, sd);
  4132. fd=sd->fd;
  4133. WFIFOHEAD(fd,packet_len_table[0x11c]);
  4134. WFIFOW(fd,0)=0x11c;
  4135. WFIFOW(fd,2)=skill_num;
  4136. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4137. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4138. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4139. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4140. WFIFOSET(fd,packet_len_table[0x11c]);
  4141. sd->menuskill_id = skill_num;
  4142. if (skill_num == AL_WARP)
  4143. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4144. else
  4145. sd->menuskill_lv = skill_lv;
  4146. return 0;
  4147. }
  4148. /*==========================================
  4149. * メモ応答
  4150. *------------------------------------------
  4151. */
  4152. int clif_skill_memo(struct map_session_data *sd,int flag)
  4153. {
  4154. int fd;
  4155. nullpo_retr(0, sd);
  4156. fd=sd->fd;
  4157. WFIFOHEAD(fd,packet_len_table[0x11e]);
  4158. WFIFOW(fd,0)=0x11e;
  4159. WFIFOB(fd,2)=flag;
  4160. WFIFOSET(fd,packet_len_table[0x11e]);
  4161. return 0;
  4162. }
  4163. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4164. {
  4165. int fd;
  4166. nullpo_retr(0, sd);
  4167. fd=sd->fd;
  4168. WFIFOHEAD(fd,packet_len_table[0x189]);
  4169. WFIFOW(fd,0)=0x189;
  4170. WFIFOW(fd,2)=flag;
  4171. WFIFOSET(fd,packet_len_table[0x189]);
  4172. return 0;
  4173. }
  4174. /*==========================================
  4175. * モンスター情報
  4176. *------------------------------------------
  4177. */
  4178. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4179. {
  4180. struct mob_data *md;
  4181. unsigned char buf[64];
  4182. int i;//, fix;
  4183. nullpo_retr(0, sd);
  4184. nullpo_retr(0, dst);
  4185. if(dst->type!=BL_MOB )
  4186. return 0;
  4187. if((md=(struct mob_data *)dst) == NULL)
  4188. return 0;
  4189. WBUFW(buf, 0)=0x18c;
  4190. WBUFW(buf, 2)=md->vd->class_;
  4191. WBUFW(buf, 4)=md->level;
  4192. WBUFW(buf, 6)=md->db->size;
  4193. WBUFL(buf, 8)=md->hp;
  4194. WBUFW(buf,12)= (battle_config.estimation_type&1?status_get_def(&md->bl):0)
  4195. +(battle_config.estimation_type&2?status_get_def2(&md->bl):0);
  4196. WBUFW(buf,14)=md->db->race;
  4197. WBUFW(buf,16)= (battle_config.estimation_type&1?status_get_mdef(&md->bl):0)
  4198. +(battle_config.estimation_type&2?status_get_mdef2(&md->bl) - (md->db->vit>>1):0);
  4199. WBUFW(buf,18)=status_get_elem_type(&md->bl);
  4200. for(i=0;i<9;i++)
  4201. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,md->def_ele);
  4202. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4203. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,md->def_ele))<0?0:fix);
  4204. if(sd->status.party_id>0)
  4205. clif_send(buf,packet_len_table[0x18c],&sd->bl,PARTY_AREA);
  4206. else{
  4207. WFIFOHEAD(sd->fd,packet_len_table[0x18c]);
  4208. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x18c]);
  4209. WFIFOSET(sd->fd,packet_len_table[0x18c]);
  4210. }
  4211. return 0;
  4212. }
  4213. /*==========================================
  4214. * アイテム合成可能リスト
  4215. *------------------------------------------
  4216. */
  4217. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4218. {
  4219. int i,c,view,fd;
  4220. nullpo_retr(0, sd);
  4221. if(sd->menuskill_id == AM_PHARMACY)
  4222. return 0; //Avoid resending the menu twice or more times...
  4223. fd=sd->fd;
  4224. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4225. WFIFOW(fd, 0)=0x18d;
  4226. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4227. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4228. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4229. WFIFOW(fd,c*8+ 4)= view;
  4230. else
  4231. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4232. WFIFOW(fd,c*8+ 6)= 0x0012;
  4233. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4234. c++;
  4235. }
  4236. }
  4237. WFIFOW(fd, 2)=c*8+8;
  4238. WFIFOSET(fd,WFIFOW(fd,2));
  4239. if(c > 0) {
  4240. sd->menuskill_id = AM_PHARMACY;
  4241. sd->menuskill_lv = trigger;
  4242. return 1;
  4243. }
  4244. return 0;
  4245. }
  4246. /*==========================================
  4247. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4248. *------------------------------------------
  4249. */
  4250. int clif_status_load(struct block_list *bl,int type, int flag)
  4251. {
  4252. int fd;
  4253. if (type == SI_BLANK) //It shows nothing on the client...
  4254. return 0;
  4255. if (bl->type != BL_PC)
  4256. return 0;
  4257. fd = ((struct map_session_data*)bl)->fd;
  4258. WFIFOHEAD(fd,packet_len_table[0x196]);
  4259. WFIFOW(fd,0)=0x0196;
  4260. WFIFOW(fd,2)=type;
  4261. WFIFOL(fd,4)=bl->id;
  4262. WFIFOB(fd,8)=flag; //Status start
  4263. WFIFOSET(fd, packet_len_table[0x196]);
  4264. return 0;
  4265. }
  4266. /*==========================================
  4267. * 状態異常アイコン/メッセージ表示
  4268. *------------------------------------------
  4269. */
  4270. int clif_status_change(struct block_list *bl,int type,int flag)
  4271. {
  4272. unsigned char buf[16];
  4273. if (type == SI_BLANK) //It shows nothing on the client...
  4274. return 0;
  4275. nullpo_retr(0, bl);
  4276. WBUFW(buf,0)=0x0196;
  4277. WBUFW(buf,2)=type;
  4278. WBUFL(buf,4)=bl->id;
  4279. WBUFB(buf,8)=flag;
  4280. clif_send(buf,packet_len_table[0x196],bl,AREA);
  4281. return 0;
  4282. }
  4283. /*==========================================
  4284. * Send message (modified by [Yor])
  4285. *------------------------------------------
  4286. */
  4287. int clif_displaymessage(const int fd, char* mes)
  4288. {
  4289. // invalid pointer?
  4290. nullpo_retr(-1, mes);
  4291. //Console [Wizputer] //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4292. if (fd == 0)
  4293. return 0;
  4294. else {
  4295. int len_mes = strlen(mes);
  4296. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4297. WFIFOHEAD(fd, 5 + len_mes);
  4298. WFIFOW(fd,0) = 0x8e;
  4299. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4300. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4301. WFIFOSET(fd, 5 + len_mes);
  4302. }
  4303. }
  4304. return 0;
  4305. }
  4306. /*==========================================
  4307. * 天の声を送信する
  4308. *------------------------------------------
  4309. */
  4310. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4311. {
  4312. unsigned char *buf;
  4313. int lp;
  4314. lp = (flag & 0x10) ? 8 : 4;
  4315. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4316. WBUFW(buf,0) = 0x9a;
  4317. WBUFW(buf,2) = len + lp;
  4318. WBUFL(buf,4) = 0x65756c62;
  4319. memcpy(WBUFP(buf,lp), mes, len);
  4320. flag &= 0x07;
  4321. clif_send(buf, WBUFW(buf,2), bl,
  4322. (flag == 1) ? ALL_SAMEMAP :
  4323. (flag == 2) ? AREA :
  4324. (flag == 3) ? SELF :
  4325. ALL_CLIENT);
  4326. if(buf) aFree(buf);
  4327. if(use_irc && irc_announce_flag && !flag)
  4328. irc_announce(mes);
  4329. return 0;
  4330. }
  4331. /*==========================================
  4332. * グローバルメッセージ
  4333. *------------------------------------------
  4334. */
  4335. void clif_GlobalMessage(struct block_list *bl,char *message)
  4336. {
  4337. char buf[100];
  4338. int len;
  4339. nullpo_retv(bl);
  4340. if(!message)
  4341. return;
  4342. len = strlen(message)+1;
  4343. WBUFW(buf,0)=0x8d;
  4344. WBUFW(buf,2)=len+8;
  4345. WBUFL(buf,4)=bl->id;
  4346. strncpy((char *) WBUFP(buf,8),message,len);
  4347. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4348. }
  4349. /*==========================================
  4350. * Send main chat message [LuzZza]
  4351. *------------------------------------------
  4352. */
  4353. void clif_MainChatMessage(char* message) {
  4354. char buf[200];
  4355. int len;
  4356. if(!message)
  4357. return;
  4358. len = strlen(message)+1;
  4359. if (len+8 > sizeof(buf)) {
  4360. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4361. len = sizeof(buf)-8;
  4362. }
  4363. WBUFW(buf,0)=0x8d;
  4364. WBUFW(buf,2)=len+8;
  4365. WBUFL(buf,4)=0;
  4366. strncpy((char *) WBUFP(buf,8),message,len);
  4367. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4368. }
  4369. /*==========================================
  4370. * Does an announce message in the given color.
  4371. *------------------------------------------
  4372. */
  4373. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4374. {
  4375. unsigned char *buf;
  4376. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4377. WBUFW(buf,0) = 0x1c3;
  4378. WBUFW(buf,2) = len + 16;
  4379. WBUFL(buf,4) = color;
  4380. WBUFW(buf,8) = 0x190; //Font style? Type?
  4381. WBUFW(buf,10) = 0x0c; //12? Font size?
  4382. WBUFL(buf,12) = 0; //Unknown!
  4383. memcpy(WBUFP(buf,16), mes, len);
  4384. flag &= 0x07;
  4385. clif_send(buf, WBUFW(buf,2), bl,
  4386. (flag == 1) ? ALL_SAMEMAP :
  4387. (flag == 2) ? AREA :
  4388. (flag == 3) ? SELF :
  4389. ALL_CLIENT);
  4390. if(buf) aFree(buf);
  4391. return 0;
  4392. }
  4393. /*==========================================
  4394. * HPSP回復エフェクトを送信する
  4395. *------------------------------------------
  4396. */
  4397. int clif_heal(int fd,int type,int val)
  4398. {
  4399. WFIFOHEAD(fd,packet_len_table[0x13d]);
  4400. WFIFOW(fd,0)=0x13d;
  4401. WFIFOW(fd,2)=type;
  4402. WFIFOW(fd,4)=val;
  4403. WFIFOSET(fd,packet_len_table[0x13d]);
  4404. return 0;
  4405. }
  4406. /*==========================================
  4407. * 復活する
  4408. *------------------------------------------
  4409. */
  4410. int clif_resurrection(struct block_list *bl,int type)
  4411. {
  4412. unsigned char buf[16];
  4413. nullpo_retr(0, bl);
  4414. WBUFW(buf,0)=0x148;
  4415. WBUFL(buf,2)=bl->id;
  4416. WBUFW(buf,6)=type;
  4417. clif_send(buf,packet_len_table[0x148],bl,type==1 ? AREA : AREA_WOS);
  4418. if (disguised(bl))
  4419. clif_spawn(bl);
  4420. return 0;
  4421. }
  4422. /*==========================================
  4423. * PVP実装?(仮)
  4424. *------------------------------------------
  4425. */
  4426. int clif_set0199(int fd,int type)
  4427. {
  4428. WFIFOHEAD(fd,packet_len_table[0x199]);
  4429. WFIFOW(fd,0)=0x199;
  4430. WFIFOW(fd,2)=type;
  4431. WFIFOSET(fd,packet_len_table[0x199]);
  4432. return 0;
  4433. }
  4434. /*==========================================
  4435. * PVP実装?(仮)
  4436. *------------------------------------------
  4437. */
  4438. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4439. {
  4440. nullpo_retr(0, sd);
  4441. if(type == 2) {
  4442. WFIFOHEAD(sd->fd,packet_len_table[0x19a]);
  4443. WFIFOW(sd->fd,0) = 0x19a;
  4444. WFIFOL(sd->fd,2) = sd->bl.id;
  4445. if(pvprank<=0)
  4446. pc_calc_pvprank(sd);
  4447. WFIFOL(sd->fd,6) = pvprank;
  4448. WFIFOL(sd->fd,10) = pvpnum;
  4449. WFIFOSET(sd->fd,packet_len_table[0x19a]);
  4450. } else {
  4451. unsigned char buf[32];
  4452. WBUFW(buf,0) = 0x19a;
  4453. WBUFL(buf,2) = sd->bl.id;
  4454. if(sd->sc.option&0x46)
  4455. // WTF? a -1 to an unsigned value...
  4456. WBUFL(buf,6) = 0xFFFFFFFF;
  4457. else
  4458. if(pvprank<=0)
  4459. pc_calc_pvprank(sd);
  4460. WBUFL(buf,6) = pvprank;
  4461. WBUFL(buf,10) = pvpnum;
  4462. if(!type)
  4463. clif_send(buf,packet_len_table[0x19a],&sd->bl,AREA);
  4464. else
  4465. clif_send(buf,packet_len_table[0x19a],&sd->bl,ALL_SAMEMAP);
  4466. }
  4467. return 0;
  4468. }
  4469. /*==========================================
  4470. *
  4471. *------------------------------------------
  4472. */
  4473. int clif_send0199(int map,int type)
  4474. {
  4475. struct block_list bl;
  4476. unsigned char buf[16];
  4477. bl.type = BL_NUL;
  4478. bl.m = map;
  4479. WBUFW(buf,0)=0x199;
  4480. WBUFW(buf,2)=type;
  4481. clif_send(buf,packet_len_table[0x199],&bl,ALL_SAMEMAP);
  4482. return 0;
  4483. }
  4484. /*==========================================
  4485. * 精錬エフェクトを送信する
  4486. *------------------------------------------
  4487. */
  4488. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  4489. {
  4490. WFIFOHEAD(fd,packet_len_table[0x188]);
  4491. WFIFOW(fd,0)=0x188;
  4492. WFIFOW(fd,2)=fail;
  4493. WFIFOW(fd,4)=index+2;
  4494. WFIFOW(fd,6)=val;
  4495. WFIFOSET(fd,packet_len_table[0x188]);
  4496. return 0;
  4497. }
  4498. /*==========================================
  4499. * Wisp/page is transmitted to the destination player
  4500. *------------------------------------------
  4501. */
  4502. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4503. {
  4504. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4505. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4506. WFIFOW(fd,0) = 0x97;
  4507. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4508. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4509. memcpy(WFIFOP(fd,28), mes, mes_len);
  4510. WFIFOSET(fd,WFIFOW(fd,2));
  4511. return 0;
  4512. }
  4513. /*==========================================
  4514. * The transmission result of Wisp/page is transmitted to the source player
  4515. *------------------------------------------
  4516. */
  4517. 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
  4518. {
  4519. WFIFOHEAD(fd,packet_len_table[0x98]);
  4520. WFIFOW(fd,0) = 0x98;
  4521. WFIFOW(fd,2) = flag;
  4522. WFIFOSET(fd,packet_len_table[0x98]);
  4523. return 0;
  4524. }
  4525. /*==========================================
  4526. * キャラID名前引き結果を送信する
  4527. *------------------------------------------
  4528. */
  4529. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4530. {
  4531. char *p= map_charid2nick(char_id);
  4532. int fd;
  4533. nullpo_retr(0, sd);
  4534. fd=sd->fd;
  4535. if(p!=NULL){
  4536. WFIFOHEAD(fd,packet_len_table[0x194]);
  4537. WFIFOW(fd,0)=0x194;
  4538. WFIFOL(fd,2)=char_id;
  4539. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4540. WFIFOSET(fd,packet_len_table[0x194]);
  4541. }else{
  4542. map_reqchariddb(sd,char_id);
  4543. chrif_searchcharid(char_id);
  4544. }
  4545. return 0;
  4546. }
  4547. /*==========================================
  4548. * カードの挿入可能リストを返す
  4549. *------------------------------------------
  4550. */
  4551. int clif_use_card(struct map_session_data *sd,int idx)
  4552. {
  4553. int i,c,ep;
  4554. int fd=sd->fd;
  4555. nullpo_retr(0, sd);
  4556. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4557. return 0;
  4558. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != 6)
  4559. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4560. ep=sd->inventory_data[idx]->equip;
  4561. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4562. WFIFOW(fd,0)=0x017b;
  4563. for(i=c=0;i<MAX_INVENTORY;i++){
  4564. int j;
  4565. if(sd->inventory_data[i] == NULL)
  4566. continue;
  4567. if(sd->inventory_data[i]->type!=4 && sd->inventory_data[i]->type!=5) // 武器防具じゃない
  4568. continue;
  4569. if(sd->status.inventory[i].card[0]==0x00ff || sd->status.inventory[i].card[0]==(short)0xff00 || sd->status.inventory[i].card[0]==0x00fe)
  4570. continue;
  4571. if(sd->status.inventory[i].identify==0 ) // 未鑑定
  4572. continue;
  4573. if((sd->inventory_data[i]->equip&ep)==0) // 装備個所が違う
  4574. continue;
  4575. if(sd->inventory_data[i]->type==4 && ep==32) // 盾カードと両手武器
  4576. continue;
  4577. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4578. if( sd->status.inventory[i].card[j]==0 )
  4579. break;
  4580. }
  4581. if(j==sd->inventory_data[i]->slot) // すでにカードが一杯
  4582. continue;
  4583. WFIFOW(fd,4+c*2)=i+2;
  4584. c++;
  4585. }
  4586. WFIFOW(fd,2)=4+c*2;
  4587. WFIFOSET(fd,WFIFOW(fd,2));
  4588. return 0;
  4589. }
  4590. /*==========================================
  4591. * カードの挿入終了
  4592. *------------------------------------------
  4593. */
  4594. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4595. {
  4596. int fd;
  4597. nullpo_retr(0, sd);
  4598. fd=sd->fd;
  4599. WFIFOHEAD(fd,packet_len_table[0x17d]);
  4600. WFIFOW(fd,0)=0x17d;
  4601. WFIFOW(fd,2)=idx_equip+2;
  4602. WFIFOW(fd,4)=idx_card+2;
  4603. WFIFOB(fd,6)=flag;
  4604. WFIFOSET(fd,packet_len_table[0x17d]);
  4605. return 0;
  4606. }
  4607. /*==========================================
  4608. * 鑑定可能アイテムリスト送信
  4609. *------------------------------------------
  4610. */
  4611. int clif_item_identify_list(struct map_session_data *sd)
  4612. {
  4613. int i,c;
  4614. int fd;
  4615. nullpo_retr(0, sd);
  4616. fd=sd->fd;
  4617. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4618. WFIFOW(fd,0)=0x177;
  4619. for(i=c=0;i<MAX_INVENTORY;i++){
  4620. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4621. WFIFOW(fd,c*2+4)=i+2;
  4622. c++;
  4623. }
  4624. }
  4625. if(c > 0) {
  4626. WFIFOW(fd,2)=c*2+4;
  4627. WFIFOSET(fd,WFIFOW(fd,2));
  4628. sd->menuskill_id = MC_IDENTIFY;
  4629. sd->menuskill_lv = c;
  4630. }
  4631. return 0;
  4632. }
  4633. /*==========================================
  4634. * 鑑定結果
  4635. *------------------------------------------
  4636. */
  4637. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4638. {
  4639. int fd;
  4640. nullpo_retr(0, sd);
  4641. fd=sd->fd;
  4642. WFIFOHEAD(fd,packet_len_table[0x179]);
  4643. WFIFOW(fd, 0)=0x179;
  4644. WFIFOW(fd, 2)=idx+2;
  4645. WFIFOB(fd, 4)=flag;
  4646. WFIFOSET(fd,packet_len_table[0x179]);
  4647. return 0;
  4648. }
  4649. /*==========================================
  4650. * 修理可能アイテムリスト送信
  4651. *------------------------------------------
  4652. */
  4653. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4654. {
  4655. int i,c;
  4656. int fd;
  4657. int nameid;
  4658. nullpo_retr(0, sd);
  4659. nullpo_retr(0, dstsd);
  4660. fd=sd->fd;
  4661. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4662. WFIFOW(fd,0)=0x1fc;
  4663. for(i=c=0;i<MAX_INVENTORY;i++){
  4664. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4665. WFIFOW(fd,c*13+4) = i;
  4666. WFIFOW(fd,c*13+6) = nameid;
  4667. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4668. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4669. WFIFOB(fd,c*13+16)= c;
  4670. c++;
  4671. }
  4672. }
  4673. if(c > 0) {
  4674. WFIFOW(fd,2)=c*13+4;
  4675. WFIFOSET(fd,WFIFOW(fd,2));
  4676. sd->menuskill_id = BS_REPAIRWEAPON;
  4677. sd->menuskill_lv = dstsd->bl.id;
  4678. }else
  4679. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4680. return 0;
  4681. }
  4682. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4683. {
  4684. int view,fd;
  4685. nullpo_retr(0, sd);
  4686. fd=sd->fd;
  4687. WFIFOHEAD(fd,packet_len_table[0x1fe]);
  4688. WFIFOW(fd, 0)=0x1fe;
  4689. if((view = itemdb_viewid(nameid)) > 0)
  4690. WFIFOW(fd, 2)=view;
  4691. else
  4692. WFIFOW(fd, 2)=nameid;
  4693. WFIFOB(fd, 4)=flag;
  4694. WFIFOSET(fd,packet_len_table[0x1fe]);
  4695. return 0;
  4696. }
  4697. /*==========================================
  4698. * Weapon Refining - Taken from jAthena
  4699. *------------------------------------------
  4700. */
  4701. int clif_item_refine_list(struct map_session_data *sd)
  4702. {
  4703. int i,c;
  4704. int fd;
  4705. int skilllv;
  4706. int wlv;
  4707. int refine_item[5];
  4708. nullpo_retr(0, sd);
  4709. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4710. fd=sd->fd;
  4711. refine_item[0] = -1;
  4712. refine_item[1] = pc_search_inventory(sd,1010);
  4713. refine_item[2] = pc_search_inventory(sd,1011);
  4714. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4715. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4716. WFIFOW(fd,0)=0x221;
  4717. for(i=c=0;i<MAX_INVENTORY;i++){
  4718. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4719. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4720. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4721. WFIFOW(fd,c*13+ 4)=i+2;
  4722. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4723. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4724. WFIFOW(fd,c*13+10)=0;
  4725. WFIFOB(fd,c*13+12)=c;
  4726. c++;
  4727. }
  4728. }
  4729. WFIFOW(fd,2)=c*13+4;
  4730. WFIFOSET(fd,WFIFOW(fd,2));
  4731. sd->menuskill_id = WS_WEAPONREFINE;
  4732. sd->menuskill_lv = skilllv;
  4733. return 0;
  4734. }
  4735. /*==========================================
  4736. * アイテムによる一時的なスキル効果
  4737. *------------------------------------------
  4738. */
  4739. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  4740. {
  4741. int fd;
  4742. nullpo_retr(0, sd);
  4743. fd=sd->fd;
  4744. WFIFOHEAD(fd,packet_len_table[0x147]);
  4745. WFIFOW(fd, 0)=0x147;
  4746. WFIFOW(fd, 2)=skillid;
  4747. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4748. WFIFOW(fd, 6)=0;
  4749. WFIFOW(fd, 8)=skilllv;
  4750. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4751. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4752. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  4753. WFIFOB(fd,38)=0;
  4754. WFIFOSET(fd,packet_len_table[0x147]);
  4755. return 0;
  4756. }
  4757. /*==========================================
  4758. * カートにアイテム追加
  4759. *------------------------------------------
  4760. */
  4761. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4762. {
  4763. int view,fd;
  4764. unsigned char *buf;
  4765. nullpo_retr(0, sd);
  4766. fd=sd->fd;
  4767. WFIFOHEAD(fd,packet_len_table[0x124]);
  4768. buf=WFIFOP(fd,0);
  4769. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4770. return 1;
  4771. WBUFW(buf,0)=0x124;
  4772. WBUFW(buf,2)=n+2;
  4773. WBUFL(buf,4)=amount;
  4774. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4775. WBUFW(buf,8)=view;
  4776. else
  4777. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4778. WBUFB(buf,10)=sd->status.cart[n].identify;
  4779. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4780. WBUFB(buf,12)=sd->status.cart[n].refine;
  4781. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4782. WFIFOSET(fd,packet_len_table[0x124]);
  4783. return 0;
  4784. }
  4785. /*==========================================
  4786. * カートからアイテム削除
  4787. *------------------------------------------
  4788. */
  4789. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4790. {
  4791. int fd;
  4792. nullpo_retr(0, sd);
  4793. fd=sd->fd;
  4794. WFIFOHEAD(fd,packet_len_table[0x125]);
  4795. WFIFOW(fd,0)=0x125;
  4796. WFIFOW(fd,2)=n+2;
  4797. WFIFOL(fd,4)=amount;
  4798. WFIFOSET(fd,packet_len_table[0x125]);
  4799. return 0;
  4800. }
  4801. /*==========================================
  4802. * カートのアイテムリスト
  4803. *------------------------------------------
  4804. */
  4805. int clif_cart_itemlist(struct map_session_data *sd)
  4806. {
  4807. struct item_data *id;
  4808. int i,n,fd;
  4809. unsigned char *buf;
  4810. nullpo_retr(0, sd);
  4811. fd=sd->fd;
  4812. WFIFOHEAD(fd, MAX_CART * 18 + 4);
  4813. buf = WFIFOP(fd,0);
  4814. #if PACKETVER < 5
  4815. for(i=0,n=0;i<MAX_CART;i++){
  4816. if(sd->status.cart[i].nameid<=0)
  4817. continue;
  4818. id = itemdb_search(sd->status.cart[i].nameid);
  4819. if(itemdb_isequip2(id))
  4820. continue;
  4821. WBUFW(buf,n*10+4)=i+2;
  4822. if(id->view_id > 0)
  4823. WBUFW(buf,n*10+6)=id->view_id;
  4824. else
  4825. WBUFW(buf,n*10+6)=sd->status.cart[i].nameid;
  4826. WBUFB(buf,n*10+8)=itemtype(id->type);
  4827. WBUFB(buf,n*10+9)=sd->status.cart[i].identify;
  4828. WBUFW(buf,n*10+10)=sd->status.cart[i].amount;
  4829. WBUFW(buf,n*10+12)=0;
  4830. n++;
  4831. }
  4832. if(n){
  4833. WBUFW(buf,0)=0x123;
  4834. WBUFW(buf,2)=4+n*10;
  4835. WFIFOSET(fd,WFIFOW(fd,2));
  4836. }
  4837. #else
  4838. for(i=0,n=0;i<MAX_CART;i++){
  4839. if(sd->status.cart[i].nameid<=0)
  4840. continue;
  4841. id = itemdb_search(sd->status.cart[i].nameid);
  4842. if(itemdb_isequip2(id))
  4843. continue;
  4844. WBUFW(buf,n*18+4)=i+2;
  4845. if(id->view_id > 0)
  4846. WBUFW(buf,n*18+6)=id->view_id;
  4847. else
  4848. WBUFW(buf,n*18+6)=sd->status.cart[i].nameid;
  4849. WBUFB(buf,n*18+8)=itemtype(id->type);
  4850. WBUFB(buf,n*18+9)=sd->status.cart[i].identify;
  4851. WBUFW(buf,n*18+10)=sd->status.cart[i].amount;
  4852. WBUFW(buf,n*18+12)=0; //Here goes the equip location, which seems unnecessary to fill for the cart data.
  4853. clif_addcards(WBUFP(buf,n*18+14), &sd->status.cart[i]);
  4854. n++;
  4855. }
  4856. if(n){
  4857. WBUFW(buf,0)=0x1ef;
  4858. WBUFW(buf,2)=4+n*18;
  4859. WFIFOSET(fd,WFIFOW(fd,2));
  4860. }
  4861. #endif
  4862. return 0;
  4863. }
  4864. /*==========================================
  4865. * カートの装備品リスト
  4866. *------------------------------------------
  4867. */
  4868. int clif_cart_equiplist(struct map_session_data *sd)
  4869. {
  4870. struct item_data *id;
  4871. int i,n,fd;
  4872. unsigned char *buf;
  4873. nullpo_retr(0, sd);
  4874. fd=sd->fd;
  4875. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  4876. buf = WFIFOP(fd,0);
  4877. for(i=0,n=0;i<MAX_INVENTORY;i++){
  4878. if(sd->status.cart[i].nameid<=0)
  4879. continue;
  4880. id = itemdb_search(sd->status.cart[i].nameid);
  4881. if(!itemdb_isequip2(id))
  4882. continue;
  4883. WBUFW(buf,n*20+4)=i+2;
  4884. if(id->view_id > 0)
  4885. WBUFW(buf,n*20+6)=id->view_id;
  4886. else
  4887. WBUFW(buf,n*20+6)=sd->status.cart[i].nameid;
  4888. WBUFB(buf,n*20+8)=itemtype(id->type);
  4889. WBUFB(buf,n*20+9)=sd->status.cart[i].identify;
  4890. WBUFW(buf,n*20+10)=id->equip;
  4891. WBUFW(buf,n*20+12)=sd->status.cart[i].equip;
  4892. WBUFB(buf,n*20+14)=sd->status.cart[i].attribute;
  4893. WBUFB(buf,n*20+15)=sd->status.cart[i].refine;
  4894. clif_addcards(WBUFP(buf, n*20+16), &sd->status.cart[i]);
  4895. n++;
  4896. }
  4897. if(n){
  4898. WBUFW(buf,0)=0x122;
  4899. WBUFW(buf,2)=4+n*20;
  4900. WFIFOSET(fd,WFIFOW(fd,2));
  4901. }
  4902. return 0;
  4903. }
  4904. /*==========================================
  4905. * 露店開設
  4906. *------------------------------------------
  4907. */
  4908. int clif_openvendingreq(struct map_session_data *sd,int num)
  4909. {
  4910. int fd;
  4911. nullpo_retr(0, sd);
  4912. fd=sd->fd;
  4913. WFIFOHEAD(fd,packet_len_table[0x12d]);
  4914. WFIFOW(fd,0)=0x12d;
  4915. WFIFOW(fd,2)=num;
  4916. WFIFOSET(fd,packet_len_table[0x12d]);
  4917. return 0;
  4918. }
  4919. /*==========================================
  4920. * 露店看板表示
  4921. *------------------------------------------
  4922. */
  4923. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  4924. {
  4925. unsigned char buf[128];
  4926. nullpo_retr(0, bl);
  4927. WBUFW(buf,0)=0x131;
  4928. WBUFL(buf,2)=bl->id;
  4929. strncpy((char*)WBUFP(buf,6),message,80);
  4930. if(fd){
  4931. WFIFOHEAD(fd,packet_len_table[0x131]);
  4932. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x131]);
  4933. WFIFOSET(fd,packet_len_table[0x131]);
  4934. }else{
  4935. clif_send(buf,packet_len_table[0x131],bl,AREA_WOS);
  4936. }
  4937. return 0;
  4938. }
  4939. /*==========================================
  4940. * 露店看板消去
  4941. *------------------------------------------
  4942. */
  4943. int clif_closevendingboard(struct block_list* bl,int fd)
  4944. {
  4945. unsigned char buf[16];
  4946. nullpo_retr(0, bl);
  4947. WBUFW(buf,0)=0x132;
  4948. WBUFL(buf,2)=bl->id;
  4949. if(fd){
  4950. WFIFOHEAD(fd,packet_len_table[0x132]);
  4951. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x132]);
  4952. WFIFOSET(fd,packet_len_table[0x132]);
  4953. }else{
  4954. clif_send(buf,packet_len_table[0x132],bl,AREA_WOS);
  4955. }
  4956. return 0;
  4957. }
  4958. /*==========================================
  4959. * 露店アイテムリスト
  4960. *------------------------------------------
  4961. */
  4962. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  4963. {
  4964. struct item_data *data;
  4965. int i,n,index,fd;
  4966. struct map_session_data *vsd;
  4967. unsigned char *buf;
  4968. nullpo_retr(0, sd);
  4969. nullpo_retr(0, vending);
  4970. nullpo_retr(0, vsd=map_id2sd(id));
  4971. fd=sd->fd;
  4972. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  4973. buf = WFIFOP(fd,0);
  4974. for(i=0,n=0;i<vsd->vend_num;i++){
  4975. if(vending[i].amount<=0)
  4976. continue;
  4977. WBUFL(buf,8+n*22)=vending[i].value;
  4978. WBUFW(buf,12+n*22)=vending[i].amount;
  4979. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  4980. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  4981. continue;
  4982. data = itemdb_search(vsd->status.cart[index].nameid);
  4983. WBUFB(buf,16+n*22)=itemtype(data->type);
  4984. if(data->view_id > 0)
  4985. WBUFW(buf,17+n*22)=data->view_id;
  4986. else
  4987. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  4988. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  4989. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  4990. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  4991. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  4992. n++;
  4993. }
  4994. if(n > 0){
  4995. WBUFW(buf,0)=0x133;
  4996. WBUFW(buf,2)=8+n*22;
  4997. WBUFL(buf,4)=id;
  4998. WFIFOSET(fd,WFIFOW(fd,2));
  4999. }
  5000. return 0;
  5001. }
  5002. /*==========================================
  5003. * 露店アイテム購入失敗
  5004. *------------------------------------------
  5005. */
  5006. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  5007. {
  5008. int fd;
  5009. nullpo_retr(0, sd);
  5010. fd=sd->fd;
  5011. WFIFOHEAD(fd,packet_len_table[0x135]);
  5012. WFIFOW(fd,0)=0x135;
  5013. WFIFOW(fd,2)=index+2;
  5014. WFIFOW(fd,4)=amount;
  5015. WFIFOB(fd,6)=fail;
  5016. WFIFOSET(fd,packet_len_table[0x135]);
  5017. return 0;
  5018. }
  5019. /*==========================================
  5020. * 露店開設成功
  5021. *------------------------------------------
  5022. */
  5023. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  5024. {
  5025. struct item_data *data;
  5026. int i,n,index,fd;
  5027. unsigned char *buf;
  5028. nullpo_retr(0, sd);
  5029. fd=sd->fd;
  5030. WFIFOHEAD(fd, 8+sd->vend_num*22);
  5031. buf = WFIFOP(fd,0);
  5032. for(i=0,n=0;i<sd->vend_num;i++){
  5033. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  5034. WBUFL(buf,8+n*22)=vending[i].value;
  5035. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  5036. WBUFW(buf,14+n*22)=vending[i].amount;
  5037. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || !sd->status.cart[index].identify ||
  5038. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  5039. continue;
  5040. data = itemdb_search(sd->status.cart[index].nameid);
  5041. WBUFB(buf,16+n*22)=itemtype(data->type);
  5042. if(data->view_id > 0)
  5043. WBUFW(buf,17+n*22)=data->view_id;
  5044. else
  5045. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  5046. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  5047. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  5048. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  5049. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  5050. n++;
  5051. }
  5052. if(n > 0){
  5053. WBUFW(buf,0)=0x136;
  5054. WBUFW(buf,2)=8+n*22;
  5055. WBUFL(buf,4)=id;
  5056. WFIFOSET(fd,WFIFOW(fd,2));
  5057. }
  5058. return n;
  5059. }
  5060. /*==========================================
  5061. * 露店アイテム販売報告
  5062. *------------------------------------------
  5063. */
  5064. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  5065. {
  5066. int fd;
  5067. nullpo_retr(0, sd);
  5068. fd=sd->fd;
  5069. WFIFOHEAD(fd,packet_len_table[0x137]);
  5070. WFIFOW(fd,0)=0x137;
  5071. WFIFOW(fd,2)=index+2;
  5072. WFIFOW(fd,4)=amount;
  5073. WFIFOSET(fd,packet_len_table[0x137]);
  5074. return 0;
  5075. }
  5076. /*==========================================
  5077. * パーティ作成完了
  5078. *------------------------------------------
  5079. */
  5080. int clif_party_created(struct map_session_data *sd,int flag)
  5081. {
  5082. int fd;
  5083. // printf("clif_party_message(%s, %d, %s)\n", p->name, account_id, mes);
  5084. nullpo_retr(0, sd);
  5085. fd=sd->fd;
  5086. WFIFOHEAD(fd,packet_len_table[0xfa]);
  5087. WFIFOW(fd,0)=0xfa;
  5088. WFIFOB(fd,2)=flag;
  5089. WFIFOSET(fd,packet_len_table[0xfa]);
  5090. return 0;
  5091. }
  5092. int clif_party_main_info(struct party *p, int fd)
  5093. {
  5094. struct map_session_data *sd;
  5095. int i;
  5096. unsigned char buf[96];
  5097. for (i=0; i<MAX_PARTY && !p->member[i].leader; i++);
  5098. if (i >= MAX_PARTY) return 0; //Should never happen...
  5099. sd = p->member[i].sd;
  5100. WBUFW(buf,0)=0x1e9;
  5101. WBUFL(buf,2)= p->member[i].account_id;
  5102. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  5103. WBUFW(buf,10)=sd?sd->bl.x:0;
  5104. WBUFW(buf,12)=sd?sd->bl.y:0;
  5105. WBUFB(buf,14)=(p->member[i].online)?0:1; //This byte is also unconfirmed...
  5106. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5107. memcpy(WBUFP(buf,39), p->member[i].name, NAME_LENGTH);
  5108. memcpy(WBUFP(buf,63), mapindex_id2name(p->member[i].map), MAP_NAME_LENGTH);
  5109. WBUFB(buf,79) = (p->item&1)?1:0;
  5110. WBUFB(buf,80) = (p->item&2)?1:0;
  5111. if(fd>=0){
  5112. WFIFOHEAD(fd,packet_len_table[0x1e9]);
  5113. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x1e9]);
  5114. WFIFOSET(fd,packet_len_table[0x1e9]);
  5115. return 1;
  5116. }
  5117. if (!sd) {
  5118. for (i=0; i<MAX_PARTY && !p->member[i].sd; i++)
  5119. if (i >= MAX_PARTY) return 0; //Should never happen...
  5120. sd=p->member[i].sd;
  5121. }
  5122. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY);
  5123. return 1;
  5124. }
  5125. int clif_party_join_info(struct party *p, struct map_session_data *sd)
  5126. {
  5127. unsigned char buf[96];
  5128. WBUFW(buf,0)=0x1e9;
  5129. WBUFL(buf,2)= sd->status.account_id;
  5130. WBUFL(buf,6)= 0; //Apparently setting this to 1 makes you adoptable.
  5131. WBUFW(buf,10)=sd->bl.x;
  5132. WBUFW(buf,12)=sd->bl.y;
  5133. WBUFB(buf,14)=0; //Unconfirmed byte.
  5134. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5135. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5136. memcpy(WBUFP(buf,63), mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  5137. WBUFB(buf,79) = (p->item&1)?1:0;
  5138. WBUFB(buf,80) = (p->item&2)?1:0;
  5139. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY_WOS);
  5140. return 1;
  5141. }
  5142. /*==========================================
  5143. * パーティ情報送信
  5144. *------------------------------------------
  5145. */
  5146. int clif_party_info(struct party *p,int fd)
  5147. {
  5148. unsigned char buf[1024];
  5149. int i,c;
  5150. struct map_session_data *sd=NULL;
  5151. nullpo_retr(0, p);
  5152. WBUFW(buf,0)=0xfb;
  5153. memcpy(WBUFP(buf,4),p->name,NAME_LENGTH);
  5154. for(i=c=0;i<MAX_PARTY;i++){
  5155. struct party_member *m=&p->member[i];
  5156. if(m->account_id>0){
  5157. if(sd==NULL) sd=m->sd;
  5158. WBUFL(buf,28+c*46)=m->account_id;
  5159. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5160. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5161. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5162. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5163. c++;
  5164. }
  5165. }
  5166. WBUFW(buf,2)=28+c*46;
  5167. if(fd>=0){ // fdが設定されてるならそれに送る
  5168. WFIFOHEAD(fd, 28+c*46);
  5169. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5170. WFIFOSET(fd,WFIFOW(fd,2));
  5171. return 9;
  5172. }
  5173. if(sd!=NULL)
  5174. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5175. return 0;
  5176. }
  5177. /*==========================================
  5178. * パーティ勧誘
  5179. *------------------------------------------
  5180. */
  5181. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5182. {
  5183. int fd;
  5184. struct party *p;
  5185. nullpo_retr(0, sd);
  5186. nullpo_retr(0, tsd);
  5187. fd=tsd->fd;
  5188. if( (p=party_search(sd->status.party_id))==NULL )
  5189. return 0;
  5190. WFIFOHEAD(fd,packet_len_table[0xfe]);
  5191. WFIFOW(fd,0)=0xfe;
  5192. WFIFOL(fd,2)=sd->status.account_id;
  5193. memcpy(WFIFOP(fd,6),p->name,NAME_LENGTH);
  5194. WFIFOSET(fd,packet_len_table[0xfe]);
  5195. return 0;
  5196. }
  5197. /*==========================================
  5198. * パーティ勧誘結果
  5199. *------------------------------------------
  5200. */
  5201. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5202. {
  5203. int fd;
  5204. nullpo_retr(0, sd);
  5205. fd=sd->fd;
  5206. WFIFOHEAD(fd,packet_len_table[0xfd]);
  5207. WFIFOW(fd,0)=0xfd;
  5208. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5209. WFIFOB(fd,26)=flag;
  5210. WFIFOSET(fd,packet_len_table[0xfd]);
  5211. return 0;
  5212. }
  5213. /*==========================================
  5214. * パーティ設定送信
  5215. * flag & 0x001=exp変更ミス
  5216. * 0x010=item変更ミス
  5217. * 0x100=一人にのみ送信
  5218. *------------------------------------------
  5219. */
  5220. int clif_party_option(struct party *p,struct map_session_data *sd,int flag)
  5221. {
  5222. unsigned char buf[16];
  5223. nullpo_retr(0, p);
  5224. // if(battle_config.etc_log)
  5225. // printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
  5226. if(sd==NULL && flag==0){
  5227. int i;
  5228. for(i=0;i<MAX_PARTY;i++)
  5229. if((sd=map_id2sd(p->member[i].account_id))!=NULL)
  5230. break;
  5231. }
  5232. if(sd==NULL)
  5233. return 0;
  5234. WBUFW(buf,0)=0x101;
  5235. WBUFW(buf,2)=((flag&0x01)?2:p->exp);
  5236. WBUFW(buf,4)=0; //NOTE: We don't know yet what this is for, it is NOT for item share rules, though. [Skotlex]
  5237. if(flag==0)
  5238. clif_send(buf,packet_len_table[0x101],&sd->bl,PARTY);
  5239. else {
  5240. WFIFOHEAD(sd->fd,packet_len_table[0x101]);
  5241. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x101]);
  5242. WFIFOSET(sd->fd,packet_len_table[0x101]);
  5243. }
  5244. return 0;
  5245. }
  5246. /*==========================================
  5247. * パーティ脱退(脱退前に呼ぶこと)
  5248. *------------------------------------------
  5249. */
  5250. int clif_party_leaved(struct party *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5251. {
  5252. unsigned char buf[64];
  5253. int i;
  5254. nullpo_retr(0, p);
  5255. WBUFW(buf,0)=0x105;
  5256. WBUFL(buf,2)=account_id;
  5257. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5258. WBUFB(buf,30)=flag&0x0f;
  5259. if((flag&0xf0)==0){
  5260. if(sd==NULL)
  5261. for(i=0;i<MAX_PARTY;i++)
  5262. if((sd=p->member[i].sd)!=NULL)
  5263. break;
  5264. if (sd!=NULL)
  5265. clif_send(buf,packet_len_table[0x105],&sd->bl,PARTY);
  5266. } else if (sd!=NULL) {
  5267. WFIFOHEAD(sd->fd,packet_len_table[0x105]);
  5268. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x105]);
  5269. WFIFOSET(sd->fd,packet_len_table[0x105]);
  5270. }
  5271. return 0;
  5272. }
  5273. /*==========================================
  5274. * パーティメッセージ送信
  5275. *------------------------------------------
  5276. */
  5277. int clif_party_message(struct party *p,int account_id,char *mes,int len)
  5278. {
  5279. struct map_session_data *sd;
  5280. int i;
  5281. nullpo_retr(0, p);
  5282. for(i=0;i<MAX_PARTY;i++){
  5283. if((sd=p->member[i].sd)!=NULL)
  5284. break;
  5285. }
  5286. if(sd!=NULL){
  5287. unsigned char buf[1024];
  5288. WBUFW(buf,0)=0x109;
  5289. WBUFW(buf,2)=len+8;
  5290. WBUFL(buf,4)=account_id;
  5291. memcpy(WBUFP(buf,8),mes,len);
  5292. clif_send(buf,len+8,&sd->bl,PARTY);
  5293. }
  5294. return 0;
  5295. }
  5296. /*==========================================
  5297. * パーティ座標通知
  5298. *------------------------------------------
  5299. */
  5300. int clif_party_xy(struct map_session_data *sd)
  5301. {
  5302. unsigned char buf[16];
  5303. nullpo_retr(0, sd);
  5304. WBUFW(buf,0)=0x107;
  5305. WBUFL(buf,2)=sd->status.account_id;
  5306. WBUFW(buf,6)=sd->bl.x;
  5307. WBUFW(buf,8)=sd->bl.y;
  5308. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  5309. return 0;
  5310. }
  5311. /*==========================================
  5312. * Sends x/y dot to a single fd. [Skotlex]
  5313. *------------------------------------------
  5314. */
  5315. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5316. {
  5317. WFIFOHEAD(fd,packet_len_table[0x107]);
  5318. WFIFOW(fd,0)=0x107;
  5319. WFIFOL(fd,2)=sd->status.account_id;
  5320. WFIFOW(fd,6)=sd->bl.x;
  5321. WFIFOW(fd,8)=sd->bl.y;
  5322. WFIFOSET(fd,packet_len_table[0x107]);
  5323. return 0;
  5324. }
  5325. /*==========================================
  5326. * パーティHP通知
  5327. *------------------------------------------
  5328. */
  5329. int clif_party_hp(struct map_session_data *sd)
  5330. {
  5331. unsigned char buf[16];
  5332. nullpo_retr(0, sd);
  5333. WBUFW(buf,0)=0x106;
  5334. WBUFL(buf,2)=sd->status.account_id;
  5335. WBUFW(buf,6)=(sd->status.hp > SHRT_MAX)?SHRT_MAX:sd->status.hp;
  5336. WBUFW(buf,8)=(sd->status.max_hp > SHRT_MAX)?SHRT_MAX:sd->status.max_hp;
  5337. clif_send(buf,packet_len_table[0x106],&sd->bl,PARTY_AREA_WOS);
  5338. return 0;
  5339. }
  5340. /*==========================================
  5341. * Sends HP bar to a single fd. [Skotlex]
  5342. *------------------------------------------
  5343. */
  5344. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5345. {
  5346. WFIFOHEAD(fd,packet_len_table[0x106]);
  5347. WFIFOW(fd,0) = 0x106;
  5348. WFIFOL(fd,2) = sd->status.account_id;
  5349. WFIFOW(fd,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5350. WFIFOW(fd,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5351. WFIFOSET (fd, packet_len_table[0x106]);
  5352. }
  5353. /*==========================================
  5354. * GMへ場所とHP通知
  5355. *------------------------------------------
  5356. */
  5357. int clif_hpmeter(struct map_session_data *sd)
  5358. {
  5359. struct map_session_data *sd2;
  5360. unsigned char buf[16];
  5361. int i, x0, y0, x1, y1;
  5362. int level;
  5363. nullpo_retr(0, sd);
  5364. x0 = sd->bl.x - AREA_SIZE;
  5365. y0 = sd->bl.y - AREA_SIZE;
  5366. x1 = sd->bl.x + AREA_SIZE;
  5367. y1 = sd->bl.y + AREA_SIZE;
  5368. WBUFW(buf,0) = 0x106;
  5369. WBUFL(buf,2) = sd->status.account_id;
  5370. WBUFW(buf,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5371. WBUFW(buf,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5372. for (i = 0; i < fd_max; i++) {
  5373. if (session[i] && (sd2 = (struct map_session_data*)session[i]->session_data) && sd != sd2 && sd2->state.auth) {
  5374. if (sd2->bl.m != sd->bl.m ||
  5375. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5376. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5377. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5378. level < pc_isGM(sd))
  5379. continue;
  5380. WFIFOHEAD (i, packet_len_table[0x106]);
  5381. memcpy (WFIFOP(i,0), buf, packet_len_table[0x106]);
  5382. WFIFOSET (i, packet_len_table[0x106]);
  5383. }
  5384. }
  5385. return 0;
  5386. }
  5387. /*==========================================
  5388. * パーティ場所移動(未使用)
  5389. *------------------------------------------
  5390. */
  5391. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5392. {
  5393. unsigned char buf[128];
  5394. nullpo_retr(0, sd);
  5395. nullpo_retr(0, p);
  5396. WBUFW(buf, 0)=0x104;
  5397. WBUFL(buf, 2)=sd->status.account_id;
  5398. WBUFL(buf, 6)=0;
  5399. WBUFW(buf,10)=sd->bl.x;
  5400. WBUFW(buf,12)=sd->bl.y;
  5401. WBUFB(buf,14)=!online;
  5402. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5403. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5404. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5405. clif_send(buf,packet_len_table[0x104],&sd->bl,PARTY);
  5406. return 0;
  5407. }
  5408. /*==========================================
  5409. * 攻撃するために移動が必要
  5410. *------------------------------------------
  5411. */
  5412. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5413. {
  5414. int fd;
  5415. nullpo_retr(0, sd);
  5416. nullpo_retr(0, bl);
  5417. fd=sd->fd;
  5418. WFIFOHEAD(fd,packet_len_table[0x139]);
  5419. WFIFOW(fd, 0)=0x139;
  5420. WFIFOL(fd, 2)=bl->id;
  5421. WFIFOW(fd, 6)=bl->x;
  5422. WFIFOW(fd, 8)=bl->y;
  5423. WFIFOW(fd,10)=sd->bl.x;
  5424. WFIFOW(fd,12)=sd->bl.y;
  5425. WFIFOW(fd,14)=sd->attackrange;
  5426. WFIFOSET(fd,packet_len_table[0x139]);
  5427. return 0;
  5428. }
  5429. /*==========================================
  5430. * 製造エフェクト
  5431. *------------------------------------------
  5432. */
  5433. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5434. {
  5435. int view,fd;
  5436. nullpo_retr(0, sd);
  5437. fd=sd->fd;
  5438. // 名前の登録と送信を先にしておく
  5439. if( map_charid2nick(sd->status.char_id)==NULL )
  5440. map_addchariddb(sd->status.char_id,sd->status.name);
  5441. clif_solved_charname(sd,sd->status.char_id);
  5442. WFIFOHEAD(fd,packet_len_table[0x18f]);
  5443. WFIFOW(fd, 0)=0x18f;
  5444. WFIFOW(fd, 2)=flag;
  5445. if((view = itemdb_viewid(nameid)) > 0)
  5446. WFIFOW(fd, 4)=view;
  5447. else
  5448. WFIFOW(fd, 4)=nameid;
  5449. WFIFOSET(fd,packet_len_table[0x18f]);
  5450. return 0;
  5451. }
  5452. // pet
  5453. int clif_catch_process(struct map_session_data *sd)
  5454. {
  5455. int fd;
  5456. nullpo_retr(0, sd);
  5457. fd=sd->fd;
  5458. WFIFOHEAD(fd,packet_len_table[0x19e]);
  5459. WFIFOW(fd,0)=0x19e;
  5460. WFIFOSET(fd,packet_len_table[0x19e]);
  5461. sd->menuskill_id = SA_TAMINGMONSTER;
  5462. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5463. sd->menuskill_lv = 0; //Free catch
  5464. else
  5465. sd->menuskill_lv = sd->itemid; //Consume catch
  5466. return 0;
  5467. }
  5468. int clif_pet_rulet(struct map_session_data *sd,int data)
  5469. {
  5470. int fd;
  5471. nullpo_retr(0, sd);
  5472. fd=sd->fd;
  5473. WFIFOHEAD(fd,packet_len_table[0x1a0]);
  5474. WFIFOW(fd,0)=0x1a0;
  5475. WFIFOB(fd,2)=data;
  5476. WFIFOSET(fd,packet_len_table[0x1a0]);
  5477. return 0;
  5478. }
  5479. /*==========================================
  5480. * pet卵リスト作成
  5481. *------------------------------------------
  5482. */
  5483. int clif_sendegg(struct map_session_data *sd)
  5484. {
  5485. //R 01a6 <len>.w <index>.w*
  5486. int i,n=0,fd;
  5487. nullpo_retr(0, sd);
  5488. fd=sd->fd;
  5489. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5490. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5491. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5492. return 0;
  5493. }
  5494. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5495. WFIFOW(fd,0)=0x1a6;
  5496. if(sd->status.pet_id <= 0) {
  5497. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5498. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5499. sd->inventory_data[i]->type!=7 ||
  5500. sd->status.inventory[i].amount<=0)
  5501. continue;
  5502. WFIFOW(fd,n*2+4)=i+2;
  5503. n++;
  5504. }
  5505. }
  5506. WFIFOW(fd,2)=4+n*2;
  5507. WFIFOSET(fd,WFIFOW(fd,2));
  5508. sd->menuskill_id = SA_TAMINGMONSTER;
  5509. sd->menuskill_lv = -1;
  5510. return 0;
  5511. }
  5512. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5513. {
  5514. int fd;
  5515. nullpo_retr(0, sd);
  5516. nullpo_retr(0, sd->pd);
  5517. fd=sd->fd;
  5518. WFIFOHEAD(fd,packet_len_table[0x1a4]);
  5519. WFIFOW(fd,0)=0x1a4;
  5520. WFIFOB(fd,2)=type;
  5521. WFIFOL(fd,3)=sd->pd->bl.id;
  5522. WFIFOL(fd,7)=param;
  5523. WFIFOSET(fd,packet_len_table[0x1a4]);
  5524. return 0;
  5525. }
  5526. int clif_send_petstatus(struct map_session_data *sd)
  5527. {
  5528. int fd;
  5529. nullpo_retr(0, sd);
  5530. fd=sd->fd;
  5531. WFIFOHEAD(fd,packet_len_table[0x1a2]);
  5532. WFIFOW(fd,0)=0x1a2;
  5533. memcpy(WFIFOP(fd,2),sd->pet.name,NAME_LENGTH);
  5534. WFIFOB(fd,26)=(battle_config.pet_rename == 1)? 0:sd->pet.rename_flag;
  5535. WFIFOW(fd,27)=sd->pet.level;
  5536. WFIFOW(fd,29)=sd->pet.hungry;
  5537. WFIFOW(fd,31)=sd->pet.intimate;
  5538. WFIFOW(fd,33)=sd->pet.equip;
  5539. WFIFOSET(fd,packet_len_table[0x1a2]);
  5540. return 0;
  5541. }
  5542. /*==========================================
  5543. *
  5544. *------------------------------------------
  5545. */
  5546. int clif_pet_emotion(struct pet_data *pd,int param)
  5547. {
  5548. unsigned char buf[16];
  5549. struct map_session_data *sd;
  5550. nullpo_retr(0, pd);
  5551. nullpo_retr(0, sd = pd->msd);
  5552. memset(buf,0,packet_len_table[0x1aa]);
  5553. WBUFW(buf,0)=0x1aa;
  5554. WBUFL(buf,2)=pd->bl.id;
  5555. if(param >= 100 && sd->petDB->talk_convert_class) {
  5556. if(sd->petDB->talk_convert_class < 0)
  5557. return 0;
  5558. else if(sd->petDB->talk_convert_class > 0) {
  5559. param -= (pd->class_ - 100)*100;
  5560. param += (sd->petDB->talk_convert_class - 100)*100;
  5561. }
  5562. }
  5563. WBUFL(buf,6)=param;
  5564. clif_send(buf,packet_len_table[0x1aa],&pd->bl,AREA);
  5565. return 0;
  5566. }
  5567. int clif_pet_performance(struct block_list *bl,int param)
  5568. {
  5569. unsigned char buf[16];
  5570. nullpo_retr(0, bl);
  5571. memset(buf,0,packet_len_table[0x1a4]);
  5572. WBUFW(buf,0)=0x1a4;
  5573. WBUFB(buf,2)=4;
  5574. WBUFL(buf,3)=bl->id;
  5575. WBUFL(buf,7)=param;
  5576. clif_send(buf,packet_len_table[0x1a4],bl,AREA);
  5577. return 0;
  5578. }
  5579. int clif_pet_equip(struct pet_data *pd,int nameid)
  5580. {
  5581. unsigned char buf[16];
  5582. nullpo_retr(0, pd);
  5583. memset(buf,0,packet_len_table[0x1a4]);
  5584. WBUFW(buf,0)=0x1a4;
  5585. WBUFB(buf,2)=3;
  5586. WBUFL(buf,3)=pd->bl.id;
  5587. WBUFL(buf,7)=pd->vd.shield;
  5588. clif_send(buf,packet_len_table[0x1a4],&pd->bl,AREA);
  5589. return 0;
  5590. }
  5591. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5592. {
  5593. int fd;
  5594. nullpo_retr(0, sd);
  5595. fd=sd->fd;
  5596. WFIFOHEAD(fd,packet_len_table[0x1a3]);
  5597. WFIFOW(fd,0)=0x1a3;
  5598. WFIFOB(fd,2)=fail;
  5599. WFIFOW(fd,3)=foodid;
  5600. WFIFOSET(fd,packet_len_table[0x1a3]);
  5601. return 0;
  5602. }
  5603. /*==========================================
  5604. * オートスペル リスト送信
  5605. *------------------------------------------
  5606. */
  5607. int clif_autospell(struct map_session_data *sd,int skilllv)
  5608. {
  5609. int fd;
  5610. nullpo_retr(0, sd);
  5611. fd=sd->fd;
  5612. WFIFOHEAD(fd,packet_len_table[0x1cd]);
  5613. WFIFOW(fd, 0)=0x1cd;
  5614. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5615. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5616. else
  5617. WFIFOL(fd,2)= 0x00000000;
  5618. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5619. WFIFOL(fd,6)= MG_COLDBOLT;
  5620. else
  5621. WFIFOL(fd,6)= 0x00000000;
  5622. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5623. WFIFOL(fd,10)= MG_FIREBOLT;
  5624. else
  5625. WFIFOL(fd,10)= 0x00000000;
  5626. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5627. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5628. else
  5629. WFIFOL(fd,14)= 0x00000000;
  5630. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5631. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5632. else
  5633. WFIFOL(fd,18)= 0x00000000;
  5634. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5635. WFIFOL(fd,22)= MG_FIREBALL;
  5636. else
  5637. WFIFOL(fd,22)= 0x00000000;
  5638. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5639. WFIFOL(fd,26)= MG_FROSTDIVER;
  5640. else
  5641. WFIFOL(fd,26)= 0x00000000;
  5642. WFIFOSET(fd,packet_len_table[0x1cd]);
  5643. sd->menuskill_id = SA_AUTOSPELL;
  5644. sd->menuskill_lv = skilllv;
  5645. return 0;
  5646. }
  5647. /*==========================================
  5648. * ディボーションの青い糸
  5649. *------------------------------------------
  5650. */
  5651. int clif_devotion(struct map_session_data *sd)
  5652. {
  5653. unsigned char buf[56];
  5654. int i,n;
  5655. nullpo_retr(0, sd);
  5656. WBUFW(buf,0)=0x1cf;
  5657. WBUFL(buf,2)=sd->bl.id;
  5658. for(i=0,n=0;i<5;i++) {
  5659. if (!sd->devotion[i])
  5660. continue;
  5661. WBUFL(buf,6+4*n)=sd->devotion[i];
  5662. n++;
  5663. }
  5664. for(;n<5;n++)
  5665. WBUFL(buf,6+4*n)=0;
  5666. WBUFB(buf,26)=8;
  5667. WBUFB(buf,27)=0;
  5668. clif_send(buf,packet_len_table[0x1cf],&sd->bl,AREA);
  5669. return 0;
  5670. }
  5671. int clif_marionette(struct block_list *src, struct block_list *target)
  5672. {
  5673. unsigned char buf[56];
  5674. int n;
  5675. WBUFW(buf,0)=0x1cf;
  5676. WBUFL(buf,2)=src->id;
  5677. for(n=0;n<5;n++)
  5678. WBUFL(buf,6+4*n)=0;
  5679. if (target) //The target goes on the second slot.
  5680. WBUFL(buf,6+4) = target->id;
  5681. WBUFB(buf,26)=8;
  5682. WBUFB(buf,27)=0;
  5683. clif_send(buf,packet_len_table[0x1cf],src,AREA);
  5684. return 0;
  5685. }
  5686. /*==========================================
  5687. * 氣球
  5688. *------------------------------------------
  5689. */
  5690. int clif_spiritball(struct map_session_data *sd)
  5691. {
  5692. unsigned char buf[16];
  5693. nullpo_retr(0, sd);
  5694. WBUFW(buf,0)=0x1d0;
  5695. WBUFL(buf,2)=sd->bl.id;
  5696. WBUFW(buf,6)=sd->spiritball;
  5697. clif_send(buf,packet_len_table[0x1d0],&sd->bl,AREA);
  5698. return 0;
  5699. }
  5700. /*==========================================
  5701. *
  5702. *------------------------------------------
  5703. */
  5704. int clif_combo_delay(struct block_list *bl,int wait)
  5705. {
  5706. unsigned char buf[32];
  5707. nullpo_retr(0, bl);
  5708. WBUFW(buf,0)=0x1d2;
  5709. WBUFL(buf,2)=bl->id;
  5710. WBUFL(buf,6)=wait;
  5711. clif_send(buf,packet_len_table[0x1d2],bl,AREA);
  5712. return 0;
  5713. }
  5714. /*==========================================
  5715. *白刃取り
  5716. *------------------------------------------
  5717. */
  5718. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5719. int _bool)
  5720. {
  5721. unsigned char buf[32];
  5722. nullpo_retr(0, src);
  5723. nullpo_retr(0, dst);
  5724. WBUFW(buf,0)=0x1d1;
  5725. WBUFL(buf,2)=src->id;
  5726. WBUFL(buf,6)=dst->id;
  5727. WBUFL(buf,10)=_bool;
  5728. clif_send(buf,packet_len_table[0x1d1],src,AREA);
  5729. return 0;
  5730. }
  5731. /*==========================================
  5732. *
  5733. *------------------------------------------
  5734. */
  5735. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5736. {
  5737. struct block_list bl;
  5738. unsigned char buf[32];
  5739. bl.type = BL_NUL;
  5740. bl.m = m;
  5741. bl.x = x;
  5742. bl.y = y;
  5743. WBUFW(buf,0) = 0x192;
  5744. WBUFW(buf,2) = x;
  5745. WBUFW(buf,4) = y;
  5746. WBUFW(buf,6) = cell_type;
  5747. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  5748. if(!type)
  5749. clif_send(buf,packet_len_table[0x192],&bl,AREA);
  5750. else
  5751. clif_send(buf,packet_len_table[0x192],&bl,ALL_SAMEMAP);
  5752. return 0;
  5753. }
  5754. /*==========================================
  5755. * MVPエフェクト
  5756. *------------------------------------------
  5757. */
  5758. int clif_mvp_effect(struct map_session_data *sd)
  5759. {
  5760. unsigned char buf[16];
  5761. nullpo_retr(0, sd);
  5762. WBUFW(buf,0)=0x10c;
  5763. WBUFL(buf,2)=sd->bl.id;
  5764. clif_send(buf,packet_len_table[0x10c],&sd->bl,AREA);
  5765. return 0;
  5766. }
  5767. /*==========================================
  5768. * MVPアイテム所得
  5769. *------------------------------------------
  5770. */
  5771. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5772. {
  5773. int view,fd;
  5774. nullpo_retr(0, sd);
  5775. fd=sd->fd;
  5776. WFIFOHEAD(fd,packet_len_table[0x10a]);
  5777. WFIFOW(fd,0)=0x10a;
  5778. if((view = itemdb_viewid(nameid)) > 0)
  5779. WFIFOW(fd,2)=view;
  5780. else
  5781. WFIFOW(fd,2)=nameid;
  5782. WFIFOSET(fd,packet_len_table[0x10a]);
  5783. return 0;
  5784. }
  5785. /*==========================================
  5786. * MVP経験値所得
  5787. *------------------------------------------
  5788. */
  5789. int clif_mvp_exp(struct map_session_data *sd,int exp)
  5790. {
  5791. int fd;
  5792. nullpo_retr(0, sd);
  5793. fd=sd->fd;
  5794. WFIFOHEAD(fd,packet_len_table[0x10b]);
  5795. WFIFOW(fd,0)=0x10b;
  5796. WFIFOL(fd,2)=exp;
  5797. WFIFOSET(fd,packet_len_table[0x10b]);
  5798. return 0;
  5799. }
  5800. /*==========================================
  5801. * ギルド作成可否通知
  5802. *------------------------------------------
  5803. */
  5804. int clif_guild_created(struct map_session_data *sd,int flag)
  5805. {
  5806. int fd;
  5807. nullpo_retr(0, sd);
  5808. fd=sd->fd;
  5809. WFIFOHEAD(fd,packet_len_table[0x167]);
  5810. WFIFOW(fd,0)=0x167;
  5811. WFIFOB(fd,2)=flag;
  5812. WFIFOSET(fd,packet_len_table[0x167]);
  5813. return 0;
  5814. }
  5815. /*==========================================
  5816. * ギルド所属通知
  5817. *------------------------------------------
  5818. */
  5819. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5820. {
  5821. int ps,fd;
  5822. nullpo_retr(0, sd);
  5823. nullpo_retr(0, g);
  5824. fd=sd->fd;
  5825. ps=guild_getposition(sd,g);
  5826. WFIFOHEAD(fd,packet_len_table[0x16c]);
  5827. memset(WFIFOP(fd,0),0,packet_len_table[0x16c]);
  5828. WFIFOW(fd,0)=0x16c;
  5829. WFIFOL(fd,2)=g->guild_id;
  5830. WFIFOL(fd,6)=g->emblem_id;
  5831. WFIFOL(fd,10)=g->position[ps].mode;
  5832. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5833. WFIFOSET(fd,packet_len_table[0x16c]);
  5834. return 0;
  5835. }
  5836. /*==========================================
  5837. * ギルドメンバログイン通知
  5838. *------------------------------------------
  5839. */
  5840. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5841. {
  5842. unsigned char buf[64];
  5843. nullpo_retr(0, g);
  5844. // printf("clif_guild_message(%s, %d, %s)\n", g->name, account_id, mes);
  5845. WBUFW(buf, 0)=0x16d;
  5846. WBUFL(buf, 2)=g->member[idx].account_id;
  5847. WBUFL(buf, 6)=g->member[idx].char_id;
  5848. WBUFL(buf,10)=flag;
  5849. if(g->member[idx].sd==NULL){
  5850. struct map_session_data *sd=guild_getavailablesd(g);
  5851. if(sd!=NULL)
  5852. clif_send(buf,packet_len_table[0x16d],&sd->bl,GUILD);
  5853. }else
  5854. clif_send(buf,packet_len_table[0x16d],&g->member[idx].sd->bl,GUILD_WOS);
  5855. return 0;
  5856. }
  5857. // Function `clif_guild_memberlogin_notice` sends info about
  5858. // logins and logouts of a guild member to the rest members.
  5859. // But at the 1st time (after a player login or map changing)
  5860. // the client won't show the message.
  5861. // So I suggest use this function for sending "first-time-info"
  5862. // to some player on entering the game or changing location.
  5863. // At next time the client would always show the message.
  5864. // The function sends all the statuses in the single packet
  5865. // to economize traffic. [LuzZza]
  5866. int clif_guild_send_onlineinfo(struct map_session_data *sd) {
  5867. struct guild *g;
  5868. char buf[14*128];
  5869. int i, count=0, p_len;
  5870. nullpo_retr(0, sd);
  5871. p_len = packet_len_table[0x16d];
  5872. if(!(g = guild_search(sd->status.guild_id)))
  5873. return 0;
  5874. for(i=0; i<g->max_member; i++) {
  5875. if(g->member[i].account_id > 0 &&
  5876. g->member[i].account_id != sd->status.account_id) {
  5877. WBUFW(buf,count*p_len) = 0x16d;
  5878. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5879. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5880. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5881. count++;
  5882. }
  5883. }
  5884. clif_send(buf,p_len*count,&sd->bl,SELF);
  5885. return 0;
  5886. }
  5887. /*==========================================
  5888. * ギルドマスター通知(14dへの応答)
  5889. *------------------------------------------
  5890. */
  5891. int clif_guild_masterormember(struct map_session_data *sd)
  5892. {
  5893. int type=0x57,fd;
  5894. nullpo_retr(0, sd);
  5895. fd=sd->fd;
  5896. if(sd->state.gmaster_flag)
  5897. type=0xd7;
  5898. WFIFOHEAD(fd,packet_len_table[0x14e]);
  5899. WFIFOW(fd,0)=0x14e;
  5900. WFIFOL(fd,2)=type;
  5901. WFIFOSET(fd,packet_len_table[0x14e]);
  5902. return 0;
  5903. }
  5904. /*==========================================
  5905. * Basic Info (Territories [Valaris])
  5906. *------------------------------------------
  5907. */
  5908. int clif_guild_basicinfo(struct map_session_data *sd)
  5909. {
  5910. int fd,i,t=0;
  5911. struct guild *g;
  5912. struct guild_castle *gc=NULL;
  5913. nullpo_retr(0, sd);
  5914. fd=sd->fd;
  5915. g=guild_search(sd->status.guild_id);
  5916. if(g==NULL)
  5917. return 0;
  5918. WFIFOHEAD(fd,packet_len_table[0x1b6]);
  5919. WFIFOW(fd, 0)=0x1b6;//0x150;
  5920. WFIFOL(fd, 2)=g->guild_id;
  5921. WFIFOL(fd, 6)=g->guild_lv;
  5922. WFIFOL(fd,10)=g->connect_member;
  5923. WFIFOL(fd,14)=g->max_member;
  5924. WFIFOL(fd,18)=g->average_lv;
  5925. WFIFOL(fd,22)=g->exp;
  5926. WFIFOL(fd,26)=g->next_exp;
  5927. WFIFOL(fd,30)=0; // 上納
  5928. WFIFOL(fd,34)=0; // VW(性格の悪さ?:性向グラフ左右)
  5929. WFIFOL(fd,38)=0; // RF(正義の度合い?:性向グラフ上下)
  5930. WFIFOL(fd,42)=0; // 人数?
  5931. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5932. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5933. for(i=0;i<MAX_GUILDCASTLE;i++){
  5934. gc=guild_castle_search(i);
  5935. if(!gc) continue;
  5936. if(g->guild_id == gc->guild_id) t++;
  5937. }
  5938. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  5939. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  5940. else
  5941. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  5942. WFIFOSET(fd,packet_len_table[WFIFOW(fd,0)]);
  5943. clif_guild_emblem(sd,g); // Guild emblem vanish fix [Valaris]
  5944. return 0;
  5945. }
  5946. /*==========================================
  5947. * ギルド同盟/敵対情報
  5948. *------------------------------------------
  5949. */
  5950. int clif_guild_allianceinfo(struct map_session_data *sd)
  5951. {
  5952. int fd,i,c;
  5953. struct guild *g;
  5954. nullpo_retr(0, sd);
  5955. fd=sd->fd;
  5956. g=guild_search(sd->status.guild_id);
  5957. if(g==NULL)
  5958. return 0;
  5959. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5960. WFIFOW(fd, 0)=0x14c;
  5961. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5962. struct guild_alliance *a=&g->alliance[i];
  5963. if(a->guild_id>0){
  5964. WFIFOL(fd,c*32+4)=a->opposition;
  5965. WFIFOL(fd,c*32+8)=a->guild_id;
  5966. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5967. c++;
  5968. }
  5969. }
  5970. WFIFOW(fd, 2)=c*32+4;
  5971. WFIFOSET(fd,WFIFOW(fd,2));
  5972. return 0;
  5973. }
  5974. /*==========================================
  5975. * ギルドメンバーリスト
  5976. *------------------------------------------
  5977. */
  5978. int clif_guild_memberlist(struct map_session_data *sd)
  5979. {
  5980. int fd;
  5981. int i,c;
  5982. struct guild *g;
  5983. nullpo_retr(0, sd);
  5984. fd=sd->fd;
  5985. if (!fd)
  5986. return 0;
  5987. g=guild_search(sd->status.guild_id);
  5988. if(g==NULL)
  5989. return 0;
  5990. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5991. WFIFOW(fd, 0)=0x154;
  5992. for(i=0,c=0;i<g->max_member;i++){
  5993. struct guild_member *m=&g->member[i];
  5994. if(m->account_id==0)
  5995. continue;
  5996. WFIFOL(fd,c*104+ 4)=m->account_id;
  5997. WFIFOL(fd,c*104+ 8)=m->char_id;
  5998. WFIFOW(fd,c*104+12)=m->hair;
  5999. WFIFOW(fd,c*104+14)=m->hair_color;
  6000. WFIFOW(fd,c*104+16)=m->gender;
  6001. WFIFOW(fd,c*104+18)=m->class_;
  6002. WFIFOW(fd,c*104+20)=m->lv;
  6003. WFIFOL(fd,c*104+22)=m->exp;
  6004. WFIFOL(fd,c*104+26)=m->online;
  6005. WFIFOL(fd,c*104+30)=m->position;
  6006. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  6007. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6008. c++;
  6009. }
  6010. WFIFOW(fd, 2)=c*104+4;
  6011. WFIFOSET(fd,WFIFOW(fd,2));
  6012. return 0;
  6013. }
  6014. /*==========================================
  6015. * ギルド役職名リスト
  6016. *------------------------------------------
  6017. */
  6018. int clif_guild_positionnamelist(struct map_session_data *sd)
  6019. {
  6020. int i,fd;
  6021. struct guild *g;
  6022. nullpo_retr(0, sd);
  6023. fd=sd->fd;
  6024. g=guild_search(sd->status.guild_id);
  6025. if(g==NULL)
  6026. return 0;
  6027. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6028. WFIFOW(fd, 0)=0x166;
  6029. for(i=0;i<MAX_GUILDPOSITION;i++){
  6030. WFIFOL(fd,i*28+4)=i;
  6031. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6032. }
  6033. WFIFOW(fd,2)=i*28+4;
  6034. WFIFOSET(fd,WFIFOW(fd,2));
  6035. return 0;
  6036. }
  6037. /*==========================================
  6038. * ギルド役職情報リスト
  6039. *------------------------------------------
  6040. */
  6041. int clif_guild_positioninfolist(struct map_session_data *sd)
  6042. {
  6043. int i,fd;
  6044. struct guild *g;
  6045. nullpo_retr(0, sd);
  6046. fd=sd->fd;
  6047. g=guild_search(sd->status.guild_id);
  6048. if(g==NULL)
  6049. return 0;
  6050. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6051. WFIFOW(fd, 0)=0x160;
  6052. for(i=0;i<MAX_GUILDPOSITION;i++){
  6053. struct guild_position *p=&g->position[i];
  6054. WFIFOL(fd,i*16+ 4)=i;
  6055. WFIFOL(fd,i*16+ 8)=p->mode;
  6056. WFIFOL(fd,i*16+12)=i;
  6057. WFIFOL(fd,i*16+16)=p->exp_mode;
  6058. }
  6059. WFIFOW(fd, 2)=i*16+4;
  6060. WFIFOSET(fd,WFIFOW(fd,2));
  6061. return 0;
  6062. }
  6063. /*==========================================
  6064. * ギルド役職変更通知
  6065. *------------------------------------------
  6066. */
  6067. int clif_guild_positionchanged(struct guild *g,int idx)
  6068. {
  6069. struct map_session_data *sd;
  6070. unsigned char buf[128];
  6071. nullpo_retr(0, g);
  6072. WBUFW(buf, 0)=0x174;
  6073. WBUFW(buf, 2)=44;
  6074. WBUFL(buf, 4)=idx;
  6075. WBUFL(buf, 8)=g->position[idx].mode;
  6076. WBUFL(buf,12)=idx;
  6077. WBUFL(buf,16)=g->position[idx].exp_mode;
  6078. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6079. if( (sd=guild_getavailablesd(g))!=NULL )
  6080. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6081. return 0;
  6082. }
  6083. /*==========================================
  6084. * ギルドメンバ変更通知
  6085. *------------------------------------------
  6086. */
  6087. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6088. {
  6089. struct map_session_data *sd;
  6090. unsigned char buf[64];
  6091. nullpo_retr(0, g);
  6092. WBUFW(buf, 0)=0x156;
  6093. WBUFW(buf, 2)=16;
  6094. WBUFL(buf, 4)=g->member[idx].account_id;
  6095. WBUFL(buf, 8)=g->member[idx].char_id;
  6096. WBUFL(buf,12)=g->member[idx].position;
  6097. if( (sd=guild_getavailablesd(g))!=NULL )
  6098. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6099. return 0;
  6100. }
  6101. /*==========================================
  6102. * ギルドエンブレム送信
  6103. *------------------------------------------
  6104. */
  6105. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6106. {
  6107. int fd;
  6108. nullpo_retr(0, sd);
  6109. nullpo_retr(0, g);
  6110. fd=sd->fd;
  6111. if(g->emblem_len<=0)
  6112. return 0;
  6113. WFIFOHEAD(fd,g->emblem_len+12);
  6114. WFIFOW(fd,0)=0x152;
  6115. WFIFOW(fd,2)=g->emblem_len+12;
  6116. WFIFOL(fd,4)=g->guild_id;
  6117. WFIFOL(fd,8)=g->emblem_id;
  6118. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6119. WFIFOSET(fd,WFIFOW(fd,2));
  6120. return 0;
  6121. }
  6122. /*==========================================
  6123. * ギルドスキル送信
  6124. *------------------------------------------
  6125. */
  6126. int clif_guild_skillinfo(struct map_session_data *sd)
  6127. {
  6128. int fd;
  6129. int i,id,c,up=1;
  6130. struct guild *g;
  6131. nullpo_retr(0, sd);
  6132. fd=sd->fd;
  6133. g=guild_search(sd->status.guild_id);
  6134. if(g==NULL)
  6135. return 0;
  6136. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6137. WFIFOW(fd,0)=0x0162;
  6138. WFIFOW(fd,4)=g->skill_point;
  6139. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6140. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6141. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6142. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  6143. WFIFOW(fd,c*37+10) = 0;
  6144. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6145. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6146. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6147. memset(WFIFOP(fd,c*37+18),0,24);
  6148. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6149. up = 1;
  6150. else
  6151. up = 0;
  6152. WFIFOB(fd,c*37+42)= up;
  6153. c++;
  6154. }
  6155. }
  6156. WFIFOW(fd,2)=c*37+6;
  6157. WFIFOSET(fd,WFIFOW(fd,2));
  6158. return 0;
  6159. }
  6160. /*==========================================
  6161. * ギルド告知送信
  6162. *------------------------------------------
  6163. */
  6164. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6165. {
  6166. int fd;
  6167. nullpo_retr(0, sd);
  6168. nullpo_retr(0, g);
  6169. fd = sd->fd;
  6170. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6171. return 0;
  6172. if (fd <= 0)
  6173. return 0;
  6174. if(*g->mes1==0 && *g->mes2==0)
  6175. return 0;
  6176. WFIFOHEAD(fd,packet_len_table[0x16f]);
  6177. WFIFOW(fd,0)=0x16f;
  6178. memcpy(WFIFOP(fd,2),g->mes1,60);
  6179. memcpy(WFIFOP(fd,62),g->mes2,120);
  6180. WFIFOSET(fd,packet_len_table[0x16f]);
  6181. return 0;
  6182. }
  6183. /*==========================================
  6184. * ギルドメンバ勧誘
  6185. *------------------------------------------
  6186. */
  6187. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6188. {
  6189. int fd;
  6190. nullpo_retr(0, sd);
  6191. nullpo_retr(0, g);
  6192. fd=sd->fd;
  6193. WFIFOHEAD(fd,packet_len_table[0x16a]);
  6194. WFIFOW(fd,0)=0x16a;
  6195. WFIFOL(fd,2)=g->guild_id;
  6196. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6197. WFIFOSET(fd,packet_len_table[0x16a]);
  6198. return 0;
  6199. }
  6200. /*==========================================
  6201. * ギルドメンバ勧誘結果
  6202. *------------------------------------------
  6203. */
  6204. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6205. {
  6206. int fd;
  6207. nullpo_retr(0, sd);
  6208. fd=sd->fd;
  6209. WFIFOHEAD(fd,packet_len_table[0x169]);
  6210. WFIFOW(fd,0)=0x169;
  6211. WFIFOB(fd,2)=flag;
  6212. WFIFOSET(fd,packet_len_table[0x169]);
  6213. return 0;
  6214. }
  6215. /*==========================================
  6216. * ギルドメンバ脱退通知
  6217. *------------------------------------------
  6218. */
  6219. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6220. {
  6221. unsigned char buf[128];
  6222. nullpo_retr(0, sd);
  6223. WBUFW(buf, 0)=0x15a;
  6224. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6225. memcpy(WBUFP(buf,26),mes,40);
  6226. clif_send(buf,packet_len_table[0x15a],&sd->bl,GUILD);
  6227. return 0;
  6228. }
  6229. /*==========================================
  6230. * ギルドメンバ追放通知
  6231. *------------------------------------------
  6232. */
  6233. int clif_guild_explusion(struct map_session_data *sd,const char *name,const char *mes,
  6234. int account_id)
  6235. {
  6236. unsigned char buf[128];
  6237. nullpo_retr(0, sd);
  6238. WBUFW(buf, 0)=0x15c;
  6239. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6240. memcpy(WBUFP(buf,26),mes,40);
  6241. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6242. clif_send(buf,packet_len_table[0x15c],&sd->bl,GUILD);
  6243. return 0;
  6244. }
  6245. /*==========================================
  6246. * ギルド追放メンバリスト
  6247. *------------------------------------------
  6248. */
  6249. int clif_guild_explusionlist(struct map_session_data *sd)
  6250. {
  6251. int fd;
  6252. int i,c;
  6253. struct guild *g;
  6254. nullpo_retr(0, sd);
  6255. fd=sd->fd;
  6256. g=guild_search(sd->status.guild_id);
  6257. if(g==NULL)
  6258. return 0;
  6259. WFIFOHEAD(fd,MAX_GUILDEXPLUSION * 88 + 4);
  6260. WFIFOW(fd,0)=0x163;
  6261. for(i=c=0;i<MAX_GUILDEXPLUSION;i++){
  6262. struct guild_explusion *e=&g->explusion[i];
  6263. if(e->account_id>0){
  6264. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6265. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6266. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6267. c++;
  6268. }
  6269. }
  6270. WFIFOW(fd,2)=c*88+4;
  6271. WFIFOSET(fd,WFIFOW(fd,2));
  6272. return 0;
  6273. }
  6274. /*==========================================
  6275. * ギルド会話
  6276. *------------------------------------------
  6277. */
  6278. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6279. {
  6280. struct map_session_data *sd;
  6281. unsigned char *buf;
  6282. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6283. WBUFW(buf, 0) = 0x17f;
  6284. WBUFW(buf, 2) = len + 4;
  6285. memcpy(WBUFP(buf,4), mes, len);
  6286. if ((sd = guild_getavailablesd(g)) != NULL)
  6287. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6288. if(buf) aFree(buf);
  6289. return 0;
  6290. }
  6291. /*==========================================
  6292. * ギルドスキル割り振り通知
  6293. *------------------------------------------
  6294. */
  6295. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6296. {
  6297. int fd;
  6298. nullpo_retr(0, sd);
  6299. fd=sd->fd;
  6300. WFIFOHEAD(fd,11);
  6301. WFIFOW(fd,0) = 0x10e;
  6302. WFIFOW(fd,2) = skill_num;
  6303. WFIFOW(fd,4) = lv;
  6304. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6305. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6306. WFIFOB(fd,10) = 1;
  6307. WFIFOSET(fd,11);
  6308. return 0;
  6309. }
  6310. /*==========================================
  6311. * ギルド同盟要請
  6312. *------------------------------------------
  6313. */
  6314. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6315. {
  6316. int fd;
  6317. nullpo_retr(0, sd);
  6318. fd=sd->fd;
  6319. WFIFOHEAD(fd,packet_len_table[0x171]);
  6320. WFIFOW(fd,0)=0x171;
  6321. WFIFOL(fd,2)=account_id;
  6322. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6323. WFIFOSET(fd,packet_len_table[0x171]);
  6324. return 0;
  6325. }
  6326. /*==========================================
  6327. * ギルド同盟結果
  6328. *------------------------------------------
  6329. */
  6330. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6331. {
  6332. int fd;
  6333. nullpo_retr(0, sd);
  6334. fd=sd->fd;
  6335. WFIFOHEAD(fd,packet_len_table[0x173]);
  6336. WFIFOW(fd,0)=0x173;
  6337. WFIFOL(fd,2)=flag;
  6338. WFIFOSET(fd,packet_len_table[0x173]);
  6339. return 0;
  6340. }
  6341. /*==========================================
  6342. * ギルド関係解消通知
  6343. *------------------------------------------
  6344. */
  6345. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6346. {
  6347. int fd;
  6348. nullpo_retr(0, sd);
  6349. fd = sd->fd;
  6350. if (fd <= 0)
  6351. return 0;
  6352. WFIFOHEAD(fd,packet_len_table[0x184]);
  6353. WFIFOW(fd,0)=0x184;
  6354. WFIFOL(fd,2)=guild_id;
  6355. WFIFOL(fd,6)=flag;
  6356. WFIFOSET(fd,packet_len_table[0x184]);
  6357. return 0;
  6358. }
  6359. /*==========================================
  6360. * ギルド敵対結果
  6361. *------------------------------------------
  6362. */
  6363. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6364. {
  6365. int fd;
  6366. nullpo_retr(0, sd);
  6367. fd=sd->fd;
  6368. WFIFOHEAD(fd,packet_len_table[0x181]);
  6369. WFIFOW(fd,0)=0x181;
  6370. WFIFOB(fd,2)=flag;
  6371. WFIFOSET(fd,packet_len_table[0x181]);
  6372. return 0;
  6373. }
  6374. /*==========================================
  6375. * ギルド関係追加
  6376. *------------------------------------------
  6377. */
  6378. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6379. {
  6380. unsigned char buf[64];
  6381. WBUFW(fd,0)=0x185;
  6382. WBUFL(fd,2)=g->alliance[idx].opposition;
  6383. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6384. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6385. clif_send(buf,packet_len_table[0x185],guild_getavailablesd(g),GUILD);
  6386. return 0;
  6387. }*/
  6388. /*==========================================
  6389. * ギルド解散通知
  6390. *------------------------------------------
  6391. */
  6392. int clif_guild_broken(struct map_session_data *sd,int flag)
  6393. {
  6394. int fd;
  6395. nullpo_retr(0, sd);
  6396. fd=sd->fd;
  6397. WFIFOHEAD(fd,packet_len_table[0x15e]);
  6398. WFIFOW(fd,0)=0x15e;
  6399. WFIFOL(fd,2)=flag;
  6400. WFIFOSET(fd,packet_len_table[0x15e]);
  6401. return 0;
  6402. }
  6403. /*==========================================
  6404. * エモーション
  6405. *------------------------------------------
  6406. */
  6407. void clif_emotion(struct block_list *bl,int type)
  6408. {
  6409. unsigned char buf[8];
  6410. nullpo_retv(bl);
  6411. WBUFW(buf,0)=0xc0;
  6412. WBUFL(buf,2)=bl->id;
  6413. WBUFB(buf,6)=type;
  6414. clif_send(buf,packet_len_table[0xc0],bl,AREA);
  6415. }
  6416. /*==========================================
  6417. * トーキーボックス
  6418. *------------------------------------------
  6419. */
  6420. void clif_talkiebox(struct block_list *bl,char* talkie)
  6421. {
  6422. unsigned char buf[86];
  6423. nullpo_retv(bl);
  6424. WBUFW(buf,0)=0x191;
  6425. WBUFL(buf,2)=bl->id;
  6426. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6427. clif_send(buf,packet_len_table[0x191],bl,AREA);
  6428. }
  6429. /*==========================================
  6430. * 結婚エフェクト
  6431. *------------------------------------------
  6432. */
  6433. void clif_wedding_effect(struct block_list *bl) {
  6434. unsigned char buf[6];
  6435. nullpo_retv(bl);
  6436. WBUFW(buf,0) = 0x1ea;
  6437. WBUFL(buf,2) = bl->id;
  6438. clif_send(buf, packet_len_table[0x1ea], bl, AREA);
  6439. }
  6440. /*==========================================
  6441. * あなたに逢いたい使用時名前叫び
  6442. *------------------------------------------
  6443. void clif_callpartner(struct map_session_data *sd)
  6444. {
  6445. unsigned char buf[26];
  6446. char *p;
  6447. nullpo_retv(sd);
  6448. if(sd->status.partner_id){
  6449. WBUFW(buf,0)=0x1e6;
  6450. p = map_charid2nick(sd->status.partner_id);
  6451. if(p){
  6452. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6453. }else{
  6454. map_reqchariddb(sd,sd->status.partner_id);
  6455. chrif_searchcharid(sd->status.partner_id);
  6456. WBUFB(buf,2) = 0;
  6457. }
  6458. clif_send(buf,packet_len_table[0x1e6],&sd->bl,AREA);
  6459. }
  6460. return;
  6461. }
  6462. */
  6463. /*==========================================
  6464. * Adopt baby [Celest]
  6465. *------------------------------------------
  6466. */
  6467. void clif_adopt_process(struct map_session_data *sd)
  6468. {
  6469. int fd;
  6470. nullpo_retv(sd);
  6471. fd=sd->fd;
  6472. WFIFOHEAD(fd,packet_len_table[0x1f8]);
  6473. WFIFOW(fd,0)=0x1f8;
  6474. WFIFOSET(fd,packet_len_table[0x1f8]);
  6475. }
  6476. /*==========================================
  6477. * Marry [DracoRPG]
  6478. *------------------------------------------
  6479. */
  6480. void clif_marriage_process(struct map_session_data *sd)
  6481. {
  6482. int fd;
  6483. nullpo_retv(sd);
  6484. fd=sd->fd;
  6485. WFIFOHEAD(fd,packet_len_table[0x1e4]);
  6486. WFIFOW(fd,0)=0x1e4;
  6487. WFIFOSET(fd,packet_len_table[0x1e4]);
  6488. }
  6489. /*==========================================
  6490. * Notice of divorce
  6491. *------------------------------------------
  6492. */
  6493. void clif_divorced(struct map_session_data *sd, char *name)
  6494. {
  6495. int fd;
  6496. nullpo_retv(sd);
  6497. fd=sd->fd;
  6498. WFIFOHEAD(fd,packet_len_table[0x205]);
  6499. WFIFOW(fd,0)=0x205;
  6500. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6501. WFIFOSET(fd, packet_len_table[0x205]);
  6502. }
  6503. /*==========================================
  6504. *
  6505. *------------------------------------------
  6506. */
  6507. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6508. nullpo_retv(sd);
  6509. WFIFOHEAD(fd,packet_len_table[0x1f6]);
  6510. WFIFOW(fd,0)=0x1f6;
  6511. WFIFOSET(fd, packet_len_table[0x1f6]);
  6512. }
  6513. /*==========================================
  6514. *
  6515. *------------------------------------------
  6516. */
  6517. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6518. nullpo_retv(sd);
  6519. WFIFOHEAD(fd,packet_len_table[0x1e2]);
  6520. WFIFOW(fd,0)=0x1e2;
  6521. WFIFOSET(fd, packet_len_table[0x1e2]);
  6522. }
  6523. /*==========================================
  6524. * 座る
  6525. *------------------------------------------
  6526. */
  6527. void clif_sitting(struct map_session_data *sd)
  6528. {
  6529. unsigned char buf[64];
  6530. nullpo_retv(sd);
  6531. WBUFW(buf, 0) = 0x8a;
  6532. WBUFL(buf, 2) = sd->bl.id;
  6533. WBUFB(buf,26) = 2;
  6534. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  6535. }
  6536. /*==========================================
  6537. *
  6538. *------------------------------------------
  6539. */
  6540. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  6541. {
  6542. unsigned char *buf;
  6543. nullpo_retr(0, sd);
  6544. buf = (unsigned char*)aMallocA((len + 5)*sizeof(unsigned char));
  6545. WBUFW(buf, 0) = 0x17f;
  6546. WBUFW(buf, 2) = len + 5;
  6547. memcpy(WBUFP(buf,4), mes, len);
  6548. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6549. if(buf) aFree(buf);
  6550. return 0;
  6551. }
  6552. /*==========================================
  6553. *
  6554. *------------------------------------------
  6555. */
  6556. int clif_GM_kickack(struct map_session_data *sd, int id)
  6557. {
  6558. int fd;
  6559. nullpo_retr(0, sd);
  6560. fd = sd->fd;
  6561. WFIFOHEAD(fd,packet_len_table[0xcd]);
  6562. WFIFOW(fd,0) = 0xcd;
  6563. WFIFOL(fd,2) = id;
  6564. WFIFOSET(fd, packet_len_table[0xcd]);
  6565. return 0;
  6566. }
  6567. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6568. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6569. {
  6570. nullpo_retr(0, tsd);
  6571. if(type)
  6572. clif_GM_kickack(sd,tsd->status.account_id);
  6573. WFIFOHEAD(tsd->fd,packet_len_table[0x18b]);
  6574. WFIFOW(tsd->fd,0) = 0x18b;
  6575. WFIFOW(tsd->fd,2) = 0;
  6576. WFIFOSET(tsd->fd,packet_len_table[0x18b]);
  6577. if (tsd->fd)
  6578. {
  6579. ShowDebug("clif_GM_kick: Disconnecting session #%d\n", tsd->fd);
  6580. clif_setwaitclose(tsd->fd);
  6581. } else { //Player has no session attached, delete it right away. [Skotlex]
  6582. map_quit(tsd);
  6583. }
  6584. return 0;
  6585. }
  6586. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6587. {
  6588. int fd;
  6589. nullpo_retr(0, sd);
  6590. nullpo_retr(0, tsd);
  6591. fd = tsd->fd;
  6592. if (fd <= 0)
  6593. return 0;
  6594. WFIFOHEAD(fd,packet_len_table[0x14b]);
  6595. WFIFOW(fd,0) = 0x14b;
  6596. WFIFOB(fd,2) = 0;
  6597. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6598. WFIFOSET(fd, packet_len_table[0x14b]);
  6599. return 0;
  6600. }
  6601. /*==========================================
  6602. *
  6603. *------------------------------------------
  6604. */
  6605. int clif_timedout(struct map_session_data *sd)
  6606. {
  6607. nullpo_retr(0, sd);
  6608. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6609. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6610. clif_setwaitclose(sd->fd); // Set session to EOF
  6611. return 0;
  6612. }
  6613. /*==========================================
  6614. * Wis拒否許可応答
  6615. *------------------------------------------
  6616. */
  6617. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6618. {
  6619. int fd;
  6620. nullpo_retr(0, sd);
  6621. fd=sd->fd;
  6622. WFIFOHEAD(fd,packet_len_table[0xd1]);
  6623. WFIFOW(fd,0)=0xd1;
  6624. WFIFOB(fd,2)=type;
  6625. WFIFOB(fd,3)=flag;
  6626. WFIFOSET(fd,packet_len_table[0xd1]);
  6627. return 0;
  6628. }
  6629. /*==========================================
  6630. * Wis全拒否許可応答
  6631. *------------------------------------------
  6632. */
  6633. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6634. {
  6635. int fd;
  6636. nullpo_retr(0, sd);
  6637. fd=sd->fd;
  6638. WFIFOHEAD(fd,packet_len_table[0xd2]);
  6639. WFIFOW(fd,0)=0xd2;
  6640. WFIFOB(fd,2)=type;
  6641. WFIFOB(fd,3)=flag;
  6642. WFIFOSET(fd,packet_len_table[0xd2]);
  6643. return 0;
  6644. }
  6645. /*==========================================
  6646. * サウンドエフェクト
  6647. *------------------------------------------
  6648. */
  6649. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  6650. {
  6651. int fd;
  6652. nullpo_retv(sd);
  6653. nullpo_retv(bl);
  6654. fd=sd->fd;
  6655. WFIFOHEAD(fd,packet_len_table[0x1d3]);
  6656. WFIFOW(fd,0)=0x1d3;
  6657. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6658. WFIFOB(fd,26)=type;
  6659. WFIFOL(fd,27)=0;
  6660. WFIFOL(fd,31)=bl->id;
  6661. WFIFOSET(fd,packet_len_table[0x1d3]);
  6662. return;
  6663. }
  6664. int clif_soundeffectall(struct block_list *bl, char *name, int type, int coverage)
  6665. {
  6666. unsigned char buf[40];
  6667. memset(buf, 0, packet_len_table[0x1d3]);
  6668. if(coverage < 0 || coverage > 22){
  6669. ShowError("clif_soundeffectall: undefined coverage.\n");
  6670. return 0;
  6671. }
  6672. nullpo_retr(0, bl);
  6673. WBUFW(buf,0)=0x1d3;
  6674. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6675. WBUFB(buf,26)=type;
  6676. WBUFL(buf,27)=0;
  6677. WBUFL(buf,31)=bl->id;
  6678. clif_send(buf, packet_len_table[0x1d3], bl, coverage);
  6679. return 0;
  6680. }
  6681. // displaying special effects (npcs, weather, etc) [Valaris]
  6682. int clif_specialeffect(struct block_list *bl, int type, int flag)
  6683. {
  6684. unsigned char buf[24];
  6685. nullpo_retr(0, bl);
  6686. memset(buf, 0, packet_len_table[0x1f3]);
  6687. WBUFW(buf,0) = 0x1f3;
  6688. WBUFL(buf,2) = bl->id;
  6689. WBUFL(buf,6) = type;
  6690. switch (flag) {
  6691. case 4:
  6692. clif_send(buf, packet_len_table[0x1f3], bl, AREA_WOS);
  6693. break;
  6694. case 3:
  6695. clif_send(buf, packet_len_table[0x1f3], bl, ALL_CLIENT);
  6696. break;
  6697. case 2:
  6698. clif_send(buf, packet_len_table[0x1f3], bl, ALL_SAMEMAP);
  6699. break;
  6700. case 1:
  6701. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  6702. break;
  6703. default:
  6704. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  6705. }
  6706. if (disguised(bl)) {
  6707. WBUFL(buf,2) = -bl->id;
  6708. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  6709. }
  6710. return 0;
  6711. }
  6712. // refresh the client's screen, getting rid of any effects
  6713. int clif_refresh(struct map_session_data *sd) {
  6714. nullpo_retr(-1, sd);
  6715. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6716. map_foreachinarea(clif_getareachar,sd->bl.m,sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,BL_ALL,sd);
  6717. return 0;
  6718. }
  6719. // updates the object's (bl) name on client
  6720. int clif_charnameack (int fd, struct block_list *bl)
  6721. {
  6722. unsigned char buf[103];
  6723. int cmd = 0x95;
  6724. nullpo_retr(0, bl);
  6725. WBUFW(buf,0) = cmd;
  6726. WBUFL(buf,2) = bl->id;
  6727. switch(bl->type) {
  6728. case BL_PC:
  6729. {
  6730. struct map_session_data *ssd = (struct map_session_data *)bl;
  6731. struct party *p = NULL;
  6732. struct guild *g = NULL;
  6733. nullpo_retr(0, ssd);
  6734. if (strlen(ssd->fakename)>1) {
  6735. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6736. break;
  6737. }
  6738. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6739. if (ssd->status.party_id > 0)
  6740. p = party_search(ssd->status.party_id);
  6741. if (ssd->status.guild_id > 0)
  6742. g = guild_search(ssd->status.guild_id);
  6743. if (p == NULL && g == NULL)
  6744. break;
  6745. WBUFW(buf, 0) = cmd = 0x195;
  6746. if (p)
  6747. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  6748. else
  6749. WBUFB(buf,30) = 0;
  6750. if (g)
  6751. {
  6752. int i, ps = -1;
  6753. for(i = 0; i < g->max_member; i++) {
  6754. if (g->member[i].account_id == ssd->status.account_id &&
  6755. g->member[i].char_id == ssd->status.char_id )
  6756. {
  6757. ps = g->member[i].position;
  6758. break;
  6759. }
  6760. }
  6761. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6762. {
  6763. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6764. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6765. } else { //Assume no guild.
  6766. WBUFB(buf,54) = 0;
  6767. WBUFB(buf,78) = 0;
  6768. }
  6769. } else {
  6770. WBUFB(buf,54) = 0;
  6771. WBUFB(buf,78) = 0;
  6772. }
  6773. }
  6774. break;
  6775. case BL_PET:
  6776. memcpy(WBUFP(buf,6), ((struct pet_data*)bl)->name, NAME_LENGTH);
  6777. break;
  6778. case BL_NPC:
  6779. memcpy(WBUFP(buf,6), ((struct npc_data*)bl)->name, NAME_LENGTH);
  6780. break;
  6781. case BL_MOB:
  6782. {
  6783. struct mob_data *md = (struct mob_data *)bl;
  6784. nullpo_retr(0, md);
  6785. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6786. if (md->guardian_data && md->guardian_data->guild_id) {
  6787. WBUFW(buf, 0) = cmd = 0x195;
  6788. WBUFB(buf,30) = 0;
  6789. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6790. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6791. } else if (battle_config.show_mob_hp == 1) {
  6792. char mobhp[50];
  6793. WBUFW(buf, 0) = cmd = 0x195;
  6794. sprintf(mobhp, "HP: %d/%d", md->hp, md->max_hp);
  6795. //Even thought mobhp ain't a name, we send it as one so the client
  6796. //can parse it. [Skotlex]
  6797. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6798. WBUFB(buf,54) = 0;
  6799. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6800. }
  6801. }
  6802. break;
  6803. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6804. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6805. // break;
  6806. return 0;
  6807. default:
  6808. if (battle_config.error_log)
  6809. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6810. return 0;
  6811. }
  6812. // if no receipient specified just update nearby clients
  6813. if (fd == 0)
  6814. clif_send(buf, packet_len_table[cmd], bl, AREA);
  6815. else {
  6816. WFIFOHEAD(fd, packet_len_table[cmd]);
  6817. memcpy(WFIFOP(fd, 0), buf, packet_len_table[cmd]);
  6818. WFIFOSET(fd, packet_len_table[cmd]);
  6819. }
  6820. return 0;
  6821. }
  6822. //Used to update when a char leaves a party/guild. [Skotlex]
  6823. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6824. int clif_charnameupdate (struct map_session_data *ssd)
  6825. {
  6826. unsigned char buf[103];
  6827. int cmd = 0x195;
  6828. struct party *p = NULL;
  6829. struct guild *g = NULL;
  6830. nullpo_retr(0, ssd);
  6831. if (strlen(ssd->fakename)>1)
  6832. return 0; //No need to update as the party/guild was not displayed anyway.
  6833. WBUFW(buf,0) = cmd;
  6834. WBUFL(buf,2) = ssd->bl.id;
  6835. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6836. if (ssd->status.party_id > 0)
  6837. p = party_search(ssd->status.party_id);
  6838. if (ssd->status.guild_id > 0)
  6839. g = guild_search(ssd->status.guild_id);
  6840. if (p)
  6841. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  6842. else
  6843. WBUFB(buf,30) = 0;
  6844. if (g)
  6845. {
  6846. int i, ps = -1;
  6847. for(i = 0; i < g->max_member; i++) {
  6848. if (g->member[i].account_id == ssd->status.account_id &&
  6849. g->member[i].char_id == ssd->status.char_id )
  6850. {
  6851. ps = g->member[i].position;
  6852. break;
  6853. }
  6854. }
  6855. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6856. {
  6857. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6858. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6859. } else { //Assume no guild.
  6860. WBUFB(buf,54) = 0;
  6861. WBUFB(buf,78) = 0;
  6862. }
  6863. } else {
  6864. WBUFB(buf,54) = 0;
  6865. WBUFB(buf,78) = 0;
  6866. }
  6867. // Update nearby clients
  6868. clif_send(buf, packet_len_table[cmd], &ssd->bl, AREA);
  6869. return 0;
  6870. }
  6871. int clif_slide(struct block_list *bl, int x, int y){
  6872. unsigned char buf[10];
  6873. nullpo_retr(0, bl);
  6874. WBUFW(buf, 0) = 0x01ff;
  6875. WBUFL(buf, 2) = bl->id;
  6876. WBUFW(buf, 6) = x;
  6877. WBUFW(buf, 8) = y;
  6878. clif_send(buf, packet_len_table[0x1ff], bl, AREA);
  6879. return 0;
  6880. }
  6881. /*------------------------------------------
  6882. * @me command by lordalfa, rewritten implementation by Skotlex
  6883. *------------------------------------------
  6884. */
  6885. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  6886. {
  6887. unsigned char buf[256]; //This should be more than sufficient, the theorical max is MESSAGE_SIZE+NAME_LENGTH + 8 (pads and extra inserted crap)
  6888. int len_mes = strlen(mes)+1; //Account for \0
  6889. if (len_mes + 8 >= 256) {
  6890. if (battle_config.error_log)
  6891. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6892. len_mes = 247; //Trunk it to avoid problems.
  6893. }
  6894. // send message to others
  6895. WBUFW(buf,0) = 0x8d;
  6896. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6897. WBUFL(buf,4) = sd->bl.id;
  6898. memcpy(WBUFP(buf,8), mes, len_mes);
  6899. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6900. // send back message to the speaker
  6901. WBUFW(buf,0) = 0x8e;
  6902. WBUFW(buf, 2) = len_mes + 4;
  6903. memcpy(WBUFP(buf,4), mes, len_mes);
  6904. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6905. return 0;
  6906. }
  6907. /*==========================
  6908. * Minimap fix [Kevin]
  6909. * Remove dot from minimap
  6910. *--------------------------
  6911. */
  6912. int clif_party_xy_remove(struct map_session_data *sd)
  6913. {
  6914. unsigned char buf[16];
  6915. nullpo_retr(0, sd);
  6916. WBUFW(buf,0)=0x107;
  6917. WBUFL(buf,2)=sd->status.account_id;
  6918. WBUFW(buf,6)=-1;
  6919. WBUFW(buf,8)=-1;
  6920. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  6921. return 0;
  6922. }
  6923. /*==========================================
  6924. * Info about Star Glaldiator save map [Komurka]
  6925. *------------------------------------------
  6926. */
  6927. void clif_feel_info(struct map_session_data *sd, int feel_level)
  6928. {
  6929. int fd=sd->fd;
  6930. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6931. WFIFOW(fd,0)=0x20e;
  6932. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  6933. WFIFOL(fd,26)=sd->bl.id;
  6934. WFIFOW(fd,30)=0x100+feel_level;
  6935. WFIFOSET(fd, packet_len_table[0x20e]);
  6936. }
  6937. /*==========================================
  6938. * Info about Star Glaldiator hate mob [Komurka]
  6939. *------------------------------------------
  6940. */
  6941. void clif_hate_mob(struct map_session_data *sd, int skilllv,int mob_id)
  6942. {
  6943. int fd=sd->fd;
  6944. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6945. WFIFOW(fd,0)=0x20e;
  6946. if (pcdb_checkid(mob_id))
  6947. strncpy(WFIFOP(fd,2),job_name(mob_id), NAME_LENGTH);
  6948. else if (mobdb_checkid(mob_id))
  6949. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6950. else //Really shouldn't happen...
  6951. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6952. WFIFOL(fd,26)=sd->bl.id;
  6953. WFIFOW(fd,30)=0xa00+skilllv-1;
  6954. WFIFOSET(fd, packet_len_table[0x20e]);
  6955. }
  6956. /*==========================================
  6957. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6958. *------------------------------------------
  6959. */
  6960. void clif_mission_mob(struct map_session_data *sd, unsigned short mob_id, unsigned short progress)
  6961. {
  6962. int fd=sd->fd;
  6963. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6964. WFIFOW(fd,0)=0x20e;
  6965. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6966. WFIFOL(fd,26)=mob_id;
  6967. WFIFOW(fd,30)=0x1400+progress; //Message to display
  6968. WFIFOSET(fd, packet_len_table[0x20e]);
  6969. }
  6970. // ---------------------
  6971. // clif_guess_PacketVer
  6972. // ---------------------
  6973. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6974. static int clif_guess_PacketVer(int fd, int get_previous)
  6975. {
  6976. static int packet_ver = -1;
  6977. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6978. RFIFOHEAD(fd);
  6979. 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]
  6980. return packet_ver;
  6981. //By default, start searching on the default one.
  6982. packet_ver = clif_config.packet_db_ver;
  6983. cmd = RFIFOW(fd,0);
  6984. packet_len = RFIFOREST(fd);
  6985. if (
  6986. cmd == clif_config.connect_cmd[packet_ver] &&
  6987. packet_len == packet_db[packet_ver][cmd].len &&
  6988. ((value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) == 0 || value == 1) &&
  6989. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) > 700000 && //Account ID is valid
  6990. value <= max_account_id &&
  6991. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) > 0 && //Char ID is valid
  6992. value <= max_char_id &&
  6993. (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) > 0 //Login 1 is a positive value (?)
  6994. )
  6995. return clif_config.packet_db_ver; //Default packet version found.
  6996. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6997. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6998. if (cmd != clif_config.connect_cmd[packet_ver] || //it is not a wanttoconnection for this version.
  6999. packet_len != packet_db[packet_ver][cmd].len) //The size of the wantoconnection packet does not matches.
  7000. continue;
  7001. if (
  7002. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < 700000 || value > max_account_id
  7003. || (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) < 1 || value > max_char_id
  7004. //What is login 1? In my tests it is a very very high value.
  7005. || (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) < 1
  7006. //This check seems redundant, all wanttoconnection packets have the gender on the very
  7007. //last byte of the packet.
  7008. || (value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) < 0 || value > 1
  7009. )
  7010. continue;
  7011. return packet_ver; //This is our best guess.
  7012. }
  7013. packet_ver = -1;
  7014. return -1;
  7015. }
  7016. // ------------
  7017. // clif_parse_*
  7018. // ------------
  7019. // パケット読み取って色々操作
  7020. /*==========================================
  7021. *
  7022. *------------------------------------------
  7023. */
  7024. void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
  7025. {
  7026. struct map_session_data *old_sd;
  7027. int cmd, account_id, char_id, login_id1, sex;
  7028. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7029. 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])
  7030. RFIFOHEAD(fd);
  7031. if (sd) {
  7032. if (battle_config.error_log)
  7033. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  7034. return;
  7035. }
  7036. packet_ver = clif_guess_PacketVer(fd, 1);
  7037. cmd = RFIFOW(fd,0);
  7038. if (packet_ver > 0)
  7039. {
  7040. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7041. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7042. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7043. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7044. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7045. if ((old_sd = map_id2sd(account_id)) != NULL)
  7046. { // if same account already connected, we disconnect the 2 sessions
  7047. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  7048. if (!old_sd->fd)
  7049. map_quit(old_sd);
  7050. else
  7051. clif_authfail_fd(old_sd->fd, 2); // same id
  7052. clif_authfail_fd(fd, 8); // still recognizes last connection
  7053. } else {
  7054. sd = (struct map_session_data*)aCalloc(1, sizeof(struct map_session_data));
  7055. sd->fd = fd;
  7056. sd->packet_ver = packet_ver;
  7057. session[fd]->session_data = sd;
  7058. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7059. WFIFOHEAD(fd,4);
  7060. WFIFOL(fd,0) = sd->bl.id;
  7061. WFIFOSET(fd,4);
  7062. chrif_authreq(sd);
  7063. }
  7064. }
  7065. return;
  7066. }
  7067. static int clif_nighttimer(int tid, unsigned int tick, int id, int data)
  7068. {
  7069. TBL_PC *sd;
  7070. sd=map_id2sd(id);
  7071. if (!sd) return 0;
  7072. //Check if character didn't instant-warped after logging in.
  7073. if (sd->bl.prev!=NULL) {
  7074. sd->state.night = 1;
  7075. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7076. }
  7077. return 0;
  7078. }
  7079. /*==========================================
  7080. * 007d クライアント側マップ読み込み完了
  7081. * map侵入時に必要なデータを全て送りつける
  7082. *------------------------------------------
  7083. */
  7084. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7085. {
  7086. int i;
  7087. if(sd->bl.prev != NULL)
  7088. return;
  7089. if(sd->npc_id) npc_event_dequeue(sd);
  7090. clif_skillinfoblock(sd);
  7091. pc_checkitem(sd);
  7092. // loadendack時
  7093. // next exp
  7094. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7095. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7096. // skill point
  7097. clif_updatestatus(sd,SP_SKILLPOINT);
  7098. // item
  7099. clif_itemlist(sd);
  7100. clif_equiplist(sd);
  7101. // cart
  7102. if(pc_iscarton(sd)){
  7103. clif_cart_itemlist(sd);
  7104. clif_cart_equiplist(sd);
  7105. clif_updatestatus(sd,SP_CARTINFO);
  7106. }
  7107. // param all
  7108. clif_initialstatus(sd);
  7109. if(battle_config.pc_invincible_time > 0) {
  7110. if(map_flag_gvg(sd->bl.m))
  7111. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7112. else
  7113. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7114. }
  7115. map_addblock(&sd->bl); // ブロック登録
  7116. clif_spawn(&sd->bl); // spawn
  7117. // party
  7118. party_send_movemap(sd);
  7119. // guild
  7120. guild_send_memberinfoshort(sd,1);
  7121. // weight max , now
  7122. clif_updatestatus(sd,SP_MAXWEIGHT);
  7123. clif_updatestatus(sd,SP_WEIGHT);
  7124. // Show hp after displacement [LuzZza]
  7125. if(sd->status.party_id)
  7126. clif_party_hp(sd);
  7127. sd->state.using_fake_npc = 0;
  7128. // pvp
  7129. //if(sd->pvp_timer!=-1 && !battle_config.pk_mode) /PVP Client crash fix* Removed timer deletion
  7130. // delete_timer(sd->pvp_timer,pc_calc_pvprank_timer);
  7131. if(map[sd->bl.m].flag.pvp){
  7132. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7133. if (sd->pvp_timer == -1)
  7134. sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
  7135. sd->pvp_rank=0;
  7136. sd->pvp_lastusers=0;
  7137. sd->pvp_point=5;
  7138. sd->pvp_won=0;
  7139. sd->pvp_lost=0;
  7140. }
  7141. clif_set0199(fd,1);
  7142. } else {
  7143. sd->pvp_timer=-1;
  7144. // set flag, if it's a duel [LuzZza]
  7145. if(sd->duel_group)
  7146. clif_set0199(fd, 1);
  7147. }
  7148. if(map_flag_gvg(sd->bl.m))
  7149. clif_set0199(fd,3);
  7150. // pet
  7151. if(sd->status.pet_id > 0 && sd->pd) {
  7152. map_addblock(&sd->pd->bl);
  7153. clif_spawn(&sd->pd->bl);
  7154. clif_send_petdata(sd,0,0);
  7155. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7156. clif_send_petstatus(sd);
  7157. }
  7158. if(sd->state.connect_new) {
  7159. sd->state.connect_new = 0;
  7160. //Delayed night effect on log-on fix for the glow-issue. Thanks to Larry.
  7161. if (night_flag) {
  7162. char tmpstr[1024];
  7163. strcpy(tmpstr, msg_txt(500)); // Actually, it's the night...
  7164. clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
  7165. if (map[sd->bl.m].flag.nightenabled)
  7166. add_timer(gettick()+1000,clif_nighttimer,sd->bl.id,0);
  7167. }
  7168. // if(sd->status.class_ != sd->vd.class_)
  7169. // clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BASE,sd->vd.class_,SELF);
  7170. if (sd->sc.option&OPTION_FALCON)
  7171. clif_status_load(&sd->bl, SI_FALCON, 1);
  7172. if (sd->sc.option&OPTION_RIDING)
  7173. clif_status_load(&sd->bl, SI_RIDING, 1);
  7174. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7175. if ((i = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7176. if(sd->bl.m == sd->feel_map[0].m
  7177. || sd->bl.m == sd->feel_map[1].m
  7178. || sd->bl.m == sd->feel_map[2].m)
  7179. sc_start(&sd->bl, SC_KNOWLEDGE, 100, i, skill_get_time(SG_KNOWLEDGE, i));
  7180. }
  7181. if(sd->status.pet_id > 0 && sd->pd && sd->pet.intimate > 900)
  7182. clif_pet_emotion(sd->pd,(sd->pd->class_ - 100)*100 + 50 + pet_hungry_val(sd));
  7183. //Removed, for some reason chars get stuck on map-change when you send this packet!? [Skotlex]
  7184. //[LuzZza]
  7185. //clif_guild_send_onlineinfo(sd);
  7186. } else
  7187. //New 'night' effect by dynamix [Skotlex]
  7188. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7189. { //Display night.
  7190. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  7191. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7192. else
  7193. sd->state.night = 1;
  7194. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7195. } else if (sd->state.night) { //Clear night display.
  7196. sd->state.night = 0;
  7197. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7198. }
  7199. // view equipment item
  7200. #if PACKETVER < 4
  7201. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7202. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7203. #else
  7204. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7205. #endif
  7206. if(sd->vd.cloth_color)
  7207. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7208. if(battle_config.muting_players && sd->status.manner < 0 && battle_config.manner_system)
  7209. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7210. // Lance
  7211. npc_script_event(sd, NPCE_LOADMAP);
  7212. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7213. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7214. clif_weather_check(sd);
  7215. map_foreachinarea(clif_getareachar,sd->bl.m,
  7216. sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,
  7217. BL_ALL,sd);
  7218. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7219. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7220. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7221. else
  7222. sd->areanpc_id = 0;
  7223. if (pc_isdead(sd)) //In case you warped dead.
  7224. clif_clearchar_area(&sd->bl, 1);
  7225. }
  7226. /*==========================================
  7227. *
  7228. *------------------------------------------
  7229. */
  7230. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7231. RFIFOHEAD(fd);
  7232. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7233. sd->server_tick = gettick();
  7234. clif_servertick(sd);
  7235. }
  7236. static int clif_walktoxy_timer(int tid, unsigned int tick, int id, int data)
  7237. {
  7238. struct map_session_data *sd;
  7239. short x,y;
  7240. if (!session[id] || (sd = session[id]->session_data) == NULL)
  7241. return 0;
  7242. if (!unit_can_move(&sd->bl))
  7243. return 0;
  7244. x = data>>16;
  7245. y = data&0xffff;
  7246. unit_walktoxy(&sd->bl, x, y, 0);
  7247. return 1;
  7248. }
  7249. /*==========================================
  7250. *
  7251. *------------------------------------------
  7252. */
  7253. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7254. int x, y;
  7255. int cmd;
  7256. unsigned int tick;
  7257. RFIFOHEAD(fd);
  7258. if (pc_isdead(sd)) {
  7259. clif_clearchar_area(&sd->bl, 1);
  7260. return;
  7261. }
  7262. if (clif_cant_act(sd) && sd->sc.opt1 != OPT1_STONEWAIT)
  7263. return;
  7264. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7265. return;
  7266. pc_stop_attack(sd);
  7267. if (sd->invincible_timer != -1)
  7268. pc_delinvincibletimer(sd);
  7269. cmd = RFIFOW(fd,0);
  7270. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7271. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7272. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7273. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7274. //Set last idle time... [Skotlex]
  7275. sd->idletime = last_tick;
  7276. tick = gettick();
  7277. if (DIFF_TICK(sd->ud.canmove_tick, tick) > 0 &&
  7278. DIFF_TICK(sd->ud.canmove_tick, tick) < 2000)
  7279. { // Delay walking command. [Skotlex]
  7280. add_timer(sd->ud.canmove_tick+1, clif_walktoxy_timer, fd, (x<<16)|y);
  7281. return;
  7282. }
  7283. if (!unit_can_move(&sd->bl))
  7284. return;
  7285. unit_walktoxy(&sd->bl, x, y, 0);
  7286. }
  7287. /*==========================================
  7288. *
  7289. *------------------------------------------
  7290. */
  7291. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7292. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7293. WFIFOW(fd,0) = 0x18b;
  7294. /* Rovert's prevent logout option fixed [Valaris] */
  7295. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7296. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7297. ) {
  7298. clif_setwaitclose(fd);
  7299. WFIFOW(fd,2)=0;
  7300. } else {
  7301. WFIFOW(fd,2)=1;
  7302. }
  7303. WFIFOSET(fd,packet_len_table[0x18b]);
  7304. }
  7305. /*==========================================
  7306. *
  7307. *------------------------------------------
  7308. */
  7309. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7310. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7311. /* if (target_id == server_char_id) {
  7312. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7313. 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).
  7314. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7315. // if we block people
  7316. if (battle_config.ban_bot < 0) {
  7317. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7318. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7319. // message about the ban
  7320. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7321. // if we ban people
  7322. } else if (battle_config.ban_bot > 0) {
  7323. 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)
  7324. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7325. // message about the ban
  7326. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7327. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7328. // message about the ban
  7329. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7330. }
  7331. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7332. // send this info cause the bot ask until get an answer, damn spam
  7333. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7334. WPACKETW(0) = 0x95;
  7335. WPACKETL(2) = server_char_id;
  7336. strncpy(WPACKETP(6), sd->status.name, 24);
  7337. SENDPACKET(fd, packet_len_table[0x95]);
  7338. // take fake player out of screen
  7339. WPACKETW(0) = 0x80;
  7340. WPACKETL(2) = server_char_id;
  7341. WPACKETB(6) = 0;
  7342. SENDPACKET(fd, packet_len_table[0x80]);
  7343. // take fake mob out of screen
  7344. WPACKETW(0) = 0x80;
  7345. WPACKETL(2) = server_fake_mob_id;
  7346. WPACKETB(6) = 0;
  7347. SENDPACKET(fd, packet_len_table[0x80]);
  7348. }
  7349. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7350. if (target_id == server_fake_mob_id) {
  7351. int fake_mob;
  7352. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7353. 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).
  7354. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7355. // if we block people
  7356. if (battle_config.ban_bot < 0) {
  7357. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7358. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7359. // message about the ban
  7360. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7361. // if we ban people
  7362. } else if (battle_config.ban_bot > 0) {
  7363. 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)
  7364. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7365. // message about the ban
  7366. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7367. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7368. // message about the ban
  7369. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7370. }
  7371. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7372. // send this info cause the bot ask until get an answer, damn spam
  7373. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7374. WPACKETW(0) = 0x95;
  7375. WPACKETL(2) = server_fake_mob_id;
  7376. 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
  7377. if (!mobdb_checkid(fake_mob))
  7378. fake_mob = 1002; // poring (default)
  7379. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7380. SENDPACKET(fd, packet_len_table[0x95]);
  7381. // take fake mob out of screen
  7382. WPACKETW(0) = 0x80;
  7383. WPACKETL(2) = server_fake_mob_id;
  7384. WPACKETB(6) = 0;
  7385. SENDPACKET(fd, packet_len_table[0x80]);
  7386. // take fake player out of screen
  7387. WPACKETW(0) = 0x80;
  7388. WPACKETL(2) = server_char_id;
  7389. WPACKETB(6) = 0;
  7390. SENDPACKET(fd, packet_len_table[0x80]);
  7391. }
  7392. */
  7393. return;
  7394. }
  7395. /*==========================================
  7396. *
  7397. *------------------------------------------
  7398. */
  7399. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7400. int account_id;
  7401. struct block_list* bl;
  7402. struct status_change *sc;
  7403. RFIFOHEAD(fd);
  7404. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7405. if(account_id<0) // for disguises [Valaris]
  7406. account_id-=account_id*2;
  7407. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7408. if ((bl = map_id2bl(account_id)) != NULL) {
  7409. sc = status_get_sc(bl);
  7410. if (sc && (
  7411. (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_CHASEWALK) && !sd->special_state.intravision) ||
  7412. sc->option&OPTION_INVISIBLE)
  7413. ) {
  7414. //Asked name of invisible player, this shouldn't be possible!
  7415. //Possible bot? Thanks to veider and qspirit
  7416. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7417. unsigned char gm_msg[256];
  7418. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requests name of invisible chars.", sd->status.name, sd->status.account_id);
  7419. ShowWarning(gm_msg);
  7420. // information is sended to all online GM
  7421. // intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7422. return;
  7423. }
  7424. clif_charnameack(fd, bl);
  7425. }
  7426. }
  7427. /*==========================================
  7428. *
  7429. *------------------------------------------
  7430. */
  7431. void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
  7432. unsigned char *message, *buf, buf2[128];
  7433. RFIFOHEAD(fd);
  7434. WFIFOHEAD(fd, RFIFOW(fd,2) + 4);
  7435. message = (unsigned char*)RFIFOP(fd,4);
  7436. if (strlen(message) < strlen(sd->status.name) || //If the incoming string is too short...
  7437. strncmp(message, sd->status.name, strlen(sd->status.name)) != 0) //Or the name does not matches...
  7438. {
  7439. unsigned char gm_msg[256];
  7440. ShowWarning("Hack on global message: character '%s' (account: %d), use an other name to send a (normal) message.\n", sd->status.name, sd->status.account_id);
  7441. // information is sended to all online GM
  7442. sprintf(gm_msg, "Hack on global message (normal message): character '%s' (account: %d) uses another name.", sd->status.name, sd->status.account_id);
  7443. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7444. if (strlen(message) == 0)
  7445. strcpy(gm_msg, " This player sends a void name and a void message.");
  7446. else
  7447. snprintf(gm_msg, 255, " This player sends (name:message): '%128s'.", message);
  7448. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7449. // message about the ban
  7450. if (battle_config.ban_spoof_namer > 0)
  7451. sprintf(gm_msg, " This player has been banned for %d minute(s).", battle_config.ban_spoof_namer);
  7452. else
  7453. sprintf(gm_msg, " This player hasn't been banned (Ban option is disabled).");
  7454. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7455. // if we ban people
  7456. if (battle_config.ban_spoof_namer > 0) {
  7457. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_spoof_namer, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7458. clif_setwaitclose(fd); // forced to disconnect because of the hack
  7459. }
  7460. else
  7461. session[fd]->eof = 1; //Disconnect them too, bad packets can cause problems down the road. [Skotlex]
  7462. return;
  7463. }
  7464. if ((is_atcommand(fd, sd, message, 0) != AtCommand_None) ||
  7465. (is_charcommand(fd, sd, message,0) != CharCommand_None))
  7466. return;
  7467. if (sd->sc.count &&
  7468. (sd->sc.data[SC_BERSERK].timer != -1 || sd->sc.data[SC_NOCHAT].timer != -1 ))
  7469. return;
  7470. if (RFIFOW(fd,2)+4 < 128)
  7471. buf = buf2; //Use a static buffer.
  7472. else
  7473. buf = (unsigned char*)aMallocA((RFIFOW(fd,2) + 4)*sizeof(char));
  7474. // send message to others
  7475. WBUFW(buf,0) = 0x8d;
  7476. WBUFW(buf,2) = RFIFOW(fd,2) + 4; // len of message - 4 + 8
  7477. WBUFL(buf,4) = sd->bl.id;
  7478. memcpy(WBUFP(buf,8), message, RFIFOW(fd,2) - 4);
  7479. clif_send(buf, WBUFW(buf,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7480. if(buf != buf2) aFree(buf);
  7481. // send back message to the speaker
  7482. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7483. WFIFOW(fd,0) = 0x8e;
  7484. WFIFOSET(fd, WFIFOW(fd,2));
  7485. #ifdef PCRE_SUPPORT
  7486. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7487. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7488. #endif
  7489. // Celest
  7490. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7491. int next = pc_nextbaseexp(sd);
  7492. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7493. switch (sd->state.snovice_flag) {
  7494. case 0:
  7495. if (strstr(message, msg_txt(504)))
  7496. sd->state.snovice_flag++;
  7497. break;
  7498. case 1:
  7499. sprintf(buf2, msg_txt(505), sd->status.name);
  7500. if (strstr(message, buf2))
  7501. sd->state.snovice_flag++;
  7502. break;
  7503. case 2:
  7504. if (strstr(message, msg_txt(506)))
  7505. sd->state.snovice_flag++;
  7506. break;
  7507. case 3:
  7508. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7509. break; //Do not override the noskill mapflag. [Skotlex]
  7510. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7511. sc_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  7512. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7513. sd->state.snovice_flag = 0;
  7514. break;
  7515. }
  7516. }
  7517. }
  7518. return;
  7519. }
  7520. int clif_message(struct block_list *bl, char* msg)
  7521. {
  7522. unsigned short msg_len = strlen(msg) + 1;
  7523. unsigned char buf[256];
  7524. nullpo_retr(0, bl);
  7525. WBUFW(buf, 0) = 0x8d;
  7526. WBUFW(buf, 2) = msg_len + 8;
  7527. WBUFL(buf, 4) = bl->id;
  7528. memcpy(WBUFP(buf, 8), msg, msg_len);
  7529. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7530. return 0;
  7531. }
  7532. /*==========================================
  7533. *
  7534. *------------------------------------------
  7535. */
  7536. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7537. // /m /mapmove (as @rura GM command)
  7538. char output[30]; // 17+4+4=26, 30 max.
  7539. char map_name[MAP_NAME_LENGTH]; //Err... map names are 15+'\0' in size, not 16+'\0' [Skotlex]
  7540. RFIFOHEAD(fd);
  7541. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7542. (pc_isGM(sd) >= get_atcommand_level(AtCommand_MapMove))) {
  7543. memcpy(map_name, RFIFOP(fd,2), MAP_NAME_LENGTH-1);
  7544. map_name[MAP_NAME_LENGTH-1]='\0';
  7545. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7546. atcommand_rura(fd, sd, "@rura", output);
  7547. }
  7548. return;
  7549. }
  7550. /*==========================================
  7551. *
  7552. *------------------------------------------
  7553. */
  7554. void clif_changed_dir(struct block_list *bl) {
  7555. unsigned char buf[64];
  7556. WBUFW(buf,0) = 0x9c;
  7557. WBUFL(buf,2) = bl->id;
  7558. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7559. WBUFB(buf,8) = unit_getdir(bl);
  7560. clif_send(buf, packet_len_table[0x9c], bl, AREA_WOS);
  7561. if (disguised(bl)) {
  7562. WBUFL(buf,2) = -bl->id;
  7563. WBUFW(buf,6) = 0;
  7564. clif_send(buf, packet_len_table[0x9c], bl, SELF);
  7565. }
  7566. return;
  7567. }
  7568. /*==========================================
  7569. *
  7570. *------------------------------------------
  7571. */
  7572. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7573. unsigned char headdir, dir;
  7574. RFIFOHEAD(fd);
  7575. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7576. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7577. pc_setdir(sd, dir, headdir);
  7578. clif_changed_dir(&sd->bl);
  7579. return;
  7580. }
  7581. /*==========================================
  7582. *
  7583. *------------------------------------------
  7584. */
  7585. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7586. unsigned char buf[64];
  7587. RFIFOHEAD(fd);
  7588. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7589. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7590. clif_skill_fail(sd, 1, 0, 1);
  7591. return;
  7592. }
  7593. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7594. if (sd->emotionlasttime >= time(NULL)) {
  7595. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7596. clif_skill_fail(sd, 1, 0, 1);
  7597. return;
  7598. }
  7599. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7600. WBUFW(buf,0) = 0xc0;
  7601. WBUFL(buf,2) = sd->bl.id;
  7602. WBUFB(buf,6) = RFIFOB(fd,2);
  7603. clif_send(buf, packet_len_table[0xc0], &sd->bl, AREA);
  7604. } else
  7605. clif_skill_fail(sd, 1, 0, 1);
  7606. }
  7607. /*==========================================
  7608. *
  7609. *------------------------------------------
  7610. */
  7611. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7612. WFIFOHEAD(fd,packet_len_table[0xc2]);
  7613. WFIFOW(fd,0) = 0xc2;
  7614. WFIFOL(fd,2) = map_getusers();
  7615. WFIFOSET(fd,packet_len_table[0xc2]);
  7616. }
  7617. /*==========================================
  7618. *
  7619. *------------------------------------------
  7620. */
  7621. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  7622. unsigned int tick;
  7623. unsigned char buf[64];
  7624. int action_type, target_id;
  7625. RFIFOHEAD(fd);
  7626. if (pc_isdead(sd)) {
  7627. clif_clearchar_area(&sd->bl, 1);
  7628. return;
  7629. }
  7630. if (sd->sc.count &&
  7631. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7632. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7633. sd->sc.data[SC_BLADESTOP].timer != -1))
  7634. return;
  7635. tick = gettick();
  7636. pc_stop_walking(sd, 1);
  7637. pc_stop_attack(sd);
  7638. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7639. action_type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7640. if(target_id<0) // for disguises [Valaris]
  7641. target_id-=(target_id*2);
  7642. switch(action_type) {
  7643. case 0x00: // once attack
  7644. case 0x07: // continuous attack
  7645. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7646. return;
  7647. if(sd->sc.option&OPTION_WEDDING || sd->vd.class_ == JOB_XMAS)
  7648. return;
  7649. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7650. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7651. clif_skill_fail(sd, 1, 4, 0);
  7652. return;
  7653. }
  7654. }
  7655. if (sd->invincible_timer != -1)
  7656. pc_delinvincibletimer(sd);
  7657. sd->idletime = last_tick;
  7658. unit_attack(&sd->bl, target_id, action_type != 0);
  7659. break;
  7660. case 0x02: // sitdown
  7661. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7662. clif_skill_fail(sd, 1, 0, 2);
  7663. break;
  7664. }
  7665. if(pc_issit(sd)) {
  7666. //Bugged client? Just refresh them.
  7667. WBUFW(buf, 0) = 0x8a;
  7668. WBUFL(buf, 2) = sd->bl.id;
  7669. WBUFB(buf,26) = 2;
  7670. clif_send(buf, packet_len_table[0x8a], &sd->bl, SELF);
  7671. return;
  7672. }
  7673. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7674. break;
  7675. if (sd->sc.count && (
  7676. sd->sc.data[SC_DANCING].timer != -1 ||
  7677. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7678. )) //No sitting during these states neither.
  7679. break;
  7680. pc_setsit(sd);
  7681. skill_gangsterparadise(sd, 1); // ギャングスターパラダイス設定 fixed Valaris
  7682. skill_rest(sd, 1); // TK_HPTIME sitting down mode [Dralnu]
  7683. clif_sitting(sd);
  7684. break;
  7685. case 0x03: // standup
  7686. if (!pc_issit(sd)) {
  7687. //Bugged client? Just refresh them.
  7688. WBUFW(buf, 0) = 0x8a;
  7689. WBUFL(buf, 2) = sd->bl.id;
  7690. WBUFB(buf,26) = 3;
  7691. clif_send(buf, packet_len_table[0x8a], &sd->bl, SELF);
  7692. return;
  7693. }
  7694. pc_setstand(sd);
  7695. skill_gangsterparadise(sd, 0); // ギャングスターパラダイス解除 fixed Valaris
  7696. skill_rest(sd, 0); // TK_HPTIME standing up mode [Dralnu]
  7697. WBUFW(buf, 0) = 0x8a;
  7698. WBUFL(buf, 2) = sd->bl.id;
  7699. WBUFB(buf,26) = 3;
  7700. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  7701. break;
  7702. }
  7703. }
  7704. /*==========================================
  7705. *
  7706. *------------------------------------------
  7707. */
  7708. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  7709. RFIFOHEAD(fd);
  7710. switch(RFIFOB(fd,2)) {
  7711. case 0x00:
  7712. if (pc_isdead(sd)) {
  7713. pc_setstand(sd);
  7714. pc_setrestartvalue(sd, 3);
  7715. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  7716. }
  7717. // in case the player's status somehow wasn't updated yet [Celest]
  7718. else if (sd->status.hp <= 0)
  7719. pc_setdead(sd);
  7720. break;
  7721. case 0x01:
  7722. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7723. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7724. {
  7725. //map_quit(sd); //A clif_quitsave is sent inmediately after this, so no need to quit yet. [Skotlex]
  7726. chrif_charselectreq(sd);
  7727. } else {
  7728. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7729. WFIFOW(fd,0)=0x18b;
  7730. WFIFOW(fd,2)=1;
  7731. WFIFOSET(fd,packet_len_table[0x018b]);
  7732. }
  7733. break;
  7734. }
  7735. }
  7736. /*==========================================
  7737. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7738. *------------------------------------------
  7739. */
  7740. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  7741. char *gm_command;
  7742. struct map_session_data *dstsd;
  7743. int i=0;
  7744. struct npc_data *npc;
  7745. char split_data[10][50];
  7746. int j=0,k=0;
  7747. char target[NAME_LENGTH+1];
  7748. char output[256];
  7749. RFIFOHEAD(fd);
  7750. //printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28));
  7751. 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)
  7752. sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28));
  7753. if ((is_charcommand(fd, sd, gm_command, 0) != CharCommand_None) ||
  7754. (is_atcommand(fd, sd, gm_command, 0) != AtCommand_None)) {
  7755. if(gm_command) aFree(gm_command);
  7756. return;
  7757. }
  7758. if(gm_command) aFree(gm_command);
  7759. if (sd->sc.count &&
  7760. (sd->sc.data[SC_BERSERK].timer!=-1 || sd->sc.data[SC_NOCHAT].timer != -1))
  7761. return;
  7762. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7763. target[NAME_LENGTH]='\0';
  7764. //Chat Logging type 'W' / Whisper
  7765. if(log_config.chat&1 //we log everything then
  7766. || ( log_config.chat&2 //if Whisper bit is on
  7767. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  7768. 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));
  7769. //-------------------------------------------------------//
  7770. // Lordalfa - Paperboy - To whisper NPC commands //
  7771. //-------------------------------------------------------//
  7772. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7773. char *whisper_tmp = target+4; //Skip the NPC: string part.
  7774. if ((npc = npc_name2id(whisper_tmp)))
  7775. {
  7776. whisper_tmp=(char *)aMallocA((strlen((char *)(RFIFOP(fd,28)))+1)*sizeof(char));
  7777. sprintf(whisper_tmp, "%s", (const char*)RFIFOP(fd,28));
  7778. for( j=0;whisper_tmp[j]!='\0';j++)
  7779. {
  7780. if(whisper_tmp[j]!='#')
  7781. {
  7782. split_data[i][j-k]=whisper_tmp[j];
  7783. }
  7784. else
  7785. {
  7786. split_data[i][j-k]='\0';
  7787. k=j+1;
  7788. i++;
  7789. }
  7790. } // Splits the message using '#' as separators
  7791. split_data[i][j-k]='\0';
  7792. aFree(whisper_tmp);
  7793. whisper_tmp=(char *)aMallocA(15*sizeof(char));
  7794. for (j=0;j<=10;j++)
  7795. {
  7796. sprintf(whisper_tmp, "@whispervar%d$", j);
  7797. set_var(sd,whisper_tmp,(char *) split_data[j]);
  7798. }//You don't need to zero them, just reset them [Kevin]
  7799. aFree(whisper_tmp);
  7800. whisper_tmp=(char *)aMallocA((strlen(npc->name)+18)*sizeof(char));
  7801. sprintf(whisper_tmp, "%s::OnWhisperGlobal", npc->name);
  7802. npc_event(sd,whisper_tmp,0); // Calls the NPC label
  7803. aFree(whisper_tmp); //I rewrote it a little to use memory allocation, a bit more stable =P [Kevin]
  7804. return;
  7805. } //should have just removed the one below that was a my bad =P
  7806. }
  7807. // Main chat [LuzZza]
  7808. if(strcmpi(target, main_chat_nick) == 0) {
  7809. if(!sd->state.mainchat) {
  7810. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7811. return;
  7812. }
  7813. if (sd->sc.data[SC_NOCHAT].timer != -1) {
  7814. clif_displaymessage(fd, msg_txt(387));
  7815. return;
  7816. }
  7817. sprintf(output, msg_txt(386), sd->status.name, (char *)RFIFOP(fd,28));
  7818. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7819. return;
  7820. }
  7821. // searching destination character
  7822. dstsd = map_nick2sd(target);
  7823. // player is not on this map-server
  7824. if (dstsd == NULL ||
  7825. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7826. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7827. // and if we ask for 'Test', we must not contact 'test' player
  7828. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7829. strcmp(dstsd->status.name, target) != 0) // not exactly same name
  7830. // send message to inter-server
  7831. intif_wis_message(sd, target, (char*)RFIFOP(fd,28), RFIFOW(fd,2)-28);
  7832. // player is on this map-server
  7833. else {
  7834. // if you send to your self, don't send anything to others
  7835. if (dstsd->fd == fd) // but, normaly, it's impossible!
  7836. clif_wis_message(fd, wisp_server_name, "You can not page yourself. Sorry.", strlen("You can not page yourself. Sorry.") + 1);
  7837. // otherwise, send message and answer immediatly
  7838. else {
  7839. if (dstsd->ignoreAll == 1) {
  7840. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7841. clif_wis_end(fd, 1); // 1: target character is not loged in
  7842. else
  7843. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7844. } else {
  7845. // if player ignore the source character
  7846. for(i = 0; i < MAX_IGNORE_LIST; i++)
  7847. if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0) {
  7848. clif_wis_end(fd, 2); // 2: ignored by target
  7849. break;
  7850. }
  7851. // if source player not found in ignore list
  7852. if (i == MAX_IGNORE_LIST) {
  7853. if(strlen(dstsd->away_message) > 0) { // Send away automessage [LuzZza]
  7854. //(Automessage has been sent)
  7855. sprintf(output, "%s %s", (char*)RFIFOP(fd,28),msg_txt(543));
  7856. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7857. clif_wis_end(fd, 0); // 0: success to send wisper
  7858. if(dstsd->state.autotrade)
  7859. //"Away [AT] - \"%s\""
  7860. sprintf(output, msg_txt(544), dstsd->away_message);
  7861. else
  7862. //"Away - \"%s\""
  7863. sprintf(output, msg_txt(545), dstsd->away_message);
  7864. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7865. } else { // Normal message
  7866. clif_wis_message(dstsd->fd, sd->status.name, (char*)RFIFOP(fd,28), RFIFOW(fd,2) - 28);
  7867. clif_wis_end(fd, 0); // 0: success to send wisper
  7868. }
  7869. }
  7870. }
  7871. }
  7872. }
  7873. return;
  7874. }
  7875. /*==========================================
  7876. *
  7877. *------------------------------------------
  7878. */
  7879. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  7880. // /b
  7881. RFIFOHEAD(fd);
  7882. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7883. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast)))
  7884. intif_GMmessage((char*)RFIFOP(fd,4), RFIFOW(fd,2)-4, 0);
  7885. }
  7886. /*==========================================
  7887. *
  7888. *------------------------------------------
  7889. */
  7890. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  7891. struct flooritem_data *fitem;
  7892. int map_object_id;
  7893. RFIFOHEAD(fd);
  7894. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7895. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7896. if (pc_isdead(sd)) {
  7897. clif_clearchar_area(&sd->bl, 1);
  7898. return;
  7899. }
  7900. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7901. return;
  7902. if (clif_cant_act(sd))
  7903. return;
  7904. if(pc_iscloaking(sd) || pc_ischasewalk(sd)) //Disable cloaking/chasewalking characters from looting [Skotlex]
  7905. return;
  7906. if(sd->sc.count && (
  7907. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  7908. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  7909. sd->sc.data[SC_NOCHAT].timer!=-1 ) //会話禁止
  7910. ) {
  7911. clif_additem(sd,0,0,6); // send fail packet! [Valaris]
  7912. return;
  7913. }
  7914. pc_takeitem(sd, fitem);
  7915. }
  7916. /*==========================================
  7917. *
  7918. *------------------------------------------
  7919. */
  7920. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  7921. int item_index, item_amount;
  7922. RFIFOHEAD(fd);
  7923. if (pc_isdead(sd)) {
  7924. clif_clearchar_area(&sd->bl, 1);
  7925. return;
  7926. }
  7927. if (clif_cant_act(sd))
  7928. return;
  7929. if (sd->sc.count && (
  7930. sd->sc.data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
  7931. sd->sc.data[SC_BLADESTOP].timer != -1//白刃取り
  7932. ))
  7933. return;
  7934. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7935. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7936. if (!pc_dropitem(sd, item_index, item_amount))
  7937. //Because the client does not likes being ignored.
  7938. clif_delitem(sd, item_index,0);
  7939. }
  7940. /*==========================================
  7941. *
  7942. *------------------------------------------
  7943. */
  7944. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  7945. int n;
  7946. RFIFOHEAD(fd);
  7947. if (pc_isdead(sd)) {
  7948. clif_clearchar_area(&sd->bl, 1);
  7949. return;
  7950. }
  7951. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7952. return;
  7953. //This flag enables you to use items while in an NPC. [Skotlex]
  7954. if (sd->npc_id) {
  7955. if (sd->npc_id != sd->npc_item_flag)
  7956. return;
  7957. } else
  7958. if (clif_trading(sd))
  7959. return;
  7960. if (sd->sc.count && (
  7961. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  7962. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  7963. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク
  7964. sd->sc.data[SC_NOCHAT].timer!=-1 ||
  7965. sd->sc.data[SC_GRAVITATION].timer!=-1 //会話禁止
  7966. ))
  7967. return;
  7968. if (sd->invincible_timer != -1)
  7969. pc_delinvincibletimer(sd);
  7970. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7971. sd->idletime = last_tick;
  7972. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7973. if(n <0 || n >= MAX_INVENTORY)
  7974. return;
  7975. if (!pc_useitem(sd,n))
  7976. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7977. }
  7978. /*==========================================
  7979. *
  7980. *------------------------------------------
  7981. */
  7982. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7983. {
  7984. int index;
  7985. RFIFOHEAD(fd);
  7986. if(pc_isdead(sd)) {
  7987. clif_clearchar_area(&sd->bl,1);
  7988. return;
  7989. }
  7990. index = RFIFOW(fd,2)-2;
  7991. if (index < 0 || index >= MAX_INVENTORY)
  7992. return; //Out of bounds check.
  7993. if(sd->npc_id) {
  7994. if (sd->npc_id != sd->npc_item_flag)
  7995. return;
  7996. } else if (clif_cant_act(sd))
  7997. return;
  7998. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  7999. return;
  8000. if(!sd->status.inventory[index].identify) { // 未鑑定
  8001. clif_equipitemack(sd,index,0,0); // fail
  8002. return;
  8003. }
  8004. //ペット用装備であるかないか
  8005. if(sd->inventory_data[index]) {
  8006. if(sd->inventory_data[index]->type != 8){
  8007. if(sd->inventory_data[index]->type == 10)
  8008. RFIFOW(fd,4)=0x8000; // 矢を無理やり装備できるように(--;
  8009. pc_equipitem(sd,index,RFIFOW(fd,4));
  8010. } else
  8011. pet_equipitem(sd,index);
  8012. }
  8013. }
  8014. /*==========================================
  8015. *
  8016. *------------------------------------------
  8017. */
  8018. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8019. {
  8020. int index;
  8021. RFIFOHEAD(fd);
  8022. if(pc_isdead(sd)) {
  8023. clif_clearchar_area(&sd->bl,1);
  8024. return;
  8025. }
  8026. if (clif_cant_act(sd))
  8027. return;
  8028. index = RFIFOW(fd,2)-2;
  8029. pc_unequipitem(sd,index,1);
  8030. }
  8031. /*==========================================
  8032. *
  8033. *------------------------------------------
  8034. */
  8035. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8036. {
  8037. RFIFOHEAD(fd);
  8038. if(pc_isdead(sd)) {
  8039. clif_clearchar_area(&sd->bl,1);
  8040. return;
  8041. }
  8042. if (clif_cant_act(sd))
  8043. return;
  8044. //Clicked on a negative ID? Player disguised as NPC! [Skotlex]
  8045. if (RFIFOL(fd,2) < 0)
  8046. return;
  8047. npc_click(sd,RFIFOL(fd,2));
  8048. }
  8049. /*==========================================
  8050. *
  8051. *------------------------------------------
  8052. */
  8053. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8054. {
  8055. RFIFOHEAD(fd);
  8056. if (sd->state.trading)
  8057. return;
  8058. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8059. }
  8060. /*==========================================
  8061. *
  8062. *------------------------------------------
  8063. */
  8064. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8065. {
  8066. int fail=0,n, i;
  8067. unsigned short *item_list;
  8068. unsigned char npc_ev[51];
  8069. struct npc_data *nd;
  8070. RFIFOHEAD(fd);
  8071. n = (RFIFOW(fd,2)-4) /4;
  8072. item_list = (unsigned short*)RFIFOP(fd,4);
  8073. if (sd->state.trading|| !sd->npc_shopid)
  8074. fail = 1;
  8075. else{
  8076. if((nd = ((struct npc_data *)map_id2bl(sd->npc_shopid))->master_nd)){
  8077. sprintf(npc_ev, "%s::OnBuyItem", nd->exname);
  8078. for(i=0;i<n;i++){
  8079. setd_sub(sd, "@bought_nameid", i, (void *)((int)item_list[i*2+1]));
  8080. setd_sub(sd, "@bought_quantity", i, (void *)((int)item_list[i*2]));
  8081. }
  8082. npc_event(sd, npc_ev, 0);
  8083. fail = 0;
  8084. }else{
  8085. fail = npc_buylist(sd,n,item_list);
  8086. }
  8087. }
  8088. sd->npc_shopid = 0; //Clear shop data.
  8089. WFIFOHEAD(fd,packet_len_table[0xca]);
  8090. WFIFOW(fd,0)=0xca;
  8091. WFIFOB(fd,2)=fail;
  8092. WFIFOSET(fd,packet_len_table[0xca]);
  8093. }
  8094. /*==========================================
  8095. *
  8096. *------------------------------------------
  8097. */
  8098. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8099. {
  8100. int fail=0,n;
  8101. unsigned short *item_list;
  8102. RFIFOHEAD(fd);
  8103. n = (RFIFOW(fd,2)-4) /4;
  8104. item_list = (unsigned short*)RFIFOP(fd,4);
  8105. if (sd->state.trading || !sd->npc_shopid)
  8106. fail = 1;
  8107. else
  8108. fail = npc_selllist(sd,n,item_list);
  8109. sd->npc_shopid = 0; //Clear shop data.
  8110. WFIFOHEAD(fd,packet_len_table[0xcb]);
  8111. WFIFOW(fd,0)=0xcb;
  8112. WFIFOB(fd,2)=fail;
  8113. WFIFOSET(fd,packet_len_table[0xcb]);
  8114. }
  8115. /*==========================================
  8116. *
  8117. *------------------------------------------
  8118. */
  8119. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8120. {
  8121. RFIFOHEAD(fd);
  8122. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8123. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8124. } else
  8125. clif_skill_fail(sd,1,0,3);
  8126. }
  8127. /*==========================================
  8128. *
  8129. *------------------------------------------
  8130. */
  8131. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8132. {
  8133. RFIFOHEAD(fd);
  8134. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8135. }
  8136. /*==========================================
  8137. *
  8138. *------------------------------------------
  8139. */
  8140. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8141. {
  8142. RFIFOHEAD(fd);
  8143. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8144. }
  8145. /*==========================================
  8146. *
  8147. *------------------------------------------
  8148. */
  8149. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8150. {
  8151. RFIFOHEAD(fd);
  8152. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8153. }
  8154. /*==========================================
  8155. *
  8156. *------------------------------------------
  8157. */
  8158. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8159. {
  8160. RFIFOHEAD(fd);
  8161. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8162. }
  8163. /*==========================================
  8164. *
  8165. *------------------------------------------
  8166. */
  8167. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8168. {
  8169. chat_leavechat(sd);
  8170. }
  8171. /*==========================================
  8172. * 取引要請を相手に送る
  8173. *------------------------------------------
  8174. */
  8175. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8176. {
  8177. struct map_session_data *t_sd;
  8178. RFIFOHEAD(fd);
  8179. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  8180. // @noask [LuzZza]
  8181. if(t_sd && t_sd->state.noask) {
  8182. // Your request has been rejected by autoreject option.
  8183. clif_displaymessage(fd, msg_txt(392));
  8184. return;
  8185. }
  8186. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8187. trade_traderequest(sd,RFIFOL(sd->fd,2));
  8188. } else
  8189. clif_skill_fail(sd,1,0,0);
  8190. }
  8191. /*==========================================
  8192. * 取引要請
  8193. *------------------------------------------
  8194. */
  8195. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8196. {
  8197. RFIFOHEAD(fd);
  8198. trade_tradeack(sd,RFIFOB(sd->fd,2));
  8199. }
  8200. /*==========================================
  8201. * アイテム追加
  8202. *------------------------------------------
  8203. */
  8204. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8205. {
  8206. RFIFOHEAD(fd);
  8207. trade_tradeadditem(sd,RFIFOW(sd->fd,2),RFIFOL(sd->fd,4));
  8208. }
  8209. /*==========================================
  8210. * アイテム追加完了(ok押し)
  8211. *------------------------------------------
  8212. */
  8213. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8214. {
  8215. trade_tradeok(sd);
  8216. }
  8217. /*==========================================
  8218. * 取引キャンセル
  8219. *------------------------------------------
  8220. */
  8221. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8222. {
  8223. trade_tradecancel(sd);
  8224. }
  8225. /*==========================================
  8226. * 取引許諾(trade押し)
  8227. *------------------------------------------
  8228. */
  8229. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8230. {
  8231. trade_tradecommit(sd);
  8232. }
  8233. /*==========================================
  8234. *
  8235. *------------------------------------------
  8236. */
  8237. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8238. {
  8239. pc_stop_attack(sd);
  8240. }
  8241. /*==========================================
  8242. * カートへアイテムを移す
  8243. *------------------------------------------
  8244. */
  8245. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8246. {
  8247. RFIFOHEAD(fd);
  8248. if (clif_trading(sd))
  8249. return;
  8250. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8251. }
  8252. /*==========================================
  8253. * カートからアイテムを出す
  8254. *------------------------------------------
  8255. */
  8256. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8257. {
  8258. RFIFOHEAD(fd);
  8259. if (clif_trading(sd))
  8260. return;
  8261. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8262. }
  8263. /*==========================================
  8264. * 付属品(鷹,ペコ,カート)をはずす
  8265. *------------------------------------------
  8266. */
  8267. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8268. {
  8269. pc_setoption(sd,0);
  8270. }
  8271. /*==========================================
  8272. * チェンジカート
  8273. *------------------------------------------
  8274. */
  8275. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8276. {
  8277. RFIFOHEAD(fd);
  8278. pc_setcart(sd,RFIFOW(fd,2));
  8279. }
  8280. /*==========================================
  8281. * ステータスアップ
  8282. *------------------------------------------
  8283. */
  8284. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8285. {
  8286. RFIFOHEAD(fd);
  8287. pc_statusup(sd,RFIFOW(fd,2));
  8288. }
  8289. /*==========================================
  8290. * スキルレベルアップ
  8291. *------------------------------------------
  8292. */
  8293. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8294. {
  8295. RFIFOHEAD(fd);
  8296. pc_skillup(sd,RFIFOW(fd,2));
  8297. }
  8298. /*==========================================
  8299. * スキル使用(ID指定)
  8300. *------------------------------------------
  8301. */
  8302. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8303. int skillnum, skilllv, lv, target_id;
  8304. unsigned int tick = gettick();
  8305. RFIFOHEAD(fd);
  8306. if (clif_cant_act(sd))
  8307. return;
  8308. if (pc_issit(sd))
  8309. return;
  8310. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8311. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8312. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8313. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8314. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8315. sd->idletime = last_tick;
  8316. if (skillnotok(skillnum, sd))
  8317. return;
  8318. if (sd->bl.id != target_id &&
  8319. !sd->state.skill_flag &&
  8320. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8321. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8322. if (sd->ud.skilltimer != -1) {
  8323. if (skillnum != SA_CASTCANCEL)
  8324. return;
  8325. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0 &&
  8326. // allow monk combos to ignore this delay [celest]
  8327. !(sd->sc.count && sd->sc.data[SC_COMBO].timer!=-1 &&
  8328. (skillnum == MO_EXTREMITYFIST ||
  8329. skillnum == MO_CHAINCOMBO ||
  8330. skillnum == MO_COMBOFINISH ||
  8331. skillnum == CH_PALMSTRIKE ||
  8332. skillnum == CH_TIGERFIST ||
  8333. skillnum == CH_CHAINCRUSH))) {
  8334. clif_skill_fail(sd, skillnum, 4, 0);
  8335. return;
  8336. }
  8337. if(sd->sc.option&OPTION_WEDDING || sd->vd.class_ == JOB_XMAS)
  8338. return;
  8339. if (sd->invincible_timer != -1)
  8340. pc_delinvincibletimer(sd);
  8341. if(target_id<0) // for disguises [Valaris]
  8342. target_id*=-1;
  8343. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8344. if (skilllv != sd->skillitemlv)
  8345. skilllv = sd->skillitemlv;
  8346. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8347. } else {
  8348. sd->skillitem = sd->skillitemlv = -1;
  8349. if (skillnum == MO_EXTREMITYFIST) {
  8350. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8351. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8352. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8353. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8354. if (!sd->state.skill_flag ) {
  8355. sd->state.skill_flag = 1;
  8356. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8357. return;
  8358. } else if (sd->bl.id == target_id) {
  8359. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8360. return;
  8361. }
  8362. }
  8363. }
  8364. if (skillnum == TK_JUMPKICK) {
  8365. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8366. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8367. if (!sd->state.skill_flag ) {
  8368. sd->state.skill_flag = 1;
  8369. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8370. return;
  8371. } else if (sd->bl.id == target_id) {
  8372. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8373. return;
  8374. }
  8375. }
  8376. }
  8377. if (skillnum >= GD_SKILLBASE && sd->state.gmaster_flag)
  8378. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8379. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8380. if (skilllv > lv)
  8381. skilllv = lv;
  8382. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8383. if (sd->state.skill_flag)
  8384. sd->state.skill_flag = 0;
  8385. }
  8386. }
  8387. }
  8388. /*==========================================
  8389. * スキル使用(場所指定)
  8390. *------------------------------------------
  8391. */
  8392. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8393. {
  8394. int lv;
  8395. unsigned int tick = gettick();
  8396. RFIFOHEAD(fd);
  8397. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8398. sd->idletime = last_tick;
  8399. if (skillnotok(skillnum, sd))
  8400. return;
  8401. if (skillmoreinfo != -1) {
  8402. if (pc_issit(sd)) {
  8403. clif_skill_fail(sd, skillnum, 0, 0);
  8404. return;
  8405. }
  8406. memcpy(talkie_mes, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8407. talkie_mes[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8408. }
  8409. if (sd->ud.skilltimer != -1)
  8410. return;
  8411. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8412. {
  8413. clif_skill_fail(sd, skillnum, 4, 0);
  8414. return;
  8415. }
  8416. if(sd->sc.option&OPTION_WEDDING || sd->vd.class_ == JOB_XMAS)
  8417. return;
  8418. if (sd->invincible_timer != -1)
  8419. pc_delinvincibletimer(sd);
  8420. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8421. if (skilllv != sd->skillitemlv)
  8422. skilllv = sd->skillitemlv;
  8423. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8424. } else {
  8425. sd->skillitem = sd->skillitemlv = -1;
  8426. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8427. if (skilllv > lv)
  8428. skilllv = lv;
  8429. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8430. }
  8431. }
  8432. }
  8433. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8434. RFIFOHEAD(fd);
  8435. if (clif_cant_act(sd))
  8436. return;
  8437. if (pc_issit(sd))
  8438. return;
  8439. clif_parse_UseSkillToPosSub(fd, sd,
  8440. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8441. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8442. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8443. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8444. -1 //Skill more info.
  8445. );
  8446. }
  8447. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8448. RFIFOHEAD(fd);
  8449. if (clif_cant_act(sd))
  8450. return;
  8451. if (pc_issit(sd))
  8452. return;
  8453. clif_parse_UseSkillToPosSub(fd, sd,
  8454. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8455. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8456. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8457. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8458. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8459. );
  8460. }
  8461. /*==========================================
  8462. * スキル使用(map指定)
  8463. *------------------------------------------
  8464. */
  8465. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8466. {
  8467. RFIFOHEAD(fd);
  8468. if (clif_cant_act(sd))
  8469. return;
  8470. if(sd->sc.option&OPTION_WEDDING || sd->vd.class_ == JOB_XMAS)
  8471. return;
  8472. if(sd->invincible_timer != -1)
  8473. pc_delinvincibletimer(sd);
  8474. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8475. }
  8476. /*==========================================
  8477. * メモ要求
  8478. *------------------------------------------
  8479. */
  8480. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8481. {
  8482. if (!pc_isdead(sd))
  8483. pc_memo(sd,-1);
  8484. }
  8485. /*==========================================
  8486. * アイテム合成
  8487. *------------------------------------------
  8488. */
  8489. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8490. {
  8491. RFIFOHEAD(fd);
  8492. if (sd->menuskill_id != AM_PHARMACY)
  8493. return;
  8494. if (clif_trading(sd)) {
  8495. //Make it fail to avoid shop exploits where you sell something different than you see.
  8496. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8497. sd->menuskill_lv = sd->menuskill_id = 0;
  8498. return;
  8499. }
  8500. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8501. sd->menuskill_lv = sd->menuskill_id = 0;
  8502. }
  8503. /*==========================================
  8504. * 武器修理
  8505. *------------------------------------------
  8506. */
  8507. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8508. {
  8509. RFIFOHEAD(fd);
  8510. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8511. return;
  8512. if (clif_trading(sd)) {
  8513. //Make it fail to avoid shop exploits where you sell something different than you see.
  8514. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8515. sd->menuskill_lv = sd->menuskill_id = 0;
  8516. return;
  8517. }
  8518. skill_repairweapon(sd,RFIFOW(fd,2));
  8519. sd->menuskill_lv = sd->menuskill_id = 0;
  8520. }
  8521. /*==========================================
  8522. *
  8523. *------------------------------------------
  8524. */
  8525. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8526. int idx;
  8527. RFIFOHEAD(fd);
  8528. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8529. return;
  8530. if (clif_trading(sd)) {
  8531. //Make it fail to avoid shop exploits where you sell something different than you see.
  8532. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8533. sd->menuskill_lv = sd->menuskill_id = 0;
  8534. return;
  8535. }
  8536. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8537. skill_weaponrefine(sd, idx-2);
  8538. sd->menuskill_lv = sd->menuskill_id = 0;
  8539. }
  8540. /*==========================================
  8541. *
  8542. *------------------------------------------
  8543. */
  8544. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8545. {
  8546. RFIFOHEAD(fd);
  8547. sd->npc_menu=RFIFOB(fd,6);
  8548. npc_scriptcont(sd,RFIFOL(fd,2));
  8549. }
  8550. /*==========================================
  8551. *
  8552. *------------------------------------------
  8553. */
  8554. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8555. {
  8556. RFIFOHEAD(fd);
  8557. #ifdef __WIN32
  8558. //For some extraordinarily eerie reason that noone has figured out yet,
  8559. //windows native compiles NEED this nullpo_retv or the function is not found!
  8560. nullpo_retv(sd);
  8561. #endif
  8562. npc_scriptcont(sd,RFIFOL(fd,2));
  8563. }
  8564. /*==========================================
  8565. *
  8566. *------------------------------------------
  8567. */
  8568. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8569. {
  8570. RFIFOHEAD(fd);
  8571. #define RFIFOL_(fd,pos) (*(int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos)))
  8572. //Input Value overflow Exploit FIX
  8573. sd->npc_amount=RFIFOL_(fd,6); //fixed by Lupus. npc_amount is (int) but was RFIFOL changing it to (unsigned int)
  8574. #undef RFIFOL_
  8575. npc_scriptcont(sd,RFIFOL(fd,2));
  8576. }
  8577. /*==========================================
  8578. *
  8579. *------------------------------------------
  8580. */
  8581. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8582. {
  8583. RFIFOHEAD(fd);
  8584. if(RFIFOW(fd,2)-7 >= sizeof(sd->npc_str)){
  8585. ShowWarning("clif: input string too long !\n");
  8586. memcpy(sd->npc_str,RFIFOP(fd,8),sizeof(sd->npc_str));
  8587. sd->npc_str[sizeof(sd->npc_str)-1]=0;
  8588. } else
  8589. strcpy(sd->npc_str,(char*)RFIFOP(fd,8));
  8590. npc_scriptcont(sd,RFIFOL(fd,4));
  8591. }
  8592. /*==========================================
  8593. *
  8594. *------------------------------------------
  8595. */
  8596. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8597. {
  8598. RFIFOHEAD(fd);
  8599. if (sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8600. npc_scriptcont(sd,RFIFOL(fd,2));
  8601. }
  8602. /*==========================================
  8603. * アイテム鑑定
  8604. *------------------------------------------
  8605. */
  8606. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8607. {
  8608. RFIFOHEAD(fd);
  8609. if (sd->menuskill_id != MC_IDENTIFY)
  8610. return;
  8611. skill_identify(sd,RFIFOW(fd,2)-2);
  8612. sd->menuskill_lv = sd->menuskill_id = 0;
  8613. }
  8614. /*==========================================
  8615. * 矢作成
  8616. *------------------------------------------
  8617. */
  8618. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8619. {
  8620. RFIFOHEAD(fd);
  8621. if (sd->menuskill_id != AC_MAKINGARROW)
  8622. return;
  8623. if (clif_trading(sd)) {
  8624. //Make it fail to avoid shop exploits where you sell something different than you see.
  8625. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8626. sd->menuskill_lv = sd->menuskill_id = 0;
  8627. return;
  8628. }
  8629. skill_arrow_create(sd,RFIFOW(fd,2));
  8630. sd->menuskill_lv = sd->menuskill_id = 0;
  8631. }
  8632. /*==========================================
  8633. * オートスペル受信
  8634. *------------------------------------------
  8635. */
  8636. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8637. {
  8638. RFIFOHEAD(fd);
  8639. if (sd->menuskill_id != SA_AUTOSPELL)
  8640. return;
  8641. skill_autospell(sd,RFIFOW(fd,2));
  8642. sd->menuskill_lv = sd->menuskill_id = 0;
  8643. }
  8644. /*==========================================
  8645. * カード使用
  8646. *------------------------------------------
  8647. */
  8648. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8649. {
  8650. RFIFOHEAD(fd);
  8651. if (sd->state.trading!= 0)
  8652. return;
  8653. clif_use_card(sd,RFIFOW(fd,2)-2);
  8654. }
  8655. /*==========================================
  8656. * カード挿入装備選択
  8657. *------------------------------------------
  8658. */
  8659. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8660. {
  8661. RFIFOHEAD(fd);
  8662. if (sd->state.trading!= 0)
  8663. return;
  8664. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8665. }
  8666. /*==========================================
  8667. * 0193 キャラID名前引き
  8668. *------------------------------------------
  8669. */
  8670. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8671. int char_id;
  8672. RFIFOHEAD(fd);
  8673. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8674. clif_solved_charname(sd, char_id);
  8675. }
  8676. /*==========================================
  8677. * 0197 /resetskill /resetstate
  8678. *------------------------------------------
  8679. */
  8680. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8681. RFIFOHEAD(fd);
  8682. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8683. pc_isGM(sd) >= get_atcommand_level(AtCommand_ResetState)) {
  8684. switch(RFIFOW(fd,2)){
  8685. case 0:
  8686. pc_resetstate(sd);
  8687. break;
  8688. case 1:
  8689. pc_resetskill(sd,1);
  8690. break;
  8691. }
  8692. }
  8693. }
  8694. /*==========================================
  8695. * 019c /lb等
  8696. *------------------------------------------
  8697. */
  8698. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  8699. unsigned char buf[512];
  8700. RFIFOHEAD(fd);
  8701. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8702. (pc_isGM(sd) >= get_atcommand_level(AtCommand_LocalBroadcast))) {
  8703. WBUFW(buf,0) = 0x9a;
  8704. WBUFW(buf,2) = RFIFOW(fd,2);
  8705. memcpy(WBUFP(buf,4), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  8706. clif_send(buf, RFIFOW(fd,2), &sd->bl, ALL_SAMEMAP);
  8707. }
  8708. }
  8709. /*==========================================
  8710. * カプラ倉庫へ入れる
  8711. *------------------------------------------
  8712. */
  8713. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  8714. int item_index, item_amount;
  8715. RFIFOHEAD(fd);
  8716. if (clif_trading(sd))
  8717. return;
  8718. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8719. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8720. if (item_index < 0 || item_index >= MAX_INVENTORY)
  8721. return;
  8722. if (sd->state.storage_flag == 1)
  8723. storage_storageadd(sd, item_index, item_amount);
  8724. else if (sd->state.storage_flag == 2)
  8725. storage_guild_storageadd(sd, item_index, item_amount);
  8726. }
  8727. /*==========================================
  8728. * カプラ倉庫から出す
  8729. *------------------------------------------
  8730. */
  8731. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  8732. int item_index, item_amount;
  8733. RFIFOHEAD(fd);
  8734. if (clif_trading(sd))
  8735. return;
  8736. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8737. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8738. if (sd->state.storage_flag == 1)
  8739. storage_storageget(sd, item_index, item_amount);
  8740. else if(sd->state.storage_flag == 2)
  8741. storage_guild_storageget(sd, item_index, item_amount);
  8742. }
  8743. /*==========================================
  8744. * カプラ倉庫へカートから入れる
  8745. *------------------------------------------
  8746. */
  8747. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  8748. RFIFOHEAD(fd);
  8749. if (clif_trading(sd))
  8750. return;
  8751. if (sd->state.storage_flag == 1)
  8752. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8753. else if (sd->state.storage_flag == 2)
  8754. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8755. }
  8756. /*==========================================
  8757. * カプラ倉庫から出す
  8758. *------------------------------------------
  8759. */
  8760. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  8761. RFIFOHEAD(fd);
  8762. if (clif_trading(sd))
  8763. return;
  8764. if (sd->state.storage_flag == 1)
  8765. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8766. else if (sd->state.storage_flag == 2)
  8767. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8768. }
  8769. /*==========================================
  8770. * カプラ倉庫を閉じる
  8771. *------------------------------------------
  8772. */
  8773. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  8774. if (sd->state.storage_flag == 1)
  8775. storage_storageclose(sd);
  8776. else if (sd->state.storage_flag == 2)
  8777. storage_guild_storageclose(sd);
  8778. }
  8779. /*==========================================
  8780. * パーティを作る
  8781. *------------------------------------------
  8782. */
  8783. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  8784. RFIFOHEAD(fd);
  8785. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8786. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8787. } else
  8788. clif_skill_fail(sd,1,0,4);
  8789. }
  8790. /*==========================================
  8791. * パーティを作る
  8792. *------------------------------------------
  8793. */
  8794. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  8795. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  8796. RFIFOHEAD(fd);
  8797. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8798. } else
  8799. clif_skill_fail(sd,1,0,4);
  8800. }
  8801. /*==========================================
  8802. * パーティに勧誘
  8803. *------------------------------------------
  8804. */
  8805. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  8806. struct map_session_data *t_sd;
  8807. RFIFOHEAD(fd);
  8808. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  8809. // @noask [LuzZza]
  8810. if(t_sd && t_sd->state.noask) {
  8811. // Your request has been rejected by autoreject option.
  8812. clif_displaymessage(fd, msg_txt(392));
  8813. return;
  8814. }
  8815. party_invite(sd, RFIFOL(fd,2));
  8816. }
  8817. /*==========================================
  8818. * パーティ勧誘返答
  8819. *------------------------------------------
  8820. */
  8821. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  8822. RFIFOHEAD(fd);
  8823. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8824. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8825. } else {
  8826. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8827. clif_skill_fail(sd,1,0,4);
  8828. }
  8829. }
  8830. /*==========================================
  8831. * パーティ脱退要求
  8832. *------------------------------------------
  8833. */
  8834. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  8835. party_leave(sd);
  8836. }
  8837. /*==========================================
  8838. * パーティ除名要求
  8839. *------------------------------------------
  8840. */
  8841. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  8842. RFIFOHEAD(fd);
  8843. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8844. }
  8845. /*==========================================
  8846. * パーティ設定変更要求
  8847. *------------------------------------------
  8848. */
  8849. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  8850. RFIFOHEAD(fd);
  8851. party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8852. }
  8853. /*==========================================
  8854. * パーティメッセージ送信要求
  8855. *------------------------------------------
  8856. */
  8857. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  8858. RFIFOHEAD(fd);
  8859. if (is_charcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != CharCommand_None ||
  8860. is_atcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != AtCommand_None)
  8861. return;
  8862. if (sd->sc.count && (
  8863. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  8864. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  8865. ))
  8866. return;
  8867. party_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  8868. }
  8869. /*==========================================
  8870. * 露店閉鎖
  8871. *------------------------------------------
  8872. */
  8873. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  8874. vending_closevending(sd);
  8875. }
  8876. /*==========================================
  8877. * 露店アイテムリスト要求
  8878. *------------------------------------------
  8879. */
  8880. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  8881. RFIFOHEAD(fd);
  8882. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8883. if(sd->npc_id)
  8884. npc_event_dequeue(sd);
  8885. }
  8886. /*==========================================
  8887. * 露店アイテム購入
  8888. *------------------------------------------
  8889. */
  8890. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  8891. RFIFOHEAD(fd);
  8892. if (clif_trading(sd))
  8893. return;
  8894. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  8895. }
  8896. /*==========================================
  8897. * 露店開設
  8898. *------------------------------------------
  8899. */
  8900. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  8901. RFIFOHEAD(fd);
  8902. if (clif_trading(sd))
  8903. return;
  8904. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  8905. }
  8906. /*==========================================
  8907. * ギルドを作る
  8908. *------------------------------------------
  8909. */
  8910. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  8911. RFIFOHEAD(fd);
  8912. guild_create(sd, (char*)RFIFOP(fd,6));
  8913. }
  8914. /*==========================================
  8915. * ギルドマスターかどうか確認
  8916. *------------------------------------------
  8917. */
  8918. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  8919. clif_guild_masterormember(sd);
  8920. }
  8921. /*==========================================
  8922. * ギルド情報要求
  8923. *------------------------------------------
  8924. */
  8925. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  8926. RFIFOHEAD(fd);
  8927. switch(RFIFOL(fd,2)){
  8928. case 0: // ギルド基本情報、同盟敵対情報
  8929. clif_guild_basicinfo(sd);
  8930. clif_guild_allianceinfo(sd);
  8931. break;
  8932. case 1: // メンバーリスト、役職名リスト
  8933. clif_guild_positionnamelist(sd);
  8934. clif_guild_memberlist(sd);
  8935. break;
  8936. case 2: // 役職名リスト、役職情報リスト
  8937. clif_guild_positionnamelist(sd);
  8938. clif_guild_positioninfolist(sd);
  8939. break;
  8940. case 3: // スキルリスト
  8941. clif_guild_skillinfo(sd);
  8942. break;
  8943. case 4: // 追放リスト
  8944. clif_guild_explusionlist(sd);
  8945. break;
  8946. default:
  8947. if (battle_config.error_log)
  8948. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8949. break;
  8950. }
  8951. }
  8952. /*==========================================
  8953. * ギルド役職変更
  8954. *------------------------------------------
  8955. */
  8956. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  8957. int i;
  8958. RFIFOHEAD(fd);
  8959. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8960. guild_change_position(sd, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8961. }
  8962. }
  8963. /*==========================================
  8964. * ギルドメンバ役職変更
  8965. *------------------------------------------
  8966. */
  8967. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  8968. int i;
  8969. RFIFOHEAD(fd);
  8970. for(i=4;i<RFIFOW(fd,2);i+=12){
  8971. guild_change_memberposition(sd->status.guild_id,
  8972. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8973. }
  8974. }
  8975. /*==========================================
  8976. * ギルドエンブレム要求
  8977. *------------------------------------------
  8978. */
  8979. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  8980. struct guild *g;
  8981. RFIFOHEAD(fd);
  8982. g=guild_search(RFIFOL(fd,2));
  8983. if(g!=NULL)
  8984. clif_guild_emblem(sd,g);
  8985. }
  8986. /*==========================================
  8987. * ギルドエンブレム変更
  8988. *------------------------------------------
  8989. */
  8990. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  8991. RFIFOHEAD(fd);
  8992. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8993. }
  8994. /*==========================================
  8995. * ギルド告知変更
  8996. *------------------------------------------
  8997. */
  8998. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  8999. RFIFOHEAD(fd);
  9000. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  9001. }
  9002. /*==========================================
  9003. * ギルド勧誘
  9004. *------------------------------------------
  9005. */
  9006. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  9007. struct map_session_data *t_sd;
  9008. RFIFOHEAD(fd);
  9009. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  9010. // @noask [LuzZza]
  9011. if(t_sd && t_sd->state.noask) {
  9012. // Your request has been rejected by autoreject option.
  9013. clif_displaymessage(fd, msg_txt(392));
  9014. return;
  9015. }
  9016. guild_invite(sd,RFIFOL(fd,2));
  9017. }
  9018. /*==========================================
  9019. * ギルド勧誘返信
  9020. *------------------------------------------
  9021. */
  9022. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9023. RFIFOHEAD(fd);
  9024. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9025. }
  9026. /*==========================================
  9027. * ギルド脱退
  9028. *------------------------------------------
  9029. */
  9030. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9031. RFIFOHEAD(fd);
  9032. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9033. }
  9034. /*==========================================
  9035. * ギルド追放
  9036. *------------------------------------------
  9037. */
  9038. void clif_parse_GuildExplusion(int fd,struct map_session_data *sd) {
  9039. RFIFOHEAD(fd);
  9040. guild_explusion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9041. }
  9042. /*==========================================
  9043. * ギルド会話
  9044. *------------------------------------------
  9045. */
  9046. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9047. RFIFOHEAD(fd);
  9048. if (is_charcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != CharCommand_None ||
  9049. is_atcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != AtCommand_None)
  9050. return;
  9051. if (sd->sc.count && (
  9052. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  9053. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  9054. ))
  9055. return;
  9056. guild_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9057. }
  9058. /*==========================================
  9059. * ギルド同盟要求
  9060. *------------------------------------------
  9061. */
  9062. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9063. struct map_session_data *t_sd;
  9064. RFIFOHEAD(fd);
  9065. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  9066. // @noask [LuzZza]
  9067. if(t_sd && t_sd->state.noask) {
  9068. // Your request has been rejected by autoreject option.
  9069. clif_displaymessage(fd, msg_txt(392));
  9070. return;
  9071. }
  9072. guild_reqalliance(sd,RFIFOL(fd,2));
  9073. }
  9074. /*==========================================
  9075. * ギルド同盟要求返信
  9076. *------------------------------------------
  9077. */
  9078. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9079. RFIFOHEAD(fd);
  9080. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9081. }
  9082. /*==========================================
  9083. * ギルド関係解消
  9084. *------------------------------------------
  9085. */
  9086. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9087. RFIFOHEAD(fd);
  9088. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9089. }
  9090. /*==========================================
  9091. * ギルド敵対
  9092. *------------------------------------------
  9093. */
  9094. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9095. struct map_session_data *t_sd;
  9096. RFIFOHEAD(fd);
  9097. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  9098. // @noask [LuzZza]
  9099. if(t_sd && t_sd->state.noask) {
  9100. // Your request has been rejected by autoreject option.
  9101. clif_displaymessage(fd, msg_txt(392));
  9102. return;
  9103. }
  9104. guild_opposition(sd,RFIFOL(fd,2));
  9105. }
  9106. /*==========================================
  9107. * ギルド解散
  9108. *------------------------------------------
  9109. */
  9110. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9111. RFIFOHEAD(fd);
  9112. guild_break(sd,(char*)RFIFOP(fd,2));
  9113. }
  9114. // pet
  9115. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9116. RFIFOHEAD(fd);
  9117. pet_menu(sd,RFIFOB(fd,2));
  9118. }
  9119. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9120. RFIFOHEAD(fd);
  9121. pet_catch_process2(sd,RFIFOL(fd,2));
  9122. }
  9123. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9124. RFIFOHEAD(fd);
  9125. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  9126. return;
  9127. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9128. sd->menuskill_lv = sd->menuskill_id = 0;
  9129. }
  9130. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9131. if(sd->pd) {
  9132. RFIFOHEAD(fd);
  9133. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9134. }
  9135. }
  9136. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9137. RFIFOHEAD(fd);
  9138. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9139. }
  9140. // Kick (right click menu for GM "(name) force to quit")
  9141. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9142. struct block_list *target;
  9143. int tid;
  9144. RFIFOHEAD(fd);
  9145. tid = RFIFOL(fd,2);
  9146. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9147. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Kick))) {
  9148. target = map_id2bl(tid);
  9149. if (target) {
  9150. if (target->type == BL_PC) {
  9151. struct map_session_data *tsd = (struct map_session_data *)target;
  9152. if (pc_isGM(sd) > pc_isGM(tsd))
  9153. clif_GM_kick(sd, tsd, 1);
  9154. else
  9155. clif_GM_kickack(sd, 0);
  9156. } else if (target->type == BL_MOB) {
  9157. struct mob_data *md = (struct mob_data *)target;
  9158. mob_damage(&sd->bl, md, md->hp, 2);
  9159. } else
  9160. clif_GM_kickack(sd, 0);
  9161. } else
  9162. clif_GM_kickack(sd, 0);
  9163. }
  9164. }
  9165. /*==========================================
  9166. * /shift
  9167. *------------------------------------------
  9168. */
  9169. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9170. char player_name[NAME_LENGTH+1];
  9171. memset(player_name, '\0', sizeof(player_name));
  9172. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9173. (pc_isGM(sd) >= get_atcommand_level(AtCommand_JumpTo))) {
  9174. RFIFOHEAD(fd);
  9175. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9176. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9177. }
  9178. return;
  9179. }
  9180. /*==========================================
  9181. * /recall
  9182. *------------------------------------------
  9183. */
  9184. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9185. char player_name[25];
  9186. memset(player_name, '\0', sizeof(player_name));
  9187. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9188. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Recall))) {
  9189. RFIFOHEAD(fd);
  9190. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9191. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9192. }
  9193. return;
  9194. }
  9195. /*==========================================
  9196. * /monster /item rewriten by [Yor]
  9197. *------------------------------------------
  9198. */
  9199. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9200. char monster_item_name[NAME_LENGTH+10]; //Additional space is for logging, eg: "@monster Poring"
  9201. int level;
  9202. memset(monster_item_name, '\0', sizeof(monster_item_name));
  9203. if (battle_config.atc_gmonly == 0 || pc_isGM(sd)) {
  9204. RFIFOHEAD(fd);
  9205. memcpy(monster_item_name, RFIFOP(fd,2), NAME_LENGTH);
  9206. if (mobdb_searchname(monster_item_name) != 0) {
  9207. if (pc_isGM(sd) >= (level =get_atcommand_level(AtCommand_Monster)))
  9208. {
  9209. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9210. if(log_config.gm && level >= log_config.gm)
  9211. { //Log action. [Skotlex]
  9212. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@spawn %s", RFIFOP(fd,2));
  9213. log_atcommand(sd, monster_item_name);
  9214. }
  9215. }
  9216. } else if (itemdb_searchname(monster_item_name) != NULL) {
  9217. if (pc_isGM(sd) >= (level = get_atcommand_level(AtCommand_Item)))
  9218. {
  9219. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9220. if(log_config.gm && level >= log_config.gm)
  9221. { //Log action. [Skotlex]
  9222. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@item %s", RFIFOP(fd,2));
  9223. log_atcommand(sd, monster_item_name);
  9224. }
  9225. }
  9226. }
  9227. }
  9228. }
  9229. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9230. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9231. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) {
  9232. if (sd->sc.option & OPTION_INVISIBLE) {
  9233. sd->sc.option &= ~OPTION_INVISIBLE;
  9234. if (sd->disguise)
  9235. status_set_viewdata(&sd->bl, sd->disguise);
  9236. else
  9237. status_set_viewdata(&sd->bl, sd->status.class_);
  9238. clif_displaymessage(fd, "Invisible: Off.");
  9239. } else {
  9240. sd->sc.option |= OPTION_INVISIBLE;
  9241. //Experimental hidden mode, changes your view class to invisible [Skotlex]
  9242. sd->vd.class_ = INVISIBLE_CLASS;
  9243. clif_displaymessage(fd, "Invisible: On.");
  9244. }
  9245. clif_changeoption(&sd->bl);
  9246. }
  9247. }
  9248. /*==========================================
  9249. * GMによるチャット禁止時間付与
  9250. *------------------------------------------
  9251. */
  9252. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9253. {
  9254. int type, limit, level;
  9255. struct block_list *bl;
  9256. struct map_session_data *dstsd;
  9257. if(!battle_config.muting_players) {
  9258. clif_displaymessage(fd, "Muting is disabled.");
  9259. return;
  9260. }
  9261. RFIFOHEAD(fd);
  9262. bl = map_id2bl(RFIFOL(fd,2));
  9263. if (!bl || bl->type != BL_PC)
  9264. return;
  9265. nullpo_retv(dstsd =(struct map_session_data *)bl);
  9266. type = RFIFOB(fd,6);
  9267. limit = RFIFOW(fd,7);
  9268. if (type == 0)
  9269. limit = 0 - limit;
  9270. //Temporarily disable chars from muting themselves due to the mysterious "DON'T USE BOT!" message. [Skotlex]
  9271. //Also, if type is 2 and the ids don't match, this is a crafted hacked packet!
  9272. //So for now, type 2is just totally disabled.
  9273. if (type == 2/*&& sd->bl.id != dstsd->bl.id*/)
  9274. return;
  9275. if (
  9276. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9277. || (type == 2 && !level)) {
  9278. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9279. if (battle_config.manner_system)
  9280. {
  9281. dstsd->status.manner -= limit;
  9282. if(dstsd->status.manner < 0)
  9283. sc_start(bl,SC_NOCHAT,100,0,0);
  9284. else
  9285. {
  9286. dstsd->status.manner = 0;
  9287. status_change_end(bl,SC_NOCHAT,-1);
  9288. }
  9289. }
  9290. ShowDebug("GMReqNoChat: name:%s type:%d limit:%d manner:%d\n", dstsd->status.name, type, limit, dstsd->status.manner);
  9291. }
  9292. return;
  9293. }
  9294. /*==========================================
  9295. * GMによるチャット禁止時間参照(?)
  9296. *------------------------------------------
  9297. */
  9298. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9299. {
  9300. int tid;
  9301. RFIFOHEAD(fd);
  9302. tid = RFIFOL(fd,2);
  9303. WFIFOHEAD(fd,packet_len_table[0x1e0]);
  9304. WFIFOW(fd,0) = 0x1e0;
  9305. WFIFOL(fd,2) = tid;
  9306. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9307. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9308. WFIFOSET(fd, packet_len_table[0x1e0]);
  9309. return;
  9310. }
  9311. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9312. char output[512];
  9313. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9314. int i, pos;
  9315. RFIFOHEAD(fd);
  9316. memset(output, '\0', sizeof(output));
  9317. nick = (char*)RFIFOP(fd,2); // speed up
  9318. RFIFOB(fd,NAME_LENGTH+1) = '\0'; // to be sure that the player name have at maximum 23 characters (nick range: [2]->[26])
  9319. //printf("Ignore: char '%s' state: %d\n", nick, RFIFOB(fd,26));
  9320. WFIFOHEAD(fd,packet_len_table[0xd1]);
  9321. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9322. WFIFOB(fd,2) = RFIFOB(fd,26);
  9323. // do nothing only if nick can not exist
  9324. if (strlen(nick) < 4) {
  9325. WFIFOB(fd,3) = 1; // fail
  9326. WFIFOSET(fd, packet_len_table[0x0d1]);
  9327. if (RFIFOB(fd,26) == 0) // type
  9328. clif_wis_message(fd, wisp_server_name, "It's impossible to block this player.", strlen("It's impossible to block this player.") + 1);
  9329. else
  9330. clif_wis_message(fd, wisp_server_name, "It's impossible to unblock this player.", strlen("It's impossible to unblock this player.") + 1);
  9331. return;
  9332. // name can exist
  9333. } else {
  9334. // deny action (we add nick only if it's not already exist
  9335. if (RFIFOB(fd,26) == 0) { // type
  9336. pos = -1;
  9337. for(i = 0; i < MAX_IGNORE_LIST; i++) {
  9338. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9339. WFIFOB(fd,3) = 1; // fail
  9340. WFIFOSET(fd, packet_len_table[0x0d1]);
  9341. clif_wis_message(fd, wisp_server_name, "This player is already blocked.", strlen("This player is already blocked.") + 1);
  9342. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9343. 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);
  9344. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9345. }
  9346. return;
  9347. } else if (pos == -1 && sd->ignore[i].name[0] == '\0')
  9348. pos = i;
  9349. }
  9350. // if a position is found and name not found, we add it in the list
  9351. if (pos != -1) {
  9352. memcpy(sd->ignore[pos].name, nick, NAME_LENGTH-1);
  9353. WFIFOB(fd,3) = 0; // success
  9354. WFIFOSET(fd, packet_len_table[0x0d1]);
  9355. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9356. 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);
  9357. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9358. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9359. 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);
  9360. }
  9361. } else {
  9362. WFIFOB(fd,3) = 1; // fail
  9363. WFIFOSET(fd, packet_len_table[0x0d1]);
  9364. clif_wis_message(fd, wisp_server_name, "You can not block more people.", strlen("You can not block more people.") + 1);
  9365. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9366. 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);
  9367. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9368. }
  9369. }
  9370. // allow action (we remove all same nicks if they exist)
  9371. } else {
  9372. pos = -1;
  9373. for(i = 0; i < MAX_IGNORE_LIST; i++)
  9374. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9375. memset(sd->ignore[i].name, 0, sizeof(sd->ignore[i].name));
  9376. if (pos == -1) {
  9377. WFIFOB(fd,3) = 0; // success
  9378. WFIFOSET(fd, packet_len_table[0x0d1]);
  9379. pos = i; // don't break, to remove ALL same nick
  9380. }
  9381. }
  9382. if (pos == -1) {
  9383. WFIFOB(fd,3) = 1; // fail
  9384. WFIFOSET(fd, packet_len_table[0x0d1]);
  9385. clif_wis_message(fd, wisp_server_name, "This player is not blocked by you.", strlen("This player is not blocked by you.") + 1);
  9386. }
  9387. }
  9388. }
  9389. // for(i = 0; i < MAX_IGNORE_LIST; i++) // for debug only
  9390. // if (sd->ignore[i].name[0] != '\0')
  9391. // printf("Ignored player: '%s'\n", sd->ignore[i].name);
  9392. return;
  9393. }
  9394. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9395. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9396. RFIFOHEAD(fd);
  9397. if (RFIFOB(fd,2) == 0) {// S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9398. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9399. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9400. WFIFOB(fd,2) = 0;
  9401. if (sd->ignoreAll == 0) {
  9402. sd->ignoreAll = 1;
  9403. WFIFOB(fd,3) = 0; // success
  9404. WFIFOSET(fd, packet_len_table[0x0d2]);
  9405. } else {
  9406. WFIFOB(fd,3) = 1; // fail
  9407. WFIFOSET(fd, packet_len_table[0x0d2]);
  9408. clif_wis_message(fd, wisp_server_name, "You already block everyone.", strlen("You already block everyone.") + 1);
  9409. }
  9410. } else {
  9411. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9412. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9413. WFIFOB(fd,2) = 1;
  9414. if (sd->ignoreAll == 1) {
  9415. sd->ignoreAll = 0;
  9416. WFIFOB(fd,3) = 0; // success
  9417. WFIFOSET(fd, packet_len_table[0x0d2]);
  9418. } else {
  9419. WFIFOB(fd,3) = 1; // fail
  9420. WFIFOSET(fd, packet_len_table[0x0d2]);
  9421. clif_wis_message(fd, wisp_server_name, "You already allow everyone.", strlen("You already allow everyone.") + 1);
  9422. }
  9423. }
  9424. return;
  9425. }
  9426. /*==========================================
  9427. * Wis拒否リスト
  9428. *------------------------------------------
  9429. */
  9430. int pstrcmp(const void *a, const void *b)
  9431. {
  9432. return strcmp((char *)a, (char *)b);
  9433. }
  9434. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9435. {
  9436. int i,j=0,count=0;
  9437. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9438. for(i = 0; i < MAX_IGNORE_LIST; i++){ //中身があるのを数える
  9439. if(sd->ignore[i].name[0] != 0)
  9440. count++;
  9441. }
  9442. WFIFOHEAD(fd, 4 + (NAME_LENGTH * count));
  9443. WFIFOW(fd,0) = 0xd4;
  9444. WFIFOW(fd,2) = 4 + (NAME_LENGTH * count);
  9445. for(i = 0; i < MAX_IGNORE_LIST; i++){
  9446. if(sd->ignore[i].name[0] != 0){
  9447. memcpy(WFIFOP(fd, 4 + j * 24),sd->ignore[i].name, NAME_LENGTH);
  9448. j++;
  9449. }
  9450. }
  9451. WFIFOSET(fd, WFIFOW(fd,2));
  9452. if(count >= MAX_IGNORE_LIST) //満タンなら最後の1個を消す
  9453. sd->ignore[MAX_IGNORE_LIST - 1].name[0] = 0;
  9454. return;
  9455. }
  9456. /*==========================================
  9457. * スパノビの/doridoriによるSPR2倍
  9458. *------------------------------------------
  9459. */
  9460. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9461. int level;
  9462. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE)
  9463. sd->doridori_counter++;
  9464. if ((sd->class_&MAPID_BASEMASK) == MAPID_TAEKWON
  9465. && sd->state.rest && (level = pc_checkskill(sd,TK_SPTIME)))
  9466. sc_start(&sd->bl,SkillStatusChangeTable[TK_SPTIME],100,level,skill_get_time(TK_SPTIME, level));
  9467. return;
  9468. }
  9469. /*==========================================
  9470. * スパノビの爆裂波動
  9471. *------------------------------------------
  9472. */
  9473. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9474. {
  9475. if(sd){
  9476. int nextbaseexp=pc_nextbaseexp(sd);
  9477. if (battle_config.etc_log){
  9478. if(nextbaseexp != 0)
  9479. 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));
  9480. else
  9481. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9482. }
  9483. 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){
  9484. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9485. sc_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  9486. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9487. }
  9488. }
  9489. return;
  9490. }
  9491. // random notes:
  9492. // 0x214: monster/player info ?
  9493. /*==========================================
  9494. * Friends List
  9495. *------------------------------------------
  9496. */
  9497. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9498. { //Toggles a single friend online/offline [Skotlex]
  9499. int i;
  9500. //Seek friend.
  9501. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9502. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9503. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9504. return; //Not found
  9505. WFIFOHEAD(sd->fd,packet_len_table[0x206]);
  9506. WFIFOW(sd->fd, 0) = 0x206;
  9507. WFIFOL(sd->fd, 2) = sd->status.friends[i].account_id;
  9508. WFIFOL(sd->fd, 6) = sd->status.friends[i].char_id;
  9509. WFIFOB(sd->fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9510. WFIFOSET(sd->fd, packet_len_table[0x206]);
  9511. }
  9512. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9513. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9514. {
  9515. int account_id, char_id, online;
  9516. account_id = va_arg(ap, int);
  9517. char_id = va_arg(ap, int);
  9518. online = va_arg(ap, int);
  9519. clif_friendslist_toggle(sd, account_id, char_id, online);
  9520. return 0;
  9521. }
  9522. //For sending the whole friends list.
  9523. void clif_friendslist_send(struct map_session_data *sd) {
  9524. int i = 0, n;
  9525. // Send friends list
  9526. WFIFOHEAD(sd->fd, MAX_FRIENDS * 32 + 4);
  9527. WFIFOW(sd->fd, 0) = 0x201;
  9528. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9529. {
  9530. WFIFOL(sd->fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9531. WFIFOL(sd->fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9532. memcpy(WFIFOP(sd->fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9533. }
  9534. if (i) {
  9535. WFIFOW(sd->fd,2) = 4 + 32 * i;
  9536. WFIFOSET(sd->fd, WFIFOW(sd->fd,2));
  9537. }
  9538. for (n = 0; n < i; n++)
  9539. { //Sending the online players
  9540. if (map_charid2sd(sd->status.friends[n].char_id))
  9541. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9542. }
  9543. }
  9544. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9545. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9546. {
  9547. int fd;
  9548. nullpo_retv(sd);
  9549. fd = sd->fd;
  9550. WFIFOHEAD(fd,packet_len_table[0x209]);
  9551. WFIFOW(fd,0) = 0x209;
  9552. WFIFOW(fd,2) = type;
  9553. if (f_sd)
  9554. {
  9555. WFIFOW(fd,4) = f_sd->status.account_id;
  9556. WFIFOW(fd,8) = f_sd->status.char_id;
  9557. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9558. }
  9559. WFIFOSET(fd, packet_len_table[0x209]);
  9560. }
  9561. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9562. struct map_session_data *f_sd;
  9563. int i, f_fd;
  9564. RFIFOHEAD(fd);
  9565. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9566. // Friend doesn't exist (no player with this name)
  9567. if (f_sd == NULL) {
  9568. clif_displaymessage(fd, msg_txt(3));
  9569. return;
  9570. }
  9571. // @noask [LuzZza]
  9572. if(f_sd->state.noask) {
  9573. // Your request has been rejected by autoreject option.
  9574. clif_displaymessage(fd, msg_txt(392));
  9575. return;
  9576. }
  9577. // Friend already exists
  9578. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9579. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9580. clif_displaymessage(fd, "Friend already exists.");
  9581. return;
  9582. }
  9583. }
  9584. if (i == MAX_FRIENDS) {
  9585. //No space, list full.
  9586. clif_friendslist_reqack(sd, f_sd, 2);
  9587. return;
  9588. }
  9589. f_fd = f_sd->fd;
  9590. WFIFOHEAD(f_fd,packet_len_table[0x207]);
  9591. WFIFOW(f_fd,0) = 0x207;
  9592. WFIFOL(f_fd,2) = sd->status.account_id;
  9593. WFIFOL(f_fd,6) = sd->status.char_id;
  9594. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9595. WFIFOSET(f_fd, packet_len_table[0x207]);
  9596. return;
  9597. }
  9598. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9599. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9600. struct map_session_data *f_sd;
  9601. int char_id, account_id;
  9602. char reply;
  9603. RFIFOHEAD(fd);
  9604. account_id = RFIFOL(fd,2);
  9605. char_id = RFIFOL(fd,6);
  9606. reply = RFIFOB(fd,10);
  9607. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9608. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9609. if (f_sd == NULL)
  9610. return;
  9611. if (reply == 0)
  9612. clif_friendslist_reqack(f_sd, sd, 1);
  9613. else {
  9614. int i;
  9615. // Find an empty slot
  9616. for (i = 0; i < MAX_FRIENDS; i++)
  9617. if (f_sd->status.friends[i].char_id == 0)
  9618. break;
  9619. if (i == MAX_FRIENDS) {
  9620. clif_friendslist_reqack(f_sd, sd, 2);
  9621. return;
  9622. }
  9623. f_sd->status.friends[i].account_id = sd->status.account_id;
  9624. f_sd->status.friends[i].char_id = sd->status.char_id;
  9625. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9626. clif_friendslist_reqack(f_sd, sd, 0);
  9627. // clif_friendslist_send(sd); //This is not needed anymore.
  9628. }
  9629. return;
  9630. }
  9631. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9632. // 0x203 </o> <ID to be removed W 4B>
  9633. int account_id, char_id;
  9634. int i, j;
  9635. RFIFOHEAD(fd);
  9636. account_id = RFIFOL(fd,2);
  9637. char_id = RFIFOL(fd,6);
  9638. // Search friend
  9639. for (i = 0; i < MAX_FRIENDS &&
  9640. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9641. if (i == MAX_FRIENDS) {
  9642. clif_displaymessage(fd, "Name not found in list.");
  9643. return;
  9644. }
  9645. // move all chars down
  9646. for(j = i + 1; j < MAX_FRIENDS; j++)
  9647. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9648. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9649. clif_displaymessage(fd, "Friend removed");
  9650. WFIFOHEAD(fd,packet_len_table[0x20a]);
  9651. WFIFOW(fd,0) = 0x20a;
  9652. WFIFOL(fd,2) = account_id;
  9653. WFIFOL(fd,6) = char_id;
  9654. WFIFOSET(fd, packet_len_table[0x20a]);
  9655. // clif_friendslist_send(sd); //This is not needed anymore.
  9656. return;
  9657. }
  9658. /*==========================================
  9659. * /killall
  9660. *------------------------------------------
  9661. */
  9662. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  9663. {
  9664. char message[50];
  9665. strncpy(message,sd->status.name, NAME_LENGTH);
  9666. is_atcommand(fd, sd, strcat(message," : @kickall"),0);
  9667. return;
  9668. }
  9669. /*==========================================
  9670. * /pvpinfo
  9671. *------------------------------------------
  9672. */
  9673. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9674. {
  9675. WFIFOHEAD(fd,packet_len_table[0x210]);
  9676. WFIFOW(fd,0) = 0x210;
  9677. //WFIFOL(fd,2) = 0; // not sure what for yet
  9678. //WFIFOL(fd,6) = 0;
  9679. WFIFOL(fd,10) = sd->pvp_won; // times won
  9680. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9681. WFIFOL(fd,18) = sd->pvp_point;
  9682. WFIFOSET(fd, packet_len_table[0x210]);
  9683. return;
  9684. }
  9685. /*==========================================
  9686. * /blacksmith
  9687. *------------------------------------------
  9688. */
  9689. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9690. {
  9691. int i;
  9692. char *name;
  9693. WFIFOHEAD(fd,packet_len_table[0x219]);
  9694. WFIFOW(fd,0) = 0x219;
  9695. //Packet size limits this list to 10 elements. [Skotlex]
  9696. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9697. if (smith_fame_list[i].id > 0) {
  9698. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9699. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9700. {
  9701. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9702. } else
  9703. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9704. } else
  9705. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9706. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9707. }
  9708. for(;i < 10; i++) { //In case the MAX is less than 10.
  9709. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9710. WFIFOL(fd, 242 + i * 4) = 0;
  9711. }
  9712. WFIFOSET(fd, packet_len_table[0x219]);
  9713. }
  9714. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9715. {
  9716. int fd = sd->fd;
  9717. WFIFOHEAD(fd,packet_len_table[0x21b]);
  9718. WFIFOW(fd,0) = 0x21b;
  9719. WFIFOL(fd,2) = points;
  9720. WFIFOL(fd,6) = sd->status.fame;
  9721. WFIFOSET(fd, packet_len_table[0x21b]);
  9722. return 0;
  9723. }
  9724. /*==========================================
  9725. * /alchemist
  9726. *------------------------------------------
  9727. */
  9728. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9729. {
  9730. int i;
  9731. char *name;
  9732. WFIFOHEAD(fd,packet_len_table[0x21a]);
  9733. WFIFOW(fd,0) = 0x21a;
  9734. //Packet size limits this list to 10 elements. [Skotlex]
  9735. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9736. if (chemist_fame_list[i].id > 0) {
  9737. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9738. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9739. {
  9740. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9741. } else
  9742. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9743. } else
  9744. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9745. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9746. }
  9747. for(;i < 10; i++) { //In case the MAX is less than 10.
  9748. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9749. WFIFOL(fd, 242 + i * 4) = 0;
  9750. }
  9751. WFIFOSET(fd, packet_len_table[0x21a]);
  9752. }
  9753. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9754. {
  9755. int fd = sd->fd;
  9756. WFIFOHEAD(fd,packet_len_table[0x21c]);
  9757. WFIFOW(fd,0) = 0x21c;
  9758. WFIFOL(fd,2) = points;
  9759. WFIFOL(fd,6) = sd->status.fame;
  9760. WFIFOSET(fd, packet_len_table[0x21c]);
  9761. return 0;
  9762. }
  9763. /*==========================================
  9764. * /taekwon
  9765. *------------------------------------------
  9766. */
  9767. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9768. {
  9769. int i;
  9770. char *name;
  9771. WFIFOHEAD(fd,packet_len_table[0x226]);
  9772. WFIFOW(fd,0) = 0x226;
  9773. //Packet size limits this list to 10 elements. [Skotlex]
  9774. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9775. if (taekwon_fame_list[i].id > 0) {
  9776. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9777. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9778. {
  9779. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9780. } else
  9781. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9782. } else
  9783. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9784. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9785. }
  9786. for(;i < 10; i++) { //In case the MAX is less than 10.
  9787. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9788. WFIFOL(fd, 242 + i * 4) = 0;
  9789. }
  9790. WFIFOSET(fd, packet_len_table[0x226]);
  9791. }
  9792. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9793. {
  9794. int fd = sd->fd;
  9795. WFIFOHEAD(fd,packet_len_table[0x224]);
  9796. WFIFOW(fd,0) = 0x224;
  9797. WFIFOL(fd,2) = points;
  9798. WFIFOL(fd,6) = sd->status.fame;
  9799. WFIFOSET(fd, packet_len_table[0x224]);
  9800. return 0;
  9801. }
  9802. /*==========================================
  9803. * PK Ranking table?
  9804. *------------------------------------------
  9805. */
  9806. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9807. {
  9808. int i;
  9809. WFIFOHEAD(fd,packet_len_table[0x238]);
  9810. WFIFOW(fd,0) = 0x238;
  9811. for(i=0;i<10;i++){
  9812. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9813. WFIFOL(fd,i*4+242) = 0;
  9814. }
  9815. WFIFOSET(fd, packet_len_table[0x238]);
  9816. return;
  9817. }
  9818. /*==========================================
  9819. * SG Feel save OK [Komurka]
  9820. *------------------------------------------
  9821. */
  9822. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9823. {
  9824. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  9825. int i;
  9826. if (sd->menuskill_id != SG_FEEL)
  9827. return;
  9828. i = sd->menuskill_lv-1;
  9829. if (i<0 || i > 2) return; //Bug?
  9830. sd->feel_map[i].index = map[sd->bl.m].index;
  9831. sd->feel_map[i].m = sd->bl.m;
  9832. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  9833. WFIFOHEAD(fd,packet_len_table[0x20e]);
  9834. WFIFOW(fd,0)=0x20e;
  9835. memcpy(WFIFOP(fd,2),map[sd->bl.m].name, MAP_NAME_LENGTH);
  9836. WFIFOL(fd,26)=sd->bl.id;
  9837. WFIFOW(fd,30)=i;
  9838. WFIFOSET(fd, packet_len_table[0x20e]);
  9839. clif_skill_nodamage(&sd->bl,&sd->bl,sd->menuskill_id,sd->menuskill_lv,1);
  9840. sd->menuskill_lv = sd->menuskill_id = 0;
  9841. }
  9842. /*==========================================
  9843. * Question about Star Glaldiator save map [Komurka]
  9844. *------------------------------------------
  9845. */
  9846. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  9847. WFIFOHEAD(fd,packet_len_table[0x253]);
  9848. WFIFOW(fd,0)=0x253;
  9849. WFIFOSET(fd, packet_len_table[0x253]);
  9850. sd->menuskill_id=SG_FEEL;
  9851. sd->menuskill_lv=skilllv;
  9852. }
  9853. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd) {
  9854. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  9855. //Missing packets are the client's reply packets to the adopt request one.
  9856. //[Skotlex]
  9857. int account_id;
  9858. struct map_session_data *sd2;
  9859. RFIFOHEAD(fd);
  9860. account_id = RFIFOL(fd,2);
  9861. sd2 = map_id2sd(account_id);
  9862. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  9863. fd = sd2->fd;
  9864. WFIFOHEAD(fd,packet_len_table[0x1f9]);
  9865. WFIFOW(fd,0)=0x1f9;
  9866. WFIFOSET(fd, packet_len_table[0x1f9]);
  9867. }
  9868. }
  9869. /*==========================================
  9870. * パケットデバッグ
  9871. *------------------------------------------
  9872. */
  9873. void clif_parse_debug(int fd,struct map_session_data *sd)
  9874. {
  9875. int i, cmd, len;
  9876. RFIFOHEAD(fd);
  9877. cmd = RFIFOW(fd,0);
  9878. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  9879. ShowDebug("packet debug 0x%4X\n",cmd);
  9880. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9881. for(i=0;i<len;i++){
  9882. if((i&15)==0)
  9883. printf("\n%04X ",i);
  9884. printf("%02X ",RFIFOB(fd,i));
  9885. }
  9886. printf("\n");
  9887. }
  9888. /*==========================================
  9889. * クライアントからのパケット解析
  9890. * socket.cのdo_parsepacketから呼び出される
  9891. *------------------------------------------
  9892. */
  9893. int clif_parse(int fd) {
  9894. int packet_len = 0, cmd, packet_ver, dump = 0;
  9895. struct map_session_data *sd;
  9896. RFIFOHEAD(fd);
  9897. if (fd <= 0)
  9898. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  9899. ShowError("clif_parse: Received invalid session %d\n", fd);
  9900. return 0;
  9901. }
  9902. sd = (struct map_session_data*)session[fd]->session_data;
  9903. // 接続が切れてるので後始末
  9904. if (!chrif_isconnect() && kick_on_disconnect)
  9905. {
  9906. ShowInfo("Closing session #%d (Not connected to Char server)\n", fd);
  9907. if (sd && sd->state.auth)
  9908. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  9909. do_close(fd);
  9910. return 0;
  9911. } else
  9912. if (session[fd]->eof) {
  9913. if (sd && sd->state.autotrade) {
  9914. //Disassociate character from the socket connection.
  9915. session[fd]->session_data = NULL;
  9916. sd->fd = 0;
  9917. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  9918. } else if (sd && sd->state.auth) {
  9919. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  9920. if (sd->status.name != NULL)
  9921. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  9922. else
  9923. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id); // Player logout display [Yor]
  9924. } else {
  9925. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  9926. 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]);
  9927. }
  9928. do_close(fd);
  9929. return 0;
  9930. }
  9931. if (RFIFOREST(fd) < 2)
  9932. return 0;
  9933. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  9934. cmd = RFIFOW(fd,0);
  9935. // 管理用パケット処理
  9936. if (cmd >= 30000) {
  9937. switch(cmd) {
  9938. case 0x7530: { //Why are we letting people know which version we are running?
  9939. WFIFOHEAD(fd, 10);
  9940. WFIFOW(fd,0) = 0x7531;
  9941. WFIFOB(fd,2) = ATHENA_MAJOR_VERSION;
  9942. WFIFOB(fd,3) = ATHENA_MINOR_VERSION;
  9943. WFIFOB(fd,4) = ATHENA_REVISION;
  9944. WFIFOB(fd,5) = ATHENA_RELEASE_FLAG;
  9945. WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG;
  9946. WFIFOB(fd,7) = ATHENA_SERVER_MAP;
  9947. WFIFOW(fd,8) = ATHENA_MOD_VERSION;
  9948. WFIFOSET(fd,10);
  9949. RFIFOSKIP(fd,2);
  9950. break;
  9951. }
  9952. case 0x7532: // 接続の切断
  9953. ShowWarning("clif_parse: session #%d disconnected for sending packet 0x04%x\n", fd, cmd);
  9954. session[fd]->eof=1;
  9955. break;
  9956. default:
  9957. ShowWarning("Unknown incoming packet (command: 0x%04x, session: %d), disconnecting.\n", cmd, fd);
  9958. session[fd]->eof=1;
  9959. break;
  9960. }
  9961. return 0;
  9962. }
  9963. // get packet version before to parse
  9964. packet_ver = 0;
  9965. if (sd) {
  9966. packet_ver = sd->packet_ver;
  9967. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  9968. session[fd]->eof = 1;
  9969. return 0;
  9970. }
  9971. } else {
  9972. // check authentification packet to know packet version
  9973. packet_ver = clif_guess_PacketVer(fd, 0);
  9974. // check if version is accepted
  9975. if (packet_ver < 5 || // reject really old client versions
  9976. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  9977. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
  9978. packet_ver > MAX_PACKET_VER) // no packet version support yet
  9979. {
  9980. ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
  9981. WFIFOHEAD(fd, 23);
  9982. WFIFOW(fd,0) = 0x6a;
  9983. WFIFOB(fd,2) = 5; // 05 = Game's EXE is not the latest version
  9984. WFIFOSET(fd,23);
  9985. packet_len = RFIFOREST(fd);
  9986. RFIFOSKIP(fd, packet_len);
  9987. clif_setwaitclose(fd);
  9988. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  9989. session[fd]->func_send(fd);
  9990. return 0;
  9991. }
  9992. }
  9993. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  9994. 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
  9995. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  9996. session[fd]->eof = 1;
  9997. return 0;
  9998. }
  9999. // パケット長を計算
  10000. packet_len = packet_db[packet_ver][cmd].len;
  10001. if (packet_len == -1) {
  10002. if (RFIFOREST(fd) < 4)
  10003. return 0; // 可変長パケットで長さの所までデータが来てない
  10004. packet_len = RFIFOW(fd,2);
  10005. if (packet_len < 4 || packet_len > 32768) {
  10006. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10007. session[fd]->eof =1;
  10008. return 0;
  10009. }
  10010. }
  10011. if ((int)RFIFOREST(fd) < packet_len)
  10012. return 0; // まだ1パケット分データが揃ってない
  10013. #if DUMP_ALL_PACKETS
  10014. dump = 1;
  10015. #endif
  10016. if (sd && sd->state.auth == 1 && sd->state.waitingdisconnect == 1) { // 切断待ちの場合パケットを処理しない
  10017. } else if (packet_db[packet_ver][cmd].func) {
  10018. if (sd
  10019. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10020. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10021. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10022. packet_db[packet_ver][cmd].func(fd, sd);
  10023. } else {
  10024. // 不明なパケット
  10025. if (battle_config.error_log) {
  10026. #if DUMP_UNKNOWN_PACKET
  10027. {
  10028. int i;
  10029. FILE *fp;
  10030. char packet_txt[256] = "save/packet.txt";
  10031. time_t now;
  10032. dump = 1;
  10033. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10034. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10035. return 1;
  10036. } else {
  10037. time(&now);
  10038. if (sd && sd->state.auth) {
  10039. if (sd->status.name != NULL)
  10040. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10041. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10042. else
  10043. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10044. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10045. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10046. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10047. for(i = 0; i < packet_len; i++) {
  10048. if ((i & 15) == 0)
  10049. fprintf(fp, "\n\t%04X ", i);
  10050. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10051. }
  10052. fprintf(fp, "\n\n");
  10053. fclose(fp);
  10054. }
  10055. }
  10056. #endif
  10057. }
  10058. }
  10059. if (dump) {
  10060. int i;
  10061. if (fd)
  10062. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10063. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10064. for(i = 0; i < packet_len; i++) {
  10065. if ((i & 15) == 0)
  10066. printf("\n%04X ",i);
  10067. printf("%02X ", RFIFOB(fd,i));
  10068. }
  10069. printf("\n");
  10070. if (sd && sd->state.auth) {
  10071. if (sd->status.name != NULL)
  10072. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10073. sd->status.account_id, sd->status.char_id, sd->status.name);
  10074. else
  10075. printf("\nAccount ID %d.\n", sd->bl.id);
  10076. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10077. printf("\nAccount ID %d.\n", sd->bl.id);
  10078. }
  10079. RFIFOSKIP(fd, packet_len);
  10080. return 0;
  10081. }
  10082. /*==========================================
  10083. * パケットデータベース読み込み
  10084. *------------------------------------------
  10085. */
  10086. static int packetdb_readdb(void)
  10087. {
  10088. FILE *fp;
  10089. char line[1024];
  10090. int ln=0;
  10091. int cmd,i,j,k,packet_ver;
  10092. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10093. struct {
  10094. void (*func)(int, struct map_session_data *);
  10095. char *name;
  10096. } clif_parse_func[]={
  10097. {clif_parse_WantToConnection,"wanttoconnection"},
  10098. {clif_parse_LoadEndAck,"loadendack"},
  10099. {clif_parse_TickSend,"ticksend"},
  10100. {clif_parse_WalkToXY,"walktoxy"},
  10101. {clif_parse_QuitGame,"quitgame"},
  10102. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10103. {clif_parse_GlobalMessage,"globalmessage"},
  10104. {clif_parse_MapMove,"mapmove"},
  10105. {clif_parse_ChangeDir,"changedir"},
  10106. {clif_parse_Emotion,"emotion"},
  10107. {clif_parse_HowManyConnections,"howmanyconnections"},
  10108. {clif_parse_ActionRequest,"actionrequest"},
  10109. {clif_parse_Restart,"restart"},
  10110. {clif_parse_Wis,"wis"},
  10111. {clif_parse_GMmessage,"gmmessage"},
  10112. {clif_parse_TakeItem,"takeitem"},
  10113. {clif_parse_DropItem,"dropitem"},
  10114. {clif_parse_UseItem,"useitem"},
  10115. {clif_parse_EquipItem,"equipitem"},
  10116. {clif_parse_UnequipItem,"unequipitem"},
  10117. {clif_parse_NpcClicked,"npcclicked"},
  10118. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10119. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10120. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10121. {clif_parse_CreateChatRoom,"createchatroom"},
  10122. {clif_parse_ChatAddMember,"chataddmember"},
  10123. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10124. {clif_parse_ChangeChatOwner,"changechatowner"},
  10125. {clif_parse_KickFromChat,"kickfromchat"},
  10126. {clif_parse_ChatLeave,"chatleave"},
  10127. {clif_parse_TradeRequest,"traderequest"},
  10128. {clif_parse_TradeAck,"tradeack"},
  10129. {clif_parse_TradeAddItem,"tradeadditem"},
  10130. {clif_parse_TradeOk,"tradeok"},
  10131. {clif_parse_TradeCancel,"tradecancel"},
  10132. {clif_parse_TradeCommit,"tradecommit"},
  10133. {clif_parse_StopAttack,"stopattack"},
  10134. {clif_parse_PutItemToCart,"putitemtocart"},
  10135. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10136. {clif_parse_RemoveOption,"removeoption"},
  10137. {clif_parse_ChangeCart,"changecart"},
  10138. {clif_parse_StatusUp,"statusup"},
  10139. {clif_parse_SkillUp,"skillup"},
  10140. {clif_parse_UseSkillToId,"useskilltoid"},
  10141. {clif_parse_UseSkillToPos,"useskilltopos"},
  10142. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10143. {clif_parse_UseSkillMap,"useskillmap"},
  10144. {clif_parse_RequestMemo,"requestmemo"},
  10145. {clif_parse_ProduceMix,"producemix"},
  10146. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10147. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10148. {clif_parse_NpcAmountInput,"npcamountinput"},
  10149. {clif_parse_NpcStringInput,"npcstringinput"},
  10150. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10151. {clif_parse_ItemIdentify,"itemidentify"},
  10152. {clif_parse_SelectArrow,"selectarrow"},
  10153. {clif_parse_AutoSpell,"autospell"},
  10154. {clif_parse_UseCard,"usecard"},
  10155. {clif_parse_InsertCard,"insertcard"},
  10156. {clif_parse_RepairItem,"repairitem"},
  10157. {clif_parse_WeaponRefine,"weaponrefine"},
  10158. {clif_parse_SolveCharName,"solvecharname"},
  10159. {clif_parse_ResetChar,"resetchar"},
  10160. {clif_parse_LGMmessage,"lgmmessage"},
  10161. {clif_parse_MoveToKafra,"movetokafra"},
  10162. {clif_parse_MoveFromKafra,"movefromkafra"},
  10163. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10164. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10165. {clif_parse_CloseKafra,"closekafra"},
  10166. {clif_parse_CreateParty,"createparty"},
  10167. {clif_parse_CreateParty2,"createparty2"},
  10168. {clif_parse_PartyInvite,"partyinvite"},
  10169. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10170. {clif_parse_LeaveParty,"leaveparty"},
  10171. {clif_parse_RemovePartyMember,"removepartymember"},
  10172. {clif_parse_PartyChangeOption,"partychangeoption"},
  10173. {clif_parse_PartyMessage,"partymessage"},
  10174. {clif_parse_CloseVending,"closevending"},
  10175. {clif_parse_VendingListReq,"vendinglistreq"},
  10176. {clif_parse_PurchaseReq,"purchasereq"},
  10177. {clif_parse_OpenVending,"openvending"},
  10178. {clif_parse_CreateGuild,"createguild"},
  10179. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10180. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10181. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10182. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10183. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10184. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10185. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10186. {clif_parse_GuildInvite,"guildinvite"},
  10187. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10188. {clif_parse_GuildLeave,"guildleave"},
  10189. {clif_parse_GuildExplusion,"guildexplusion"},
  10190. {clif_parse_GuildMessage,"guildmessage"},
  10191. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10192. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10193. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10194. {clif_parse_GuildOpposition,"guildopposition"},
  10195. {clif_parse_GuildBreak,"guildbreak"},
  10196. {clif_parse_PetMenu,"petmenu"},
  10197. {clif_parse_CatchPet,"catchpet"},
  10198. {clif_parse_SelectEgg,"selectegg"},
  10199. {clif_parse_SendEmotion,"sendemotion"},
  10200. {clif_parse_ChangePetName,"changepetname"},
  10201. {clif_parse_GMKick,"gmkick"},
  10202. {clif_parse_GMHide,"gmhide"},
  10203. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10204. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10205. {clif_parse_NoviceDoriDori,"sndoridori"},
  10206. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10207. {clif_parse_PMIgnore,"wisexin"},
  10208. {clif_parse_PMIgnoreList,"wisexlist"},
  10209. {clif_parse_PMIgnoreAll,"wisall"},
  10210. {clif_parse_FriendsListAdd,"friendslistadd"},
  10211. {clif_parse_FriendsListRemove,"friendslistremove"},
  10212. {clif_parse_FriendsListReply,"friendslistreply"},
  10213. {clif_parse_GMKillAll,"killall"},
  10214. {clif_parse_Recall,"summon"},
  10215. {clif_parse_GM_Monster_Item,"itemmonster"},
  10216. {clif_parse_Shift,"shift"},
  10217. {clif_parse_Blacksmith,"blacksmith"},
  10218. {clif_parse_Alchemist,"alchemist"},
  10219. {clif_parse_Taekwon,"taekwon"},
  10220. {clif_parse_RankingPk,"rankingpk"},
  10221. {clif_parse_FeelSaveOk,"feelsaveok"},
  10222. {clif_parse_AdoptRequest,"adopt"},
  10223. {clif_parse_debug,"debug"},
  10224. {NULL,NULL}
  10225. };
  10226. sprintf(line, "%s/packet_db.txt", db_path);
  10227. if( (fp=fopen(line,"r"))==NULL ){
  10228. ShowFatalError("can't read %s\n", line);
  10229. exit(1);
  10230. }
  10231. clif_config.packet_db_ver = MAX_PACKET_VER;
  10232. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10233. while(fgets(line,1020,fp)){
  10234. if(line[0]=='/' && line[1]=='/')
  10235. continue;
  10236. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10237. if(strcmpi(w1,"packet_ver")==0) {
  10238. int prev_ver = packet_ver;
  10239. packet_ver = atoi(w2);
  10240. if (packet_ver > MAX_PACKET_VER)
  10241. { //Check to avoid overflowing. [Skotlex]
  10242. ShowWarning("The packet_db table only has support up to version %d\n", MAX_PACKET_VER);
  10243. break;
  10244. }
  10245. // copy from previous version into new version and continue
  10246. // - indicating all following packets should be read into the newer version
  10247. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10248. continue;
  10249. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10250. //This is the preferred version.
  10251. if(strcmpi(w2,"default")==0)
  10252. clif_config.packet_db_ver = MAX_PACKET_VER;
  10253. else {
  10254. // to manually set the packet DB version
  10255. clif_config.packet_db_ver = atoi(w2);
  10256. // check for invalid version
  10257. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10258. clif_config.packet_db_ver < 0)
  10259. clif_config.packet_db_ver = MAX_PACKET_VER;
  10260. }
  10261. continue;
  10262. }
  10263. }
  10264. memset(str,0,sizeof(str));
  10265. for(j=0,p=line;j<4 && p;j++){
  10266. str[j]=p;
  10267. p=strchr(p,',');
  10268. if(p) *p++=0;
  10269. }
  10270. if(str[0]==NULL)
  10271. continue;
  10272. cmd=strtol(str[0],(char **)NULL,0);
  10273. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10274. continue;
  10275. if(str[1]==NULL){
  10276. ShowError("packet_db: packet len error\n");
  10277. continue;
  10278. }
  10279. k = atoi(str[1]);
  10280. packet_db[packet_ver][cmd].len = k;
  10281. if(str[2]==NULL){
  10282. packet_db[packet_ver][cmd].func = NULL;
  10283. ln++;
  10284. continue;
  10285. }
  10286. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10287. if(clif_parse_func[j].name != NULL &&
  10288. strcmp(str[2],clif_parse_func[j].name)==0)
  10289. {
  10290. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10291. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10292. for(i=0;i<MAX_PACKET_DB;i++){
  10293. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10294. {
  10295. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10296. break;
  10297. }
  10298. }
  10299. }
  10300. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10301. break;
  10302. }
  10303. }
  10304. // set the identifying cmd for the packet_db version
  10305. if (strcmp(str[2],"wanttoconnection")==0)
  10306. clif_config.connect_cmd[packet_ver] = cmd;
  10307. if(str[3]==NULL){
  10308. ShowError("packet_db: packet error\n");
  10309. exit(1);
  10310. }
  10311. for(j=0,p2=str[3];p2;j++){
  10312. str2[j]=p2;
  10313. p2=strchr(p2,':');
  10314. if(p2) *p2++=0;
  10315. k = atoi(str2[j]);
  10316. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10317. packet_db[packet_ver][cmd].pos[j] = k;
  10318. }
  10319. ln++;
  10320. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10321. // 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);
  10322. }
  10323. fclose(fp);
  10324. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10325. { //Locate the nearest version that we still support. [Skotlex]
  10326. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10327. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10328. }
  10329. 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);
  10330. return 0;
  10331. }
  10332. /*==========================================
  10333. *
  10334. *------------------------------------------
  10335. */
  10336. int do_init_clif(void) {
  10337. #ifndef __WIN32
  10338. int i;
  10339. #endif
  10340. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10341. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10342. memset(packet_db,0,sizeof(packet_db));
  10343. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10344. packetdb_readdb();
  10345. set_defaultparse(clif_parse);
  10346. #ifdef __WIN32
  10347. //if (!make_listen_port(map_port)) {
  10348. if (!make_listen_bind(bind_ip,map_port)) {
  10349. ShowFatalError("cant bind game port\n");
  10350. exit(1);
  10351. }
  10352. #else
  10353. for(i = 0; i < 10; i++) {
  10354. //if (make_listen_port(map_port))
  10355. if (make_listen_bind(bind_ip,map_port))
  10356. break;
  10357. sleep(20);
  10358. }
  10359. if (i == 10) {
  10360. ShowFatalError("cant bind game port\n");
  10361. exit(1);
  10362. }
  10363. #endif
  10364. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10365. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10366. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10367. add_timer_func_list(clif_nighttimer, "clif_nighttimer");
  10368. add_timer_func_list(clif_walktoxy_timer, "clif_walktoxy_timer");
  10369. return 0;
  10370. }