clif.c 316 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631
  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 = aCalloc(1, 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. unsigned char buf[16];
  676. WBUFW(buf,0) = 0x80;
  677. WBUFL(buf,2) = id;
  678. WBUFB(buf,6) = type;
  679. WFIFOHEAD(fd, packet_len_table[0x80]);
  680. memcpy(WFIFOP(fd,0), buf, 7);
  681. WFIFOSET(fd, packet_len_table[0x80]);
  682. return 0;
  683. }
  684. void clif_get_weapon_view(TBL_PC* sd, short *rhand, short *lhand)
  685. {
  686. #if PACKETVER > 3
  687. struct item_data *id;
  688. #endif
  689. if (sd->vd.class_ == JOB_XMAS || sd->vd.class_ == JOB_WEDDING)
  690. {
  691. *rhand = *lhand = 0;
  692. return;
  693. }
  694. #if PACKETVER < 4
  695. *rhand = sd->status.weapon;
  696. *lhand = sd->status.shield;
  697. #else
  698. if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]])
  699. {
  700. id = sd->inventory_data[sd->equip_index[9]];
  701. if (id->view_id > 0)
  702. *rhand = id->view_id;
  703. else
  704. *rhand = id->nameid;
  705. } else
  706. *rhand = 0;
  707. if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
  708. && sd->inventory_data[sd->equip_index[8]])
  709. {
  710. id = sd->inventory_data[sd->equip_index[8]];
  711. if (id->view_id > 0)
  712. *lhand = id->view_id;
  713. else
  714. *lhand = id->nameid;
  715. } else
  716. *lhand = 0;
  717. #endif
  718. }
  719. static void clif_get_guild_data(struct block_list *bl, long *guild_id, short *emblem_id)
  720. {
  721. //TODO: There has to be a way to clean this up.
  722. switch (bl->type) {
  723. case BL_PC:
  724. *guild_id = ((TBL_PC*)bl)->status.guild_id;
  725. *emblem_id = ((TBL_PC*)bl)->guild_emblem_id;
  726. break;
  727. case BL_MOB:
  728. if (((TBL_MOB*)bl)->guardian_data) {
  729. *guild_id =((TBL_MOB*)bl)->guardian_data->guild_id;
  730. *emblem_id =((TBL_MOB*)bl)->guardian_data->emblem_id;
  731. }
  732. break;
  733. case BL_NPC:
  734. if (bl->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) {
  735. struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id);
  736. if (g) {
  737. *guild_id =g->guild_id;
  738. *emblem_id =g->emblem_id;
  739. }
  740. }
  741. break;
  742. default:
  743. *guild_id = status_get_guild_id(bl);
  744. }
  745. return;
  746. }
  747. /*==========================================
  748. *
  749. *------------------------------------------
  750. */
  751. static int clif_set0078(struct block_list *bl, struct view_data *vd, unsigned char *buf) {
  752. struct status_change *sc;
  753. struct map_session_data *sd;
  754. long guild_id=0;
  755. unsigned short emblem_id=0, lv;
  756. unsigned short dir;
  757. nullpo_retr(0, bl);
  758. BL_CAST(BL_PC, bl, sd);
  759. sc = status_get_sc(bl);
  760. clif_get_guild_data(bl, &guild_id, &emblem_id);
  761. dir = unit_getdir(bl);
  762. lv = status_get_lv(bl);
  763. if(pcdb_checkid(vd->class_)) {
  764. #if PACKETVER > 3
  765. memset(buf,0,packet_len_table[0x1d8]);
  766. WBUFW(buf,0)=0x1d8;
  767. WBUFL(buf,2)=bl->id;
  768. WBUFW(buf,6)=status_get_speed(bl);
  769. if (sc) {
  770. WBUFW(buf,8)=sc->opt1;
  771. WBUFW(buf,10)=sc->opt2;
  772. WBUFW(buf,12)=sc->option;
  773. WBUFW(buf,42)=sc->opt3;
  774. }
  775. WBUFW(buf,14)=vd->class_;
  776. WBUFW(buf,16)=vd->hair_style;
  777. WBUFW(buf,18)=vd->weapon;
  778. WBUFW(buf,20)=vd->shield;
  779. WBUFW(buf,22)=vd->head_bottom;
  780. WBUFW(buf,24)=vd->head_top;
  781. WBUFW(buf,26)=vd->head_mid;
  782. WBUFW(buf,28)=vd->hair_color;
  783. WBUFW(buf,30)=vd->cloth_color;
  784. WBUFW(buf,32)=sd?sd->head_dir:dir;
  785. WBUFL(buf,34)=guild_id;
  786. WBUFL(buf,38)=emblem_id;
  787. if (sd) {
  788. WBUFW(buf,40)=sd->status.manner;
  789. WBUFB(buf,44)=sd->status.karma;
  790. }
  791. WBUFB(buf,45)=vd->sex;
  792. WBUFPOS(buf,46,bl->x,bl->y);
  793. WBUFB(buf,48)|=dir & 0x0f;
  794. WBUFB(buf,49)=5;
  795. WBUFB(buf,50)=5;
  796. WBUFB(buf,51)=vd->dead_sit;
  797. WBUFW(buf,52)=clif_setlevel(lv);
  798. return packet_len_table[0x1d8];
  799. #else
  800. memset(buf,0,packet_len_table[0x78]);
  801. WBUFW(buf,0)=0x78;
  802. WBUFL(buf,2)=bl->id;
  803. WBUFW(buf,6)=status_get_speed(bl);
  804. if (sc) {
  805. WBUFW(buf,8)=sc->opt1;
  806. WBUFW(buf,10)=sc->opt2;
  807. WBUFW(buf,12)=sc->option;
  808. }
  809. WBUFW(buf,14)=vd->class_;
  810. WBUFW(buf,16)=vd->hair_style;
  811. WBUFW(buf,18)=vd->weapon;
  812. WBUFW(buf,20)=vd->head_bottom;
  813. WBUFW(buf,22)=vd->shield;
  814. WBUFW(buf,24)=vd->head_top;
  815. WBUFW(buf,26)=vd->head_mid;
  816. WBUFW(buf,28)=vd->hair_color;
  817. WBUFW(buf,30)=vd->cloth_color;
  818. WBUFW(buf,32)=sd?sd->head_dir:dir;
  819. WBUFL(buf,34)=guild_id;
  820. WBUFL(buf,38)=emblem_id;
  821. if (sd) {
  822. WBUFW(buf,42)=sd->status.manner;
  823. WBUFB(buf,44)=sd->status.karma;
  824. }
  825. WBUFB(buf,45)=vd->sex;
  826. WBUFPOS(buf,46,bl->x,bl->y);
  827. WBUFB(buf,48)|=dir&0x0f;
  828. WBUFB(buf,49)=5;
  829. WBUFB(buf,50)=5;
  830. WBUFB(buf,51)=vd->dead_sit;
  831. WBUFW(buf,52)=clif_setlevel(lv);
  832. return packet_len_table[0x78];
  833. #endif
  834. }
  835. //Non-player sprites need just a few fields filled.
  836. memset(buf,0,packet_len_table[0x78]);
  837. WBUFW(buf,0)=0x78;
  838. WBUFL(buf,2)=bl->id;
  839. WBUFW(buf,6)=status_get_speed(bl);
  840. if (sc) {
  841. WBUFW(buf,8)=sc->opt1;
  842. WBUFW(buf,10)=sc->opt2;
  843. WBUFW(buf,12)=sc->option;
  844. }
  845. WBUFW(buf,14)=vd->class_;
  846. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  847. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  848. if (bl->type == BL_NPC && vd->class_ == 722)
  849. { //The hell, why flags work like this?
  850. WBUFL(buf,22)=emblem_id;
  851. WBUFL(buf,26)=guild_id;
  852. }
  853. WBUFW(buf,32)=dir;
  854. WBUFL(buf,34)=guild_id;
  855. WBUFL(buf,38)=emblem_id;
  856. WBUFPOS(buf,46,bl->x,bl->y);
  857. WBUFB(buf,48)|=dir&0x0f;
  858. WBUFB(buf,49)=5;
  859. WBUFB(buf,50)=5;
  860. WBUFW(buf,52)=clif_setlevel(lv);
  861. return packet_len_table[0x78];
  862. }
  863. /*==========================================
  864. *
  865. *------------------------------------------
  866. */
  867. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf) {
  868. struct status_change *sc;
  869. struct map_session_data *sd;
  870. long guild_id=0;
  871. unsigned short emblem_id=0, lv;
  872. nullpo_retr(0, bl);
  873. BL_CAST(BL_PC, bl, sd);
  874. sc = status_get_sc(bl);
  875. clif_get_guild_data(bl, &guild_id, &emblem_id);
  876. lv = status_get_lv(bl);
  877. if(pcdb_checkid(vd->class_)) {
  878. #if PACKETVER > 6
  879. //Packet 0x22c, still in construction. [Skotlex]
  880. memset(buf,0,packet_len_table[0x22c]);
  881. WBUFW(buf,0)=0x22c;
  882. WBUFL(buf,2)=bl->id;
  883. WBUFW(buf,6)=status_get_speed(bl);
  884. if (sc) {
  885. WBUFW(buf,8)= sc->opt1;
  886. WBUFW(buf,10)= sc->opt2;
  887. WBUFL(buf,12)= sc->option;
  888. WBUFL(buf,48)= sc->opt3;
  889. }
  890. WBUFW(buf,16)=vd->class_;
  891. WBUFW(buf,18)=vd->hair_style;
  892. WBUFW(buf,20)=vd->weapon;
  893. WBUFW(buf,22)=vd->shield;
  894. WBUFW(buf,24)=vd->head_bottom;
  895. WBUFL(buf,26)=gettick();
  896. WBUFW(buf,30)=vd->head_top;
  897. WBUFW(buf,32)=vd->head_mid;
  898. WBUFW(buf,34)=vd->hair_color;
  899. WBUFW(buf,36)=vd->cloth_color;
  900. WBUFW(buf,38)=sd?sd->head_dir:unit_getdir(bl);
  901. WBUFL(buf,40)=guild_id;
  902. WBUFW(buf,44)=emblem_id;
  903. if (sd) {
  904. WBUFW(buf,46)=sd->status.manner;
  905. WBUFB(buf,52)=sd->status.karma;
  906. }
  907. WBUFB(buf,53)=vd->sex;
  908. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  909. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  910. WBUFB(buf,60)=0;
  911. WBUFB(buf,61)=0;
  912. WBUFW(buf,62)=clif_setlevel(lv);
  913. return packet_len_table[0x22c];
  914. #elif PACKETVER > 3
  915. memset(buf,0,packet_len_table[0x1da]);
  916. WBUFW(buf,0)=0x1da;
  917. WBUFL(buf,2)=bl->id;
  918. WBUFW(buf,6)=status_get_speed(bl);
  919. if (sc) {
  920. WBUFW(buf,8)=sc->opt1;
  921. WBUFW(buf,10)=sc->opt2;
  922. WBUFW(buf,12)=sc->option;
  923. WBUFW(buf,46)=sc->opt3;
  924. }
  925. WBUFW(buf,14)=vd->class_;
  926. WBUFW(buf,16)=vd->hair_style;
  927. WBUFW(buf,18)=vd->weapon;
  928. WBUFW(buf,20)=vd->shield;
  929. WBUFW(buf,22)=vd->head_bottom;
  930. WBUFL(buf,24)=gettick();
  931. WBUFW(buf,28)=vd->head_top;
  932. WBUFW(buf,30)=vd->head_mid;
  933. WBUFW(buf,32)=vd->hair_color;
  934. WBUFW(buf,34)=vd->cloth_color;
  935. WBUFW(buf,36)=sd?sd->head_dir:unit_getdir(bl);
  936. WBUFL(buf,38)=guild_id;
  937. WBUFW(buf,42)=emblem_id;
  938. if (sd) {
  939. WBUFW(buf,44)=sd->status.manner;
  940. WBUFB(buf,48)=sd->status.karma;
  941. }
  942. WBUFB(buf,49)=vd->sex;
  943. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  944. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  945. WBUFB(buf,56)=5;
  946. WBUFB(buf,57)=5;
  947. WBUFW(buf,58)=clif_setlevel(lv);
  948. return packet_len_table[0x1da];
  949. #else
  950. memset(buf,0,packet_len_table[0x7b]);
  951. WBUFW(buf,0)=0x7b;
  952. WBUFL(buf,2)=bl->id;
  953. WBUFW(buf,6)=status_get_speed(bl);
  954. if (sc) {
  955. WBUFW(buf,8)=sc->opt1;
  956. WBUFW(buf,10)=sc->opt2;
  957. WBUFW(buf,12)=sc->option;
  958. WBUFW(buf,46)=sc->opt3;
  959. }
  960. WBUFW(buf,14)=vd->class_;
  961. WBUFW(buf,16)=vd->hair_style;
  962. WBUFW(buf,18)=vd->weapon;
  963. WBUFW(buf,20)=vd->head_bottom;
  964. WBUFL(buf,22)=gettick();
  965. WBUFW(buf,26)=vd->shield;
  966. WBUFW(buf,28)=vd->head_top;
  967. WBUFW(buf,30)=vd->head_mid;
  968. WBUFW(buf,32)=vd->hair_color;
  969. WBUFW(buf,34)=vd->cloth_color;
  970. WBUFW(buf,36)=sd?sd->head_dir:unit_getdir(bl);
  971. WBUFL(buf,38)=guild_id;
  972. WBUFL(buf,42)=emblem_id;
  973. if (sd)
  974. WBUFB(buf,48)=sd->status.karma;
  975. WBUFB(buf,49)=vd->sex;
  976. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  977. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  978. WBUFB(buf,56)=5;
  979. WBUFB(buf,57)=5;
  980. WBUFW(buf,58)=clif_setlevel(lv);
  981. return packet_len_table[0x7b];
  982. #endif
  983. }
  984. //Non-player sprites only require a few fields.
  985. memset(buf,0,packet_len_table[0x7b]);
  986. WBUFW(buf,0)=0x7b;
  987. WBUFL(buf,2)=bl->id;
  988. WBUFW(buf,6)=status_get_speed(bl);
  989. if (sc) {
  990. WBUFW(buf,8)=sc->opt1;
  991. WBUFW(buf,10)=sc->opt2;
  992. WBUFW(buf,12)=sc->option;
  993. WBUFW(buf,46)=sc->opt3;
  994. }
  995. WBUFW(buf,14)=vd->class_;
  996. WBUFW(buf,16)=vd->hair_style; //For pets
  997. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  998. WBUFL(buf,22)=gettick();
  999. WBUFW(buf,36)=unit_getdir(bl);
  1000. WBUFL(buf,38)=guild_id;
  1001. WBUFL(buf,42)=emblem_id;
  1002. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1003. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1004. WBUFB(buf,56)=5;
  1005. WBUFB(buf,57)=5;
  1006. WBUFW(buf,58)=clif_setlevel(lv);
  1007. return packet_len_table[0x7b];
  1008. }
  1009. //Modifies the buffer for disguise characters and sends it to self.
  1010. //Flag = 0: change id to negative, buf will have disguise data.
  1011. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1012. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1013. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag) {
  1014. if (flag) {
  1015. WBUFL(buf,2)=sd->bl.id;
  1016. WBUFW(buf,12)=OPTION_INVISIBLE;
  1017. WBUFW(buf,14)=sd->status.class_;
  1018. } else {
  1019. WBUFL(buf,2)=-sd->bl.id;
  1020. }
  1021. clif_send(buf, len, &sd->bl, SELF);
  1022. }
  1023. /*==========================================
  1024. * クラスチェンジ typeはMobの場合は1で他は0?
  1025. *------------------------------------------
  1026. */
  1027. int clif_class_change(struct block_list *bl,int class_,int type)
  1028. {
  1029. unsigned char buf[16];
  1030. nullpo_retr(0, bl);
  1031. if(!pcdb_checkid(class_)) {
  1032. WBUFW(buf,0)=0x1b0;
  1033. WBUFL(buf,2)=bl->id;
  1034. WBUFB(buf,6)=type;
  1035. WBUFL(buf,7)=class_;
  1036. clif_send(buf,packet_len_table[0x1b0],bl,AREA);
  1037. }
  1038. return 0;
  1039. }
  1040. /*==========================================
  1041. *
  1042. *------------------------------------------
  1043. */
  1044. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1045. {
  1046. WFIFOHEAD(fd, packet_len_table[0x1e1]);
  1047. WFIFOW(fd,0)=0x1e1;
  1048. WFIFOL(fd,2)=sd->bl.id;
  1049. WFIFOW(fd,6)=sd->spiritball;
  1050. WFIFOSET(fd, packet_len_table[0x1e1]);
  1051. }
  1052. /*==========================================
  1053. *
  1054. *------------------------------------------
  1055. */
  1056. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1057. WFIFOHEAD(fd, packet_len_table[0x192]);
  1058. WFIFOW(fd,0) = 0x192;
  1059. WFIFOW(fd,2) = x;
  1060. WFIFOW(fd,4) = y;
  1061. WFIFOW(fd,6) = type;
  1062. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1063. WFIFOSET(fd,packet_len_table[0x192]);
  1064. return 0;
  1065. }
  1066. /*==========================================
  1067. *
  1068. *------------------------------------------
  1069. */
  1070. static void clif_weather_check(struct map_session_data *sd) {
  1071. int m = sd->bl.m, fd = sd->fd;
  1072. if (map[m].flag.snow
  1073. || map[m].flag.clouds
  1074. || map[m].flag.fog
  1075. || map[m].flag.fireworks
  1076. || map[m].flag.sakura
  1077. || map[m].flag.leaves
  1078. || map[m].flag.rain
  1079. || map[m].flag.clouds2)
  1080. {
  1081. WFIFOHEAD(fd, packet_len_table[0x7c]);
  1082. WFIFOW(fd,0)=0x7c;
  1083. WFIFOL(fd,2)=-10;
  1084. WFIFOW(fd,6)=0;
  1085. WFIFOW(fd,8)=0;
  1086. WFIFOW(fd,10)=0;
  1087. WFIFOW(fd,12)=OPTION_INVISIBLE;
  1088. WFIFOW(fd,20)=100;
  1089. WFIFOPOS(fd,36,sd->bl.x,sd->bl.y);
  1090. WFIFOSET(fd,packet_len_table[0x7c]);
  1091. if (map[m].flag.snow)
  1092. clif_weather_sub(fd, 162);
  1093. if (map[m].flag.clouds)
  1094. clif_weather_sub(fd, 233);
  1095. if (map[m].flag.clouds2)
  1096. clif_weather_sub(fd, 516);
  1097. if (map[m].flag.fog)
  1098. clif_weather_sub(fd, 515);
  1099. if (map[m].flag.fireworks) {
  1100. clif_weather_sub(fd, 297);
  1101. clif_weather_sub(fd, 299);
  1102. clif_weather_sub(fd, 301);
  1103. }
  1104. if (map[m].flag.sakura)
  1105. clif_weather_sub(fd, 163);
  1106. if (map[m].flag.leaves)
  1107. clif_weather_sub(fd, 333);
  1108. if (map[m].flag.rain)
  1109. clif_weather_sub(fd, 161);
  1110. }
  1111. }
  1112. // new and improved weather display [Valaris]
  1113. int clif_weather_sub(int fd, int type) {
  1114. WFIFOHEAD(fd, packet_len_table[0x1f3]);
  1115. WFIFOW(fd,0) = 0x1f3;
  1116. WFIFOL(fd,2) = -10;
  1117. WFIFOL(fd,6) = type;
  1118. WFIFOSET(fd,packet_len_table[0x1f3]);
  1119. return 0;
  1120. }
  1121. int clif_weather(int m) {
  1122. int i;
  1123. struct map_session_data *sd=NULL;
  1124. for(i = 0; i < fd_max; i++) {
  1125. if (session[i] && (sd = session[i]->session_data) != NULL && sd->state.auth && sd->bl.m == m) {
  1126. WFIFOHEAD(sd->fd, packet_len_table[0x80]);
  1127. WFIFOW(sd->fd,0) = 0x80;
  1128. WFIFOL(sd->fd,2) = -10;
  1129. WFIFOB(sd->fd,6) = 0;
  1130. WFIFOSET(sd->fd,packet_len_table[0x80]);
  1131. clif_weather_check(sd);
  1132. }
  1133. }
  1134. return 0;
  1135. }
  1136. int clif_spawn(struct block_list *bl)
  1137. {
  1138. unsigned char buf[128];
  1139. struct view_data *vd;
  1140. nullpo_retr(0, bl);
  1141. vd = status_get_viewdata(bl);
  1142. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1143. return 0;
  1144. if (pcdb_checkid(vd->class_))
  1145. { //Player spawn packet.
  1146. clif_set0078(bl, vd, buf);
  1147. #if PACKETVER > 3
  1148. if (WBUFW(buf,0)==0x78) {
  1149. WBUFW(buf, 0) = 0x79;
  1150. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1151. clif_send(buf, packet_len_table[0x79], bl, AREA_WOS);
  1152. if (disguised(bl))
  1153. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x79], 0);
  1154. } else {
  1155. #endif
  1156. WBUFW(buf, 0) = 0x1d9;
  1157. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1158. clif_send(buf, packet_len_table[0x1d9], bl, AREA_WOS);
  1159. if (disguised(bl))
  1160. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x1d9], 0);
  1161. #if PACKETVER > 3
  1162. }
  1163. #endif
  1164. } else { //Mob spawn packet.
  1165. struct status_change *sc = status_get_sc(bl);
  1166. WBUFW(buf,0)=0x7c;
  1167. WBUFL(buf,2)=bl->id;
  1168. WBUFW(buf,6)=status_get_speed(bl);
  1169. WBUFW(buf,8)=sc?sc->opt1:0;
  1170. WBUFW(buf,10)=sc?sc->opt2:0;
  1171. WBUFW(buf,12)=sc?sc->option:0;
  1172. WBUFW(buf,20)=vd->class_;
  1173. WBUFPOS(buf,36,bl->x,bl->y);
  1174. clif_send(buf,packet_len_table[0x7c],bl,AREA_WOS);
  1175. if (disguised(bl)) {
  1176. WBUFL(buf,2)=-bl->id;
  1177. clif_send(buf,packet_len_table[0x7c],bl,SELF);
  1178. }
  1179. }
  1180. if (vd->cloth_color)
  1181. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1182. switch (bl->type)
  1183. {
  1184. case BL_PC:
  1185. {
  1186. TBL_PC *sd = ((TBL_PC*)bl);
  1187. if (sd->spiritball > 0)
  1188. clif_spiritball(sd);
  1189. if(sd->state.size==2) // tiny/big players [Valaris]
  1190. clif_specialeffect(bl,423,0);
  1191. else if(sd->state.size==1)
  1192. clif_specialeffect(bl,421,0);
  1193. }
  1194. break;
  1195. case BL_MOB:
  1196. {
  1197. TBL_MOB *md = ((TBL_MOB*)bl);
  1198. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1199. clif_specialeffect(&md->bl,423,0);
  1200. else if(md->special_state.size==1)
  1201. clif_specialeffect(&md->bl,421,0);
  1202. }
  1203. break;
  1204. }
  1205. return 0;
  1206. }
  1207. /*==========================================
  1208. *
  1209. *------------------------------------------
  1210. */
  1211. int clif_servertick(struct map_session_data *sd)
  1212. {
  1213. int fd;
  1214. nullpo_retr(0, sd);
  1215. fd=sd->fd;
  1216. WFIFOHEAD(fd, packet_len_table[0x7f]);
  1217. WFIFOW(fd,0)=0x7f;
  1218. WFIFOL(fd,2)=sd->server_tick;
  1219. WFIFOSET(fd,packet_len_table[0x7f]);
  1220. return 0;
  1221. }
  1222. /*==========================================
  1223. *
  1224. *------------------------------------------
  1225. */
  1226. int clif_walkok(struct map_session_data *sd)
  1227. {
  1228. int fd;
  1229. nullpo_retr(0, sd);
  1230. fd=sd->fd;
  1231. WFIFOHEAD(fd, packet_len_table[0x87]);
  1232. WFIFOW(fd,0)=0x87;
  1233. WFIFOL(fd,2)=gettick();
  1234. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1235. WFIFOB(fd,11)=0x88;
  1236. WFIFOSET(fd,packet_len_table[0x87]);
  1237. return 0;
  1238. }
  1239. /*==========================================
  1240. *
  1241. *------------------------------------------
  1242. */
  1243. int clif_movepc(struct map_session_data *sd) {
  1244. unsigned char buf[256];
  1245. nullpo_retr(0, sd);
  1246. if (map[sd->bl.m].flag.snow
  1247. || map[sd->bl.m].flag.clouds
  1248. || map[sd->bl.m].flag.fog
  1249. || map[sd->bl.m].flag.fireworks
  1250. || map[sd->bl.m].flag.sakura
  1251. || map[sd->bl.m].flag.leaves
  1252. || map[sd->bl.m].flag.rain
  1253. || map[sd->bl.m].flag.clouds2
  1254. ) {
  1255. memset(buf,0,packet_len_table[0x7b]);
  1256. WBUFW(buf,0)=0x7b;
  1257. WBUFL(buf,2)=-10;
  1258. WBUFW(buf,6)=sd->speed;
  1259. WBUFW(buf,8)=0;
  1260. WBUFW(buf,10)=0;
  1261. WBUFW(buf,12)=OPTION_INVISIBLE;
  1262. WBUFW(buf,14)=100;
  1263. WBUFL(buf,22)=gettick();
  1264. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1265. WBUFB(buf,56)=5;
  1266. WBUFB(buf,57)=5;
  1267. clif_send(buf, packet_len_table[0x7b], &sd->bl, SELF);
  1268. }
  1269. return 0;
  1270. }
  1271. /*==========================================
  1272. *
  1273. *------------------------------------------
  1274. */
  1275. int clif_move(struct block_list *bl) {
  1276. struct view_data *vd;
  1277. struct unit_data *ud;
  1278. unsigned char buf[256];
  1279. int len;
  1280. nullpo_retr(0, bl);
  1281. vd = status_get_viewdata(bl);
  1282. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1283. return 0;
  1284. ud = unit_bl2ud(bl);
  1285. nullpo_retr(0, ud);
  1286. len = clif_set007b(bl,vd,ud,buf);
  1287. clif_send(buf,len,bl,AREA_WOS);
  1288. if (disguised(bl))
  1289. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1290. //Stupid client that needs this resent every time someone walks :X
  1291. if(vd->cloth_color)
  1292. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1293. switch(bl->type)
  1294. {
  1295. case BL_PC:
  1296. {
  1297. TBL_PC *sd = ((TBL_PC*)bl);
  1298. clif_movepc(sd);
  1299. if(sd->state.size==2) // tiny/big players [Valaris]
  1300. clif_specialeffect(&sd->bl,423,0);
  1301. else if(sd->state.size==1)
  1302. clif_specialeffect(&sd->bl,421,0);
  1303. }
  1304. break;
  1305. case BL_MOB:
  1306. {
  1307. TBL_MOB *md = ((TBL_MOB*)bl);
  1308. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1309. clif_specialeffect(&md->bl,423,0);
  1310. else if(md->special_state.size==1)
  1311. clif_specialeffect(&md->bl,421,0);
  1312. }
  1313. break;
  1314. }
  1315. return 0;
  1316. }
  1317. /*==========================================
  1318. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1319. *------------------------------------------
  1320. */
  1321. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1322. struct map_session_data *sd = NULL;
  1323. if (chrif_isconnect())
  1324. { //Remove player from map server
  1325. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1326. map_quit(sd);
  1327. } else //Save later.
  1328. add_timer(tick + 10000, clif_delayquit, id, 0);
  1329. return 0;
  1330. }
  1331. /*==========================================
  1332. *
  1333. *------------------------------------------
  1334. */
  1335. void clif_quitsave(int fd,struct map_session_data *sd)
  1336. {
  1337. if (chrif_isconnect() && (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1338. !battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout))
  1339. map_quit(sd);
  1340. else if (sd->fd)
  1341. { //Disassociate session from player (session is deleted after this function was called)
  1342. //And set a timer to delete this player later.
  1343. session[fd]->session_data = NULL;
  1344. sd->fd = 0;
  1345. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1346. }
  1347. }
  1348. /*==========================================
  1349. *
  1350. *------------------------------------------
  1351. */
  1352. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1353. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1354. session[id]->eof = 1;
  1355. return 0;
  1356. }
  1357. /*==========================================
  1358. *
  1359. *------------------------------------------
  1360. */
  1361. void clif_setwaitclose(int fd) {
  1362. struct map_session_data *sd;
  1363. // if player is not already in the game (double connection probably)
  1364. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1365. // limited timer, just to send information.
  1366. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1367. } else
  1368. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1369. }
  1370. /*==========================================
  1371. *
  1372. *------------------------------------------
  1373. */
  1374. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1375. int fd;
  1376. nullpo_retr(0, sd);
  1377. fd = sd->fd;
  1378. WFIFOHEAD(fd, packet_len_table[0x91]);
  1379. WFIFOW(fd,0) = 0x91;
  1380. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1381. WFIFOW(fd,18) = x;
  1382. WFIFOW(fd,20) = y;
  1383. WFIFOSET(fd, packet_len_table[0x91]);
  1384. if(pc_isdead(sd)) // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  1385. clif_clearchar_area(&sd->bl,1);
  1386. return 0;
  1387. }
  1388. /*==========================================
  1389. *
  1390. *------------------------------------------
  1391. */
  1392. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1393. int fd;
  1394. nullpo_retr(0, sd);
  1395. fd = sd->fd;
  1396. WFIFOHEAD(fd, packet_len_table[0x92]);
  1397. WFIFOW(fd,0) = 0x92;
  1398. //Better not trust the null-terminator is there. [Skotlex]
  1399. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1400. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1401. WFIFOW(fd,18) = x;
  1402. WFIFOW(fd,20) = y;
  1403. WFIFOL(fd,22) = ip;
  1404. WFIFOW(fd,26) = port;
  1405. WFIFOSET(fd, packet_len_table[0x92]);
  1406. return 0;
  1407. }
  1408. int clif_blown(struct block_list *bl) {
  1409. //Previous Aegis versions simply used clif_fixpos, but it seems clif_slide works better on current clients.
  1410. // return clif_fixpos(bl);
  1411. return clif_slide(bl, bl->x, bl->y);
  1412. }
  1413. /*==========================================
  1414. *
  1415. *------------------------------------------
  1416. */
  1417. int clif_fixpos(struct block_list *bl) {
  1418. unsigned char buf[16];
  1419. nullpo_retr(0, bl);
  1420. WBUFW(buf,0)=0x88;
  1421. WBUFL(buf,2)=bl->id;
  1422. WBUFW(buf,6)=bl->x;
  1423. WBUFW(buf,8)=bl->y;
  1424. clif_send(buf, packet_len_table[0x88], bl, AREA);
  1425. if (disguised(bl)) {
  1426. WBUFL(buf,2)=-bl->id;
  1427. clif_send(buf, packet_len_table[0x88], bl, SELF);
  1428. }
  1429. return 0;
  1430. }
  1431. /*==========================================
  1432. *
  1433. *------------------------------------------
  1434. */
  1435. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1436. int fd;
  1437. nullpo_retr(0, sd);
  1438. fd=sd->fd;
  1439. WFIFOHEAD(fd, packet_len_table[0xc4]);
  1440. WFIFOW(fd,0)=0xc4;
  1441. WFIFOL(fd,2)=id;
  1442. WFIFOSET(fd,packet_len_table[0xc4]);
  1443. return 0;
  1444. }
  1445. /*==========================================
  1446. *
  1447. *------------------------------------------
  1448. */
  1449. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1450. struct item_data *id;
  1451. int fd,i,val;
  1452. nullpo_retr(0, sd);
  1453. nullpo_retr(0, nd);
  1454. fd=sd->fd;
  1455. WFIFOHEAD(fd, 200 * 11 + 4);
  1456. WFIFOW(fd,0)=0xc6;
  1457. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1458. id = itemdb_search(nd->u.shop_item[i].nameid);
  1459. val=nd->u.shop_item[i].value;
  1460. WFIFOL(fd,4+i*11)=val;
  1461. if (!id->flag.value_notdc)
  1462. val=pc_modifybuyvalue(sd,val);
  1463. WFIFOL(fd,8+i*11)=val;
  1464. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1465. if (id->view_id > 0)
  1466. WFIFOW(fd,13+i*11)=id->view_id;
  1467. else
  1468. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1469. }
  1470. WFIFOW(fd,2)=i*11+4;
  1471. WFIFOSET(fd,WFIFOW(fd,2));
  1472. return 0;
  1473. }
  1474. /*==========================================
  1475. *
  1476. *------------------------------------------
  1477. */
  1478. int clif_selllist(struct map_session_data *sd) {
  1479. int fd,i,c=0,val;
  1480. nullpo_retr(0, sd);
  1481. fd=sd->fd;
  1482. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1483. WFIFOW(fd,0)=0xc7;
  1484. for(i=0;i<MAX_INVENTORY;i++) {
  1485. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1486. if (!itemdb_cansell(sd->status.inventory[i].nameid, pc_isGM(sd)))
  1487. continue;
  1488. val=sd->inventory_data[i]->value_sell;
  1489. if (val < 0)
  1490. continue;
  1491. WFIFOW(fd,4+c*10)=i+2;
  1492. WFIFOL(fd,6+c*10)=val;
  1493. if (!sd->inventory_data[i]->flag.value_notoc)
  1494. val=pc_modifysellvalue(sd,val);
  1495. WFIFOL(fd,10+c*10)=val;
  1496. c++;
  1497. }
  1498. }
  1499. WFIFOW(fd,2)=c*10+4;
  1500. WFIFOSET(fd,WFIFOW(fd,2));
  1501. return 0;
  1502. }
  1503. /*==========================================
  1504. *
  1505. *------------------------------------------
  1506. */
  1507. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  1508. int fd;
  1509. int slen = strlen(mes) + 9;
  1510. WFIFOHEAD(fd, slen);
  1511. nullpo_retr(0, sd);
  1512. fd=sd->fd;
  1513. WFIFOW(fd,0)=0xb4;
  1514. WFIFOW(fd,2)=slen;
  1515. WFIFOL(fd,4)=npcid;
  1516. strcpy((char*)WFIFOP(fd,8),mes);
  1517. WFIFOSET(fd,WFIFOW(fd,2));
  1518. return 0;
  1519. }
  1520. /*==========================================
  1521. *
  1522. *------------------------------------------
  1523. */
  1524. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  1525. int fd;
  1526. nullpo_retr(0, sd);
  1527. fd=sd->fd;
  1528. WFIFOHEAD(fd, packet_len_table[0xb5]);
  1529. WFIFOW(fd,0)=0xb5;
  1530. WFIFOL(fd,2)=npcid;
  1531. WFIFOSET(fd,packet_len_table[0xb5]);
  1532. return 0;
  1533. }
  1534. /*==========================================
  1535. *
  1536. *------------------------------------------
  1537. */
  1538. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  1539. int fd;
  1540. nullpo_retr(0, sd);
  1541. fd=sd->fd;
  1542. WFIFOHEAD(fd, packet_len_table[0xb6]);
  1543. WFIFOW(fd,0)=0xb6;
  1544. WFIFOL(fd,2)=npcid;
  1545. WFIFOSET(fd,packet_len_table[0xb6]);
  1546. return 0;
  1547. }
  1548. /*==========================================
  1549. *
  1550. *------------------------------------------
  1551. */
  1552. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1553. int fd = sd->fd;
  1554. sd->npc_id = npcid;
  1555. sd->state.using_fake_npc = 1;
  1556. memset(WFIFOP(fd,0), 0, packet_len_table[0x78]);
  1557. WFIFOW(fd,0)=0x78;
  1558. WFIFOL(fd,2)=npcid;
  1559. WFIFOW(fd,14)=111;
  1560. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y);
  1561. WFIFOB(fd,49)=5;
  1562. WFIFOB(fd,50)=5;
  1563. WFIFOSET(fd, packet_len_table[0x78]);
  1564. return;
  1565. }
  1566. /*==========================================
  1567. *
  1568. *------------------------------------------
  1569. */
  1570. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  1571. int fd;
  1572. int slen = strlen(mes) + 8;
  1573. WFIFOHEAD(fd, slen);
  1574. nullpo_retr(0, sd);
  1575. fd=sd->fd;
  1576. WFIFOW(fd,0)=0xb7;
  1577. WFIFOW(fd,2)=slen;
  1578. WFIFOL(fd,4)=npcid;
  1579. strcpy((char*)WFIFOP(fd,8),mes);
  1580. WFIFOSET(fd,WFIFOW(fd,2));
  1581. return 0;
  1582. }
  1583. /*==========================================
  1584. *
  1585. *------------------------------------------
  1586. */
  1587. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  1588. int fd;
  1589. nullpo_retr(0, sd);
  1590. fd=sd->fd;
  1591. WFIFOHEAD(fd, packet_len_table[0x142]);
  1592. WFIFOW(fd,0)=0x142;
  1593. WFIFOL(fd,2)=npcid;
  1594. WFIFOSET(fd,packet_len_table[0x142]);
  1595. return 0;
  1596. }
  1597. /*==========================================
  1598. *
  1599. *------------------------------------------
  1600. */
  1601. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1602. int fd;
  1603. nullpo_retr(0, sd);
  1604. fd=sd->fd;
  1605. WFIFOHEAD(fd, packet_len_table[0x1d4]);
  1606. WFIFOW(fd,0)=0x1d4;
  1607. WFIFOL(fd,2)=npcid;
  1608. WFIFOSET(fd,packet_len_table[0x1d4]);
  1609. return 0;
  1610. }
  1611. /*==========================================
  1612. *
  1613. *------------------------------------------
  1614. */
  1615. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  1616. int fd;
  1617. nullpo_retr(0, sd);
  1618. fd=sd->fd;
  1619. WFIFOHEAD(fd, packet_len_table[0x144]);
  1620. WFIFOW(fd,0)=0x144;
  1621. WFIFOL(fd,2)=npc_id;
  1622. WFIFOL(fd,6)=type;
  1623. WFIFOL(fd,10)=x;
  1624. WFIFOL(fd,14)=y;
  1625. WFIFOB(fd,18)=id;
  1626. WFIFOL(fd,19)=color;
  1627. WFIFOSET(fd,packet_len_table[0x144]);
  1628. return 0;
  1629. }
  1630. /*==========================================
  1631. *
  1632. *------------------------------------------
  1633. */
  1634. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  1635. int fd;
  1636. nullpo_retr(0, sd);
  1637. fd=sd->fd;
  1638. WFIFOHEAD(fd, packet_len_table[0x1b3]);
  1639. WFIFOW(fd,0)=0x1b3;
  1640. strncpy((char*)WFIFOP(fd,2),image,64);
  1641. WFIFOB(fd,66)=type;
  1642. WFIFOSET(fd,packet_len_table[0x1b3]);
  1643. return 0;
  1644. }
  1645. /*==========================================
  1646. * Fills in card data from the given item and into the buffer. [Skotlex]
  1647. *------------------------------------------
  1648. */
  1649. static void clif_addcards(unsigned char* buf, struct item* item)
  1650. {
  1651. int i=0,j;
  1652. if (item == NULL) { //Blank data
  1653. WBUFW(buf,0)=0;
  1654. WBUFW(buf,2)=0;
  1655. WBUFW(buf,4)=0;
  1656. WBUFW(buf,6)=0;
  1657. return;
  1658. }
  1659. if(item->card[0]==(short)0xff00) { //pet eggs
  1660. WBUFW(buf,0)=0;
  1661. WBUFW(buf,2)=0;
  1662. WBUFW(buf,4)=0;
  1663. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1664. return;
  1665. }
  1666. if(item->card[0]==0x00ff || item->card[0]==0x00fe) { //Forged/created items
  1667. WBUFW(buf,0)=item->card[0];
  1668. WBUFW(buf,2)=item->card[1];
  1669. WBUFW(buf,4)=item->card[2];
  1670. WBUFW(buf,6)=item->card[3];
  1671. return;
  1672. }
  1673. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1674. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1675. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1676. //Normal items.
  1677. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1678. WBUFW(buf,0)=j;
  1679. else
  1680. WBUFW(buf,0)= item->card[i];
  1681. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1682. WBUFW(buf,2)=j;
  1683. else
  1684. WBUFW(buf,2)=item->card[i];
  1685. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1686. WBUFW(buf,4)=j;
  1687. else
  1688. WBUFW(buf,4)=item->card[i];
  1689. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1690. WBUFW(buf,6)=j;
  1691. else
  1692. WBUFW(buf,6)=item->card[i];
  1693. }
  1694. /*==========================================
  1695. *
  1696. *------------------------------------------
  1697. */
  1698. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  1699. int fd;
  1700. unsigned char *buf;
  1701. nullpo_retr(0, sd);
  1702. fd = sd->fd;
  1703. if (!session_isActive(fd)) //Sasuke-
  1704. return 0;
  1705. WFIFOHEAD(fd,packet_len_table[0xa0]);
  1706. buf = WFIFOP(fd,0);
  1707. if(fail) {
  1708. WBUFW(buf,0)=0xa0;
  1709. WBUFW(buf,2)=n+2;
  1710. WBUFW(buf,4)=amount;
  1711. WBUFW(buf,6)=0;
  1712. WBUFB(buf,8)=0;
  1713. WBUFB(buf,9)=0;
  1714. WBUFB(buf,10)=0;
  1715. WBUFW(buf,11)=0;
  1716. WBUFW(buf,13)=0;
  1717. WBUFW(buf,15)=0;
  1718. WBUFW(buf,17)=0;
  1719. WBUFW(buf,19)=0;
  1720. WBUFB(buf,21)=0;
  1721. WBUFB(buf,22)=fail;
  1722. } else {
  1723. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1724. return 1;
  1725. WBUFW(buf,0)=0xa0;
  1726. WBUFW(buf,2)=n+2;
  1727. WBUFW(buf,4)=amount;
  1728. if (sd->inventory_data[n]->view_id > 0)
  1729. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  1730. else
  1731. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  1732. WBUFB(buf,8)=sd->status.inventory[n].identify;
  1733. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  1734. WBUFB(buf,10)=sd->status.inventory[n].refine;
  1735. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  1736. WBUFW(buf,19)=pc_equippoint(sd,n);
  1737. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  1738. WBUFB(buf,22)=fail;
  1739. }
  1740. WFIFOSET(fd,packet_len_table[0xa0]);
  1741. return 0;
  1742. }
  1743. /*==========================================
  1744. *
  1745. *------------------------------------------
  1746. */
  1747. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1748. {
  1749. int fd;
  1750. nullpo_retr(0, sd);
  1751. fd=sd->fd;
  1752. WFIFOHEAD(fd, packet_len_table[0xaf]);
  1753. WFIFOW(fd,0)=0xaf;
  1754. WFIFOW(fd,2)=n+2;
  1755. WFIFOW(fd,4)=amount;
  1756. WFIFOSET(fd,packet_len_table[0xaf]);
  1757. return 0;
  1758. }
  1759. /*==========================================
  1760. *
  1761. *------------------------------------------
  1762. */
  1763. int clif_itemlist(struct map_session_data *sd)
  1764. {
  1765. int i,n,fd,arrow=-1;
  1766. unsigned char *buf;
  1767. nullpo_retr(0, sd);
  1768. fd=sd->fd;
  1769. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1770. buf = WFIFOP(fd,0);
  1771. #if PACKETVER < 5
  1772. WBUFW(buf,0)=0xa3;
  1773. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1774. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  1775. continue;
  1776. WBUFW(buf,n*10+4)=i+2;
  1777. if (sd->inventory_data[i]->view_id > 0)
  1778. WBUFW(buf,n*10+6)=sd->inventory_data[i]->view_id;
  1779. else
  1780. WBUFW(buf,n*10+6)=sd->status.inventory[i].nameid;
  1781. WBUFB(buf,n*10+8)=itemtype(sd->inventory_data[i]->type);
  1782. WBUFB(buf,n*10+9)=sd->status.inventory[i].identify;
  1783. WBUFW(buf,n*10+10)=sd->status.inventory[i].amount;
  1784. if (sd->inventory_data[i]->equip == 0x8000) {
  1785. WBUFW(buf,n*10+12)=0x8000;
  1786. if (sd->status.inventory[i].equip)
  1787. arrow=i; // ついでに矢装備チェック
  1788. } else
  1789. WBUFW(buf,n*10+12)=0;
  1790. n++;
  1791. }
  1792. if (n) {
  1793. WBUFW(buf,2)=4+n*10;
  1794. WFIFOSET(fd,WFIFOW(fd,2));
  1795. }
  1796. #else
  1797. WBUFW(buf,0)=0x1ee;
  1798. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1799. if(sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  1800. continue;
  1801. WBUFW(buf,n*18+4)=i+2;
  1802. if(sd->inventory_data[i]->view_id > 0)
  1803. WBUFW(buf,n*18+6)=sd->inventory_data[i]->view_id;
  1804. else
  1805. WBUFW(buf,n*18+6)=sd->status.inventory[i].nameid;
  1806. WBUFB(buf,n*18+8)=itemtype(sd->inventory_data[i]->type);
  1807. WBUFB(buf,n*18+9)=sd->status.inventory[i].identify;
  1808. WBUFW(buf,n*18+10)=sd->status.inventory[i].amount;
  1809. if (sd->inventory_data[i]->equip == 0x8000) {
  1810. WBUFW(buf,n*18+12)=0x8000;
  1811. if(sd->status.inventory[i].equip)
  1812. arrow=i; // ついでに矢装備チェック
  1813. } else
  1814. WBUFW(buf,n*18+12)=0;
  1815. clif_addcards(WBUFP(buf, n*18+14), &sd->status.inventory[i]);
  1816. n++;
  1817. }
  1818. if (n) {
  1819. WBUFW(buf,2)=4+n*18;
  1820. WFIFOSET(fd,WFIFOW(fd,2));
  1821. }
  1822. #endif
  1823. if(arrow >= 0)
  1824. clif_arrowequip(sd,arrow);
  1825. return 0;
  1826. }
  1827. /*==========================================
  1828. *
  1829. *------------------------------------------
  1830. */
  1831. int clif_equiplist(struct map_session_data *sd)
  1832. {
  1833. int i,n,fd;
  1834. nullpo_retr(0, sd);
  1835. fd=sd->fd;
  1836. if (!session_isActive(fd))
  1837. return 0;
  1838. WFIFOHEAD(fd, 4 + MAX_INVENTORY * 20);
  1839. WFIFOW(fd,0)=0xa4;
  1840. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1841. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL || !itemdb_isequip2(sd->inventory_data[i]))
  1842. continue;
  1843. WFIFOW(fd,n*20+4)=i+2;
  1844. if(sd->inventory_data[i]->view_id > 0)
  1845. WFIFOW(fd,n*20+6)=sd->inventory_data[i]->view_id;
  1846. else
  1847. WFIFOW(fd,n*20+6)=sd->status.inventory[i].nameid;
  1848. WFIFOB(fd,n*20+8)=itemtype(sd->inventory_data[i]->type);
  1849. WFIFOB(fd,n*20+9)=sd->status.inventory[i].identify;
  1850. WFIFOW(fd,n*20+10)=pc_equippoint(sd,i);
  1851. WFIFOW(fd,n*20+12)=sd->status.inventory[i].equip;
  1852. WFIFOB(fd,n*20+14)=sd->status.inventory[i].attribute;
  1853. WFIFOB(fd,n*20+15)=sd->status.inventory[i].refine;
  1854. clif_addcards(WFIFOP(fd, n*20+16), &sd->status.inventory[i]);
  1855. n++;
  1856. }
  1857. if(n){
  1858. WFIFOW(fd,2)=4+n*20;
  1859. WFIFOSET(fd,WFIFOW(fd,2));
  1860. }
  1861. return 0;
  1862. }
  1863. /*==========================================
  1864. * カプラさんに預けてある消耗品&収集品リスト
  1865. *------------------------------------------
  1866. */
  1867. int clif_storageitemlist(struct map_session_data *sd,struct storage *stor)
  1868. {
  1869. struct item_data *id;
  1870. int i,n,fd;
  1871. unsigned char *buf;
  1872. nullpo_retr(0, sd);
  1873. nullpo_retr(0, stor);
  1874. fd=sd->fd;
  1875. WFIFOHEAD(fd,MAX_STORAGE * 18 + 4);
  1876. buf = WFIFOP(fd,0);
  1877. #if PACKETVER < 5
  1878. WBUFW(buf,0)=0xa5;
  1879. for(i=0,n=0;i<MAX_STORAGE;i++){
  1880. if(stor->storage_[i].nameid<=0)
  1881. continue;
  1882. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1883. if(itemdb_isequip2(id))
  1884. continue;
  1885. WBUFW(buf,n*10+4)=i+1;
  1886. if(id->view_id > 0)
  1887. WBUFW(buf,n*10+6)=id->view_id;
  1888. else
  1889. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  1890. WBUFB(buf,n*10+8)=itemtype(id->type);
  1891. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  1892. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  1893. WBUFW(buf,n*10+12)=0;
  1894. n++;
  1895. }
  1896. if(n){
  1897. WBUFW(buf,2)=4+n*10;
  1898. WFIFOSET(fd,WFIFOW(fd,2));
  1899. }
  1900. #else
  1901. WBUFW(buf,0)=0x1f0;
  1902. for(i=0,n=0;i<MAX_STORAGE;i++){
  1903. if(stor->storage_[i].nameid<=0)
  1904. continue;
  1905. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1906. if(itemdb_isequip2(id))
  1907. continue;
  1908. WBUFW(buf,n*18+4)=i+1;
  1909. if(id->view_id > 0)
  1910. WBUFW(buf,n*18+6)=id->view_id;
  1911. else
  1912. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  1913. WBUFB(buf,n*18+8)=itemtype(id->type);
  1914. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  1915. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  1916. WBUFW(buf,n*18+12)=0;
  1917. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  1918. n++;
  1919. }
  1920. if(n){
  1921. WBUFW(buf,2)=4+n*18;
  1922. WFIFOSET(fd,WFIFOW(fd,2));
  1923. }
  1924. #endif
  1925. return 0;
  1926. }
  1927. /*==========================================
  1928. * カプラさんに預けてある装備リスト
  1929. *------------------------------------------
  1930. */
  1931. int clif_storageequiplist(struct map_session_data *sd,struct storage *stor)
  1932. {
  1933. struct item_data *id;
  1934. int i,n,fd;
  1935. unsigned char *buf;
  1936. nullpo_retr(0, sd);
  1937. nullpo_retr(0, stor);
  1938. fd=sd->fd;
  1939. WFIFOHEAD(fd,MAX_STORAGE * 20 + 4);
  1940. buf = WFIFOP(fd,0);
  1941. WBUFW(buf,0)=0xa6;
  1942. for(i=0,n=0;i<MAX_STORAGE;i++){
  1943. if(stor->storage_[i].nameid<=0)
  1944. continue;
  1945. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1946. if(!itemdb_isequip2(id))
  1947. continue;
  1948. WBUFW(buf,n*20+4)=i+1;
  1949. if(id->view_id > 0)
  1950. WBUFW(buf,n*20+6)=id->view_id;
  1951. else
  1952. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  1953. WBUFB(buf,n*20+8)=itemtype(id->type);
  1954. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  1955. WBUFW(buf,n*20+10)=id->equip;
  1956. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  1957. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  1958. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  1959. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  1960. n++;
  1961. }
  1962. if(n){
  1963. WBUFW(buf,2)=4+n*20;
  1964. WFIFOSET(fd,WFIFOW(fd,2));
  1965. }
  1966. return 0;
  1967. }
  1968. /*==========================================
  1969. *
  1970. *------------------------------------------
  1971. */
  1972. int clif_guildstorageitemlist(struct map_session_data *sd,struct guild_storage *stor)
  1973. {
  1974. struct item_data *id;
  1975. int i,n,fd;
  1976. unsigned char *buf;
  1977. nullpo_retr(0, sd);
  1978. nullpo_retr(0, stor);
  1979. fd=sd->fd;
  1980. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 18 + 4);
  1981. buf=WFIFOP(fd,0);
  1982. #if PACKETVER < 5
  1983. WBUFW(buf,0)=0xa5;
  1984. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  1985. if(stor->storage_[i].nameid<=0)
  1986. continue;
  1987. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1988. if(itemdb_isequip2(id))
  1989. continue;
  1990. WBUFW(buf,n*10+4)=i+1;
  1991. if(id->view_id > 0)
  1992. WBUFW(buf,n*10+6)=id->view_id;
  1993. else
  1994. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  1995. WBUFB(buf,n*10+8)=itemtype(id->type);
  1996. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  1997. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  1998. WBUFW(buf,n*10+12)=0;
  1999. n++;
  2000. }
  2001. if(n){
  2002. WBUFW(buf,2)=4+n*10;
  2003. WFIFOSET(fd,WFIFOW(fd,2));
  2004. }
  2005. #else
  2006. WBUFW(buf,0)=0x1f0;
  2007. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2008. if(stor->storage_[i].nameid<=0)
  2009. continue;
  2010. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2011. if(itemdb_isequip2(id))
  2012. continue;
  2013. WBUFW(buf,n*18+4)=i+1;
  2014. if(id->view_id > 0)
  2015. WBUFW(buf,n*18+6)=id->view_id;
  2016. else
  2017. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  2018. WBUFB(buf,n*18+8)=itemtype(id->type);
  2019. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  2020. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  2021. WBUFW(buf,n*18+12)=0;
  2022. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  2023. n++;
  2024. }
  2025. if(n){
  2026. WBUFW(buf,2)=4+n*18;
  2027. WFIFOSET(fd,WFIFOW(fd,2));
  2028. }
  2029. #endif
  2030. return 0;
  2031. }
  2032. /*==========================================
  2033. *
  2034. *------------------------------------------
  2035. */
  2036. int clif_guildstorageequiplist(struct map_session_data *sd,struct guild_storage *stor)
  2037. {
  2038. struct item_data *id;
  2039. int i,n,fd;
  2040. unsigned char *buf;
  2041. nullpo_retr(0, sd);
  2042. fd=sd->fd;
  2043. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 20 + 4);
  2044. buf=WFIFOP(fd,0);
  2045. WBUFW(buf,0)=0xa6;
  2046. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2047. if(stor->storage_[i].nameid<=0)
  2048. continue;
  2049. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2050. if(!itemdb_isequip2(id))
  2051. continue;
  2052. WBUFW(buf,n*20+4)=i+1;
  2053. if(id->view_id > 0)
  2054. WBUFW(buf,n*20+6)=id->view_id;
  2055. else
  2056. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2057. WBUFB(buf,n*20+8)=itemtype(id->type);
  2058. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2059. WBUFW(buf,n*20+10)=id->equip;
  2060. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2061. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2062. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2063. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2064. n++;
  2065. }
  2066. if(n){
  2067. WBUFW(buf,2)=4+n*20;
  2068. WFIFOSET(fd,WFIFOW(fd,2));
  2069. }
  2070. return 0;
  2071. }
  2072. // Guild XY locators [Valaris]
  2073. int clif_guild_xy(struct map_session_data *sd)
  2074. {
  2075. unsigned char buf[10];
  2076. nullpo_retr(0, sd);
  2077. WBUFW(buf,0)=0x1eb;
  2078. WBUFL(buf,2)=sd->status.account_id;
  2079. WBUFW(buf,6)=sd->bl.x;
  2080. WBUFW(buf,8)=sd->bl.y;
  2081. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2082. return 0;
  2083. }
  2084. /*==========================================
  2085. * Sends x/y dot to a single fd. [Skotlex]
  2086. *------------------------------------------
  2087. */
  2088. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2089. {
  2090. WFIFOHEAD(fd,packet_len_table[0x1eb]);
  2091. WFIFOW(fd,0)=0x1eb;
  2092. WFIFOL(fd,2)=sd->status.account_id;
  2093. WFIFOW(fd,6)=sd->bl.x;
  2094. WFIFOW(fd,8)=sd->bl.y;
  2095. WFIFOSET(fd,packet_len_table[0x1eb]);
  2096. return 0;
  2097. }
  2098. // Guild XY locators [Valaris]
  2099. int clif_guild_xy_remove(struct map_session_data *sd)
  2100. {
  2101. unsigned char buf[10];
  2102. nullpo_retr(0, sd);
  2103. WBUFW(buf,0)=0x1eb;
  2104. WBUFL(buf,2)=sd->status.account_id;
  2105. WBUFW(buf,6)=-1;
  2106. WBUFW(buf,8)=-1;
  2107. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2108. return 0;
  2109. }
  2110. /*==========================================
  2111. * ステータスを送りつける
  2112. * 表示専用数字はこの中で計算して送る
  2113. *------------------------------------------
  2114. */
  2115. int clif_updatestatus(struct map_session_data *sd,int type)
  2116. {
  2117. int fd,len=8;
  2118. nullpo_retr(0, sd);
  2119. fd=sd->fd;
  2120. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2121. return 0;
  2122. WFIFOHEAD(fd, 14);
  2123. WFIFOW(fd,0)=0xb0;
  2124. WFIFOW(fd,2)=type;
  2125. switch(type){
  2126. // 00b0
  2127. case SP_WEIGHT:
  2128. pc_checkweighticon(sd);
  2129. WFIFOW(fd,0)=0xb0;
  2130. WFIFOW(fd,2)=type; //Added this packet back, Temp fix to the slow motion [Lupus]
  2131. WFIFOL(fd,4)=sd->weight;
  2132. break;
  2133. case SP_MAXWEIGHT:
  2134. WFIFOL(fd,4)=sd->max_weight;
  2135. break;
  2136. case SP_SPEED:
  2137. WFIFOL(fd,4)=sd->speed;
  2138. break;
  2139. case SP_BASELEVEL:
  2140. WFIFOL(fd,4)=sd->status.base_level;
  2141. break;
  2142. case SP_JOBLEVEL:
  2143. WFIFOL(fd,4)=sd->status.job_level;
  2144. break;
  2145. case SP_MANNER:
  2146. WFIFOL(fd,4)=sd->status.manner;
  2147. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2148. break;
  2149. case SP_STATUSPOINT:
  2150. WFIFOL(fd,4)=sd->status.status_point;
  2151. break;
  2152. case SP_SKILLPOINT:
  2153. WFIFOL(fd,4)=sd->status.skill_point;
  2154. break;
  2155. case SP_HIT:
  2156. WFIFOL(fd,4)=sd->hit;
  2157. break;
  2158. case SP_FLEE1:
  2159. WFIFOL(fd,4)=sd->flee;
  2160. break;
  2161. case SP_FLEE2:
  2162. WFIFOL(fd,4)=sd->flee2/10;
  2163. break;
  2164. case SP_MAXHP:
  2165. WFIFOL(fd,4)=sd->status.max_hp;
  2166. break;
  2167. case SP_MAXSP:
  2168. WFIFOL(fd,4)=sd->status.max_sp;
  2169. break;
  2170. case SP_HP:
  2171. WFIFOL(fd,4)=sd->status.hp;
  2172. if (sd->status.party_id)
  2173. clif_party_hp(sd);
  2174. if (battle_config.disp_hpmeter)
  2175. clif_hpmeter(sd);
  2176. break;
  2177. case SP_SP:
  2178. WFIFOL(fd,4)=sd->status.sp;
  2179. break;
  2180. case SP_ASPD:
  2181. WFIFOL(fd,4)=sd->aspd;
  2182. break;
  2183. case SP_ATK1:
  2184. WFIFOL(fd,4)=sd->base_atk+sd->right_weapon.watk+sd->left_weapon.watk;
  2185. break;
  2186. case SP_DEF1:
  2187. WFIFOL(fd,4)=sd->def;
  2188. break;
  2189. case SP_MDEF1:
  2190. WFIFOL(fd,4)=sd->mdef;
  2191. break;
  2192. case SP_ATK2:
  2193. WFIFOL(fd,4)=sd->right_weapon.watk2 + sd->left_weapon.watk2;
  2194. break;
  2195. case SP_DEF2:
  2196. WFIFOL(fd,4)=sd->def2;
  2197. break;
  2198. case SP_MDEF2:
  2199. WFIFOL(fd,4)=sd->mdef2;
  2200. break;
  2201. case SP_CRITICAL:
  2202. WFIFOL(fd,4)=sd->critical/10;
  2203. break;
  2204. case SP_MATK1:
  2205. WFIFOL(fd,4)=sd->matk1;
  2206. break;
  2207. case SP_MATK2:
  2208. WFIFOL(fd,4)=sd->matk2;
  2209. break;
  2210. case SP_ZENY:
  2211. WFIFOW(fd,0)=0xb1;
  2212. if(sd->status.zeny < 0)
  2213. sd->status.zeny = 0;
  2214. WFIFOL(fd,4)=sd->status.zeny;
  2215. break;
  2216. case SP_BASEEXP:
  2217. WFIFOW(fd,0)=0xb1;
  2218. WFIFOL(fd,4)=sd->status.base_exp;
  2219. break;
  2220. case SP_JOBEXP:
  2221. WFIFOW(fd,0)=0xb1;
  2222. WFIFOL(fd,4)=sd->status.job_exp;
  2223. break;
  2224. case SP_NEXTBASEEXP:
  2225. WFIFOW(fd,0)=0xb1;
  2226. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2227. break;
  2228. case SP_NEXTJOBEXP:
  2229. WFIFOW(fd,0)=0xb1;
  2230. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2231. break;
  2232. // 00be 終了
  2233. case SP_USTR:
  2234. case SP_UAGI:
  2235. case SP_UVIT:
  2236. case SP_UINT:
  2237. case SP_UDEX:
  2238. case SP_ULUK:
  2239. WFIFOW(fd,0)=0xbe;
  2240. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2241. len=5;
  2242. break;
  2243. // 013a 終了
  2244. case SP_ATTACKRANGE:
  2245. WFIFOW(fd,0)=0x13a;
  2246. WFIFOW(fd,2)=sd->attackrange;
  2247. len=4;
  2248. break;
  2249. // 0141 終了
  2250. case SP_STR:
  2251. WFIFOW(fd,0)=0x141;
  2252. WFIFOL(fd,2)=type;
  2253. WFIFOL(fd,6)=sd->status.str;
  2254. WFIFOL(fd,10)=sd->paramb[0] + sd->parame[0];
  2255. len=14;
  2256. break;
  2257. case SP_AGI:
  2258. WFIFOW(fd,0)=0x141;
  2259. WFIFOL(fd,2)=type;
  2260. WFIFOL(fd,6)=sd->status.agi;
  2261. WFIFOL(fd,10)=sd->paramb[1] + sd->parame[1];
  2262. len=14;
  2263. break;
  2264. case SP_VIT:
  2265. WFIFOW(fd,0)=0x141;
  2266. WFIFOL(fd,2)=type;
  2267. WFIFOL(fd,6)=sd->status.vit;
  2268. WFIFOL(fd,10)=sd->paramb[2] + sd->parame[2];
  2269. len=14;
  2270. break;
  2271. case SP_INT:
  2272. WFIFOW(fd,0)=0x141;
  2273. WFIFOL(fd,2)=type;
  2274. WFIFOL(fd,6)=sd->status.int_;
  2275. WFIFOL(fd,10)=sd->paramb[3] + sd->parame[3];
  2276. len=14;
  2277. break;
  2278. case SP_DEX:
  2279. WFIFOW(fd,0)=0x141;
  2280. WFIFOL(fd,2)=type;
  2281. WFIFOL(fd,6)=sd->status.dex;
  2282. WFIFOL(fd,10)=sd->paramb[4] + sd->parame[4];
  2283. len=14;
  2284. break;
  2285. case SP_LUK:
  2286. WFIFOW(fd,0)=0x141;
  2287. WFIFOL(fd,2)=type;
  2288. WFIFOL(fd,6)=sd->status.luk;
  2289. WFIFOL(fd,10)=sd->paramb[5] + sd->parame[5];
  2290. len=14;
  2291. break;
  2292. case SP_CARTINFO:
  2293. WFIFOW(fd,0)=0x121;
  2294. WFIFOW(fd,2)=sd->cart_num;
  2295. WFIFOW(fd,4)=sd->cart_max_num;
  2296. WFIFOL(fd,6)=sd->cart_weight;
  2297. WFIFOL(fd,10)=sd->cart_max_weight;
  2298. len=14;
  2299. break;
  2300. default:
  2301. if(battle_config.error_log)
  2302. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2303. return 1;
  2304. }
  2305. WFIFOSET(fd,len);
  2306. return 0;
  2307. }
  2308. int clif_changestatus(struct block_list *bl,int type,int val)
  2309. {
  2310. unsigned char buf[12];
  2311. struct map_session_data *sd = NULL;
  2312. nullpo_retr(0, bl);
  2313. if(bl->type == BL_PC)
  2314. sd = (struct map_session_data *)bl;
  2315. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2316. if(sd){
  2317. WBUFW(buf,0)=0x1ab;
  2318. WBUFL(buf,2)=bl->id;
  2319. WBUFW(buf,6)=type;
  2320. switch(type){
  2321. case SP_MANNER:
  2322. WBUFL(buf,8)=val;
  2323. break;
  2324. default:
  2325. if(battle_config.error_log)
  2326. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2327. return 1;
  2328. }
  2329. clif_send(buf,packet_len_table[0x1ab],bl,AREA_WOS);
  2330. }
  2331. return 0;
  2332. }
  2333. /*==========================================
  2334. *
  2335. *------------------------------------------
  2336. */
  2337. int clif_changelook(struct block_list *bl,int type,int val)
  2338. {
  2339. unsigned char buf[32];
  2340. struct map_session_data *sd = NULL;
  2341. struct view_data *vd;
  2342. nullpo_retr(0, bl);
  2343. vd = status_get_viewdata(bl);
  2344. nullpo_retr(0, vd);
  2345. if(bl->type == BL_PC)
  2346. sd = (struct map_session_data *)bl;
  2347. switch(type) {
  2348. case LOOK_WEAPON:
  2349. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2350. else vd->weapon = val;
  2351. break;
  2352. case LOOK_SHIELD:
  2353. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2354. else vd->shield = val;
  2355. break;
  2356. case LOOK_BASE:
  2357. vd->class_ = val;
  2358. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2359. vd->weapon = vd->shield = 0;
  2360. if (
  2361. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2362. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2363. )
  2364. vd->cloth_color = 0;
  2365. break;
  2366. case LOOK_HAIR:
  2367. vd->hair_style = val;
  2368. break;
  2369. case LOOK_HEAD_BOTTOM:
  2370. vd->head_bottom = val;
  2371. break;
  2372. case LOOK_HEAD_TOP:
  2373. vd->head_top = val;
  2374. break;
  2375. case LOOK_HEAD_MID:
  2376. vd->head_mid = val;
  2377. break;
  2378. case LOOK_HAIR_COLOR:
  2379. vd->hair_color = val;
  2380. break;
  2381. case LOOK_CLOTHES_COLOR:
  2382. if (
  2383. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2384. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2385. )
  2386. val = 0;
  2387. vd->cloth_color = val;
  2388. break;
  2389. case LOOK_SHOES:
  2390. #if PACKETVER > 3
  2391. if (sd) {
  2392. int n;
  2393. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2394. if(sd->inventory_data[n]->view_id > 0)
  2395. val = sd->inventory_data[n]->view_id;
  2396. else
  2397. val = sd->status.inventory[n].nameid;
  2398. }
  2399. val = 0;
  2400. }
  2401. #endif
  2402. //Shoes? No packet uses this....
  2403. break;
  2404. }
  2405. #if PACKETVER < 4
  2406. WBUFW(buf,0)=0xc3;
  2407. WBUFL(buf,2)=bl->id;
  2408. WBUFB(buf,6)=type;
  2409. WBUFB(buf,7)=val;
  2410. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2411. #else
  2412. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2413. WBUFW(buf,0)=0x1d7;
  2414. WBUFL(buf,2)=bl->id;
  2415. WBUFB(buf,6)=LOOK_WEAPON;
  2416. WBUFW(buf,7)=vd->weapon;
  2417. WBUFW(buf,9)=vd->shield;
  2418. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2419. }
  2420. else if(type == LOOK_BASE && val > 255)
  2421. {
  2422. WBUFW(buf,0)=0x1d7;
  2423. WBUFL(buf,2)=bl->id;
  2424. WBUFB(buf,6)=type;
  2425. WBUFW(buf,7)=val;
  2426. WBUFW(buf,9)=0;
  2427. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2428. } else {
  2429. WBUFW(buf,0)=0xc3;
  2430. WBUFL(buf,2)=bl->id;
  2431. WBUFB(buf,6)=type;
  2432. WBUFB(buf,7)=val;
  2433. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2434. }
  2435. #endif
  2436. return 0;
  2437. }
  2438. //Sends a change-base-look packet required for traps as they are triggered.
  2439. void clif_changetraplook(struct block_list *bl,int val)
  2440. {
  2441. unsigned char buf[32];
  2442. #if PACKETVER < 4
  2443. WBUFW(buf,0)=0xc3;
  2444. WBUFL(buf,2)=bl->id;
  2445. WBUFB(buf,6)=LOOK_BASE;
  2446. WBUFB(buf,7)=val;
  2447. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2448. #else
  2449. if (val > 255)
  2450. {
  2451. WBUFW(buf,0)=0x1d7;
  2452. WBUFL(buf,2)=bl->id;
  2453. WBUFB(buf,6)=LOOK_BASE;
  2454. WBUFW(buf,7)=val;
  2455. WBUFW(buf,9)=0;
  2456. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2457. } else {
  2458. WBUFW(buf,0)=0xc3;
  2459. WBUFL(buf,2)=bl->id;
  2460. WBUFB(buf,6)=LOOK_BASE;
  2461. WBUFB(buf,7)=val;
  2462. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2463. }
  2464. #endif
  2465. }
  2466. //For the stupid cloth-dye bug. Resends the given view data
  2467. //to the area specified by bl.
  2468. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2469. {
  2470. unsigned char buf[32];
  2471. #if PACKETVER < 4
  2472. WBUFW(buf,0)=0xc3;
  2473. WBUFL(buf,2)=id;
  2474. WBUFB(buf,6)=type;
  2475. WBUFB(buf,7)=val;
  2476. clif_send(buf,packet_len_table[0xc3],bl,area);
  2477. #else
  2478. if(type == LOOK_BASE && val > 255)
  2479. {
  2480. WBUFW(buf,0)=0x1d7;
  2481. WBUFL(buf,2)=id;
  2482. WBUFB(buf,6)=type;
  2483. WBUFW(buf,7)=val;
  2484. WBUFW(buf,9)=0;
  2485. clif_send(buf,packet_len_table[0x1d7],bl,area);
  2486. } else {
  2487. WBUFW(buf,0)=0xc3;
  2488. WBUFL(buf,2)=id;
  2489. WBUFB(buf,6)=type;
  2490. WBUFB(buf,7)=val;
  2491. clif_send(buf,packet_len_table[0xc3],bl,area);
  2492. }
  2493. #endif
  2494. return;
  2495. }
  2496. /*==========================================
  2497. *
  2498. *------------------------------------------
  2499. */
  2500. int clif_initialstatus(struct map_session_data *sd)
  2501. {
  2502. int fd;
  2503. unsigned char *buf;
  2504. nullpo_retr(0, sd);
  2505. fd=sd->fd;
  2506. WFIFOHEAD(fd,packet_len_table[0xbd]);
  2507. buf=WFIFOP(fd,0);
  2508. WBUFW(buf,0)=0xbd;
  2509. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2510. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2511. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2512. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2513. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2514. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2515. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2516. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2517. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2518. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2519. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2520. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2521. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2522. WBUFW(buf,16) = sd->base_atk + sd->right_weapon.watk + sd->left_weapon.watk;
  2523. WBUFW(buf,18) = sd->right_weapon.watk2 + sd->left_weapon.watk2; //atk bonus
  2524. WBUFW(buf,20) = sd->matk1;
  2525. WBUFW(buf,22) = sd->matk2;
  2526. WBUFW(buf,24) = sd->def; // def
  2527. WBUFW(buf,26) = sd->def2;
  2528. WBUFW(buf,28) = sd->mdef; // mdef
  2529. WBUFW(buf,30) = sd->mdef2;
  2530. WBUFW(buf,32) = sd->hit;
  2531. WBUFW(buf,34) = sd->flee;
  2532. WBUFW(buf,36) = sd->flee2/10;
  2533. WBUFW(buf,38) = sd->critical/10;
  2534. WBUFW(buf,40) = sd->status.karma;
  2535. WBUFW(buf,42) = sd->status.manner;
  2536. WFIFOSET(fd,packet_len_table[0xbd]);
  2537. clif_updatestatus(sd,SP_STR);
  2538. clif_updatestatus(sd,SP_AGI);
  2539. clif_updatestatus(sd,SP_VIT);
  2540. clif_updatestatus(sd,SP_INT);
  2541. clif_updatestatus(sd,SP_DEX);
  2542. clif_updatestatus(sd,SP_LUK);
  2543. clif_updatestatus(sd,SP_ATTACKRANGE);
  2544. clif_updatestatus(sd,SP_ASPD);
  2545. return 0;
  2546. }
  2547. /*==========================================
  2548. *矢装備
  2549. *------------------------------------------
  2550. */
  2551. int clif_arrowequip(struct map_session_data *sd,int val)
  2552. {
  2553. int fd;
  2554. nullpo_retr(0, sd);
  2555. pc_stop_attack(sd); // [Valaris]
  2556. fd=sd->fd;
  2557. WFIFOHEAD(fd, packet_len_table[0x013c]);
  2558. WFIFOW(fd,0)=0x013c;
  2559. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2560. WFIFOSET(fd,packet_len_table[0x013c]);
  2561. return 0;
  2562. }
  2563. /*==========================================
  2564. *
  2565. *------------------------------------------
  2566. */
  2567. int clif_arrow_fail(struct map_session_data *sd,int type)
  2568. {
  2569. int fd;
  2570. nullpo_retr(0, sd);
  2571. fd=sd->fd;
  2572. WFIFOHEAD(fd, packet_len_table[0x013b]);
  2573. WFIFOW(fd,0)=0x013b;
  2574. WFIFOW(fd,2)=type;
  2575. WFIFOSET(fd,packet_len_table[0x013b]);
  2576. return 0;
  2577. }
  2578. /*==========================================
  2579. * 作成可能 矢リスト送信
  2580. *------------------------------------------
  2581. */
  2582. int clif_arrow_create_list(struct map_session_data *sd)
  2583. {
  2584. int i, c, j;
  2585. int fd;
  2586. nullpo_retr(0, sd);
  2587. fd = sd->fd;
  2588. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2589. WFIFOW(fd,0) = 0x1ad;
  2590. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2591. if (skill_arrow_db[i].nameid > 0 &&
  2592. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2593. !sd->status.inventory[j].equip)
  2594. {
  2595. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2596. WFIFOW(fd,c*2+4) = j;
  2597. else
  2598. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2599. c++;
  2600. }
  2601. }
  2602. WFIFOW(fd,2) = c*2+4;
  2603. WFIFOSET(fd, WFIFOW(fd,2));
  2604. if (c > 0) {
  2605. sd->menuskill_id = AC_MAKINGARROW;
  2606. sd->menuskill_lv = c;
  2607. }
  2608. return 0;
  2609. }
  2610. /*==========================================
  2611. *
  2612. *------------------------------------------
  2613. */
  2614. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2615. {
  2616. int fd;
  2617. nullpo_retr(0, sd);
  2618. fd=sd->fd;
  2619. WFIFOHEAD(fd,packet_len_table[0xbc]);
  2620. WFIFOW(fd,0)=0xbc;
  2621. WFIFOW(fd,2)=type;
  2622. WFIFOB(fd,4)=ok;
  2623. WFIFOB(fd,5)=val;
  2624. WFIFOSET(fd,packet_len_table[0xbc]);
  2625. return 0;
  2626. }
  2627. /*==========================================
  2628. *
  2629. *------------------------------------------
  2630. */
  2631. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2632. {
  2633. int fd;
  2634. nullpo_retr(0, sd);
  2635. fd=sd->fd;
  2636. WFIFOHEAD(fd,packet_len_table[0xaa]);
  2637. WFIFOW(fd,0)=0xaa;
  2638. WFIFOW(fd,2)=n+2;
  2639. WFIFOW(fd,4)=pos;
  2640. WFIFOB(fd,6)=ok;
  2641. WFIFOSET(fd,packet_len_table[0xaa]);
  2642. return 0;
  2643. }
  2644. /*==========================================
  2645. *
  2646. *------------------------------------------
  2647. */
  2648. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2649. {
  2650. int fd;
  2651. nullpo_retr(0, sd);
  2652. fd=sd->fd;
  2653. WFIFOHEAD(fd,packet_len_table[0xac]);
  2654. WFIFOW(fd,0)=0xac;
  2655. WFIFOW(fd,2)=n+2;
  2656. WFIFOW(fd,4)=pos;
  2657. WFIFOB(fd,6)=ok;
  2658. WFIFOSET(fd,packet_len_table[0xac]);
  2659. return 0;
  2660. }
  2661. /*==========================================
  2662. *
  2663. *------------------------------------------
  2664. */
  2665. int clif_misceffect(struct block_list* bl,int type)
  2666. {
  2667. unsigned char buf[32];
  2668. nullpo_retr(0, bl);
  2669. WBUFW(buf,0) = 0x19b;
  2670. WBUFL(buf,2) = bl->id;
  2671. WBUFL(buf,6) = type;
  2672. clif_send(buf,packet_len_table[0x19b],bl,AREA);
  2673. return 0;
  2674. }
  2675. int clif_misceffect2(struct block_list *bl, int type) {
  2676. unsigned char buf[24];
  2677. nullpo_retr(0, bl);
  2678. memset(buf, 0, packet_len_table[0x1f3]);
  2679. WBUFW(buf,0) = 0x1f3;
  2680. WBUFL(buf,2) = bl->id;
  2681. WBUFL(buf,6) = type;
  2682. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  2683. return 0;
  2684. }
  2685. /*==========================================
  2686. * 表示オプション変更
  2687. *------------------------------------------
  2688. */
  2689. int clif_changeoption(struct block_list* bl)
  2690. {
  2691. unsigned char buf[32];
  2692. struct status_change *sc;
  2693. nullpo_retr(0, bl);
  2694. sc = status_get_sc(bl);
  2695. WBUFW(buf,0) = 0x119;
  2696. WBUFL(buf,2) = bl->id;
  2697. WBUFW(buf,6) = sc?sc->opt1:0;
  2698. WBUFW(buf,8) = sc?sc->opt2:0;
  2699. WBUFW(buf,10) = sc?sc->option:0;
  2700. WBUFB(buf,12) = 0; // ??
  2701. if(disguised(bl)) {
  2702. clif_send(buf,packet_len_table[0x119],bl,AREA_WOS);
  2703. WBUFL(buf,2) = -bl->id;
  2704. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2705. WBUFL(buf,2) = bl->id;
  2706. WBUFW(buf,10) = OPTION_INVISIBLE;
  2707. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2708. } else
  2709. clif_send(buf,packet_len_table[0x119],bl,AREA);
  2710. return 0;
  2711. }
  2712. /*==========================================
  2713. *
  2714. *------------------------------------------
  2715. */
  2716. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2717. {
  2718. nullpo_retr(0, sd);
  2719. if(!ok) {
  2720. int fd=sd->fd;
  2721. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2722. WFIFOW(fd,0)=0xa8;
  2723. WFIFOW(fd,2)=index+2;
  2724. WFIFOW(fd,4)=amount;
  2725. WFIFOB(fd,6)=ok;
  2726. WFIFOSET(fd,packet_len_table[0xa8]);
  2727. }
  2728. else {
  2729. #if PACKETVER < 3
  2730. int fd=sd->fd;
  2731. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2732. WFIFOW(fd,0)=0xa8;
  2733. WFIFOW(fd,2)=index+2;
  2734. WFIFOW(fd,4)=amount;
  2735. WFIFOB(fd,6)=ok;
  2736. WFIFOSET(fd,packet_len_table[0xa8]);
  2737. #else
  2738. unsigned char buf[32];
  2739. WBUFW(buf,0)=0x1c8;
  2740. WBUFW(buf,2)=index+2;
  2741. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2742. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2743. else
  2744. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2745. WBUFL(buf,6)=sd->bl.id;
  2746. WBUFW(buf,10)=amount;
  2747. WBUFB(buf,12)=ok;
  2748. clif_send(buf,packet_len_table[0x1c8],&sd->bl,AREA);
  2749. #endif
  2750. }
  2751. return 0;
  2752. }
  2753. /*==========================================
  2754. *
  2755. *------------------------------------------
  2756. */
  2757. int clif_createchat(struct map_session_data *sd,int fail)
  2758. {
  2759. int fd;
  2760. nullpo_retr(0, sd);
  2761. fd=sd->fd;
  2762. WFIFOHEAD(fd,packet_len_table[0xd6]);
  2763. WFIFOW(fd,0)=0xd6;
  2764. WFIFOB(fd,2)=fail;
  2765. WFIFOSET(fd,packet_len_table[0xd6]);
  2766. return 0;
  2767. }
  2768. /*==========================================
  2769. *
  2770. *------------------------------------------
  2771. */
  2772. int clif_dispchat(struct chat_data *cd,int fd)
  2773. {
  2774. unsigned char buf[128]; // 最大title(60バイト)+17
  2775. if(cd==NULL || *cd->owner==NULL)
  2776. return 1;
  2777. WBUFW(buf,0)=0xd7;
  2778. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  2779. WBUFL(buf,4)=(*cd->owner)->id;
  2780. WBUFL(buf,8)=cd->bl.id;
  2781. WBUFW(buf,12)=cd->limit;
  2782. WBUFW(buf,14)=cd->users;
  2783. WBUFB(buf,16)=cd->pub;
  2784. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2785. if(fd){
  2786. WFIFOHEAD(fd, WBUFW(buf,2));
  2787. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2788. WFIFOSET(fd,WBUFW(buf,2));
  2789. } else {
  2790. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  2791. }
  2792. return 0;
  2793. }
  2794. /*==========================================
  2795. * chatの状態変更成功
  2796. * 外部の人用と命令コード(d7->df)が違うだけ
  2797. *------------------------------------------
  2798. */
  2799. int clif_changechatstatus(struct chat_data *cd)
  2800. {
  2801. unsigned char buf[128]; // 最大title(60バイト)+17
  2802. if(cd==NULL || cd->usersd[0]==NULL)
  2803. return 1;
  2804. WBUFW(buf,0)=0xdf;
  2805. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  2806. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  2807. WBUFL(buf,8)=cd->bl.id;
  2808. WBUFW(buf,12)=cd->limit;
  2809. WBUFW(buf,14)=cd->users;
  2810. WBUFB(buf,16)=cd->pub;
  2811. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2812. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2813. return 0;
  2814. }
  2815. /*==========================================
  2816. *
  2817. *------------------------------------------
  2818. */
  2819. int clif_clearchat(struct chat_data *cd,int fd)
  2820. {
  2821. unsigned char buf[32];
  2822. nullpo_retr(0, cd);
  2823. WBUFW(buf,0)=0xd8;
  2824. WBUFL(buf,2)=cd->bl.id;
  2825. if(fd){
  2826. WFIFOHEAD(fd,packet_len_table[0xd8]);
  2827. memcpy(WFIFOP(fd,0),buf,packet_len_table[0xd8]);
  2828. WFIFOSET(fd,packet_len_table[0xd8]);
  2829. } else {
  2830. clif_send(buf,packet_len_table[0xd8],*cd->owner,AREA_WOSC);
  2831. }
  2832. return 0;
  2833. }
  2834. /*==========================================
  2835. *
  2836. *------------------------------------------
  2837. */
  2838. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2839. {
  2840. int fd;
  2841. nullpo_retr(0, sd);
  2842. fd=sd->fd;
  2843. WFIFOHEAD(fd,packet_len_table[0xda]);
  2844. WFIFOW(fd,0)=0xda;
  2845. WFIFOB(fd,2)=fail;
  2846. WFIFOSET(fd,packet_len_table[0xda]);
  2847. return 0;
  2848. }
  2849. /*==========================================
  2850. *
  2851. *------------------------------------------
  2852. */
  2853. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2854. {
  2855. int fd;
  2856. int i;
  2857. nullpo_retr(0, sd);
  2858. nullpo_retr(0, cd);
  2859. fd = sd->fd;
  2860. if (!session_isActive(fd))
  2861. return 0;
  2862. WFIFOHEAD(fd, 8 + (28*cd->users));
  2863. WFIFOW(fd, 0) = 0xdb;
  2864. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2865. WFIFOL(fd, 4) = cd->bl.id;
  2866. for (i = 0; i < cd->users; i++) {
  2867. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  2868. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2869. }
  2870. WFIFOSET(fd, WFIFOW(fd, 2));
  2871. return 0;
  2872. }
  2873. /*==========================================
  2874. *
  2875. *------------------------------------------
  2876. */
  2877. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2878. {
  2879. unsigned char buf[32];
  2880. nullpo_retr(0, sd);
  2881. nullpo_retr(0, cd);
  2882. WBUFW(buf, 0) = 0x0dc;
  2883. WBUFW(buf, 2) = cd->users;
  2884. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2885. clif_send(buf,packet_len_table[0xdc],&sd->bl,CHAT_WOS);
  2886. return 0;
  2887. }
  2888. /*==========================================
  2889. *
  2890. *------------------------------------------
  2891. */
  2892. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  2893. {
  2894. unsigned char buf[64];
  2895. nullpo_retr(0, sd);
  2896. nullpo_retr(0, cd);
  2897. WBUFW(buf, 0) = 0xe1;
  2898. WBUFL(buf, 2) = 1;
  2899. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2900. WBUFW(buf,30) = 0xe1;
  2901. WBUFL(buf,32) = 0;
  2902. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2903. clif_send(buf,packet_len_table[0xe1]*2,&sd->bl,CHAT);
  2904. return 0;
  2905. }
  2906. /*==========================================
  2907. *
  2908. *------------------------------------------
  2909. */
  2910. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  2911. {
  2912. unsigned char buf[32];
  2913. nullpo_retr(0, sd);
  2914. nullpo_retr(0, cd);
  2915. WBUFW(buf, 0) = 0xdd;
  2916. WBUFW(buf, 2) = cd->users-1;
  2917. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2918. WBUFB(buf,28) = 0;
  2919. clif_send(buf,packet_len_table[0xdd],&sd->bl,CHAT);
  2920. return 0;
  2921. }
  2922. /*==========================================
  2923. * 取り引き要請受け
  2924. *------------------------------------------
  2925. */
  2926. int clif_traderequest(struct map_session_data *sd,char *name)
  2927. {
  2928. int fd;
  2929. nullpo_retr(0, sd);
  2930. fd=sd->fd;
  2931. WFIFOHEAD(fd,packet_len_table[0xe5]);
  2932. WFIFOW(fd,0)=0xe5;
  2933. strcpy((char*)WFIFOP(fd,2),name);
  2934. WFIFOSET(fd,packet_len_table[0xe5]);
  2935. return 0;
  2936. }
  2937. /*==========================================
  2938. * 取り引き要求応答
  2939. *------------------------------------------
  2940. */
  2941. int clif_tradestart(struct map_session_data *sd,int type)
  2942. {
  2943. int fd;
  2944. nullpo_retr(0, sd);
  2945. fd=sd->fd;
  2946. WFIFOHEAD(fd,packet_len_table[0xe7]);
  2947. WFIFOW(fd,0)=0xe7;
  2948. WFIFOB(fd,2)=type;
  2949. WFIFOSET(fd,packet_len_table[0xe7]);
  2950. return 0;
  2951. }
  2952. /*==========================================
  2953. * 相手方からのアイテム追加
  2954. *------------------------------------------
  2955. */
  2956. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  2957. {
  2958. int fd;
  2959. nullpo_retr(0, sd);
  2960. nullpo_retr(0, tsd);
  2961. fd=tsd->fd;
  2962. WFIFOHEAD(fd,packet_len_table[0xe9]);
  2963. WFIFOW(fd,0)=0xe9;
  2964. WFIFOL(fd,2)=amount;
  2965. if(index==0){
  2966. WFIFOW(fd,6) = 0; // type id
  2967. WFIFOB(fd,8) = 0; //identify flag
  2968. WFIFOB(fd,9) = 0; // attribute
  2969. WFIFOB(fd,10)= 0; //refine
  2970. WFIFOW(fd,11)= 0; //card (4w)
  2971. WFIFOW(fd,13)= 0; //card (4w)
  2972. WFIFOW(fd,15)= 0; //card (4w)
  2973. WFIFOW(fd,17)= 0; //card (4w)
  2974. }
  2975. else{
  2976. index-=2; //index fix
  2977. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2978. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2979. else
  2980. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2981. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2982. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2983. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2984. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2985. }
  2986. WFIFOSET(fd,packet_len_table[0xe9]);
  2987. return 0;
  2988. }
  2989. /*==========================================
  2990. * アイテム追加成功/失敗
  2991. *------------------------------------------
  2992. */
  2993. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  2994. {
  2995. int fd;
  2996. nullpo_retr(0, sd);
  2997. fd=sd->fd;
  2998. WFIFOHEAD(fd,packet_len_table[0xea]);
  2999. WFIFOW(fd,0)=0xea;
  3000. WFIFOW(fd,2)=index;
  3001. WFIFOB(fd,4)=fail;
  3002. WFIFOSET(fd,packet_len_table[0xea]);
  3003. return 0;
  3004. }
  3005. /*==========================================
  3006. * 取り引きok押し
  3007. *------------------------------------------
  3008. */
  3009. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3010. {
  3011. int fd;
  3012. nullpo_retr(0, sd);
  3013. fd=sd->fd;
  3014. WFIFOHEAD(fd,packet_len_table[0xec]);
  3015. WFIFOW(fd,0)=0xec;
  3016. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3017. WFIFOSET(fd,packet_len_table[0xec]);
  3018. return 0;
  3019. }
  3020. /*==========================================
  3021. * 取り引きがキャンセルされました
  3022. *------------------------------------------
  3023. */
  3024. int clif_tradecancelled(struct map_session_data *sd)
  3025. {
  3026. int fd;
  3027. nullpo_retr(0, sd);
  3028. fd=sd->fd;
  3029. WFIFOHEAD(fd,packet_len_table[0xee]);
  3030. WFIFOW(fd,0)=0xee;
  3031. WFIFOSET(fd,packet_len_table[0xee]);
  3032. return 0;
  3033. }
  3034. /*==========================================
  3035. * 取り引き完了
  3036. *------------------------------------------
  3037. */
  3038. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3039. {
  3040. int fd;
  3041. nullpo_retr(0, sd);
  3042. fd=sd->fd;
  3043. WFIFOHEAD(fd,packet_len_table[0xf0]);
  3044. WFIFOW(fd,0)=0xf0;
  3045. WFIFOB(fd,2)=fail;
  3046. WFIFOSET(fd,packet_len_table[0xf0]);
  3047. return 0;
  3048. }
  3049. /*==========================================
  3050. * カプラ倉庫のアイテム数を更新
  3051. *------------------------------------------
  3052. */
  3053. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3054. {
  3055. int fd;
  3056. nullpo_retr(0, sd);
  3057. nullpo_retr(0, stor);
  3058. fd=sd->fd;
  3059. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3060. WFIFOW(fd,0) = 0xf2; // update storage amount
  3061. WFIFOW(fd,2) = stor->storage_amount; //items
  3062. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3063. WFIFOSET(fd,packet_len_table[0xf2]);
  3064. return 0;
  3065. }
  3066. /*==========================================
  3067. * カプラ倉庫にアイテムを追加する
  3068. *------------------------------------------
  3069. */
  3070. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3071. {
  3072. int view,fd;
  3073. nullpo_retr(0, sd);
  3074. nullpo_retr(0, stor);
  3075. fd=sd->fd;
  3076. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3077. WFIFOW(fd,0) =0xf4; // Storage item added
  3078. WFIFOW(fd,2) =index+1; // index
  3079. WFIFOL(fd,4) =amount; // amount
  3080. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3081. WFIFOW(fd,8) =view;
  3082. else
  3083. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3084. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3085. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3086. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3087. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3088. WFIFOSET(fd,packet_len_table[0xf4]);
  3089. return 0;
  3090. }
  3091. /*==========================================
  3092. *
  3093. *------------------------------------------
  3094. */
  3095. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3096. {
  3097. int fd;
  3098. nullpo_retr(0, sd);
  3099. nullpo_retr(0, stor);
  3100. fd=sd->fd;
  3101. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3102. WFIFOW(fd,0) = 0xf2; // update storage amount
  3103. WFIFOW(fd,2) = stor->storage_amount; //items
  3104. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3105. WFIFOSET(fd,packet_len_table[0xf2]);
  3106. return 0;
  3107. }
  3108. /*==========================================
  3109. *
  3110. *------------------------------------------
  3111. */
  3112. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3113. {
  3114. int view,fd;
  3115. nullpo_retr(0, sd);
  3116. nullpo_retr(0, stor);
  3117. fd=sd->fd;
  3118. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3119. WFIFOW(fd,0) =0xf4; // Storage item added
  3120. WFIFOW(fd,2) =index+1; // index
  3121. WFIFOL(fd,4) =amount; // amount
  3122. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3123. WFIFOW(fd,8) =view;
  3124. else
  3125. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3126. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3127. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3128. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3129. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3130. WFIFOSET(fd,packet_len_table[0xf4]);
  3131. return 0;
  3132. }
  3133. /*==========================================
  3134. * カプラ倉庫からアイテムを取り去る
  3135. *------------------------------------------
  3136. */
  3137. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3138. {
  3139. int fd;
  3140. nullpo_retr(0, sd);
  3141. fd=sd->fd;
  3142. WFIFOHEAD(fd,packet_len_table[0xf6]);
  3143. WFIFOW(fd,0)=0xf6; // Storage item removed
  3144. WFIFOW(fd,2)=index+1;
  3145. WFIFOL(fd,4)=amount;
  3146. WFIFOSET(fd,packet_len_table[0xf6]);
  3147. return 0;
  3148. }
  3149. /*==========================================
  3150. * カプラ倉庫を閉じる
  3151. *------------------------------------------
  3152. */
  3153. int clif_storageclose(struct map_session_data *sd)
  3154. {
  3155. int fd;
  3156. nullpo_retr(0, sd);
  3157. fd=sd->fd;
  3158. WFIFOHEAD(fd,packet_len_table[0xf8]);
  3159. WFIFOW(fd,0)=0xf8; // Storage Closed
  3160. WFIFOSET(fd,packet_len_table[0xf8]);
  3161. return 0;
  3162. }
  3163. //
  3164. // callback系 ?
  3165. //
  3166. /*==========================================
  3167. * PC表示
  3168. *------------------------------------------
  3169. */
  3170. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3171. {
  3172. int len;
  3173. if(dstsd->chatID){
  3174. struct chat_data *cd;
  3175. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3176. if(cd && cd->usersd[0]==dstsd)
  3177. clif_dispchat(cd,sd->fd);
  3178. }
  3179. if(dstsd->vender_id)
  3180. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3181. if(dstsd->spiritball > 0)
  3182. clif_spiritball_single(sd->fd, dstsd);
  3183. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3184. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3185. )
  3186. clif_hpmeter_single(sd->fd, dstsd);
  3187. if(dstsd->status.manner < 0 && battle_config.manner_system)
  3188. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3189. // pvp circle for duel [LuzZza]
  3190. /*
  3191. if(dstsd->duel_group)
  3192. clif_specialeffect(&dstsd->bl, 159, 4);
  3193. */
  3194. }
  3195. void clif_getareachar_char(struct map_session_data* sd,struct block_list *bl)
  3196. {
  3197. struct unit_data *ud;
  3198. struct view_data *vd;
  3199. int len;
  3200. vd = status_get_viewdata(bl);
  3201. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3202. return;
  3203. ud = unit_bl2ud(bl);
  3204. if (ud && ud->walktimer != -1)
  3205. {
  3206. #if PACKETVER < 4
  3207. WFIFOHEAD(sd->fd, packet_len_table[0x7b]);
  3208. #else
  3209. WFIFOHEAD(sd->fd, packet_len_table[0x1da]);
  3210. #endif
  3211. len = clif_set007b(bl,vd,ud,WFIFOP(sd->fd,0));
  3212. WFIFOSET(sd->fd,len);
  3213. } else {
  3214. #if PACKETVER < 4
  3215. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3216. #else
  3217. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3218. #endif
  3219. len = clif_set0078(bl,vd,WFIFOP(sd->fd,0));
  3220. WFIFOSET(sd->fd,len);
  3221. }
  3222. if (vd->cloth_color)
  3223. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3224. switch (bl->type)
  3225. {
  3226. case BL_PC:
  3227. {
  3228. TBL_PC* tsd = (TBL_PC*)bl;
  3229. clif_getareachar_pc(sd, tsd);
  3230. if(tsd->state.size==2) // tiny/big players [Valaris]
  3231. clif_specialeffect(bl,423,0);
  3232. else if(tsd->state.size==1)
  3233. clif_specialeffect(bl,421,0);
  3234. }
  3235. break;
  3236. case BL_NPC:
  3237. {
  3238. if(((TBL_NPC*)bl)->chat_id)
  3239. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3240. }
  3241. break;
  3242. case BL_MOB:
  3243. {
  3244. TBL_MOB* md = (TBL_MOB*)bl;
  3245. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3246. clif_specialeffect(bl,423,0);
  3247. else if(md->special_state.size==1)
  3248. clif_specialeffect(bl,421,0);
  3249. }
  3250. break;
  3251. }
  3252. }
  3253. /*==========================================
  3254. * Older fix pos packet.
  3255. *------------------------------------------
  3256. */
  3257. int clif_fixpos2(struct block_list* bl)
  3258. {
  3259. struct unit_data *ud;
  3260. struct view_data *vd;
  3261. unsigned char buf[256];
  3262. int len;
  3263. nullpo_retr(0, bl);
  3264. ud = unit_bl2ud(bl);
  3265. vd = status_get_viewdata(bl);
  3266. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3267. return 0;
  3268. if(ud && ud->walktimer != -1)
  3269. len = clif_set007b(bl,vd,ud,buf);
  3270. else
  3271. len = clif_set0078(bl,vd,buf);
  3272. if (disguised(bl)) {
  3273. clif_send(buf,len,bl,AREA_WOS);
  3274. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  3275. clif_setdisguise((TBL_PC*)bl, buf, len, 1);
  3276. } else
  3277. clif_send(buf,len,bl,AREA);
  3278. return 0;
  3279. }
  3280. //Modifies the type of damage according to status changes [Skotlex]
  3281. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3282. /*==========================================
  3283. * Estimates walk delay based on the damage criteria. [Skotlex]
  3284. *------------------------------------------
  3285. */
  3286. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3287. if (type == 4 || type == 9 || damage <=0)
  3288. return 0;
  3289. if (bl->type == BL_PC) {
  3290. if (battle_config.pc_walk_delay_rate != 100)
  3291. delay = delay*battle_config.pc_walk_delay_rate/100;
  3292. } else
  3293. if (battle_config.walk_delay_rate != 100)
  3294. delay = delay*battle_config.walk_delay_rate/100;
  3295. if (div_ > 1) //Multi-hit skills mean higher delays.
  3296. delay += battle_config.multihit_delay*(div_-1);
  3297. if (delay <= 0)
  3298. return 0;
  3299. return delay>0?delay:0;
  3300. }
  3301. /*==========================================
  3302. * 通常攻撃エフェクト&ダメージ
  3303. *------------------------------------------
  3304. */
  3305. 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)
  3306. {
  3307. unsigned char buf[256];
  3308. struct status_change *sc;
  3309. nullpo_retr(0, src);
  3310. nullpo_retr(0, dst);
  3311. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3312. sc = status_get_sc(dst);
  3313. if(sc && sc->count) {
  3314. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3315. if(damage > 0)
  3316. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3317. if(damage2 > 0)
  3318. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3319. }
  3320. }
  3321. WBUFW(buf,0)=0x8a;
  3322. WBUFL(buf,2)=src->id;
  3323. WBUFL(buf,6)=dst->id;
  3324. WBUFL(buf,10)=tick;
  3325. WBUFL(buf,14)=sdelay;
  3326. WBUFL(buf,18)=ddelay;
  3327. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3328. WBUFW(buf,22)=-1;
  3329. WBUFW(buf,27)=-1;
  3330. } else {
  3331. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3332. WBUFW(buf,27)=damage2;
  3333. }
  3334. WBUFW(buf,24)=div;
  3335. WBUFB(buf,26)=type;
  3336. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3337. if(disguised(src)) {
  3338. WBUFL(buf,2)=-src->id;
  3339. if(damage > 0)
  3340. WBUFW(buf,22)=-1;
  3341. if(damage2 > 0)
  3342. WBUFW(buf,27)=-1;
  3343. clif_send(buf,packet_len_table[0x8a],src,SELF);
  3344. }
  3345. if (disguised(dst)) {
  3346. WBUFL(buf,6)=-dst->id;
  3347. if (disguised(src))
  3348. WBUFL(buf,2)=src->id;
  3349. else {
  3350. if(damage > 0)
  3351. WBUFW(buf,22)=-1;
  3352. if(damage2 > 0)
  3353. WBUFW(buf,27)=-1;
  3354. }
  3355. clif_send(buf,packet_len_table[0x8a],dst,SELF);
  3356. }
  3357. //Return adjusted can't walk delay for further processing.
  3358. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3359. }
  3360. /*==========================================
  3361. *
  3362. *------------------------------------------
  3363. */
  3364. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3365. {
  3366. int view,fd;
  3367. fd=sd->fd;
  3368. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3369. WFIFOHEAD(fd,packet_len_table[0x9d]);
  3370. WFIFOW(fd,0)=0x9d;
  3371. WFIFOL(fd,2)=fitem->bl.id;
  3372. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3373. WFIFOW(fd,6)=view;
  3374. else
  3375. WFIFOW(fd,6)=fitem->item_data.nameid;
  3376. WFIFOB(fd,8)=fitem->item_data.identify;
  3377. WFIFOW(fd,9)=fitem->bl.x;
  3378. WFIFOW(fd,11)=fitem->bl.y;
  3379. WFIFOW(fd,13)=fitem->item_data.amount;
  3380. WFIFOB(fd,15)=fitem->subx;
  3381. WFIFOB(fd,16)=fitem->suby;
  3382. WFIFOSET(fd,packet_len_table[0x9d]);
  3383. }
  3384. /*==========================================
  3385. * 場所スキルエフェクトが視界に入る
  3386. *------------------------------------------
  3387. */
  3388. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3389. {
  3390. int fd;
  3391. struct block_list *bl;
  3392. fd=sd->fd;
  3393. bl=map_id2bl(unit->group->src_id);
  3394. #if PACKETVER >= 3
  3395. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3396. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3397. memset(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3398. WFIFOW(fd, 0)=0x1c9;
  3399. WFIFOL(fd, 2)=unit->bl.id;
  3400. WFIFOL(fd, 6)=unit->group->src_id;
  3401. WFIFOW(fd,10)=unit->bl.x;
  3402. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3403. WFIFOB(fd,14)=unit->group->unit_id;
  3404. WFIFOB(fd,15)=1;
  3405. WFIFOB(fd,16)=1;
  3406. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3407. WFIFOSET(fd,packet_len_table[0x1c9]);
  3408. return 0;
  3409. }
  3410. #endif
  3411. WFIFOHEAD(fd,packet_len_table[0x11f]);
  3412. memset(WFIFOP(fd,0),0,packet_len_table[0x11f]);
  3413. WFIFOW(fd, 0)=0x11f;
  3414. WFIFOL(fd, 2)=unit->bl.id;
  3415. WFIFOL(fd, 6)=unit->group->src_id;
  3416. WFIFOW(fd,10)=unit->bl.x;
  3417. WFIFOW(fd,12)=unit->bl.y;
  3418. //Use invisible unit id for traps.
  3419. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3420. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3421. else
  3422. WFIFOB(fd,14)=unit->group->unit_id;
  3423. WFIFOB(fd,15)=0;
  3424. WFIFOSET(fd,packet_len_table[0x11f]);
  3425. if(unit->group->skill_id == WZ_ICEWALL)
  3426. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3427. return 0;
  3428. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3429. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3430. memset(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3431. WFIFOW(fd, 0)=0x1c9;
  3432. WFIFOL(fd, 2)=unit->bl.id;
  3433. WFIFOL(fd, 6)=unit->group->src_id;
  3434. WFIFOW(fd,10)=unit->bl.x;
  3435. WFIFOW(fd,12)=unit->bl.y;
  3436. WFIFOB(fd,14)=unit->group->unit_id;
  3437. WFIFOB(fd,15)=1;
  3438. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3439. WFIFOB(fd,16)=1;
  3440. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3441. } else {
  3442. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3443. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3444. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3445. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3446. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3447. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3448. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3449. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3450. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3451. //37-39
  3452. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3453. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3454. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3455. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3456. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3457. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3458. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3459. //65-68
  3460. //69-72
  3461. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3462. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3463. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3464. }
  3465. WFIFOSET(fd,packet_len_table[0x1c9]);
  3466. #endif
  3467. if(unit->group->skill_id == WZ_ICEWALL)
  3468. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3469. return 0;
  3470. */
  3471. }
  3472. /*==========================================
  3473. * 場所スキルエフェクトが視界から消える
  3474. *------------------------------------------
  3475. */
  3476. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3477. {
  3478. nullpo_retr(0, unit);
  3479. WFIFOHEAD(fd,packet_len_table[0x120]);
  3480. WFIFOW(fd, 0)=0x120;
  3481. WFIFOL(fd, 2)=unit->bl.id;
  3482. WFIFOSET(fd,packet_len_table[0x120]);
  3483. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3484. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3485. return 0;
  3486. }
  3487. /*==========================================
  3488. *
  3489. *------------------------------------------
  3490. */
  3491. int clif_01ac(struct block_list *bl)
  3492. {
  3493. unsigned char buf[32];
  3494. nullpo_retr(0, bl);
  3495. WBUFW(buf, 0) = 0x1ac;
  3496. WBUFL(buf, 2) = bl->id;
  3497. clif_send(buf,packet_len_table[0x1ac],bl,AREA);
  3498. return 0;
  3499. }
  3500. /*==========================================
  3501. *
  3502. *------------------------------------------
  3503. */
  3504. int clif_getareachar(struct block_list* bl,va_list ap)
  3505. {
  3506. struct map_session_data *sd;
  3507. nullpo_retr(0, bl);
  3508. nullpo_retr(0, ap);
  3509. sd=va_arg(ap,struct map_session_data*);
  3510. if (sd == NULL || session[sd->fd] == NULL)
  3511. return 0;
  3512. switch(bl->type){
  3513. case BL_ITEM:
  3514. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3515. break;
  3516. case BL_SKILL:
  3517. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3518. break;
  3519. default:
  3520. if(&sd->bl == bl)
  3521. break;
  3522. clif_getareachar_char(sd,bl);
  3523. break;
  3524. }
  3525. return 0;
  3526. }
  3527. /*==========================================
  3528. * tbl has gone out of view-size of bl
  3529. *------------------------------------------
  3530. */
  3531. int clif_outsight(struct block_list *bl,va_list ap)
  3532. {
  3533. struct block_list *tbl;
  3534. struct view_data *vd;
  3535. TBL_PC *sd, *tsd;
  3536. tbl=va_arg(ap,struct block_list*);
  3537. if(bl == tbl) return 0;
  3538. BL_CAST(BL_PC, bl, sd);
  3539. BL_CAST(BL_PC, tbl, tsd);
  3540. if (tsd && tsd->fd)
  3541. { //tsd has lost sight of the bl object.
  3542. switch(bl->type){
  3543. case BL_PC:
  3544. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3545. clif_clearchar_id(bl->id,0,tsd->fd);
  3546. if(sd->chatID){
  3547. struct chat_data *cd;
  3548. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3549. if(cd->usersd[0]==sd)
  3550. clif_dispchat(cd,tsd->fd);
  3551. }
  3552. if(sd->vender_id)
  3553. clif_closevendingboard(bl,tsd->fd);
  3554. break;
  3555. case BL_ITEM:
  3556. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3557. break;
  3558. case BL_SKILL:
  3559. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3560. break;
  3561. default:
  3562. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3563. clif_clearchar_id(bl->id,0,tsd->fd);
  3564. break;
  3565. }
  3566. }
  3567. if (sd && sd->fd)
  3568. { //sd is watching tbl go out of view.
  3569. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3570. clif_clearchar_id(tbl->id,0,sd->fd);
  3571. }
  3572. return 0;
  3573. }
  3574. /*==========================================
  3575. * tbl has come into view of bl
  3576. *------------------------------------------
  3577. */
  3578. int clif_insight(struct block_list *bl,va_list ap)
  3579. {
  3580. struct block_list *tbl;
  3581. TBL_PC *sd, *tsd;
  3582. tbl=va_arg(ap,struct block_list*);
  3583. if (bl == tbl) return 0;
  3584. BL_CAST(BL_PC, bl, sd);
  3585. BL_CAST(BL_PC, tbl, tsd);
  3586. if (tsd && tsd->fd)
  3587. { //Tell tsd that bl entered into his view
  3588. switch(bl->type){
  3589. case BL_ITEM:
  3590. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3591. break;
  3592. case BL_SKILL:
  3593. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3594. break;
  3595. default:
  3596. clif_getareachar_char(tsd,bl);
  3597. break;
  3598. }
  3599. }
  3600. if (sd && sd->fd)
  3601. { //Tell sd that tbl walked into his view
  3602. clif_getareachar_char(sd,tbl);
  3603. }
  3604. return 0;
  3605. }
  3606. /*==========================================
  3607. *
  3608. *------------------------------------------
  3609. */
  3610. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3611. {
  3612. int fd,id, inf2;
  3613. nullpo_retr(0, sd);
  3614. fd=sd->fd;
  3615. if( (id=sd->status.skill[skillid].id) <= 0 )
  3616. return 0;
  3617. WFIFOHEAD(fd,packet_len_table[0x147]);
  3618. WFIFOW(fd,0)=0x147;
  3619. WFIFOW(fd,2) = id;
  3620. if(type < 0)
  3621. WFIFOW(fd,4) = skill_get_inf(id);
  3622. else
  3623. WFIFOW(fd,4) = type;
  3624. WFIFOW(fd,6) = 0;
  3625. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3626. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3627. if(range < 0)
  3628. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3629. WFIFOW(fd,12)= range;
  3630. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3631. inf2 = skill_get_inf2(id);
  3632. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3633. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3634. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill))
  3635. //WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_get_max(id) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3636. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3637. else
  3638. WFIFOB(fd,38) = 0;
  3639. WFIFOSET(fd,packet_len_table[0x147]);
  3640. return 0;
  3641. }
  3642. /*==========================================
  3643. * スキルリストを送信する
  3644. *------------------------------------------
  3645. */
  3646. int clif_skillinfoblock(struct map_session_data *sd)
  3647. {
  3648. int fd;
  3649. int i,c,len=4,id, inf2;
  3650. nullpo_retr(0, sd);
  3651. fd=sd->fd;
  3652. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3653. WFIFOW(fd,0)=0x10f;
  3654. for ( i = c = 0; i < MAX_SKILL; i++){
  3655. if( (id=sd->status.skill[i].id)!=0 ){
  3656. WFIFOW(fd,len ) = id;
  3657. WFIFOW(fd,len+2) = skill_get_inf(id);
  3658. WFIFOW(fd,len+4) = 0;
  3659. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3660. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3661. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3662. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3663. inf2 = skill_get_inf2(id);
  3664. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3665. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3666. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill) )
  3667. //WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_get_max(id) && sd->status.skill[i].flag ==0 )? 1:0;
  3668. 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;
  3669. else
  3670. WFIFOB(fd,len+36) = 0;
  3671. len+=37;
  3672. c++;
  3673. }
  3674. }
  3675. WFIFOW(fd,2)=len;
  3676. WFIFOSET(fd,len);
  3677. return 0;
  3678. }
  3679. /*==========================================
  3680. * スキル割り振り通知
  3681. *------------------------------------------
  3682. */
  3683. int clif_skillup(struct map_session_data *sd,int skill_num)
  3684. {
  3685. int fd;
  3686. nullpo_retr(0, sd);
  3687. fd=sd->fd;
  3688. WFIFOHEAD(fd,packet_len_table[0x10e]);
  3689. WFIFOW(fd,0) = 0x10e;
  3690. WFIFOW(fd,2) = skill_num;
  3691. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3692. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3693. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3694. //WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_get_max(sd->status.skill[skill_num].id)) ? 1 : 0;
  3695. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3696. WFIFOSET(fd,packet_len_table[0x10e]);
  3697. return 0;
  3698. }
  3699. /*==========================================
  3700. * スキル詠唱エフェクトを送信する
  3701. *------------------------------------------
  3702. */
  3703. int clif_skillcasting(struct block_list* bl,
  3704. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  3705. {
  3706. int pl = skill_get_pl(skill_num);
  3707. unsigned char buf[32];
  3708. WBUFW(buf,0) = 0x13e;
  3709. WBUFL(buf,2) = src_id;
  3710. WBUFL(buf,6) = dst_id;
  3711. WBUFW(buf,10) = dst_x;
  3712. WBUFW(buf,12) = dst_y;
  3713. WBUFW(buf,14) = skill_num;
  3714. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3715. WBUFL(buf,20) = casttime;
  3716. clif_send(buf,packet_len_table[0x13e], bl, AREA);
  3717. if (disguised(bl)) {
  3718. WBUFL(buf,2) = -src_id;
  3719. WBUFL(buf,20) = 0;
  3720. clif_send(buf,packet_len_table[0x13e], bl, SELF);
  3721. }
  3722. return 0;
  3723. }
  3724. /*==========================================
  3725. *
  3726. *------------------------------------------
  3727. */
  3728. int clif_skillcastcancel(struct block_list* bl)
  3729. {
  3730. unsigned char buf[16];
  3731. nullpo_retr(0, bl);
  3732. WBUFW(buf,0) = 0x1b9;
  3733. WBUFL(buf,2) = bl->id;
  3734. clif_send(buf,packet_len_table[0x1b9], bl, AREA);
  3735. return 0;
  3736. }
  3737. /*==========================================
  3738. * スキル詠唱失敗
  3739. *------------------------------------------
  3740. */
  3741. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3742. {
  3743. int fd;
  3744. nullpo_retr(0, sd);
  3745. fd=sd->fd;
  3746. // reset all variables [celest]
  3747. // Should be handled now by the unit_* code.
  3748. sd->skillitem = sd->skillitemlv = -1;
  3749. if(type==0x4 && !sd->state.showdelay)
  3750. return 0;
  3751. WFIFOHEAD(fd,packet_len_table[0x110]);
  3752. WFIFOW(fd,0) = 0x110;
  3753. WFIFOW(fd,2) = skill_id;
  3754. WFIFOW(fd,4) = btype;
  3755. WFIFOW(fd,6) = 0;
  3756. WFIFOB(fd,8) = 0;
  3757. WFIFOB(fd,9) = type;
  3758. WFIFOSET(fd,packet_len_table[0x110]);
  3759. return 0;
  3760. }
  3761. /*==========================================
  3762. * スキル攻撃エフェクト&ダメージ
  3763. *------------------------------------------
  3764. */
  3765. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  3766. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3767. {
  3768. unsigned char buf[64];
  3769. struct status_change *sc;
  3770. nullpo_retr(0, src);
  3771. nullpo_retr(0, dst);
  3772. type = (type>0)?type:skill_get_hit(skill_id);
  3773. type = clif_calc_delay(type, ddelay);
  3774. sc = status_get_sc(dst);
  3775. if(sc && sc->count) {
  3776. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3777. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3778. }
  3779. #if PACKETVER < 3
  3780. WBUFW(buf,0)=0x114;
  3781. WBUFW(buf,2)=skill_id;
  3782. WBUFL(buf,4)=src->id;
  3783. WBUFL(buf,8)=dst->id;
  3784. WBUFL(buf,12)=tick;
  3785. WBUFL(buf,16)=sdelay;
  3786. WBUFL(buf,20)=ddelay;
  3787. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3788. WBUFW(buf,24)=-1;
  3789. } else {
  3790. WBUFW(buf,24)=damage;
  3791. }
  3792. WBUFW(buf,26)=skill_lv;
  3793. WBUFW(buf,28)=div;
  3794. WBUFB(buf,30)=type;
  3795. clif_send(buf,packet_len_table[0x114],src,AREA);
  3796. if(disguised(src)) {
  3797. WBUFL(buf,4)=-src->id;
  3798. if(damage > 0)
  3799. WBUFW(buf,24)=-1;
  3800. clif_send(buf,packet_len_table[0x114],src,SELF);
  3801. }
  3802. if (disguised(dst)) {
  3803. WBUFL(buf,8)=-dst->id;
  3804. if (disguised(src))
  3805. WBUFL(buf,4)=src->id;
  3806. else if(damage > 0)
  3807. WBUFW(buf,24)=-1;
  3808. clif_send(buf,packet_len_table[0x114],dst,SELF);
  3809. }
  3810. #else
  3811. WBUFW(buf,0)=0x1de;
  3812. WBUFW(buf,2)=skill_id;
  3813. WBUFL(buf,4)=src->id;
  3814. WBUFL(buf,8)=dst->id;
  3815. WBUFL(buf,12)=tick;
  3816. WBUFL(buf,16)=sdelay;
  3817. WBUFL(buf,20)=ddelay;
  3818. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3819. WBUFL(buf,24)=-1;
  3820. } else {
  3821. WBUFL(buf,24)=damage;
  3822. }
  3823. WBUFW(buf,28)=skill_lv;
  3824. WBUFW(buf,30)=div;
  3825. WBUFB(buf,32)=type;
  3826. clif_send(buf,packet_len_table[0x1de],src,AREA);
  3827. if(disguised(src)) {
  3828. WBUFL(buf,4)=-src->id;
  3829. if(damage > 0)
  3830. WBUFW(buf,24)=-1;
  3831. clif_send(buf,packet_len_table[0x1de],src,SELF);
  3832. }
  3833. if (disguised(dst)) {
  3834. WBUFL(buf,8)=-dst->id;
  3835. if (disguised(src))
  3836. WBUFL(buf,4)=src->id;
  3837. else if(damage > 0)
  3838. WBUFW(buf,24)=-1;
  3839. clif_send(buf,packet_len_table[0x1de],dst,SELF);
  3840. }
  3841. #endif
  3842. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3843. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3844. }
  3845. /*==========================================
  3846. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3847. *------------------------------------------
  3848. */
  3849. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  3850. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3851. {
  3852. unsigned char buf[64];
  3853. struct status_change *sc;
  3854. nullpo_retr(0, src);
  3855. nullpo_retr(0, dst);
  3856. type = (type>0)?type:skill_get_hit(skill_id);
  3857. type = clif_calc_delay(type, ddelay);
  3858. sc = status_get_sc(dst);
  3859. if(sc && sc->count) {
  3860. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3861. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3862. }
  3863. WBUFW(buf,0)=0x115;
  3864. WBUFW(buf,2)=skill_id;
  3865. WBUFL(buf,4)=src->id;
  3866. WBUFL(buf,8)=dst->id;
  3867. WBUFL(buf,12)=tick;
  3868. WBUFL(buf,16)=sdelay;
  3869. WBUFL(buf,20)=ddelay;
  3870. WBUFW(buf,24)=dst->x;
  3871. WBUFW(buf,26)=dst->y;
  3872. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3873. WBUFW(buf,28)=-1;
  3874. } else {
  3875. WBUFW(buf,28)=damage;
  3876. }
  3877. WBUFW(buf,30)=skill_lv;
  3878. WBUFW(buf,32)=div;
  3879. WBUFB(buf,34)=type;
  3880. clif_send(buf,packet_len_table[0x115],src,AREA);
  3881. if(disguised(src)) {
  3882. WBUFL(buf,4)=-src->id;
  3883. if(damage > 0)
  3884. WBUFW(buf,28)=-1;
  3885. clif_send(buf,packet_len_table[0x115],src,SELF);
  3886. }
  3887. if (disguised(dst)) {
  3888. WBUFL(buf,8)=-dst->id;
  3889. if (disguised(src))
  3890. WBUFL(buf,4)=src->id;
  3891. else if(damage > 0)
  3892. WBUFW(buf,28)=-1;
  3893. clif_send(buf,packet_len_table[0x115],dst,SELF);
  3894. }
  3895. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3896. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3897. }
  3898. /*==========================================
  3899. * 支援/回復スキルエフェクト
  3900. *------------------------------------------
  3901. */
  3902. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  3903. int skill_id,int heal,int fail)
  3904. {
  3905. unsigned char buf[32];
  3906. nullpo_retr(0, src);
  3907. nullpo_retr(0, dst);
  3908. WBUFW(buf,0)=0x11a;
  3909. WBUFW(buf,2)=skill_id;
  3910. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  3911. WBUFL(buf,6)=dst->id;
  3912. WBUFL(buf,10)=src->id;
  3913. WBUFB(buf,14)=fail;
  3914. clif_send(buf,packet_len_table[0x11a],src,AREA);
  3915. if(disguised(src)) {
  3916. WBUFL(buf,10)=-src->id;
  3917. clif_send(buf,packet_len_table[0x115],src,SELF);
  3918. }
  3919. if (disguised(dst)) {
  3920. WBUFL(buf,6)=-dst->id;
  3921. if (disguised(src))
  3922. WBUFL(buf,10)=src->id;
  3923. clif_send(buf,packet_len_table[0x115],dst,SELF);
  3924. }
  3925. return fail;
  3926. }
  3927. /*==========================================
  3928. * 場所スキルエフェクト
  3929. *------------------------------------------
  3930. */
  3931. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3932. {
  3933. unsigned char buf[32];
  3934. nullpo_retr(0, src);
  3935. WBUFW(buf,0)=0x117;
  3936. WBUFW(buf,2)=skill_id;
  3937. WBUFL(buf,4)=src->id;
  3938. WBUFW(buf,8)=val;
  3939. WBUFW(buf,10)=x;
  3940. WBUFW(buf,12)=y;
  3941. WBUFL(buf,14)=tick;
  3942. clif_send(buf,packet_len_table[0x117],src,AREA);
  3943. if(disguised(src)) {
  3944. WBUFL(buf,4)=-src->id;
  3945. clif_send(buf,packet_len_table[0x117],src,SELF);
  3946. }
  3947. return 0;
  3948. }
  3949. /*==========================================
  3950. * 場所スキルエフェクト表示
  3951. *------------------------------------------
  3952. */
  3953. int clif_skill_setunit(struct skill_unit *unit)
  3954. {
  3955. unsigned char buf[128];
  3956. struct block_list *bl;
  3957. nullpo_retr(0, unit);
  3958. bl=map_id2bl(unit->group->src_id);
  3959. // These are invisible client-side, but are necessary because
  3960. // otherwise the client will not know who caused the attack.
  3961. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  3962. // return 0;
  3963. #if PACKETVER >= 3
  3964. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3965. memset(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  3966. WBUFW(buf, 0)=0x1c9;
  3967. WBUFL(buf, 2)=unit->bl.id;
  3968. WBUFL(buf, 6)=unit->group->src_id;
  3969. WBUFW(buf,10)=unit->bl.x;
  3970. WBUFW(buf,12)=unit->bl.y;
  3971. WBUFB(buf,14)=unit->group->unit_id;
  3972. WBUFB(buf,15)=1;
  3973. WBUFB(buf,16)=1;
  3974. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3975. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  3976. return 0;
  3977. }
  3978. #endif
  3979. memset(WBUFP(buf, 0),0,packet_len_table[0x11f]);
  3980. WBUFW(buf, 0)=0x11f;
  3981. WBUFL(buf, 2)=unit->bl.id;
  3982. WBUFL(buf, 6)=unit->group->src_id;
  3983. WBUFW(buf,10)=unit->bl.x;
  3984. WBUFW(buf,12)=unit->bl.y;
  3985. WBUFB(buf,14)=unit->group->unit_id;
  3986. WBUFB(buf,15)=0;
  3987. clif_send(buf,packet_len_table[0x11f],&unit->bl,AREA);
  3988. return 0;
  3989. /* Previous mysterious implementation noone really understands. [Skotlex]
  3990. memset(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  3991. WBUFW(buf, 0)=0x1c9;
  3992. WBUFL(buf, 2)=unit->bl.id;
  3993. WBUFL(buf, 6)=unit->group->src_id;
  3994. WBUFW(buf,10)=unit->bl.x;
  3995. WBUFW(buf,12)=unit->bl.y;
  3996. WBUFB(buf,14)=unit->group->unit_id;
  3997. WBUFB(buf,15)=1;
  3998. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  3999. WBUFB(buf,16)=1;
  4000. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4001. } else {
  4002. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4003. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4004. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4005. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4006. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4007. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4008. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4009. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4010. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4011. //37-39
  4012. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4013. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4014. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4015. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4016. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4017. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4018. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4019. //65-68
  4020. //69-72
  4021. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4022. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4023. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4024. }
  4025. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4026. #endif
  4027. return 0;
  4028. */
  4029. }
  4030. /*==========================================
  4031. * 場所スキルエフェクト削除
  4032. *------------------------------------------
  4033. */
  4034. int clif_skill_delunit(struct skill_unit *unit)
  4035. {
  4036. unsigned char buf[16];
  4037. nullpo_retr(0, unit);
  4038. WBUFW(buf, 0)=0x120;
  4039. WBUFL(buf, 2)=unit->bl.id;
  4040. clif_send(buf,packet_len_table[0x120],&unit->bl,AREA);
  4041. return 0;
  4042. }
  4043. /*==========================================
  4044. * ワープ場所選択
  4045. *------------------------------------------
  4046. */
  4047. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4048. const char *map1,const char *map2,const char *map3,const char *map4)
  4049. {
  4050. int fd;
  4051. nullpo_retr(0, sd);
  4052. fd=sd->fd;
  4053. WFIFOHEAD(fd,packet_len_table[0x11c]);
  4054. WFIFOW(fd,0)=0x11c;
  4055. WFIFOW(fd,2)=skill_num;
  4056. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4057. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4058. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4059. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4060. WFIFOSET(fd,packet_len_table[0x11c]);
  4061. sd->menuskill_id = skill_num;
  4062. if (skill_num == AL_WARP)
  4063. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4064. else
  4065. sd->menuskill_lv = skill_lv;
  4066. return 0;
  4067. }
  4068. /*==========================================
  4069. * メモ応答
  4070. *------------------------------------------
  4071. */
  4072. int clif_skill_memo(struct map_session_data *sd,int flag)
  4073. {
  4074. int fd;
  4075. nullpo_retr(0, sd);
  4076. fd=sd->fd;
  4077. WFIFOHEAD(fd,packet_len_table[0x11e]);
  4078. WFIFOW(fd,0)=0x11e;
  4079. WFIFOB(fd,2)=flag;
  4080. WFIFOSET(fd,packet_len_table[0x11e]);
  4081. return 0;
  4082. }
  4083. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4084. {
  4085. int fd;
  4086. nullpo_retr(0, sd);
  4087. fd=sd->fd;
  4088. WFIFOHEAD(fd,packet_len_table[0x189]);
  4089. WFIFOW(fd,0)=0x189;
  4090. WFIFOW(fd,2)=flag;
  4091. WFIFOSET(fd,packet_len_table[0x189]);
  4092. return 0;
  4093. }
  4094. /*==========================================
  4095. * モンスター情報
  4096. *------------------------------------------
  4097. */
  4098. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4099. {
  4100. struct mob_data *md;
  4101. unsigned char buf[64];
  4102. int i;//, fix;
  4103. nullpo_retr(0, sd);
  4104. nullpo_retr(0, dst);
  4105. if(dst->type!=BL_MOB )
  4106. return 0;
  4107. if((md=(struct mob_data *)dst) == NULL)
  4108. return 0;
  4109. WBUFW(buf, 0)=0x18c;
  4110. WBUFW(buf, 2)=md->vd->class_;
  4111. WBUFW(buf, 4)=md->level;
  4112. WBUFW(buf, 6)=md->db->size;
  4113. WBUFL(buf, 8)=md->hp;
  4114. WBUFW(buf,12)= (battle_config.estimation_type&1?status_get_def(&md->bl):0)
  4115. +(battle_config.estimation_type&2?status_get_def2(&md->bl):0);
  4116. WBUFW(buf,14)=md->db->race;
  4117. WBUFW(buf,16)= (battle_config.estimation_type&1?status_get_mdef(&md->bl):0)
  4118. +(battle_config.estimation_type&2?status_get_mdef2(&md->bl) - (md->db->vit>>1):0);
  4119. WBUFW(buf,18)=status_get_elem_type(&md->bl);
  4120. for(i=0;i<9;i++)
  4121. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,md->def_ele);
  4122. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4123. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,md->def_ele))<0?0:fix);
  4124. if(sd->status.party_id>0)
  4125. clif_send(buf,packet_len_table[0x18c],&sd->bl,PARTY_AREA);
  4126. else{
  4127. WFIFOHEAD(sd->fd,packet_len_table[0x18c]);
  4128. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x18c]);
  4129. WFIFOSET(sd->fd,packet_len_table[0x18c]);
  4130. }
  4131. return 0;
  4132. }
  4133. /*==========================================
  4134. * アイテム合成可能リスト
  4135. *------------------------------------------
  4136. */
  4137. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4138. {
  4139. int i,c,view,fd;
  4140. nullpo_retr(0, sd);
  4141. if(sd->menuskill_id == AM_PHARMACY)
  4142. return 0; //Avoid resending the menu twice or more times...
  4143. fd=sd->fd;
  4144. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4145. WFIFOW(fd, 0)=0x18d;
  4146. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4147. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4148. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4149. WFIFOW(fd,c*8+ 4)= view;
  4150. else
  4151. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4152. WFIFOW(fd,c*8+ 6)= 0x0012;
  4153. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4154. c++;
  4155. }
  4156. }
  4157. WFIFOW(fd, 2)=c*8+8;
  4158. WFIFOSET(fd,WFIFOW(fd,2));
  4159. if(c > 0) {
  4160. sd->menuskill_id = AM_PHARMACY;
  4161. sd->menuskill_lv = trigger;
  4162. return 1;
  4163. }
  4164. return 0;
  4165. }
  4166. /*==========================================
  4167. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4168. *------------------------------------------
  4169. */
  4170. int clif_status_load(struct block_list *bl,int type, int flag)
  4171. {
  4172. int fd;
  4173. if (type == SI_BLANK) //It shows nothing on the client...
  4174. return 0;
  4175. if (bl->type != BL_PC)
  4176. return 0;
  4177. fd = ((struct map_session_data*)bl)->fd;
  4178. WFIFOHEAD(fd,packet_len_table[0x196]);
  4179. WFIFOW(fd,0)=0x0196;
  4180. WFIFOW(fd,2)=type;
  4181. WFIFOL(fd,4)=bl->id;
  4182. WFIFOB(fd,8)=flag; //Status start
  4183. WFIFOSET(fd, packet_len_table[0x196]);
  4184. return 0;
  4185. }
  4186. /*==========================================
  4187. * 状態異常アイコン/メッセージ表示
  4188. *------------------------------------------
  4189. */
  4190. int clif_status_change(struct block_list *bl,int type,int flag)
  4191. {
  4192. unsigned char buf[16];
  4193. if (type == SI_BLANK) //It shows nothing on the client...
  4194. return 0;
  4195. nullpo_retr(0, bl);
  4196. WBUFW(buf,0)=0x0196;
  4197. WBUFW(buf,2)=type;
  4198. WBUFL(buf,4)=bl->id;
  4199. WBUFB(buf,8)=flag;
  4200. clif_send(buf,packet_len_table[0x196],bl,AREA);
  4201. return 0;
  4202. }
  4203. /*==========================================
  4204. * Send message (modified by [Yor])
  4205. *------------------------------------------
  4206. */
  4207. int clif_displaymessage(const int fd, char* mes)
  4208. {
  4209. // invalid pointer?
  4210. nullpo_retr(-1, mes);
  4211. //Console [Wizputer] //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4212. if (fd == 0)
  4213. return 0;
  4214. else {
  4215. int len_mes = strlen(mes);
  4216. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4217. WFIFOHEAD(fd, 5 + len_mes);
  4218. WFIFOW(fd,0) = 0x8e;
  4219. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4220. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4221. WFIFOSET(fd, 5 + len_mes);
  4222. }
  4223. }
  4224. return 0;
  4225. }
  4226. /*==========================================
  4227. * 天の声を送信する
  4228. *------------------------------------------
  4229. */
  4230. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4231. {
  4232. unsigned char *buf;
  4233. int lp;
  4234. lp = (flag & 0x10) ? 8 : 4;
  4235. buf = (unsigned char*)aCallocA(len + lp + 8, sizeof(unsigned char));
  4236. WBUFW(buf,0) = 0x9a;
  4237. WBUFW(buf,2) = len + lp;
  4238. WBUFL(buf,4) = 0x65756c62;
  4239. memcpy(WBUFP(buf,lp), mes, len);
  4240. flag &= 0x07;
  4241. clif_send(buf, WBUFW(buf,2), bl,
  4242. (flag == 1) ? ALL_SAMEMAP :
  4243. (flag == 2) ? AREA :
  4244. (flag == 3) ? SELF :
  4245. ALL_CLIENT);
  4246. if(buf) aFree(buf);
  4247. if(use_irc && irc_announce_flag && !flag)
  4248. irc_announce(mes);
  4249. return 0;
  4250. }
  4251. /*==========================================
  4252. * グローバルメッセージ
  4253. *------------------------------------------
  4254. */
  4255. void clif_GlobalMessage(struct block_list *bl,char *message)
  4256. {
  4257. char buf[100];
  4258. int len;
  4259. nullpo_retv(bl);
  4260. if(!message)
  4261. return;
  4262. len = strlen(message)+1;
  4263. WBUFW(buf,0)=0x8d;
  4264. WBUFW(buf,2)=len+8;
  4265. WBUFL(buf,4)=bl->id;
  4266. strncpy((char *) WBUFP(buf,8),message,len);
  4267. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,AREA_CHAT_WOC);
  4268. }
  4269. /*==========================================
  4270. * Send main chat message [LuzZza]
  4271. *------------------------------------------
  4272. */
  4273. void clif_MainChatMessage(char* message) {
  4274. char buf[200];
  4275. int len;
  4276. if(!message)
  4277. return;
  4278. len = strlen(message)+1;
  4279. if (len+8 > sizeof(buf)) {
  4280. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4281. len = sizeof(buf)-8;
  4282. }
  4283. WBUFW(buf,0)=0x8d;
  4284. WBUFW(buf,2)=len+8;
  4285. WBUFL(buf,4)=0;
  4286. strncpy((char *) WBUFP(buf,8),message,len);
  4287. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4288. }
  4289. /*==========================================
  4290. * Does an announce message in the given color.
  4291. *------------------------------------------
  4292. */
  4293. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4294. {
  4295. unsigned char *buf;
  4296. buf = (unsigned char*)aCallocA(len + 16, sizeof(unsigned char));
  4297. WBUFW(buf,0) = 0x1c3;
  4298. WBUFW(buf,2) = len + 16;
  4299. WBUFL(buf,4) = color;
  4300. WBUFW(buf,8) = 0x190; //Font style? Type?
  4301. WBUFW(buf,10) = 0x0c; //12? Font size?
  4302. WBUFL(buf,12) = 0; //Unknown!
  4303. memcpy(WBUFP(buf,16), mes, len);
  4304. flag &= 0x07;
  4305. clif_send(buf, WBUFW(buf,2), bl,
  4306. (flag == 1) ? ALL_SAMEMAP :
  4307. (flag == 2) ? AREA :
  4308. (flag == 3) ? SELF :
  4309. ALL_CLIENT);
  4310. if(buf) aFree(buf);
  4311. return 0;
  4312. }
  4313. /*==========================================
  4314. * HPSP回復エフェクトを送信する
  4315. *------------------------------------------
  4316. */
  4317. int clif_heal(int fd,int type,int val)
  4318. {
  4319. WFIFOHEAD(fd,packet_len_table[0x13d]);
  4320. WFIFOW(fd,0)=0x13d;
  4321. WFIFOW(fd,2)=type;
  4322. WFIFOW(fd,4)=val;
  4323. WFIFOSET(fd,packet_len_table[0x13d]);
  4324. return 0;
  4325. }
  4326. /*==========================================
  4327. * 復活する
  4328. *------------------------------------------
  4329. */
  4330. int clif_resurrection(struct block_list *bl,int type)
  4331. {
  4332. unsigned char buf[16];
  4333. nullpo_retr(0, bl);
  4334. WBUFW(buf,0)=0x148;
  4335. WBUFL(buf,2)=bl->id;
  4336. WBUFW(buf,6)=type;
  4337. clif_send(buf,packet_len_table[0x148],bl,type==1 ? AREA : AREA_WOS);
  4338. if (disguised(bl))
  4339. clif_spawn(bl);
  4340. return 0;
  4341. }
  4342. /*==========================================
  4343. * PVP実装?(仮)
  4344. *------------------------------------------
  4345. */
  4346. int clif_set0199(int fd,int type)
  4347. {
  4348. WFIFOHEAD(fd,packet_len_table[0x199]);
  4349. WFIFOW(fd,0)=0x199;
  4350. WFIFOW(fd,2)=type;
  4351. WFIFOSET(fd,packet_len_table[0x199]);
  4352. return 0;
  4353. }
  4354. /*==========================================
  4355. * PVP実装?(仮)
  4356. *------------------------------------------
  4357. */
  4358. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4359. {
  4360. nullpo_retr(0, sd);
  4361. if(type == 2) {
  4362. WFIFOHEAD(sd->fd,packet_len_table[0x19a]);
  4363. WFIFOW(sd->fd,0) = 0x19a;
  4364. WFIFOL(sd->fd,2) = sd->bl.id;
  4365. if(pvprank<=0)
  4366. pc_calc_pvprank(sd);
  4367. WFIFOL(sd->fd,6) = pvprank;
  4368. WFIFOL(sd->fd,10) = pvpnum;
  4369. WFIFOSET(sd->fd,packet_len_table[0x19a]);
  4370. } else {
  4371. unsigned char buf[32];
  4372. WBUFW(buf,0) = 0x19a;
  4373. WBUFL(buf,2) = sd->bl.id;
  4374. if(sd->sc.option&0x46)
  4375. // WTF? a -1 to an unsigned value...
  4376. WBUFL(buf,6) = 0xFFFFFFFF;
  4377. else
  4378. if(pvprank<=0)
  4379. pc_calc_pvprank(sd);
  4380. WBUFL(buf,6) = pvprank;
  4381. WBUFL(buf,10) = pvpnum;
  4382. if(!type)
  4383. clif_send(buf,packet_len_table[0x19a],&sd->bl,AREA);
  4384. else
  4385. clif_send(buf,packet_len_table[0x19a],&sd->bl,ALL_SAMEMAP);
  4386. }
  4387. return 0;
  4388. }
  4389. /*==========================================
  4390. *
  4391. *------------------------------------------
  4392. */
  4393. int clif_send0199(int map,int type)
  4394. {
  4395. struct block_list bl;
  4396. unsigned char buf[16];
  4397. bl.type = BL_NUL;
  4398. bl.m = map;
  4399. WBUFW(buf,0)=0x199;
  4400. WBUFW(buf,2)=type;
  4401. clif_send(buf,packet_len_table[0x199],&bl,ALL_SAMEMAP);
  4402. return 0;
  4403. }
  4404. /*==========================================
  4405. * 精錬エフェクトを送信する
  4406. *------------------------------------------
  4407. */
  4408. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  4409. {
  4410. WFIFOHEAD(fd,packet_len_table[0x188]);
  4411. WFIFOW(fd,0)=0x188;
  4412. WFIFOW(fd,2)=fail;
  4413. WFIFOW(fd,4)=index+2;
  4414. WFIFOW(fd,6)=val;
  4415. WFIFOSET(fd,packet_len_table[0x188]);
  4416. return 0;
  4417. }
  4418. /*==========================================
  4419. * Wisp/page is transmitted to the destination player
  4420. *------------------------------------------
  4421. */
  4422. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4423. {
  4424. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4425. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4426. WFIFOW(fd,0) = 0x97;
  4427. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4428. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4429. memcpy(WFIFOP(fd,28), mes, mes_len);
  4430. WFIFOSET(fd,WFIFOW(fd,2));
  4431. return 0;
  4432. }
  4433. /*==========================================
  4434. * The transmission result of Wisp/page is transmitted to the source player
  4435. *------------------------------------------
  4436. */
  4437. 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
  4438. {
  4439. WFIFOHEAD(fd,packet_len_table[0x98]);
  4440. WFIFOW(fd,0) = 0x98;
  4441. WFIFOW(fd,2) = flag;
  4442. WFIFOSET(fd,packet_len_table[0x98]);
  4443. return 0;
  4444. }
  4445. /*==========================================
  4446. * キャラID名前引き結果を送信する
  4447. *------------------------------------------
  4448. */
  4449. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4450. {
  4451. char *p= map_charid2nick(char_id);
  4452. int fd;
  4453. nullpo_retr(0, sd);
  4454. fd=sd->fd;
  4455. if(p!=NULL){
  4456. WFIFOHEAD(fd,packet_len_table[0x194]);
  4457. WFIFOW(fd,0)=0x194;
  4458. WFIFOL(fd,2)=char_id;
  4459. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4460. WFIFOSET(fd,packet_len_table[0x194]);
  4461. }else{
  4462. map_reqchariddb(sd,char_id);
  4463. chrif_searchcharid(char_id);
  4464. }
  4465. return 0;
  4466. }
  4467. /*==========================================
  4468. * カードの挿入可能リストを返す
  4469. *------------------------------------------
  4470. */
  4471. int clif_use_card(struct map_session_data *sd,int idx)
  4472. {
  4473. int i,c,ep;
  4474. int fd=sd->fd;
  4475. nullpo_retr(0, sd);
  4476. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4477. return 0;
  4478. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != 6)
  4479. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4480. ep=sd->inventory_data[idx]->equip;
  4481. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4482. WFIFOW(fd,0)=0x017b;
  4483. for(i=c=0;i<MAX_INVENTORY;i++){
  4484. int j;
  4485. if(sd->inventory_data[i] == NULL)
  4486. continue;
  4487. if(sd->inventory_data[i]->type!=4 && sd->inventory_data[i]->type!=5) // 武器防具じゃない
  4488. continue;
  4489. if(sd->status.inventory[i].card[0]==0x00ff || sd->status.inventory[i].card[0]==(short)0xff00 || sd->status.inventory[i].card[0]==0x00fe)
  4490. continue;
  4491. if(sd->status.inventory[i].identify==0 ) // 未鑑定
  4492. continue;
  4493. if((sd->inventory_data[i]->equip&ep)==0) // 装備個所が違う
  4494. continue;
  4495. if(sd->inventory_data[i]->type==4 && ep==32) // 盾カードと両手武器
  4496. continue;
  4497. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4498. if( sd->status.inventory[i].card[j]==0 )
  4499. break;
  4500. }
  4501. if(j==sd->inventory_data[i]->slot) // すでにカードが一杯
  4502. continue;
  4503. WFIFOW(fd,4+c*2)=i+2;
  4504. c++;
  4505. }
  4506. WFIFOW(fd,2)=4+c*2;
  4507. WFIFOSET(fd,WFIFOW(fd,2));
  4508. return 0;
  4509. }
  4510. /*==========================================
  4511. * カードの挿入終了
  4512. *------------------------------------------
  4513. */
  4514. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4515. {
  4516. int fd;
  4517. nullpo_retr(0, sd);
  4518. fd=sd->fd;
  4519. WFIFOHEAD(fd,packet_len_table[0x17d]);
  4520. WFIFOW(fd,0)=0x17d;
  4521. WFIFOW(fd,2)=idx_equip+2;
  4522. WFIFOW(fd,4)=idx_card+2;
  4523. WFIFOB(fd,6)=flag;
  4524. WFIFOSET(fd,packet_len_table[0x17d]);
  4525. return 0;
  4526. }
  4527. /*==========================================
  4528. * 鑑定可能アイテムリスト送信
  4529. *------------------------------------------
  4530. */
  4531. int clif_item_identify_list(struct map_session_data *sd)
  4532. {
  4533. int i,c;
  4534. int fd;
  4535. nullpo_retr(0, sd);
  4536. fd=sd->fd;
  4537. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4538. WFIFOW(fd,0)=0x177;
  4539. for(i=c=0;i<MAX_INVENTORY;i++){
  4540. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){
  4541. WFIFOW(fd,c*2+4)=i+2;
  4542. c++;
  4543. }
  4544. }
  4545. if(c > 0) {
  4546. WFIFOW(fd,2)=c*2+4;
  4547. WFIFOSET(fd,WFIFOW(fd,2));
  4548. sd->menuskill_id = MC_IDENTIFY;
  4549. sd->menuskill_lv = c;
  4550. }
  4551. return 0;
  4552. }
  4553. /*==========================================
  4554. * 鑑定結果
  4555. *------------------------------------------
  4556. */
  4557. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4558. {
  4559. int fd;
  4560. nullpo_retr(0, sd);
  4561. fd=sd->fd;
  4562. WFIFOHEAD(fd,packet_len_table[0x179]);
  4563. WFIFOW(fd, 0)=0x179;
  4564. WFIFOW(fd, 2)=idx+2;
  4565. WFIFOB(fd, 4)=flag;
  4566. WFIFOSET(fd,packet_len_table[0x179]);
  4567. return 0;
  4568. }
  4569. /*==========================================
  4570. * 修理可能アイテムリスト送信
  4571. *------------------------------------------
  4572. */
  4573. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4574. {
  4575. int i,c;
  4576. int fd;
  4577. int nameid;
  4578. nullpo_retr(0, sd);
  4579. nullpo_retr(0, dstsd);
  4580. fd=sd->fd;
  4581. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4582. WFIFOW(fd,0)=0x1fc;
  4583. for(i=c=0;i<MAX_INVENTORY;i++){
  4584. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4585. WFIFOW(fd,c*13+4) = i;
  4586. WFIFOW(fd,c*13+6) = nameid;
  4587. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4588. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4589. WFIFOB(fd,c*13+16)= c;
  4590. c++;
  4591. }
  4592. }
  4593. if(c > 0) {
  4594. WFIFOW(fd,2)=c*13+4;
  4595. WFIFOSET(fd,WFIFOW(fd,2));
  4596. sd->menuskill_id = BS_REPAIRWEAPON;
  4597. sd->menuskill_lv = dstsd->bl.id;
  4598. }else
  4599. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4600. return 0;
  4601. }
  4602. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4603. {
  4604. int view,fd;
  4605. nullpo_retr(0, sd);
  4606. fd=sd->fd;
  4607. WFIFOHEAD(fd,packet_len_table[0x1fe]);
  4608. WFIFOW(fd, 0)=0x1fe;
  4609. if((view = itemdb_viewid(nameid)) > 0)
  4610. WFIFOW(fd, 2)=view;
  4611. else
  4612. WFIFOW(fd, 2)=nameid;
  4613. WFIFOB(fd, 4)=flag;
  4614. WFIFOSET(fd,packet_len_table[0x1fe]);
  4615. return 0;
  4616. }
  4617. /*==========================================
  4618. * Weapon Refining - Taken from jAthena
  4619. *------------------------------------------
  4620. */
  4621. int clif_item_refine_list(struct map_session_data *sd)
  4622. {
  4623. int i,c;
  4624. int fd;
  4625. int skilllv;
  4626. int wlv;
  4627. int refine_item[5];
  4628. nullpo_retr(0, sd);
  4629. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4630. fd=sd->fd;
  4631. refine_item[0] = -1;
  4632. refine_item[1] = pc_search_inventory(sd,1010);
  4633. refine_item[2] = pc_search_inventory(sd,1011);
  4634. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4635. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4636. WFIFOW(fd,0)=0x221;
  4637. for(i=c=0;i<MAX_INVENTORY;i++){
  4638. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4639. sd->status.inventory[i].identify==1 && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4640. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4641. WFIFOW(fd,c*13+ 4)=i+2;
  4642. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4643. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4644. WFIFOW(fd,c*13+10)=0;
  4645. WFIFOB(fd,c*13+12)=c;
  4646. c++;
  4647. }
  4648. }
  4649. WFIFOW(fd,2)=c*13+4;
  4650. WFIFOSET(fd,WFIFOW(fd,2));
  4651. sd->menuskill_id = WS_WEAPONREFINE;
  4652. sd->menuskill_lv = skilllv;
  4653. return 0;
  4654. }
  4655. /*==========================================
  4656. * アイテムによる一時的なスキル効果
  4657. *------------------------------------------
  4658. */
  4659. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  4660. {
  4661. int fd;
  4662. nullpo_retr(0, sd);
  4663. fd=sd->fd;
  4664. WFIFOHEAD(fd,packet_len_table[0x147]);
  4665. WFIFOW(fd, 0)=0x147;
  4666. WFIFOW(fd, 2)=skillid;
  4667. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4668. WFIFOW(fd, 6)=0;
  4669. WFIFOW(fd, 8)=skilllv;
  4670. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4671. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4672. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  4673. WFIFOB(fd,38)=0;
  4674. WFIFOSET(fd,packet_len_table[0x147]);
  4675. return 0;
  4676. }
  4677. /*==========================================
  4678. * カートにアイテム追加
  4679. *------------------------------------------
  4680. */
  4681. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4682. {
  4683. int view,fd;
  4684. unsigned char *buf;
  4685. nullpo_retr(0, sd);
  4686. fd=sd->fd;
  4687. WFIFOHEAD(fd,packet_len_table[0x124]);
  4688. buf=WFIFOP(fd,0);
  4689. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4690. return 1;
  4691. WBUFW(buf,0)=0x124;
  4692. WBUFW(buf,2)=n+2;
  4693. WBUFL(buf,4)=amount;
  4694. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4695. WBUFW(buf,8)=view;
  4696. else
  4697. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4698. WBUFB(buf,10)=sd->status.cart[n].identify;
  4699. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4700. WBUFB(buf,12)=sd->status.cart[n].refine;
  4701. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4702. WFIFOSET(fd,packet_len_table[0x124]);
  4703. return 0;
  4704. }
  4705. /*==========================================
  4706. * カートからアイテム削除
  4707. *------------------------------------------
  4708. */
  4709. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4710. {
  4711. int fd;
  4712. nullpo_retr(0, sd);
  4713. fd=sd->fd;
  4714. WFIFOHEAD(fd,packet_len_table[0x125]);
  4715. WFIFOW(fd,0)=0x125;
  4716. WFIFOW(fd,2)=n+2;
  4717. WFIFOL(fd,4)=amount;
  4718. WFIFOSET(fd,packet_len_table[0x125]);
  4719. return 0;
  4720. }
  4721. /*==========================================
  4722. * カートのアイテムリスト
  4723. *------------------------------------------
  4724. */
  4725. int clif_cart_itemlist(struct map_session_data *sd)
  4726. {
  4727. struct item_data *id;
  4728. int i,n,fd;
  4729. unsigned char *buf;
  4730. nullpo_retr(0, sd);
  4731. fd=sd->fd;
  4732. WFIFOHEAD(fd, MAX_CART * 18 + 4);
  4733. buf = WFIFOP(fd,0);
  4734. #if PACKETVER < 5
  4735. for(i=0,n=0;i<MAX_CART;i++){
  4736. if(sd->status.cart[i].nameid<=0)
  4737. continue;
  4738. id = itemdb_search(sd->status.cart[i].nameid);
  4739. if(itemdb_isequip2(id))
  4740. continue;
  4741. WBUFW(buf,n*10+4)=i+2;
  4742. if(id->view_id > 0)
  4743. WBUFW(buf,n*10+6)=id->view_id;
  4744. else
  4745. WBUFW(buf,n*10+6)=sd->status.cart[i].nameid;
  4746. WBUFB(buf,n*10+8)=itemtype(id->type);
  4747. WBUFB(buf,n*10+9)=sd->status.cart[i].identify;
  4748. WBUFW(buf,n*10+10)=sd->status.cart[i].amount;
  4749. WBUFW(buf,n*10+12)=0;
  4750. n++;
  4751. }
  4752. if(n){
  4753. WBUFW(buf,0)=0x123;
  4754. WBUFW(buf,2)=4+n*10;
  4755. WFIFOSET(fd,WFIFOW(fd,2));
  4756. }
  4757. #else
  4758. for(i=0,n=0;i<MAX_CART;i++){
  4759. if(sd->status.cart[i].nameid<=0)
  4760. continue;
  4761. id = itemdb_search(sd->status.cart[i].nameid);
  4762. if(itemdb_isequip2(id))
  4763. continue;
  4764. WBUFW(buf,n*18+4)=i+2;
  4765. if(id->view_id > 0)
  4766. WBUFW(buf,n*18+6)=id->view_id;
  4767. else
  4768. WBUFW(buf,n*18+6)=sd->status.cart[i].nameid;
  4769. WBUFB(buf,n*18+8)=itemtype(id->type);
  4770. WBUFB(buf,n*18+9)=sd->status.cart[i].identify;
  4771. WBUFW(buf,n*18+10)=sd->status.cart[i].amount;
  4772. WBUFW(buf,n*18+12)=0; //Here goes the equip location, which seems unnecessary to fill for the cart data.
  4773. clif_addcards(WBUFP(buf,n*18+14), &sd->status.cart[i]);
  4774. n++;
  4775. }
  4776. if(n){
  4777. WBUFW(buf,0)=0x1ef;
  4778. WBUFW(buf,2)=4+n*18;
  4779. WFIFOSET(fd,WFIFOW(fd,2));
  4780. }
  4781. #endif
  4782. return 0;
  4783. }
  4784. /*==========================================
  4785. * カートの装備品リスト
  4786. *------------------------------------------
  4787. */
  4788. int clif_cart_equiplist(struct map_session_data *sd)
  4789. {
  4790. struct item_data *id;
  4791. int i,n,fd;
  4792. unsigned char *buf;
  4793. nullpo_retr(0, sd);
  4794. fd=sd->fd;
  4795. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  4796. buf = WFIFOP(fd,0);
  4797. for(i=0,n=0;i<MAX_INVENTORY;i++){
  4798. if(sd->status.cart[i].nameid<=0)
  4799. continue;
  4800. id = itemdb_search(sd->status.cart[i].nameid);
  4801. if(!itemdb_isequip2(id))
  4802. continue;
  4803. WBUFW(buf,n*20+4)=i+2;
  4804. if(id->view_id > 0)
  4805. WBUFW(buf,n*20+6)=id->view_id;
  4806. else
  4807. WBUFW(buf,n*20+6)=sd->status.cart[i].nameid;
  4808. WBUFB(buf,n*20+8)=itemtype(id->type);
  4809. WBUFB(buf,n*20+9)=sd->status.cart[i].identify;
  4810. WBUFW(buf,n*20+10)=id->equip;
  4811. WBUFW(buf,n*20+12)=sd->status.cart[i].equip;
  4812. WBUFB(buf,n*20+14)=sd->status.cart[i].attribute;
  4813. WBUFB(buf,n*20+15)=sd->status.cart[i].refine;
  4814. clif_addcards(WBUFP(buf, n*20+16), &sd->status.cart[i]);
  4815. n++;
  4816. }
  4817. if(n){
  4818. WBUFW(buf,0)=0x122;
  4819. WBUFW(buf,2)=4+n*20;
  4820. WFIFOSET(fd,WFIFOW(fd,2));
  4821. }
  4822. return 0;
  4823. }
  4824. /*==========================================
  4825. * 露店開設
  4826. *------------------------------------------
  4827. */
  4828. int clif_openvendingreq(struct map_session_data *sd,int num)
  4829. {
  4830. int fd;
  4831. nullpo_retr(0, sd);
  4832. fd=sd->fd;
  4833. WFIFOHEAD(fd,packet_len_table[0x12d]);
  4834. WFIFOW(fd,0)=0x12d;
  4835. WFIFOW(fd,2)=num;
  4836. WFIFOSET(fd,packet_len_table[0x12d]);
  4837. return 0;
  4838. }
  4839. /*==========================================
  4840. * 露店看板表示
  4841. *------------------------------------------
  4842. */
  4843. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  4844. {
  4845. unsigned char buf[128];
  4846. nullpo_retr(0, bl);
  4847. WBUFW(buf,0)=0x131;
  4848. WBUFL(buf,2)=bl->id;
  4849. strncpy((char*)WBUFP(buf,6),message,80);
  4850. if(fd){
  4851. WFIFOHEAD(fd,packet_len_table[0x131]);
  4852. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x131]);
  4853. WFIFOSET(fd,packet_len_table[0x131]);
  4854. }else{
  4855. clif_send(buf,packet_len_table[0x131],bl,AREA_WOS);
  4856. }
  4857. return 0;
  4858. }
  4859. /*==========================================
  4860. * 露店看板消去
  4861. *------------------------------------------
  4862. */
  4863. int clif_closevendingboard(struct block_list* bl,int fd)
  4864. {
  4865. unsigned char buf[16];
  4866. nullpo_retr(0, bl);
  4867. WBUFW(buf,0)=0x132;
  4868. WBUFL(buf,2)=bl->id;
  4869. if(fd){
  4870. WFIFOHEAD(fd,packet_len_table[0x132]);
  4871. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x132]);
  4872. WFIFOSET(fd,packet_len_table[0x132]);
  4873. }else{
  4874. clif_send(buf,packet_len_table[0x132],bl,AREA_WOS);
  4875. }
  4876. return 0;
  4877. }
  4878. /*==========================================
  4879. * 露店アイテムリスト
  4880. *------------------------------------------
  4881. */
  4882. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  4883. {
  4884. struct item_data *data;
  4885. int i,n,index,fd;
  4886. struct map_session_data *vsd;
  4887. unsigned char *buf;
  4888. nullpo_retr(0, sd);
  4889. nullpo_retr(0, vending);
  4890. nullpo_retr(0, vsd=map_id2sd(id));
  4891. fd=sd->fd;
  4892. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  4893. buf = WFIFOP(fd,0);
  4894. for(i=0,n=0;i<vsd->vend_num;i++){
  4895. if(vending[i].amount<=0)
  4896. continue;
  4897. WBUFL(buf,8+n*22)=vending[i].value;
  4898. WBUFW(buf,12+n*22)=vending[i].amount;
  4899. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  4900. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  4901. continue;
  4902. data = itemdb_search(vsd->status.cart[index].nameid);
  4903. WBUFB(buf,16+n*22)=itemtype(data->type);
  4904. if(data->view_id > 0)
  4905. WBUFW(buf,17+n*22)=data->view_id;
  4906. else
  4907. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  4908. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  4909. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  4910. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  4911. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  4912. n++;
  4913. }
  4914. if(n > 0){
  4915. WBUFW(buf,0)=0x133;
  4916. WBUFW(buf,2)=8+n*22;
  4917. WBUFL(buf,4)=id;
  4918. WFIFOSET(fd,WFIFOW(fd,2));
  4919. }
  4920. return 0;
  4921. }
  4922. /*==========================================
  4923. * 露店アイテム購入失敗
  4924. *------------------------------------------
  4925. */
  4926. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  4927. {
  4928. int fd;
  4929. nullpo_retr(0, sd);
  4930. fd=sd->fd;
  4931. WFIFOHEAD(fd,packet_len_table[0x135]);
  4932. WFIFOW(fd,0)=0x135;
  4933. WFIFOW(fd,2)=index+2;
  4934. WFIFOW(fd,4)=amount;
  4935. WFIFOB(fd,6)=fail;
  4936. WFIFOSET(fd,packet_len_table[0x135]);
  4937. return 0;
  4938. }
  4939. /*==========================================
  4940. * 露店開設成功
  4941. *------------------------------------------
  4942. */
  4943. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  4944. {
  4945. struct item_data *data;
  4946. int i,n,index,fd;
  4947. unsigned char *buf;
  4948. nullpo_retr(0, sd);
  4949. fd=sd->fd;
  4950. WFIFOHEAD(fd, 8+sd->vend_num*22);
  4951. buf = WFIFOP(fd,0);
  4952. for(i=0,n=0;i<sd->vend_num;i++){
  4953. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  4954. WBUFL(buf,8+n*22)=vending[i].value;
  4955. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  4956. WBUFW(buf,14+n*22)=vending[i].amount;
  4957. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || sd->status.cart[index].identify==0 ||
  4958. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  4959. continue;
  4960. data = itemdb_search(sd->status.cart[index].nameid);
  4961. WBUFB(buf,16+n*22)=itemtype(data->type);
  4962. if(data->view_id > 0)
  4963. WBUFW(buf,17+n*22)=data->view_id;
  4964. else
  4965. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  4966. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  4967. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  4968. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  4969. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  4970. n++;
  4971. }
  4972. if(n > 0){
  4973. WBUFW(buf,0)=0x136;
  4974. WBUFW(buf,2)=8+n*22;
  4975. WBUFL(buf,4)=id;
  4976. WFIFOSET(fd,WFIFOW(fd,2));
  4977. }
  4978. return n;
  4979. }
  4980. /*==========================================
  4981. * 露店アイテム販売報告
  4982. *------------------------------------------
  4983. */
  4984. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  4985. {
  4986. int fd;
  4987. nullpo_retr(0, sd);
  4988. fd=sd->fd;
  4989. WFIFOHEAD(fd,packet_len_table[0x137]);
  4990. WFIFOW(fd,0)=0x137;
  4991. WFIFOW(fd,2)=index+2;
  4992. WFIFOW(fd,4)=amount;
  4993. WFIFOSET(fd,packet_len_table[0x137]);
  4994. return 0;
  4995. }
  4996. /*==========================================
  4997. * パーティ作成完了
  4998. *------------------------------------------
  4999. */
  5000. int clif_party_created(struct map_session_data *sd,int flag)
  5001. {
  5002. int fd;
  5003. // printf("clif_party_message(%s, %d, %s)\n", p->name, account_id, mes);
  5004. nullpo_retr(0, sd);
  5005. fd=sd->fd;
  5006. WFIFOHEAD(fd,packet_len_table[0xfa]);
  5007. WFIFOW(fd,0)=0xfa;
  5008. WFIFOB(fd,2)=flag;
  5009. WFIFOSET(fd,packet_len_table[0xfa]);
  5010. return 0;
  5011. }
  5012. int clif_party_main_info(struct party *p, int fd)
  5013. {
  5014. struct map_session_data *sd;
  5015. int i;
  5016. unsigned char buf[96];
  5017. for (i=0; i<MAX_PARTY && !p->member[i].leader; i++);
  5018. if (i >= MAX_PARTY) return 0; //Should never happen...
  5019. sd = p->member[i].sd;
  5020. WBUFW(buf,0)=0x1e9;
  5021. WBUFL(buf,2)= p->member[i].account_id;
  5022. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  5023. WBUFW(buf,10)=sd?sd->bl.x:0;
  5024. WBUFW(buf,12)=sd?sd->bl.y:0;
  5025. WBUFB(buf,14)=(p->member[i].online)?0:1; //This byte is also unconfirmed...
  5026. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5027. memcpy(WBUFP(buf,39), p->member[i].name, NAME_LENGTH);
  5028. memcpy(WBUFP(buf,63), mapindex_id2name(p->member[i].map), MAP_NAME_LENGTH);
  5029. WBUFB(buf,79) = (p->item&1)?1:0;
  5030. WBUFB(buf,80) = (p->item&2)?1:0;
  5031. if(fd>=0){
  5032. WFIFOHEAD(fd,packet_len_table[0x1e9]);
  5033. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x1e9]);
  5034. WFIFOSET(fd,packet_len_table[0x1e9]);
  5035. return 1;
  5036. }
  5037. if (!sd) {
  5038. for (i=0; i<MAX_PARTY && !p->member[i].sd; i++)
  5039. if (i >= MAX_PARTY) return 0; //Should never happen...
  5040. sd=p->member[i].sd;
  5041. }
  5042. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY);
  5043. return 1;
  5044. }
  5045. /*==========================================
  5046. * パーティ情報送信
  5047. *------------------------------------------
  5048. */
  5049. int clif_party_info(struct party *p,int fd)
  5050. {
  5051. unsigned char buf[1024];
  5052. int i,c;
  5053. struct map_session_data *sd=NULL;
  5054. nullpo_retr(0, p);
  5055. WBUFW(buf,0)=0xfb;
  5056. memcpy(WBUFP(buf,4),p->name,NAME_LENGTH);
  5057. for(i=c=0;i<MAX_PARTY;i++){
  5058. struct party_member *m=&p->member[i];
  5059. if(m->account_id>0){
  5060. if(sd==NULL) sd=m->sd;
  5061. WBUFL(buf,28+c*46)=m->account_id;
  5062. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5063. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5064. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5065. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5066. c++;
  5067. }
  5068. }
  5069. WBUFW(buf,2)=28+c*46;
  5070. if(fd>=0){ // fdが設定されてるならそれに送る
  5071. WFIFOHEAD(fd, 28+c*46);
  5072. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5073. WFIFOSET(fd,WFIFOW(fd,2));
  5074. return 9;
  5075. }
  5076. if(sd!=NULL)
  5077. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5078. return 0;
  5079. }
  5080. /*==========================================
  5081. * パーティ勧誘
  5082. *------------------------------------------
  5083. */
  5084. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5085. {
  5086. int fd;
  5087. struct party *p;
  5088. nullpo_retr(0, sd);
  5089. nullpo_retr(0, tsd);
  5090. fd=tsd->fd;
  5091. if( (p=party_search(sd->status.party_id))==NULL )
  5092. return 0;
  5093. WFIFOHEAD(fd,packet_len_table[0xfe]);
  5094. WFIFOW(fd,0)=0xfe;
  5095. WFIFOL(fd,2)=sd->status.account_id;
  5096. memcpy(WFIFOP(fd,6),p->name,NAME_LENGTH);
  5097. WFIFOSET(fd,packet_len_table[0xfe]);
  5098. return 0;
  5099. }
  5100. /*==========================================
  5101. * パーティ勧誘結果
  5102. *------------------------------------------
  5103. */
  5104. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5105. {
  5106. int fd;
  5107. nullpo_retr(0, sd);
  5108. fd=sd->fd;
  5109. WFIFOHEAD(fd,packet_len_table[0xfd]);
  5110. WFIFOW(fd,0)=0xfd;
  5111. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5112. WFIFOB(fd,26)=flag;
  5113. WFIFOSET(fd,packet_len_table[0xfd]);
  5114. return 0;
  5115. }
  5116. /*==========================================
  5117. * パーティ設定送信
  5118. * flag & 0x001=exp変更ミス
  5119. * 0x010=item変更ミス
  5120. * 0x100=一人にのみ送信
  5121. *------------------------------------------
  5122. */
  5123. int clif_party_option(struct party *p,struct map_session_data *sd,int flag)
  5124. {
  5125. unsigned char buf[16];
  5126. nullpo_retr(0, p);
  5127. // if(battle_config.etc_log)
  5128. // printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
  5129. if(sd==NULL && flag==0){
  5130. int i;
  5131. for(i=0;i<MAX_PARTY;i++)
  5132. if((sd=map_id2sd(p->member[i].account_id))!=NULL)
  5133. break;
  5134. }
  5135. if(sd==NULL)
  5136. return 0;
  5137. WBUFW(buf,0)=0x101;
  5138. WBUFW(buf,2)=((flag&0x01)?2:p->exp);
  5139. WBUFW(buf,4)=0; //NOTE: We don't know yet what this is for, it is NOT for item share rules, though. [Skotlex]
  5140. if(flag==0)
  5141. clif_send(buf,packet_len_table[0x101],&sd->bl,PARTY);
  5142. else {
  5143. WFIFOHEAD(sd->fd,packet_len_table[0x101]);
  5144. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x101]);
  5145. WFIFOSET(sd->fd,packet_len_table[0x101]);
  5146. }
  5147. return 0;
  5148. }
  5149. /*==========================================
  5150. * パーティ脱退(脱退前に呼ぶこと)
  5151. *------------------------------------------
  5152. */
  5153. int clif_party_leaved(struct party *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5154. {
  5155. unsigned char buf[64];
  5156. int i;
  5157. nullpo_retr(0, p);
  5158. WBUFW(buf,0)=0x105;
  5159. WBUFL(buf,2)=account_id;
  5160. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5161. WBUFB(buf,30)=flag&0x0f;
  5162. if((flag&0xf0)==0){
  5163. if(sd==NULL)
  5164. for(i=0;i<MAX_PARTY;i++)
  5165. if((sd=p->member[i].sd)!=NULL)
  5166. break;
  5167. if (sd!=NULL)
  5168. clif_send(buf,packet_len_table[0x105],&sd->bl,PARTY);
  5169. } else if (sd!=NULL) {
  5170. WFIFOHEAD(sd->fd,packet_len_table[0x105]);
  5171. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x105]);
  5172. WFIFOSET(sd->fd,packet_len_table[0x105]);
  5173. }
  5174. return 0;
  5175. }
  5176. /*==========================================
  5177. * パーティメッセージ送信
  5178. *------------------------------------------
  5179. */
  5180. int clif_party_message(struct party *p,int account_id,char *mes,int len)
  5181. {
  5182. struct map_session_data *sd;
  5183. int i;
  5184. nullpo_retr(0, p);
  5185. for(i=0;i<MAX_PARTY;i++){
  5186. if((sd=p->member[i].sd)!=NULL)
  5187. break;
  5188. }
  5189. if(sd!=NULL){
  5190. unsigned char buf[1024];
  5191. WBUFW(buf,0)=0x109;
  5192. WBUFW(buf,2)=len+8;
  5193. WBUFL(buf,4)=account_id;
  5194. memcpy(WBUFP(buf,8),mes,len);
  5195. clif_send(buf,len+8,&sd->bl,PARTY);
  5196. }
  5197. return 0;
  5198. }
  5199. /*==========================================
  5200. * パーティ座標通知
  5201. *------------------------------------------
  5202. */
  5203. int clif_party_xy(struct map_session_data *sd)
  5204. {
  5205. unsigned char buf[16];
  5206. nullpo_retr(0, sd);
  5207. WBUFW(buf,0)=0x107;
  5208. WBUFL(buf,2)=sd->status.account_id;
  5209. WBUFW(buf,6)=sd->bl.x;
  5210. WBUFW(buf,8)=sd->bl.y;
  5211. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  5212. return 0;
  5213. }
  5214. /*==========================================
  5215. * Sends x/y dot to a single fd. [Skotlex]
  5216. *------------------------------------------
  5217. */
  5218. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5219. {
  5220. WFIFOHEAD(fd,packet_len_table[0x107]);
  5221. WFIFOW(fd,0)=0x107;
  5222. WFIFOL(fd,2)=sd->status.account_id;
  5223. WFIFOW(fd,6)=sd->bl.x;
  5224. WFIFOW(fd,8)=sd->bl.y;
  5225. WFIFOSET(fd,packet_len_table[0x107]);
  5226. return 0;
  5227. }
  5228. /*==========================================
  5229. * パーティHP通知
  5230. *------------------------------------------
  5231. */
  5232. int clif_party_hp(struct map_session_data *sd)
  5233. {
  5234. unsigned char buf[16];
  5235. nullpo_retr(0, sd);
  5236. WBUFW(buf,0)=0x106;
  5237. WBUFL(buf,2)=sd->status.account_id;
  5238. WBUFW(buf,6)=(sd->status.hp > 0x7fff)? 0x7fff:sd->status.hp;
  5239. WBUFW(buf,8)=(sd->status.max_hp > 0x7fff)? 0x7fff:sd->status.max_hp;
  5240. clif_send(buf,packet_len_table[0x106],&sd->bl,PARTY_AREA_WOS);
  5241. return 0;
  5242. }
  5243. /*==========================================
  5244. * Sends HP bar to a single fd. [Skotlex]
  5245. *------------------------------------------
  5246. */
  5247. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5248. {
  5249. WFIFOHEAD(fd,packet_len_table[0x106]);
  5250. WFIFOW(fd,0) = 0x106;
  5251. WFIFOL(fd,2) = sd->status.account_id;
  5252. WFIFOW(fd,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5253. WFIFOW(fd,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5254. WFIFOSET (fd, packet_len_table[0x106]);
  5255. }
  5256. /*==========================================
  5257. * GMへ場所とHP通知
  5258. *------------------------------------------
  5259. */
  5260. int clif_hpmeter(struct map_session_data *sd)
  5261. {
  5262. struct map_session_data *sd2;
  5263. unsigned char buf[16];
  5264. int i, x0, y0, x1, y1;
  5265. int level;
  5266. nullpo_retr(0, sd);
  5267. x0 = sd->bl.x - AREA_SIZE;
  5268. y0 = sd->bl.y - AREA_SIZE;
  5269. x1 = sd->bl.x + AREA_SIZE;
  5270. y1 = sd->bl.y + AREA_SIZE;
  5271. WBUFW(buf,0) = 0x106;
  5272. WBUFL(buf,2) = sd->status.account_id;
  5273. WBUFW(buf,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5274. WBUFW(buf,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5275. for (i = 0; i < fd_max; i++) {
  5276. if (session[i] && (sd2 = (struct map_session_data*)session[i]->session_data) && sd != sd2 && sd2->state.auth) {
  5277. if (sd2->bl.m != sd->bl.m ||
  5278. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5279. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5280. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5281. level < pc_isGM(sd))
  5282. continue;
  5283. WFIFOHEAD (i, packet_len_table[0x106]);
  5284. memcpy (WFIFOP(i,0), buf, packet_len_table[0x106]);
  5285. WFIFOSET (i, packet_len_table[0x106]);
  5286. }
  5287. }
  5288. return 0;
  5289. }
  5290. /*==========================================
  5291. * パーティ場所移動(未使用)
  5292. *------------------------------------------
  5293. */
  5294. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5295. {
  5296. unsigned char buf[128];
  5297. nullpo_retr(0, sd);
  5298. nullpo_retr(0, p);
  5299. WBUFW(buf, 0)=0x104;
  5300. WBUFL(buf, 2)=sd->status.account_id;
  5301. WBUFL(buf, 6)=0;
  5302. WBUFW(buf,10)=sd->bl.x;
  5303. WBUFW(buf,12)=sd->bl.y;
  5304. WBUFB(buf,14)=!online;
  5305. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5306. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5307. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5308. clif_send(buf,packet_len_table[0x104],&sd->bl,PARTY);
  5309. return 0;
  5310. }
  5311. /*==========================================
  5312. * 攻撃するために移動が必要
  5313. *------------------------------------------
  5314. */
  5315. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5316. {
  5317. int fd;
  5318. nullpo_retr(0, sd);
  5319. nullpo_retr(0, bl);
  5320. fd=sd->fd;
  5321. WFIFOHEAD(fd,packet_len_table[0x139]);
  5322. WFIFOW(fd, 0)=0x139;
  5323. WFIFOL(fd, 2)=bl->id;
  5324. WFIFOW(fd, 6)=bl->x;
  5325. WFIFOW(fd, 8)=bl->y;
  5326. WFIFOW(fd,10)=sd->bl.x;
  5327. WFIFOW(fd,12)=sd->bl.y;
  5328. WFIFOW(fd,14)=sd->attackrange;
  5329. WFIFOSET(fd,packet_len_table[0x139]);
  5330. return 0;
  5331. }
  5332. /*==========================================
  5333. * 製造エフェクト
  5334. *------------------------------------------
  5335. */
  5336. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5337. {
  5338. int view,fd;
  5339. nullpo_retr(0, sd);
  5340. fd=sd->fd;
  5341. // 名前の登録と送信を先にしておく
  5342. if( map_charid2nick(sd->status.char_id)==NULL )
  5343. map_addchariddb(sd->status.char_id,sd->status.name);
  5344. clif_solved_charname(sd,sd->status.char_id);
  5345. WFIFOHEAD(fd,packet_len_table[0x18f]);
  5346. WFIFOW(fd, 0)=0x18f;
  5347. WFIFOW(fd, 2)=flag;
  5348. if((view = itemdb_viewid(nameid)) > 0)
  5349. WFIFOW(fd, 4)=view;
  5350. else
  5351. WFIFOW(fd, 4)=nameid;
  5352. WFIFOSET(fd,packet_len_table[0x18f]);
  5353. return 0;
  5354. }
  5355. // pet
  5356. int clif_catch_process(struct map_session_data *sd)
  5357. {
  5358. int fd;
  5359. nullpo_retr(0, sd);
  5360. fd=sd->fd;
  5361. WFIFOHEAD(fd,packet_len_table[0x19e]);
  5362. WFIFOW(fd,0)=0x19e;
  5363. WFIFOSET(fd,packet_len_table[0x19e]);
  5364. sd->menuskill_id = SA_TAMINGMONSTER;
  5365. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5366. sd->menuskill_lv = 0; //Free catch
  5367. else
  5368. sd->menuskill_lv = sd->itemid; //Consume catch
  5369. return 0;
  5370. }
  5371. int clif_pet_rulet(struct map_session_data *sd,int data)
  5372. {
  5373. int fd;
  5374. nullpo_retr(0, sd);
  5375. fd=sd->fd;
  5376. WFIFOHEAD(fd,packet_len_table[0x1a0]);
  5377. WFIFOW(fd,0)=0x1a0;
  5378. WFIFOB(fd,2)=data;
  5379. WFIFOSET(fd,packet_len_table[0x1a0]);
  5380. return 0;
  5381. }
  5382. /*==========================================
  5383. * pet卵リスト作成
  5384. *------------------------------------------
  5385. */
  5386. int clif_sendegg(struct map_session_data *sd)
  5387. {
  5388. //R 01a6 <len>.w <index>.w*
  5389. int i,n=0,fd;
  5390. nullpo_retr(0, sd);
  5391. fd=sd->fd;
  5392. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5393. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5394. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5395. return 0;
  5396. }
  5397. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5398. WFIFOW(fd,0)=0x1a6;
  5399. if(sd->status.pet_id <= 0) {
  5400. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5401. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5402. sd->inventory_data[i]->type!=7 ||
  5403. sd->status.inventory[i].amount<=0)
  5404. continue;
  5405. WFIFOW(fd,n*2+4)=i+2;
  5406. n++;
  5407. }
  5408. }
  5409. WFIFOW(fd,2)=4+n*2;
  5410. WFIFOSET(fd,WFIFOW(fd,2));
  5411. sd->menuskill_id = SA_TAMINGMONSTER;
  5412. sd->menuskill_lv = -1;
  5413. return 0;
  5414. }
  5415. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5416. {
  5417. int fd;
  5418. nullpo_retr(0, sd);
  5419. nullpo_retr(0, sd->pd);
  5420. fd=sd->fd;
  5421. WFIFOHEAD(fd,packet_len_table[0x1a4]);
  5422. WFIFOW(fd,0)=0x1a4;
  5423. WFIFOB(fd,2)=type;
  5424. WFIFOL(fd,3)=sd->pd->bl.id;
  5425. WFIFOL(fd,7)=param;
  5426. WFIFOSET(fd,packet_len_table[0x1a4]);
  5427. return 0;
  5428. }
  5429. int clif_send_petstatus(struct map_session_data *sd)
  5430. {
  5431. int fd;
  5432. nullpo_retr(0, sd);
  5433. fd=sd->fd;
  5434. WFIFOHEAD(fd,packet_len_table[0x1a2]);
  5435. WFIFOW(fd,0)=0x1a2;
  5436. memcpy(WFIFOP(fd,2),sd->pet.name,NAME_LENGTH);
  5437. WFIFOB(fd,26)=(battle_config.pet_rename == 1)? 0:sd->pet.rename_flag;
  5438. WFIFOW(fd,27)=sd->pet.level;
  5439. WFIFOW(fd,29)=sd->pet.hungry;
  5440. WFIFOW(fd,31)=sd->pet.intimate;
  5441. WFIFOW(fd,33)=sd->pet.equip;
  5442. WFIFOSET(fd,packet_len_table[0x1a2]);
  5443. return 0;
  5444. }
  5445. /*==========================================
  5446. *
  5447. *------------------------------------------
  5448. */
  5449. int clif_pet_emotion(struct pet_data *pd,int param)
  5450. {
  5451. unsigned char buf[16];
  5452. struct map_session_data *sd;
  5453. nullpo_retr(0, pd);
  5454. nullpo_retr(0, sd = pd->msd);
  5455. memset(buf,0,packet_len_table[0x1aa]);
  5456. WBUFW(buf,0)=0x1aa;
  5457. WBUFL(buf,2)=pd->bl.id;
  5458. if(param >= 100 && sd->petDB->talk_convert_class) {
  5459. if(sd->petDB->talk_convert_class < 0)
  5460. return 0;
  5461. else if(sd->petDB->talk_convert_class > 0) {
  5462. param -= (pd->class_ - 100)*100;
  5463. param += (sd->petDB->talk_convert_class - 100)*100;
  5464. }
  5465. }
  5466. WBUFL(buf,6)=param;
  5467. clif_send(buf,packet_len_table[0x1aa],&pd->bl,AREA);
  5468. return 0;
  5469. }
  5470. int clif_pet_performance(struct block_list *bl,int param)
  5471. {
  5472. unsigned char buf[16];
  5473. nullpo_retr(0, bl);
  5474. memset(buf,0,packet_len_table[0x1a4]);
  5475. WBUFW(buf,0)=0x1a4;
  5476. WBUFB(buf,2)=4;
  5477. WBUFL(buf,3)=bl->id;
  5478. WBUFL(buf,7)=param;
  5479. clif_send(buf,packet_len_table[0x1a4],bl,AREA);
  5480. return 0;
  5481. }
  5482. int clif_pet_equip(struct pet_data *pd,int nameid)
  5483. {
  5484. unsigned char buf[16];
  5485. nullpo_retr(0, pd);
  5486. memset(buf,0,packet_len_table[0x1a4]);
  5487. WBUFW(buf,0)=0x1a4;
  5488. WBUFB(buf,2)=3;
  5489. WBUFL(buf,3)=pd->bl.id;
  5490. WBUFL(buf,7)=pd->vd.shield;
  5491. clif_send(buf,packet_len_table[0x1a4],&pd->bl,AREA);
  5492. return 0;
  5493. }
  5494. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5495. {
  5496. int fd;
  5497. nullpo_retr(0, sd);
  5498. fd=sd->fd;
  5499. WFIFOHEAD(fd,packet_len_table[0x1a3]);
  5500. WFIFOW(fd,0)=0x1a3;
  5501. WFIFOB(fd,2)=fail;
  5502. WFIFOW(fd,3)=foodid;
  5503. WFIFOSET(fd,packet_len_table[0x1a3]);
  5504. return 0;
  5505. }
  5506. /*==========================================
  5507. * オートスペル リスト送信
  5508. *------------------------------------------
  5509. */
  5510. int clif_autospell(struct map_session_data *sd,int skilllv)
  5511. {
  5512. int fd;
  5513. nullpo_retr(0, sd);
  5514. fd=sd->fd;
  5515. WFIFOHEAD(fd,packet_len_table[0x1cd]);
  5516. WFIFOW(fd, 0)=0x1cd;
  5517. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5518. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5519. else
  5520. WFIFOL(fd,2)= 0x00000000;
  5521. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5522. WFIFOL(fd,6)= MG_COLDBOLT;
  5523. else
  5524. WFIFOL(fd,6)= 0x00000000;
  5525. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5526. WFIFOL(fd,10)= MG_FIREBOLT;
  5527. else
  5528. WFIFOL(fd,10)= 0x00000000;
  5529. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5530. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5531. else
  5532. WFIFOL(fd,14)= 0x00000000;
  5533. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5534. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5535. else
  5536. WFIFOL(fd,18)= 0x00000000;
  5537. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5538. WFIFOL(fd,22)= MG_FIREBALL;
  5539. else
  5540. WFIFOL(fd,22)= 0x00000000;
  5541. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5542. WFIFOL(fd,26)= MG_FROSTDIVER;
  5543. else
  5544. WFIFOL(fd,26)= 0x00000000;
  5545. WFIFOSET(fd,packet_len_table[0x1cd]);
  5546. sd->menuskill_id = SA_AUTOSPELL;
  5547. sd->menuskill_lv = skilllv;
  5548. return 0;
  5549. }
  5550. /*==========================================
  5551. * ディボーションの青い糸
  5552. *------------------------------------------
  5553. */
  5554. int clif_devotion(struct map_session_data *sd)
  5555. {
  5556. unsigned char buf[56];
  5557. int i,n;
  5558. nullpo_retr(0, sd);
  5559. WBUFW(buf,0)=0x1cf;
  5560. WBUFL(buf,2)=sd->bl.id;
  5561. for(i=0,n=0;i<5;i++) {
  5562. if (!sd->devotion[i])
  5563. continue;
  5564. WBUFL(buf,6+4*n)=sd->devotion[i];
  5565. n++;
  5566. }
  5567. for(;n<5;n++)
  5568. WBUFL(buf,6+4*n)=0;
  5569. WBUFB(buf,26)=8;
  5570. WBUFB(buf,27)=0;
  5571. clif_send(buf,packet_len_table[0x1cf],&sd->bl,AREA);
  5572. return 0;
  5573. }
  5574. int clif_marionette(struct block_list *src, struct block_list *target)
  5575. {
  5576. unsigned char buf[56];
  5577. int n;
  5578. WBUFW(buf,0)=0x1cf;
  5579. WBUFL(buf,2)=src->id;
  5580. for(n=0;n<5;n++)
  5581. WBUFL(buf,6+4*n)=0;
  5582. if (target) //The target goes on the second slot.
  5583. WBUFL(buf,6+4) = target->id;
  5584. WBUFB(buf,26)=8;
  5585. WBUFB(buf,27)=0;
  5586. clif_send(buf,packet_len_table[0x1cf],src,AREA);
  5587. return 0;
  5588. }
  5589. /*==========================================
  5590. * 氣球
  5591. *------------------------------------------
  5592. */
  5593. int clif_spiritball(struct map_session_data *sd)
  5594. {
  5595. unsigned char buf[16];
  5596. nullpo_retr(0, sd);
  5597. WBUFW(buf,0)=0x1d0;
  5598. WBUFL(buf,2)=sd->bl.id;
  5599. WBUFW(buf,6)=sd->spiritball;
  5600. clif_send(buf,packet_len_table[0x1d0],&sd->bl,AREA);
  5601. return 0;
  5602. }
  5603. /*==========================================
  5604. *
  5605. *------------------------------------------
  5606. */
  5607. int clif_combo_delay(struct block_list *bl,int wait)
  5608. {
  5609. unsigned char buf[32];
  5610. nullpo_retr(0, bl);
  5611. WBUFW(buf,0)=0x1d2;
  5612. WBUFL(buf,2)=bl->id;
  5613. WBUFL(buf,6)=wait;
  5614. clif_send(buf,packet_len_table[0x1d2],bl,AREA);
  5615. return 0;
  5616. }
  5617. /*==========================================
  5618. *白刃取り
  5619. *------------------------------------------
  5620. */
  5621. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5622. int _bool)
  5623. {
  5624. unsigned char buf[32];
  5625. nullpo_retr(0, src);
  5626. nullpo_retr(0, dst);
  5627. WBUFW(buf,0)=0x1d1;
  5628. WBUFL(buf,2)=src->id;
  5629. WBUFL(buf,6)=dst->id;
  5630. WBUFL(buf,10)=_bool;
  5631. clif_send(buf,packet_len_table[0x1d1],src,AREA);
  5632. return 0;
  5633. }
  5634. /*==========================================
  5635. *
  5636. *------------------------------------------
  5637. */
  5638. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5639. {
  5640. struct block_list bl;
  5641. unsigned char buf[32];
  5642. bl.type = BL_NUL;
  5643. bl.m = m;
  5644. bl.x = x;
  5645. bl.y = y;
  5646. WBUFW(buf,0) = 0x192;
  5647. WBUFW(buf,2) = x;
  5648. WBUFW(buf,4) = y;
  5649. WBUFW(buf,6) = cell_type;
  5650. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  5651. if(!type)
  5652. clif_send(buf,packet_len_table[0x192],&bl,AREA);
  5653. else
  5654. clif_send(buf,packet_len_table[0x192],&bl,ALL_SAMEMAP);
  5655. return 0;
  5656. }
  5657. /*==========================================
  5658. * MVPエフェクト
  5659. *------------------------------------------
  5660. */
  5661. int clif_mvp_effect(struct map_session_data *sd)
  5662. {
  5663. unsigned char buf[16];
  5664. nullpo_retr(0, sd);
  5665. WBUFW(buf,0)=0x10c;
  5666. WBUFL(buf,2)=sd->bl.id;
  5667. clif_send(buf,packet_len_table[0x10c],&sd->bl,AREA);
  5668. return 0;
  5669. }
  5670. /*==========================================
  5671. * MVPアイテム所得
  5672. *------------------------------------------
  5673. */
  5674. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5675. {
  5676. int view,fd;
  5677. nullpo_retr(0, sd);
  5678. fd=sd->fd;
  5679. WFIFOHEAD(fd,packet_len_table[0x10a]);
  5680. WFIFOW(fd,0)=0x10a;
  5681. if((view = itemdb_viewid(nameid)) > 0)
  5682. WFIFOW(fd,2)=view;
  5683. else
  5684. WFIFOW(fd,2)=nameid;
  5685. WFIFOSET(fd,packet_len_table[0x10a]);
  5686. return 0;
  5687. }
  5688. /*==========================================
  5689. * MVP経験値所得
  5690. *------------------------------------------
  5691. */
  5692. int clif_mvp_exp(struct map_session_data *sd,int exp)
  5693. {
  5694. int fd;
  5695. nullpo_retr(0, sd);
  5696. fd=sd->fd;
  5697. WFIFOHEAD(fd,packet_len_table[0x10b]);
  5698. WFIFOW(fd,0)=0x10b;
  5699. WFIFOL(fd,2)=exp;
  5700. WFIFOSET(fd,packet_len_table[0x10b]);
  5701. return 0;
  5702. }
  5703. /*==========================================
  5704. * ギルド作成可否通知
  5705. *------------------------------------------
  5706. */
  5707. int clif_guild_created(struct map_session_data *sd,int flag)
  5708. {
  5709. int fd;
  5710. nullpo_retr(0, sd);
  5711. fd=sd->fd;
  5712. WFIFOHEAD(fd,packet_len_table[0x167]);
  5713. WFIFOW(fd,0)=0x167;
  5714. WFIFOB(fd,2)=flag;
  5715. WFIFOSET(fd,packet_len_table[0x167]);
  5716. return 0;
  5717. }
  5718. /*==========================================
  5719. * ギルド所属通知
  5720. *------------------------------------------
  5721. */
  5722. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5723. {
  5724. int ps,fd;
  5725. nullpo_retr(0, sd);
  5726. nullpo_retr(0, g);
  5727. fd=sd->fd;
  5728. ps=guild_getposition(sd,g);
  5729. WFIFOHEAD(fd,packet_len_table[0x16c]);
  5730. memset(WFIFOP(fd,0),0,packet_len_table[0x16c]);
  5731. WFIFOW(fd,0)=0x16c;
  5732. WFIFOL(fd,2)=g->guild_id;
  5733. WFIFOL(fd,6)=g->emblem_id;
  5734. WFIFOL(fd,10)=g->position[ps].mode;
  5735. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5736. WFIFOSET(fd,packet_len_table[0x16c]);
  5737. return 0;
  5738. }
  5739. /*==========================================
  5740. * ギルドメンバログイン通知
  5741. *------------------------------------------
  5742. */
  5743. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5744. {
  5745. unsigned char buf[64];
  5746. nullpo_retr(0, g);
  5747. // printf("clif_guild_message(%s, %d, %s)\n", g->name, account_id, mes);
  5748. WBUFW(buf, 0)=0x16d;
  5749. WBUFL(buf, 2)=g->member[idx].account_id;
  5750. WBUFL(buf, 6)=g->member[idx].char_id;
  5751. WBUFL(buf,10)=flag;
  5752. if(g->member[idx].sd==NULL){
  5753. struct map_session_data *sd=guild_getavailablesd(g);
  5754. if(sd!=NULL)
  5755. clif_send(buf,packet_len_table[0x16d],&sd->bl,GUILD);
  5756. }else
  5757. clif_send(buf,packet_len_table[0x16d],&g->member[idx].sd->bl,GUILD_WOS);
  5758. return 0;
  5759. }
  5760. // Function `clif_guild_memberlogin_notice` sends info about
  5761. // logins and logouts of a guild member to the rest members.
  5762. // But at the 1st time (after a player login or map changing)
  5763. // the client won't show the message.
  5764. // So I suggest use this function for sending "first-time-info"
  5765. // to some player on entering the game or changing location.
  5766. // At next time the client would always show the message.
  5767. // The function sends all the statuses in the single packet
  5768. // to economize traffic. [LuzZza]
  5769. int clif_guild_send_onlineinfo(struct map_session_data *sd) {
  5770. struct guild *g;
  5771. char buf[14*128];
  5772. int i, count=0, p_len;
  5773. nullpo_retr(0, sd);
  5774. p_len = packet_len_table[0x16d];
  5775. if(!(g = guild_search(sd->status.guild_id)))
  5776. return 0;
  5777. for(i=0; i<g->max_member; i++) {
  5778. if(g->member[i].account_id > 0 &&
  5779. g->member[i].account_id != sd->status.account_id) {
  5780. WBUFW(buf,count*p_len) = 0x16d;
  5781. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5782. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5783. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5784. count++;
  5785. }
  5786. }
  5787. clif_send(buf,p_len*count,&sd->bl,SELF);
  5788. return 0;
  5789. }
  5790. /*==========================================
  5791. * ギルドマスター通知(14dへの応答)
  5792. *------------------------------------------
  5793. */
  5794. int clif_guild_masterormember(struct map_session_data *sd)
  5795. {
  5796. int type=0x57,fd;
  5797. nullpo_retr(0, sd);
  5798. fd=sd->fd;
  5799. if(sd->state.gmaster_flag)
  5800. type=0xd7;
  5801. WFIFOHEAD(fd,packet_len_table[0x14e]);
  5802. WFIFOW(fd,0)=0x14e;
  5803. WFIFOL(fd,2)=type;
  5804. WFIFOSET(fd,packet_len_table[0x14e]);
  5805. return 0;
  5806. }
  5807. /*==========================================
  5808. * Basic Info (Territories [Valaris])
  5809. *------------------------------------------
  5810. */
  5811. int clif_guild_basicinfo(struct map_session_data *sd)
  5812. {
  5813. int fd,i,t=0;
  5814. struct guild *g;
  5815. struct guild_castle *gc=NULL;
  5816. nullpo_retr(0, sd);
  5817. fd=sd->fd;
  5818. g=guild_search(sd->status.guild_id);
  5819. if(g==NULL)
  5820. return 0;
  5821. WFIFOHEAD(fd,packet_len_table[0x1b6]);
  5822. WFIFOW(fd, 0)=0x1b6;//0x150;
  5823. WFIFOL(fd, 2)=g->guild_id;
  5824. WFIFOL(fd, 6)=g->guild_lv;
  5825. WFIFOL(fd,10)=g->connect_member;
  5826. WFIFOL(fd,14)=g->max_member;
  5827. WFIFOL(fd,18)=g->average_lv;
  5828. WFIFOL(fd,22)=g->exp;
  5829. WFIFOL(fd,26)=g->next_exp;
  5830. WFIFOL(fd,30)=0; // 上納
  5831. WFIFOL(fd,34)=0; // VW(性格の悪さ?:性向グラフ左右)
  5832. WFIFOL(fd,38)=0; // RF(正義の度合い?:性向グラフ上下)
  5833. WFIFOL(fd,42)=0; // 人数?
  5834. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5835. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5836. for(i=0;i<MAX_GUILDCASTLE;i++){
  5837. gc=guild_castle_search(i);
  5838. if(!gc) continue;
  5839. if(g->guild_id == gc->guild_id) t++;
  5840. }
  5841. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  5842. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  5843. else
  5844. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  5845. WFIFOSET(fd,packet_len_table[WFIFOW(fd,0)]);
  5846. clif_guild_emblem(sd,g); // Guild emblem vanish fix [Valaris]
  5847. return 0;
  5848. }
  5849. /*==========================================
  5850. * ギルド同盟/敵対情報
  5851. *------------------------------------------
  5852. */
  5853. int clif_guild_allianceinfo(struct map_session_data *sd)
  5854. {
  5855. int fd,i,c;
  5856. struct guild *g;
  5857. nullpo_retr(0, sd);
  5858. fd=sd->fd;
  5859. g=guild_search(sd->status.guild_id);
  5860. if(g==NULL)
  5861. return 0;
  5862. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5863. WFIFOW(fd, 0)=0x14c;
  5864. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5865. struct guild_alliance *a=&g->alliance[i];
  5866. if(a->guild_id>0){
  5867. WFIFOL(fd,c*32+4)=a->opposition;
  5868. WFIFOL(fd,c*32+8)=a->guild_id;
  5869. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5870. c++;
  5871. }
  5872. }
  5873. WFIFOW(fd, 2)=c*32+4;
  5874. WFIFOSET(fd,WFIFOW(fd,2));
  5875. return 0;
  5876. }
  5877. /*==========================================
  5878. * ギルドメンバーリスト
  5879. *------------------------------------------
  5880. */
  5881. int clif_guild_memberlist(struct map_session_data *sd)
  5882. {
  5883. int fd;
  5884. int i,c;
  5885. struct guild *g;
  5886. nullpo_retr(0, sd);
  5887. fd=sd->fd;
  5888. if (!fd)
  5889. return 0;
  5890. g=guild_search(sd->status.guild_id);
  5891. if(g==NULL)
  5892. return 0;
  5893. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5894. WFIFOW(fd, 0)=0x154;
  5895. for(i=0,c=0;i<g->max_member;i++){
  5896. struct guild_member *m=&g->member[i];
  5897. if(m->account_id==0)
  5898. continue;
  5899. WFIFOL(fd,c*104+ 4)=m->account_id;
  5900. WFIFOL(fd,c*104+ 8)=m->char_id;
  5901. WFIFOW(fd,c*104+12)=m->hair;
  5902. WFIFOW(fd,c*104+14)=m->hair_color;
  5903. WFIFOW(fd,c*104+16)=m->gender;
  5904. WFIFOW(fd,c*104+18)=m->class_;
  5905. WFIFOW(fd,c*104+20)=m->lv;
  5906. WFIFOL(fd,c*104+22)=m->exp;
  5907. WFIFOL(fd,c*104+26)=m->online;
  5908. WFIFOL(fd,c*104+30)=m->position;
  5909. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5910. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5911. c++;
  5912. }
  5913. WFIFOW(fd, 2)=c*104+4;
  5914. WFIFOSET(fd,WFIFOW(fd,2));
  5915. return 0;
  5916. }
  5917. /*==========================================
  5918. * ギルド役職名リスト
  5919. *------------------------------------------
  5920. */
  5921. int clif_guild_positionnamelist(struct map_session_data *sd)
  5922. {
  5923. int i,fd;
  5924. struct guild *g;
  5925. nullpo_retr(0, sd);
  5926. fd=sd->fd;
  5927. g=guild_search(sd->status.guild_id);
  5928. if(g==NULL)
  5929. return 0;
  5930. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5931. WFIFOW(fd, 0)=0x166;
  5932. for(i=0;i<MAX_GUILDPOSITION;i++){
  5933. WFIFOL(fd,i*28+4)=i;
  5934. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5935. }
  5936. WFIFOW(fd,2)=i*28+4;
  5937. WFIFOSET(fd,WFIFOW(fd,2));
  5938. return 0;
  5939. }
  5940. /*==========================================
  5941. * ギルド役職情報リスト
  5942. *------------------------------------------
  5943. */
  5944. int clif_guild_positioninfolist(struct map_session_data *sd)
  5945. {
  5946. int i,fd;
  5947. struct guild *g;
  5948. nullpo_retr(0, sd);
  5949. fd=sd->fd;
  5950. g=guild_search(sd->status.guild_id);
  5951. if(g==NULL)
  5952. return 0;
  5953. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5954. WFIFOW(fd, 0)=0x160;
  5955. for(i=0;i<MAX_GUILDPOSITION;i++){
  5956. struct guild_position *p=&g->position[i];
  5957. WFIFOL(fd,i*16+ 4)=i;
  5958. WFIFOL(fd,i*16+ 8)=p->mode;
  5959. WFIFOL(fd,i*16+12)=i;
  5960. WFIFOL(fd,i*16+16)=p->exp_mode;
  5961. }
  5962. WFIFOW(fd, 2)=i*16+4;
  5963. WFIFOSET(fd,WFIFOW(fd,2));
  5964. return 0;
  5965. }
  5966. /*==========================================
  5967. * ギルド役職変更通知
  5968. *------------------------------------------
  5969. */
  5970. int clif_guild_positionchanged(struct guild *g,int idx)
  5971. {
  5972. struct map_session_data *sd;
  5973. unsigned char buf[128];
  5974. nullpo_retr(0, g);
  5975. WBUFW(buf, 0)=0x174;
  5976. WBUFW(buf, 2)=44;
  5977. WBUFL(buf, 4)=idx;
  5978. WBUFL(buf, 8)=g->position[idx].mode;
  5979. WBUFL(buf,12)=idx;
  5980. WBUFL(buf,16)=g->position[idx].exp_mode;
  5981. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5982. if( (sd=guild_getavailablesd(g))!=NULL )
  5983. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5984. return 0;
  5985. }
  5986. /*==========================================
  5987. * ギルドメンバ変更通知
  5988. *------------------------------------------
  5989. */
  5990. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5991. {
  5992. struct map_session_data *sd;
  5993. unsigned char buf[64];
  5994. nullpo_retr(0, g);
  5995. WBUFW(buf, 0)=0x156;
  5996. WBUFW(buf, 2)=16;
  5997. WBUFL(buf, 4)=g->member[idx].account_id;
  5998. WBUFL(buf, 8)=g->member[idx].char_id;
  5999. WBUFL(buf,12)=g->member[idx].position;
  6000. if( (sd=guild_getavailablesd(g))!=NULL )
  6001. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6002. return 0;
  6003. }
  6004. /*==========================================
  6005. * ギルドエンブレム送信
  6006. *------------------------------------------
  6007. */
  6008. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6009. {
  6010. int fd;
  6011. nullpo_retr(0, sd);
  6012. nullpo_retr(0, g);
  6013. fd=sd->fd;
  6014. if(g->emblem_len<=0)
  6015. return 0;
  6016. WFIFOHEAD(fd,g->emblem_len+12);
  6017. WFIFOW(fd,0)=0x152;
  6018. WFIFOW(fd,2)=g->emblem_len+12;
  6019. WFIFOL(fd,4)=g->guild_id;
  6020. WFIFOL(fd,8)=g->emblem_id;
  6021. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6022. WFIFOSET(fd,WFIFOW(fd,2));
  6023. return 0;
  6024. }
  6025. /*==========================================
  6026. * ギルドスキル送信
  6027. *------------------------------------------
  6028. */
  6029. int clif_guild_skillinfo(struct map_session_data *sd)
  6030. {
  6031. int fd;
  6032. int i,id,c,up=1;
  6033. struct guild *g;
  6034. nullpo_retr(0, sd);
  6035. fd=sd->fd;
  6036. g=guild_search(sd->status.guild_id);
  6037. if(g==NULL)
  6038. return 0;
  6039. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6040. WFIFOW(fd,0)=0x0162;
  6041. WFIFOW(fd,4)=g->skill_point;
  6042. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6043. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6044. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6045. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  6046. WFIFOW(fd,c*37+10) = 0;
  6047. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6048. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6049. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6050. memset(WFIFOP(fd,c*37+18),0,24);
  6051. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6052. up = 1;
  6053. else
  6054. up = 0;
  6055. WFIFOB(fd,c*37+42)= up;
  6056. c++;
  6057. }
  6058. }
  6059. WFIFOW(fd,2)=c*37+6;
  6060. WFIFOSET(fd,WFIFOW(fd,2));
  6061. return 0;
  6062. }
  6063. /*==========================================
  6064. * ギルド告知送信
  6065. *------------------------------------------
  6066. */
  6067. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6068. {
  6069. int fd;
  6070. nullpo_retr(0, sd);
  6071. nullpo_retr(0, g);
  6072. fd = sd->fd;
  6073. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6074. return 0;
  6075. if (fd <= 0)
  6076. return 0;
  6077. if(*g->mes1==0 && *g->mes2==0)
  6078. return 0;
  6079. WFIFOHEAD(fd,packet_len_table[0x16f]);
  6080. WFIFOW(fd,0)=0x16f;
  6081. memcpy(WFIFOP(fd,2),g->mes1,60);
  6082. memcpy(WFIFOP(fd,62),g->mes2,120);
  6083. WFIFOSET(fd,packet_len_table[0x16f]);
  6084. return 0;
  6085. }
  6086. /*==========================================
  6087. * ギルドメンバ勧誘
  6088. *------------------------------------------
  6089. */
  6090. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6091. {
  6092. int fd;
  6093. nullpo_retr(0, sd);
  6094. nullpo_retr(0, g);
  6095. fd=sd->fd;
  6096. WFIFOHEAD(fd,packet_len_table[0x16a]);
  6097. WFIFOW(fd,0)=0x16a;
  6098. WFIFOL(fd,2)=g->guild_id;
  6099. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6100. WFIFOSET(fd,packet_len_table[0x16a]);
  6101. return 0;
  6102. }
  6103. /*==========================================
  6104. * ギルドメンバ勧誘結果
  6105. *------------------------------------------
  6106. */
  6107. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6108. {
  6109. int fd;
  6110. nullpo_retr(0, sd);
  6111. fd=sd->fd;
  6112. WFIFOHEAD(fd,packet_len_table[0x169]);
  6113. WFIFOW(fd,0)=0x169;
  6114. WFIFOB(fd,2)=flag;
  6115. WFIFOSET(fd,packet_len_table[0x169]);
  6116. return 0;
  6117. }
  6118. /*==========================================
  6119. * ギルドメンバ脱退通知
  6120. *------------------------------------------
  6121. */
  6122. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6123. {
  6124. unsigned char buf[128];
  6125. nullpo_retr(0, sd);
  6126. WBUFW(buf, 0)=0x15a;
  6127. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6128. memcpy(WBUFP(buf,26),mes,40);
  6129. clif_send(buf,packet_len_table[0x15a],&sd->bl,GUILD);
  6130. return 0;
  6131. }
  6132. /*==========================================
  6133. * ギルドメンバ追放通知
  6134. *------------------------------------------
  6135. */
  6136. int clif_guild_explusion(struct map_session_data *sd,const char *name,const char *mes,
  6137. int account_id)
  6138. {
  6139. unsigned char buf[128];
  6140. nullpo_retr(0, sd);
  6141. WBUFW(buf, 0)=0x15c;
  6142. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6143. memcpy(WBUFP(buf,26),mes,40);
  6144. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6145. clif_send(buf,packet_len_table[0x15c],&sd->bl,GUILD);
  6146. return 0;
  6147. }
  6148. /*==========================================
  6149. * ギルド追放メンバリスト
  6150. *------------------------------------------
  6151. */
  6152. int clif_guild_explusionlist(struct map_session_data *sd)
  6153. {
  6154. int fd;
  6155. int i,c;
  6156. struct guild *g;
  6157. nullpo_retr(0, sd);
  6158. fd=sd->fd;
  6159. g=guild_search(sd->status.guild_id);
  6160. if(g==NULL)
  6161. return 0;
  6162. WFIFOHEAD(fd,MAX_GUILDEXPLUSION * 88 + 4);
  6163. WFIFOW(fd,0)=0x163;
  6164. for(i=c=0;i<MAX_GUILDEXPLUSION;i++){
  6165. struct guild_explusion *e=&g->explusion[i];
  6166. if(e->account_id>0){
  6167. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6168. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6169. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6170. c++;
  6171. }
  6172. }
  6173. WFIFOW(fd,2)=c*88+4;
  6174. WFIFOSET(fd,WFIFOW(fd,2));
  6175. return 0;
  6176. }
  6177. /*==========================================
  6178. * ギルド会話
  6179. *------------------------------------------
  6180. */
  6181. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6182. {
  6183. struct map_session_data *sd;
  6184. unsigned char *buf;
  6185. buf = (unsigned char*)aCallocA(len + 4, sizeof(unsigned char));
  6186. WBUFW(buf, 0) = 0x17f;
  6187. WBUFW(buf, 2) = len + 4;
  6188. memcpy(WBUFP(buf,4), mes, len);
  6189. if ((sd = guild_getavailablesd(g)) != NULL)
  6190. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6191. if(buf) aFree(buf);
  6192. return 0;
  6193. }
  6194. /*==========================================
  6195. * ギルドスキル割り振り通知
  6196. *------------------------------------------
  6197. */
  6198. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6199. {
  6200. int fd;
  6201. nullpo_retr(0, sd);
  6202. fd=sd->fd;
  6203. WFIFOHEAD(fd,11);
  6204. WFIFOW(fd,0) = 0x10e;
  6205. WFIFOW(fd,2) = skill_num;
  6206. WFIFOW(fd,4) = lv;
  6207. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6208. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6209. WFIFOB(fd,10) = 1;
  6210. WFIFOSET(fd,11);
  6211. return 0;
  6212. }
  6213. /*==========================================
  6214. * ギルド同盟要請
  6215. *------------------------------------------
  6216. */
  6217. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6218. {
  6219. int fd;
  6220. nullpo_retr(0, sd);
  6221. fd=sd->fd;
  6222. WFIFOHEAD(fd,packet_len_table[0x171]);
  6223. WFIFOW(fd,0)=0x171;
  6224. WFIFOL(fd,2)=account_id;
  6225. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6226. WFIFOSET(fd,packet_len_table[0x171]);
  6227. return 0;
  6228. }
  6229. /*==========================================
  6230. * ギルド同盟結果
  6231. *------------------------------------------
  6232. */
  6233. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6234. {
  6235. int fd;
  6236. nullpo_retr(0, sd);
  6237. fd=sd->fd;
  6238. WFIFOHEAD(fd,packet_len_table[0x173]);
  6239. WFIFOW(fd,0)=0x173;
  6240. WFIFOL(fd,2)=flag;
  6241. WFIFOSET(fd,packet_len_table[0x173]);
  6242. return 0;
  6243. }
  6244. /*==========================================
  6245. * ギルド関係解消通知
  6246. *------------------------------------------
  6247. */
  6248. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6249. {
  6250. int fd;
  6251. nullpo_retr(0, sd);
  6252. fd = sd->fd;
  6253. if (fd <= 0)
  6254. return 0;
  6255. WFIFOHEAD(fd,packet_len_table[0x184]);
  6256. WFIFOW(fd,0)=0x184;
  6257. WFIFOL(fd,2)=guild_id;
  6258. WFIFOL(fd,6)=flag;
  6259. WFIFOSET(fd,packet_len_table[0x184]);
  6260. return 0;
  6261. }
  6262. /*==========================================
  6263. * ギルド敵対結果
  6264. *------------------------------------------
  6265. */
  6266. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6267. {
  6268. int fd;
  6269. nullpo_retr(0, sd);
  6270. fd=sd->fd;
  6271. WFIFOHEAD(fd,packet_len_table[0x181]);
  6272. WFIFOW(fd,0)=0x181;
  6273. WFIFOB(fd,2)=flag;
  6274. WFIFOSET(fd,packet_len_table[0x181]);
  6275. return 0;
  6276. }
  6277. /*==========================================
  6278. * ギルド関係追加
  6279. *------------------------------------------
  6280. */
  6281. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6282. {
  6283. unsigned char buf[64];
  6284. WBUFW(fd,0)=0x185;
  6285. WBUFL(fd,2)=g->alliance[idx].opposition;
  6286. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6287. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6288. clif_send(buf,packet_len_table[0x185],guild_getavailablesd(g),GUILD);
  6289. return 0;
  6290. }*/
  6291. /*==========================================
  6292. * ギルド解散通知
  6293. *------------------------------------------
  6294. */
  6295. int clif_guild_broken(struct map_session_data *sd,int flag)
  6296. {
  6297. int fd;
  6298. nullpo_retr(0, sd);
  6299. fd=sd->fd;
  6300. WFIFOHEAD(fd,packet_len_table[0x15e]);
  6301. WFIFOW(fd,0)=0x15e;
  6302. WFIFOL(fd,2)=flag;
  6303. WFIFOSET(fd,packet_len_table[0x15e]);
  6304. return 0;
  6305. }
  6306. /*==========================================
  6307. * エモーション
  6308. *------------------------------------------
  6309. */
  6310. void clif_emotion(struct block_list *bl,int type)
  6311. {
  6312. unsigned char buf[8];
  6313. nullpo_retv(bl);
  6314. WBUFW(buf,0)=0xc0;
  6315. WBUFL(buf,2)=bl->id;
  6316. WBUFB(buf,6)=type;
  6317. clif_send(buf,packet_len_table[0xc0],bl,AREA);
  6318. }
  6319. /*==========================================
  6320. * トーキーボックス
  6321. *------------------------------------------
  6322. */
  6323. void clif_talkiebox(struct block_list *bl,char* talkie)
  6324. {
  6325. unsigned char buf[86];
  6326. nullpo_retv(bl);
  6327. WBUFW(buf,0)=0x191;
  6328. WBUFL(buf,2)=bl->id;
  6329. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6330. clif_send(buf,packet_len_table[0x191],bl,AREA);
  6331. }
  6332. /*==========================================
  6333. * 結婚エフェクト
  6334. *------------------------------------------
  6335. */
  6336. void clif_wedding_effect(struct block_list *bl) {
  6337. unsigned char buf[6];
  6338. nullpo_retv(bl);
  6339. WBUFW(buf,0) = 0x1ea;
  6340. WBUFL(buf,2) = bl->id;
  6341. clif_send(buf, packet_len_table[0x1ea], bl, AREA);
  6342. }
  6343. /*==========================================
  6344. * あなたに逢いたい使用時名前叫び
  6345. *------------------------------------------
  6346. void clif_callpartner(struct map_session_data *sd)
  6347. {
  6348. unsigned char buf[26];
  6349. char *p;
  6350. nullpo_retv(sd);
  6351. if(sd->status.partner_id){
  6352. WBUFW(buf,0)=0x1e6;
  6353. p = map_charid2nick(sd->status.partner_id);
  6354. if(p){
  6355. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6356. }else{
  6357. map_reqchariddb(sd,sd->status.partner_id);
  6358. chrif_searchcharid(sd->status.partner_id);
  6359. WBUFB(buf,2) = 0;
  6360. }
  6361. clif_send(buf,packet_len_table[0x1e6],&sd->bl,AREA);
  6362. }
  6363. return;
  6364. }
  6365. */
  6366. /*==========================================
  6367. * Adopt baby [Celest]
  6368. *------------------------------------------
  6369. */
  6370. void clif_adopt_process(struct map_session_data *sd)
  6371. {
  6372. int fd;
  6373. nullpo_retv(sd);
  6374. fd=sd->fd;
  6375. WFIFOHEAD(fd,packet_len_table[0x1f8]);
  6376. WFIFOW(fd,0)=0x1f8;
  6377. WFIFOSET(fd,packet_len_table[0x1f8]);
  6378. }
  6379. /*==========================================
  6380. * Marry [DracoRPG]
  6381. *------------------------------------------
  6382. */
  6383. void clif_marriage_process(struct map_session_data *sd)
  6384. {
  6385. int fd;
  6386. nullpo_retv(sd);
  6387. fd=sd->fd;
  6388. WFIFOHEAD(fd,packet_len_table[0x1e4]);
  6389. WFIFOW(fd,0)=0x1e4;
  6390. WFIFOSET(fd,packet_len_table[0x1e4]);
  6391. }
  6392. /*==========================================
  6393. * Notice of divorce
  6394. *------------------------------------------
  6395. */
  6396. void clif_divorced(struct map_session_data *sd, char *name)
  6397. {
  6398. int fd;
  6399. nullpo_retv(sd);
  6400. fd=sd->fd;
  6401. WFIFOHEAD(fd,packet_len_table[0x205]);
  6402. WFIFOW(fd,0)=0x205;
  6403. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6404. WFIFOSET(fd, packet_len_table[0x205]);
  6405. }
  6406. /*==========================================
  6407. *
  6408. *------------------------------------------
  6409. */
  6410. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6411. nullpo_retv(sd);
  6412. WFIFOHEAD(fd,packet_len_table[0x1f6]);
  6413. WFIFOW(fd,0)=0x1f6;
  6414. WFIFOSET(fd, packet_len_table[0x1f6]);
  6415. }
  6416. /*==========================================
  6417. *
  6418. *------------------------------------------
  6419. */
  6420. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6421. nullpo_retv(sd);
  6422. WFIFOHEAD(fd,packet_len_table[0x1e2]);
  6423. WFIFOW(fd,0)=0x1e2;
  6424. WFIFOSET(fd, packet_len_table[0x1e2]);
  6425. }
  6426. /*==========================================
  6427. * 座る
  6428. *------------------------------------------
  6429. */
  6430. void clif_sitting(struct map_session_data *sd)
  6431. {
  6432. unsigned char buf[64];
  6433. nullpo_retv(sd);
  6434. WBUFW(buf, 0) = 0x8a;
  6435. WBUFL(buf, 2) = sd->bl.id;
  6436. WBUFB(buf,26) = 2;
  6437. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  6438. }
  6439. /*==========================================
  6440. *
  6441. *------------------------------------------
  6442. */
  6443. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  6444. {
  6445. unsigned char *buf;
  6446. nullpo_retr(0, sd);
  6447. buf = (unsigned char*)aCallocA(len + 5, sizeof(unsigned char));
  6448. WBUFW(buf, 0) = 0x17f;
  6449. WBUFW(buf, 2) = len + 5;
  6450. memcpy(WBUFP(buf,4), mes, len);
  6451. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6452. if(buf) aFree(buf);
  6453. return 0;
  6454. }
  6455. /*==========================================
  6456. *
  6457. *------------------------------------------
  6458. */
  6459. int clif_GM_kickack(struct map_session_data *sd, int id)
  6460. {
  6461. int fd;
  6462. nullpo_retr(0, sd);
  6463. fd = sd->fd;
  6464. WFIFOHEAD(fd,packet_len_table[0xcd]);
  6465. WFIFOW(fd,0) = 0xcd;
  6466. WFIFOL(fd,2) = id;
  6467. WFIFOSET(fd, packet_len_table[0xcd]);
  6468. return 0;
  6469. }
  6470. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6471. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6472. {
  6473. nullpo_retr(0, tsd);
  6474. if(type)
  6475. clif_GM_kickack(sd,tsd->status.account_id);
  6476. WFIFOHEAD(tsd->fd,packet_len_table[0x18b]);
  6477. WFIFOW(tsd->fd,0) = 0x18b;
  6478. WFIFOW(tsd->fd,2) = 0;
  6479. WFIFOSET(tsd->fd,packet_len_table[0x18b]);
  6480. if (tsd->fd)
  6481. {
  6482. ShowDebug("clif_GM_kick: Disconnecting session #%d\n", tsd->fd);
  6483. clif_setwaitclose(tsd->fd);
  6484. } else { //Player has no session attached, delete it right away. [Skotlex]
  6485. map_quit(tsd);
  6486. }
  6487. return 0;
  6488. }
  6489. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6490. {
  6491. int fd;
  6492. nullpo_retr(0, sd);
  6493. nullpo_retr(0, tsd);
  6494. fd = tsd->fd;
  6495. if (fd <= 0)
  6496. return 0;
  6497. WFIFOHEAD(fd,packet_len_table[0x14b]);
  6498. WFIFOW(fd,0) = 0x14b;
  6499. WFIFOB(fd,2) = 0;
  6500. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6501. WFIFOSET(fd, packet_len_table[0x14b]);
  6502. return 0;
  6503. }
  6504. /*==========================================
  6505. *
  6506. *------------------------------------------
  6507. */
  6508. int clif_timedout(struct map_session_data *sd)
  6509. {
  6510. nullpo_retr(0, sd);
  6511. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6512. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6513. clif_setwaitclose(sd->fd); // Set session to EOF
  6514. return 0;
  6515. }
  6516. /*==========================================
  6517. * Wis拒否許可応答
  6518. *------------------------------------------
  6519. */
  6520. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6521. {
  6522. int fd;
  6523. nullpo_retr(0, sd);
  6524. fd=sd->fd;
  6525. WFIFOHEAD(fd,packet_len_table[0xd1]);
  6526. WFIFOW(fd,0)=0xd1;
  6527. WFIFOB(fd,2)=type;
  6528. WFIFOB(fd,3)=flag;
  6529. WFIFOSET(fd,packet_len_table[0xd1]);
  6530. return 0;
  6531. }
  6532. /*==========================================
  6533. * Wis全拒否許可応答
  6534. *------------------------------------------
  6535. */
  6536. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6537. {
  6538. int fd;
  6539. nullpo_retr(0, sd);
  6540. fd=sd->fd;
  6541. WFIFOHEAD(fd,packet_len_table[0xd2]);
  6542. WFIFOW(fd,0)=0xd2;
  6543. WFIFOB(fd,2)=type;
  6544. WFIFOB(fd,3)=flag;
  6545. WFIFOSET(fd,packet_len_table[0xd2]);
  6546. return 0;
  6547. }
  6548. /*==========================================
  6549. * サウンドエフェクト
  6550. *------------------------------------------
  6551. */
  6552. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  6553. {
  6554. int fd;
  6555. nullpo_retv(sd);
  6556. nullpo_retv(bl);
  6557. fd=sd->fd;
  6558. WFIFOHEAD(fd,packet_len_table[0x1d3]);
  6559. WFIFOW(fd,0)=0x1d3;
  6560. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6561. WFIFOB(fd,26)=type;
  6562. WFIFOL(fd,27)=0;
  6563. WFIFOL(fd,31)=bl->id;
  6564. WFIFOSET(fd,packet_len_table[0x1d3]);
  6565. return;
  6566. }
  6567. int clif_soundeffectall(struct block_list *bl, char *name, int type, int coverage)
  6568. {
  6569. unsigned char buf[40];
  6570. memset(buf, 0, packet_len_table[0x1d3]);
  6571. if(coverage < 0 || coverage > 22){
  6572. ShowError("clif_soundeffectall: undefined coverage.\n");
  6573. return 0;
  6574. }
  6575. nullpo_retr(0, bl);
  6576. WBUFW(buf,0)=0x1d3;
  6577. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6578. WBUFB(buf,26)=type;
  6579. WBUFL(buf,27)=0;
  6580. WBUFL(buf,31)=bl->id;
  6581. clif_send(buf, packet_len_table[0x1d3], bl, coverage);
  6582. return 0;
  6583. }
  6584. // displaying special effects (npcs, weather, etc) [Valaris]
  6585. int clif_specialeffect(struct block_list *bl, int type, int flag)
  6586. {
  6587. unsigned char buf[24];
  6588. nullpo_retr(0, bl);
  6589. memset(buf, 0, packet_len_table[0x1f3]);
  6590. WBUFW(buf,0) = 0x1f3;
  6591. WBUFL(buf,2) = bl->id;
  6592. WBUFL(buf,6) = type;
  6593. switch (flag) {
  6594. case 4:
  6595. clif_send(buf, packet_len_table[0x1f3], bl, AREA_WOS);
  6596. break;
  6597. case 3:
  6598. clif_send(buf, packet_len_table[0x1f3], bl, ALL_CLIENT);
  6599. break;
  6600. case 2:
  6601. clif_send(buf, packet_len_table[0x1f3], bl, ALL_SAMEMAP);
  6602. break;
  6603. case 1:
  6604. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  6605. break;
  6606. default:
  6607. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  6608. }
  6609. if (disguised(bl)) {
  6610. WBUFL(buf,2) = -bl->id;
  6611. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  6612. }
  6613. return 0;
  6614. }
  6615. // refresh the client's screen, getting rid of any effects
  6616. int clif_refresh(struct map_session_data *sd) {
  6617. nullpo_retr(-1, sd);
  6618. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6619. 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);
  6620. return 0;
  6621. }
  6622. // updates the object's (bl) name on client
  6623. int clif_charnameack (int fd, struct block_list *bl)
  6624. {
  6625. unsigned char buf[103];
  6626. int cmd = 0x95;
  6627. nullpo_retr(0, bl);
  6628. WBUFW(buf,0) = cmd;
  6629. WBUFL(buf,2) = bl->id;
  6630. switch(bl->type) {
  6631. case BL_PC:
  6632. {
  6633. struct map_session_data *ssd = (struct map_session_data *)bl;
  6634. struct party *p = NULL;
  6635. struct guild *g = NULL;
  6636. nullpo_retr(0, ssd);
  6637. if (strlen(ssd->fakename)>1) {
  6638. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6639. break;
  6640. }
  6641. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6642. if (ssd->status.party_id > 0)
  6643. p = party_search(ssd->status.party_id);
  6644. if (ssd->status.guild_id > 0)
  6645. g = guild_search(ssd->status.guild_id);
  6646. if (p == NULL && g == NULL)
  6647. break;
  6648. WBUFW(buf, 0) = cmd = 0x195;
  6649. if (p)
  6650. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  6651. else
  6652. WBUFB(buf,30) = 0;
  6653. if (g)
  6654. {
  6655. int i, ps = -1;
  6656. for(i = 0; i < g->max_member; i++) {
  6657. if (g->member[i].account_id == ssd->status.account_id &&
  6658. g->member[i].char_id == ssd->status.char_id )
  6659. {
  6660. ps = g->member[i].position;
  6661. break;
  6662. }
  6663. }
  6664. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6665. {
  6666. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6667. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6668. } else { //Assume no guild.
  6669. WBUFB(buf,54) = 0;
  6670. WBUFB(buf,78) = 0;
  6671. }
  6672. } else {
  6673. WBUFB(buf,54) = 0;
  6674. WBUFB(buf,78) = 0;
  6675. }
  6676. }
  6677. break;
  6678. case BL_PET:
  6679. memcpy(WBUFP(buf,6), ((struct pet_data*)bl)->name, NAME_LENGTH);
  6680. break;
  6681. case BL_NPC:
  6682. memcpy(WBUFP(buf,6), ((struct npc_data*)bl)->name, NAME_LENGTH);
  6683. break;
  6684. case BL_MOB:
  6685. {
  6686. struct mob_data *md = (struct mob_data *)bl;
  6687. nullpo_retr(0, md);
  6688. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6689. if (md->guardian_data && md->guardian_data->guild_id) {
  6690. WBUFW(buf, 0) = cmd = 0x195;
  6691. WBUFB(buf,30) = 0;
  6692. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6693. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6694. } else if (battle_config.show_mob_hp == 1) {
  6695. char mobhp[50];
  6696. WBUFW(buf, 0) = cmd = 0x195;
  6697. sprintf(mobhp, "HP: %d/%d", md->hp, md->max_hp);
  6698. //Even thought mobhp ain't a name, we send it as one so the client
  6699. //can parse it. [Skotlex]
  6700. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6701. WBUFB(buf,54) = 0;
  6702. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6703. }
  6704. }
  6705. break;
  6706. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6707. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6708. // break;
  6709. return 0;
  6710. default:
  6711. if (battle_config.error_log)
  6712. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6713. return 0;
  6714. }
  6715. // if no receipient specified just update nearby clients
  6716. if (fd == 0)
  6717. clif_send(buf, packet_len_table[cmd], bl, AREA);
  6718. else {
  6719. WFIFOHEAD(fd, packet_len_table[cmd]);
  6720. memcpy(WFIFOP(fd, 0), buf, packet_len_table[cmd]);
  6721. WFIFOSET(fd, packet_len_table[cmd]);
  6722. }
  6723. return 0;
  6724. }
  6725. //Used to update when a char leaves a party/guild. [Skotlex]
  6726. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6727. int clif_charnameupdate (struct map_session_data *ssd)
  6728. {
  6729. unsigned char buf[103];
  6730. int cmd = 0x195;
  6731. struct party *p = NULL;
  6732. struct guild *g = NULL;
  6733. nullpo_retr(0, ssd);
  6734. if (strlen(ssd->fakename)>1)
  6735. return 0; //No need to update as the party/guild was not displayed anyway.
  6736. WBUFW(buf,0) = cmd;
  6737. WBUFL(buf,2) = ssd->bl.id;
  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)
  6744. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  6745. else
  6746. WBUFB(buf,30) = 0;
  6747. if (g)
  6748. {
  6749. int i, ps = -1;
  6750. for(i = 0; i < g->max_member; i++) {
  6751. if (g->member[i].account_id == ssd->status.account_id &&
  6752. g->member[i].char_id == ssd->status.char_id )
  6753. {
  6754. ps = g->member[i].position;
  6755. break;
  6756. }
  6757. }
  6758. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6759. {
  6760. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6761. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6762. } else { //Assume no guild.
  6763. WBUFB(buf,54) = 0;
  6764. WBUFB(buf,78) = 0;
  6765. }
  6766. } else {
  6767. WBUFB(buf,54) = 0;
  6768. WBUFB(buf,78) = 0;
  6769. }
  6770. // Update nearby clients
  6771. clif_send(buf, packet_len_table[cmd], &ssd->bl, AREA);
  6772. return 0;
  6773. }
  6774. int clif_slide(struct block_list *bl, int x, int y){
  6775. unsigned char buf[10];
  6776. nullpo_retr(0, bl);
  6777. WBUFW(buf, 0) = 0x01ff;
  6778. WBUFL(buf, 2) = bl->id;
  6779. WBUFW(buf, 6) = x;
  6780. WBUFW(buf, 8) = y;
  6781. clif_send(buf, packet_len_table[0x1ff], bl, AREA);
  6782. return 0;
  6783. }
  6784. /*------------------------------------------
  6785. * @me command by lordalfa, rewritten implementation by Skotlex
  6786. *------------------------------------------
  6787. */
  6788. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  6789. {
  6790. unsigned char buf[256]; //This should be more than sufficient, the theorical max is MESSAGE_SIZE+NAME_LENGTH + 8 (pads and extra inserted crap)
  6791. int len_mes = strlen(mes)+1; //Account for \0
  6792. if (len_mes + 8 >= 256) {
  6793. if (battle_config.error_log)
  6794. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6795. len_mes = 247; //Trunk it to avoid problems.
  6796. }
  6797. // send message to others
  6798. WBUFW(buf,0) = 0x8d;
  6799. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6800. WBUFL(buf,4) = sd->bl.id;
  6801. memcpy(WBUFP(buf,8), mes, len_mes);
  6802. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6803. // send back message to the speaker
  6804. WBUFW(buf,0) = 0x8e;
  6805. WBUFW(buf, 2) = len_mes + 4;
  6806. memcpy(WBUFP(buf,4), mes, len_mes);
  6807. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6808. return 0;
  6809. }
  6810. /*==========================
  6811. * Minimap fix [Kevin]
  6812. * Remove dot from minimap
  6813. *--------------------------
  6814. */
  6815. int clif_party_xy_remove(struct map_session_data *sd)
  6816. {
  6817. unsigned char buf[16];
  6818. nullpo_retr(0, sd);
  6819. WBUFW(buf,0)=0x107;
  6820. WBUFL(buf,2)=sd->status.account_id;
  6821. WBUFW(buf,6)=-1;
  6822. WBUFW(buf,8)=-1;
  6823. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  6824. return 0;
  6825. }
  6826. /*==========================================
  6827. * Info about Star Glaldiator save map [Komurka]
  6828. *------------------------------------------
  6829. */
  6830. void clif_feel_info(struct map_session_data *sd, int feel_level)
  6831. {
  6832. int fd=sd->fd;
  6833. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6834. WFIFOW(fd,0)=0x20e;
  6835. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  6836. WFIFOL(fd,26)=sd->bl.id;
  6837. WFIFOW(fd,30)=0x100+feel_level;
  6838. WFIFOSET(fd, packet_len_table[0x20e]);
  6839. }
  6840. /*==========================================
  6841. * Info about Star Glaldiator hate mob [Komurka]
  6842. *------------------------------------------
  6843. */
  6844. void clif_hate_mob(struct map_session_data *sd, int skilllv,int mob_id)
  6845. {
  6846. int fd=sd->fd;
  6847. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6848. WFIFOW(fd,0)=0x20e;
  6849. if (pcdb_checkid(mob_id))
  6850. strncpy(WFIFOP(fd,2),job_name(mob_id), NAME_LENGTH);
  6851. else if (mobdb_checkid(mob_id))
  6852. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6853. else //Really shouldn't happen...
  6854. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6855. WFIFOL(fd,26)=sd->bl.id;
  6856. WFIFOW(fd,30)=0xa00+skilllv-1;
  6857. WFIFOSET(fd, packet_len_table[0x20e]);
  6858. }
  6859. /*==========================================
  6860. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6861. *------------------------------------------
  6862. */
  6863. void clif_mission_mob(struct map_session_data *sd, unsigned short mob_id, unsigned short progress)
  6864. {
  6865. int fd=sd->fd;
  6866. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6867. WFIFOW(fd,0)=0x20e;
  6868. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6869. WFIFOL(fd,26)=mob_id;
  6870. WFIFOW(fd,30)=0x1400+progress; //Message to display
  6871. WFIFOSET(fd, packet_len_table[0x20e]);
  6872. }
  6873. // ---------------------
  6874. // clif_guess_PacketVer
  6875. // ---------------------
  6876. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6877. static int clif_guess_PacketVer(int fd, int get_previous)
  6878. {
  6879. static int packet_ver = -1;
  6880. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6881. RFIFOHEAD(fd);
  6882. 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]
  6883. return packet_ver;
  6884. //By default, start searching on the default one.
  6885. packet_ver = clif_config.packet_db_ver;
  6886. cmd = RFIFOW(fd,0);
  6887. packet_len = RFIFOREST(fd);
  6888. if (
  6889. cmd == clif_config.connect_cmd[packet_ver] &&
  6890. packet_len == packet_db[packet_ver][cmd].len &&
  6891. ((value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) == 0 || value == 1) &&
  6892. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) > 700000 && //Account ID is valid
  6893. value <= max_account_id &&
  6894. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) > 0 && //Char ID is valid
  6895. value <= max_char_id &&
  6896. (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) > 0 //Login 1 is a positive value (?)
  6897. )
  6898. return clif_config.packet_db_ver; //Default packet version found.
  6899. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6900. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6901. if (cmd != clif_config.connect_cmd[packet_ver] || //it is not a wanttoconnection for this version.
  6902. packet_len != packet_db[packet_ver][cmd].len) //The size of the wantoconnection packet does not matches.
  6903. continue;
  6904. if (
  6905. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < 700000 || value > max_account_id
  6906. || (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) < 1 || value > max_char_id
  6907. //What is login 1? In my tests it is a very very high value.
  6908. || (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) < 1
  6909. //This check seems redundant, all wanttoconnection packets have the gender on the very
  6910. //last byte of the packet.
  6911. || (value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) < 0 || value > 1
  6912. )
  6913. continue;
  6914. return packet_ver; //This is our best guess.
  6915. }
  6916. packet_ver = -1;
  6917. return -1;
  6918. }
  6919. // ------------
  6920. // clif_parse_*
  6921. // ------------
  6922. // パケット読み取って色々操作
  6923. /*==========================================
  6924. *
  6925. *------------------------------------------
  6926. */
  6927. void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
  6928. {
  6929. struct map_session_data *old_sd;
  6930. int cmd, account_id, char_id, login_id1, sex;
  6931. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6932. 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])
  6933. RFIFOHEAD(fd);
  6934. if (sd) {
  6935. if (battle_config.error_log)
  6936. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  6937. return;
  6938. }
  6939. packet_ver = clif_guess_PacketVer(fd, 1);
  6940. cmd = RFIFOW(fd,0);
  6941. if (packet_ver > 0)
  6942. {
  6943. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6944. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6945. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6946. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6947. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6948. if ((old_sd = map_id2sd(account_id)) != NULL)
  6949. { // if same account already connected, we disconnect the 2 sessions
  6950. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  6951. if (!old_sd->fd)
  6952. map_quit(old_sd);
  6953. else
  6954. clif_authfail_fd(old_sd->fd, 2); // same id
  6955. clif_authfail_fd(fd, 8); // still recognizes last connection
  6956. } else {
  6957. sd = (struct map_session_data*)aCalloc(1, sizeof(struct map_session_data));
  6958. sd->fd = fd;
  6959. sd->packet_ver = packet_ver;
  6960. session[fd]->session_data = sd;
  6961. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6962. WFIFOHEAD(fd,4);
  6963. WFIFOL(fd,0) = sd->bl.id;
  6964. WFIFOSET(fd,4);
  6965. chrif_authreq(sd);
  6966. }
  6967. }
  6968. return;
  6969. }
  6970. static int clif_nighttimer(int tid, unsigned int tick, int id, int data)
  6971. {
  6972. TBL_PC *sd;
  6973. sd=map_id2sd(id);
  6974. if (!sd) return 0;
  6975. //Check if character didn't instant-warped after logging in.
  6976. if (sd->bl.prev!=NULL) {
  6977. sd->state.night = 1;
  6978. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6979. }
  6980. return 0;
  6981. }
  6982. /*==========================================
  6983. * 007d クライアント側マップ読み込み完了
  6984. * map侵入時に必要なデータを全て送りつける
  6985. *------------------------------------------
  6986. */
  6987. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6988. {
  6989. int i;
  6990. if(sd->bl.prev != NULL)
  6991. return;
  6992. if(sd->npc_id) npc_event_dequeue(sd);
  6993. clif_skillinfoblock(sd);
  6994. pc_checkitem(sd);
  6995. // loadendack時
  6996. // next exp
  6997. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6998. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6999. // skill point
  7000. clif_updatestatus(sd,SP_SKILLPOINT);
  7001. // item
  7002. clif_itemlist(sd);
  7003. clif_equiplist(sd);
  7004. // cart
  7005. if(pc_iscarton(sd)){
  7006. clif_cart_itemlist(sd);
  7007. clif_cart_equiplist(sd);
  7008. clif_updatestatus(sd,SP_CARTINFO);
  7009. }
  7010. // param all
  7011. clif_initialstatus(sd);
  7012. if(battle_config.pc_invincible_time > 0) {
  7013. if(map_flag_gvg(sd->bl.m))
  7014. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7015. else
  7016. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7017. }
  7018. map_addblock(&sd->bl); // ブロック登録
  7019. clif_spawn(&sd->bl); // spawn
  7020. // party
  7021. party_send_movemap(sd);
  7022. // guild
  7023. guild_send_memberinfoshort(sd,1);
  7024. // weight max , now
  7025. clif_updatestatus(sd,SP_MAXWEIGHT);
  7026. clif_updatestatus(sd,SP_WEIGHT);
  7027. // Show hp after displacement [LuzZza]
  7028. if(sd->status.party_id)
  7029. clif_party_hp(sd);
  7030. // pvp
  7031. //if(sd->pvp_timer!=-1 && !battle_config.pk_mode) /PVP Client crash fix* Removed timer deletion
  7032. // delete_timer(sd->pvp_timer,pc_calc_pvprank_timer);
  7033. if(map[sd->bl.m].flag.pvp){
  7034. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7035. if (sd->pvp_timer == -1)
  7036. sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
  7037. sd->pvp_rank=0;
  7038. sd->pvp_lastusers=0;
  7039. sd->pvp_point=5;
  7040. sd->pvp_won=0;
  7041. sd->pvp_lost=0;
  7042. }
  7043. clif_set0199(fd,1);
  7044. } else {
  7045. sd->pvp_timer=-1;
  7046. // set flag, if it's a duel [LuzZza]
  7047. if(sd->duel_group)
  7048. clif_set0199(fd, 1);
  7049. }
  7050. if(map_flag_gvg(sd->bl.m))
  7051. clif_set0199(fd,3);
  7052. // pet
  7053. if(sd->status.pet_id > 0 && sd->pd) {
  7054. map_addblock(&sd->pd->bl);
  7055. clif_spawn(&sd->pd->bl);
  7056. clif_send_petdata(sd,0,0);
  7057. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7058. clif_send_petstatus(sd);
  7059. }
  7060. if(sd->state.connect_new) {
  7061. sd->state.connect_new = 0;
  7062. //Delayed night effect on log-on fix for the glow-issue. Thanks to Larry.
  7063. if (night_flag) {
  7064. char tmpstr[1024];
  7065. strcpy(tmpstr, msg_txt(500)); // Actually, it's the night...
  7066. clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
  7067. if (map[sd->bl.m].flag.nightenabled)
  7068. add_timer(gettick()+1000,clif_nighttimer,sd->bl.id,0);
  7069. }
  7070. // if(sd->status.class_ != sd->vd.class_)
  7071. // clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BASE,sd->vd.class_,SELF);
  7072. if (sd->sc.option&OPTION_FALCON)
  7073. clif_status_load(&sd->bl, SI_FALCON, 1);
  7074. if (sd->sc.option&OPTION_RIDING)
  7075. clif_status_load(&sd->bl, SI_RIDING, 1);
  7076. if(sd->status.pet_id > 0 && sd->pd && sd->pet.intimate > 900)
  7077. clif_pet_emotion(sd->pd,(sd->pd->class_ - 100)*100 + 50 + pet_hungry_val(sd));
  7078. //[LuzZza]
  7079. clif_guild_send_onlineinfo(sd);
  7080. } else
  7081. //New 'night' effect by dynamix [Skotlex]
  7082. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7083. { //Display night.
  7084. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  7085. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7086. else
  7087. sd->state.night = 1;
  7088. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7089. } else if (sd->state.night) { //Clear night display.
  7090. sd->state.night = 0;
  7091. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7092. }
  7093. // view equipment item
  7094. #if PACKETVER < 4
  7095. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7096. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7097. #else
  7098. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7099. #endif
  7100. if(sd->vd.cloth_color)
  7101. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7102. if(battle_config.muting_players && sd->status.manner < 0 && battle_config.manner_system)
  7103. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7104. // Lance
  7105. if (script_config.event_script_type == 0) {
  7106. struct npc_data *npc;
  7107. if ((npc = npc_name2id(script_config.loadmap_event_name))) {
  7108. run_script(npc->u.scr.script,0,sd->bl.id,npc->bl.id);
  7109. ShowStatus("Event '"CL_WHITE"%s"CL_RESET"' executed.\n", script_config.loadmap_event_name);
  7110. }
  7111. } else {
  7112. ShowStatus("%d '"CL_WHITE"%s"CL_RESET"' events executed.\n",
  7113. npc_event_doall_id(script_config.loadmap_event_name, sd->bl.id), script_config.loadmap_event_name);
  7114. }
  7115. if ((i = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7116. if(sd->bl.m == sd->feel_map[0].m
  7117. || sd->bl.m == sd->feel_map[1].m
  7118. || sd->bl.m == sd->feel_map[2].m)
  7119. sc_start(&sd->bl, SC_KNOWLEDGE, 100, i, skill_get_time(SG_KNOWLEDGE, i));
  7120. }
  7121. if (
  7122. pc_checkskill(sd,SG_SUN_COMFORT) ||
  7123. pc_checkskill(sd,SG_MOON_COMFORT) ||
  7124. pc_checkskill(sd,SG_STAR_COMFORT))
  7125. status_calc_pc(sd,0);
  7126. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7127. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7128. clif_weather_check(sd);
  7129. map_foreachinarea(clif_getareachar,sd->bl.m,
  7130. sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,
  7131. BL_ALL,sd);
  7132. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7133. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7134. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7135. else
  7136. sd->areanpc_id = 0;
  7137. if (pc_isdead(sd)) //In case you warped dead.
  7138. clif_clearchar_area(&sd->bl, 1);
  7139. }
  7140. /*==========================================
  7141. *
  7142. *------------------------------------------
  7143. */
  7144. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7145. RFIFOHEAD(fd);
  7146. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7147. sd->server_tick = gettick();
  7148. clif_servertick(sd);
  7149. }
  7150. /*==========================================
  7151. *
  7152. *------------------------------------------
  7153. */
  7154. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7155. int x, y;
  7156. int cmd;
  7157. RFIFOHEAD(fd);
  7158. if (pc_isdead(sd)) {
  7159. clif_clearchar_area(&sd->bl, 1);
  7160. return;
  7161. }
  7162. if (clif_cant_act(sd) && sd->sc.opt1 != OPT1_STONEWAIT)
  7163. return;
  7164. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7165. return;
  7166. pc_stop_attack(sd);
  7167. if (!unit_can_move(&sd->bl))
  7168. return;
  7169. if (sd->invincible_timer != -1)
  7170. pc_delinvincibletimer(sd);
  7171. cmd = RFIFOW(fd,0);
  7172. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7173. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7174. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7175. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7176. //Set last idle time... [Skotlex]
  7177. sd->idletime = last_tick;
  7178. unit_walktoxy(&sd->bl, x, y, 0);
  7179. }
  7180. /*==========================================
  7181. *
  7182. *------------------------------------------
  7183. */
  7184. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7185. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7186. WFIFOW(fd,0) = 0x18b;
  7187. /* Rovert's prevent logout option fixed [Valaris] */
  7188. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7189. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7190. ) {
  7191. clif_setwaitclose(fd);
  7192. WFIFOW(fd,2)=0;
  7193. } else {
  7194. WFIFOW(fd,2)=1;
  7195. }
  7196. WFIFOSET(fd,packet_len_table[0x18b]);
  7197. }
  7198. /*==========================================
  7199. *
  7200. *------------------------------------------
  7201. */
  7202. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7203. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7204. /* if (target_id == server_char_id) {
  7205. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7206. 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).
  7207. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7208. // if we block people
  7209. if (battle_config.ban_bot < 0) {
  7210. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7211. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7212. // message about the ban
  7213. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7214. // if we ban people
  7215. } else if (battle_config.ban_bot > 0) {
  7216. 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)
  7217. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7218. // message about the ban
  7219. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7220. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7221. // message about the ban
  7222. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7223. }
  7224. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7225. // send this info cause the bot ask until get an answer, damn spam
  7226. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7227. WPACKETW(0) = 0x95;
  7228. WPACKETL(2) = server_char_id;
  7229. strncpy(WPACKETP(6), sd->status.name, 24);
  7230. SENDPACKET(fd, packet_len_table[0x95]);
  7231. // take fake player out of screen
  7232. WPACKETW(0) = 0x80;
  7233. WPACKETL(2) = server_char_id;
  7234. WPACKETB(6) = 0;
  7235. SENDPACKET(fd, packet_len_table[0x80]);
  7236. // take fake mob out of screen
  7237. WPACKETW(0) = 0x80;
  7238. WPACKETL(2) = server_fake_mob_id;
  7239. WPACKETB(6) = 0;
  7240. SENDPACKET(fd, packet_len_table[0x80]);
  7241. }
  7242. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7243. if (target_id == server_fake_mob_id) {
  7244. int fake_mob;
  7245. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7246. 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).
  7247. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7248. // if we block people
  7249. if (battle_config.ban_bot < 0) {
  7250. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7251. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7252. // message about the ban
  7253. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7254. // if we ban people
  7255. } else if (battle_config.ban_bot > 0) {
  7256. 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)
  7257. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7258. // message about the ban
  7259. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7260. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7261. // message about the ban
  7262. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7263. }
  7264. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7265. // send this info cause the bot ask until get an answer, damn spam
  7266. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7267. WPACKETW(0) = 0x95;
  7268. WPACKETL(2) = server_fake_mob_id;
  7269. 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
  7270. if (!mobdb_checkid(fake_mob))
  7271. fake_mob = 1002; // poring (default)
  7272. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7273. SENDPACKET(fd, packet_len_table[0x95]);
  7274. // take fake mob out of screen
  7275. WPACKETW(0) = 0x80;
  7276. WPACKETL(2) = server_fake_mob_id;
  7277. WPACKETB(6) = 0;
  7278. SENDPACKET(fd, packet_len_table[0x80]);
  7279. // take fake player out of screen
  7280. WPACKETW(0) = 0x80;
  7281. WPACKETL(2) = server_char_id;
  7282. WPACKETB(6) = 0;
  7283. SENDPACKET(fd, packet_len_table[0x80]);
  7284. }
  7285. */
  7286. return;
  7287. }
  7288. /*==========================================
  7289. *
  7290. *------------------------------------------
  7291. */
  7292. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7293. int account_id;
  7294. struct block_list* bl;
  7295. struct status_change *sc;
  7296. RFIFOHEAD(fd);
  7297. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7298. if(account_id<0) // for disguises [Valaris]
  7299. account_id-=account_id*2;
  7300. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7301. if ((bl = map_id2bl(account_id)) != NULL) {
  7302. sc = status_get_sc(bl);
  7303. if (sc && (
  7304. (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_CHASEWALK) && !sd->special_state.intravision) ||
  7305. sc->option&OPTION_INVISIBLE)
  7306. ) {
  7307. //Asked name of invisible player, this shouldn't be possible!
  7308. //Possible bot? Thanks to veider and qspirit
  7309. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7310. unsigned char gm_msg[256];
  7311. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requests name of invisible chars.", sd->status.name, sd->status.account_id);
  7312. ShowWarning(gm_msg);
  7313. // information is sended to all online GM
  7314. // intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7315. return;
  7316. }
  7317. clif_charnameack(fd, bl);
  7318. }
  7319. }
  7320. /*==========================================
  7321. *
  7322. *------------------------------------------
  7323. */
  7324. void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
  7325. unsigned char *message, *buf, buf2[128];
  7326. RFIFOHEAD(fd);
  7327. WFIFOHEAD(fd, RFIFOW(fd,2) + 4);
  7328. message = (unsigned char*)RFIFOP(fd,4);
  7329. if (strlen(message) < strlen(sd->status.name) || //If the incoming string is too short...
  7330. strncmp(message, sd->status.name, strlen(sd->status.name)) != 0) //Or the name does not matches...
  7331. {
  7332. unsigned char gm_msg[256];
  7333. 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);
  7334. // information is sended to all online GM
  7335. sprintf(gm_msg, "Hack on global message (normal message): character '%s' (account: %d) uses another name.", sd->status.name, sd->status.account_id);
  7336. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7337. if (strlen(message) == 0)
  7338. strcpy(gm_msg, " This player sends a void name and a void message.");
  7339. else
  7340. snprintf(gm_msg, 255, " This player sends (name:message): '%128s'.", message);
  7341. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7342. // message about the ban
  7343. if (battle_config.ban_spoof_namer > 0)
  7344. sprintf(gm_msg, " This player has been banned for %d minute(s).", battle_config.ban_spoof_namer);
  7345. else
  7346. sprintf(gm_msg, " This player hasn't been banned (Ban option is disabled).");
  7347. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7348. // if we ban people
  7349. if (battle_config.ban_spoof_namer > 0) {
  7350. 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)
  7351. clif_setwaitclose(fd); // forced to disconnect because of the hack
  7352. }
  7353. else
  7354. session[fd]->eof = 1; //Disconnect them too, bad packets can cause problems down the road. [Skotlex]
  7355. return;
  7356. }
  7357. if ((is_atcommand(fd, sd, message, 0) != AtCommand_None) ||
  7358. (is_charcommand(fd, sd, message,0) != CharCommand_None))
  7359. return;
  7360. if (sd->sc.count &&
  7361. (sd->sc.data[SC_BERSERK].timer != -1 || sd->sc.data[SC_NOCHAT].timer != -1 ))
  7362. return;
  7363. if (RFIFOW(fd,2)+4 < 128)
  7364. buf = buf2; //Use a static buffer.
  7365. else
  7366. buf = (unsigned char*)aCallocA(RFIFOW(fd,2) + 4, sizeof(char));
  7367. // send message to others
  7368. WBUFW(buf,0) = 0x8d;
  7369. WBUFW(buf,2) = RFIFOW(fd,2) + 4; // len of message - 4 + 8
  7370. WBUFL(buf,4) = sd->bl.id;
  7371. memcpy(WBUFP(buf,8), message, RFIFOW(fd,2) - 4);
  7372. clif_send(buf, WBUFW(buf,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7373. if(buf != buf2) aFree(buf);
  7374. // send back message to the speaker
  7375. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7376. WFIFOW(fd,0) = 0x8e;
  7377. WFIFOSET(fd, WFIFOW(fd,2));
  7378. #ifdef PCRE_SUPPORT
  7379. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7380. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7381. #endif
  7382. // Celest
  7383. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7384. int next = pc_nextbaseexp(sd);
  7385. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7386. switch (sd->state.snovice_flag) {
  7387. case 0:
  7388. if (strstr(message, msg_txt(504)))
  7389. sd->state.snovice_flag++;
  7390. break;
  7391. case 1:
  7392. sprintf(buf2, msg_txt(505), sd->status.name);
  7393. if (strstr(message, buf2))
  7394. sd->state.snovice_flag++;
  7395. break;
  7396. case 2:
  7397. if (strstr(message, msg_txt(506)))
  7398. sd->state.snovice_flag++;
  7399. break;
  7400. case 3:
  7401. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7402. break; //Do not override the noskill mapflag. [Skotlex]
  7403. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7404. sc_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  7405. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7406. sd->state.snovice_flag = 0;
  7407. break;
  7408. }
  7409. }
  7410. }
  7411. return;
  7412. }
  7413. int clif_message(struct block_list *bl, char* msg)
  7414. {
  7415. unsigned short msg_len = strlen(msg) + 1;
  7416. unsigned char buf[256];
  7417. nullpo_retr(0, bl);
  7418. WBUFW(buf, 0) = 0x8d;
  7419. WBUFW(buf, 2) = msg_len + 8;
  7420. WBUFL(buf, 4) = bl->id;
  7421. memcpy(WBUFP(buf, 8), msg, msg_len);
  7422. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7423. return 0;
  7424. }
  7425. /*==========================================
  7426. *
  7427. *------------------------------------------
  7428. */
  7429. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7430. // /m /mapmove (as @rura GM command)
  7431. char output[30]; // 17+4+4=26, 30 max.
  7432. char map_name[MAP_NAME_LENGTH]; //Err... map names are 15+'\0' in size, not 16+'\0' [Skotlex]
  7433. RFIFOHEAD(fd);
  7434. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7435. (pc_isGM(sd) >= get_atcommand_level(AtCommand_MapMove))) {
  7436. memcpy(map_name, RFIFOP(fd,2), MAP_NAME_LENGTH-1);
  7437. map_name[MAP_NAME_LENGTH-1]='\0';
  7438. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7439. atcommand_rura(fd, sd, "@rura", output);
  7440. }
  7441. return;
  7442. }
  7443. /*==========================================
  7444. *
  7445. *------------------------------------------
  7446. */
  7447. void clif_changed_dir(struct block_list *bl) {
  7448. unsigned char buf[64];
  7449. WBUFW(buf,0) = 0x9c;
  7450. WBUFL(buf,2) = bl->id;
  7451. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7452. WBUFB(buf,8) = unit_getdir(bl);
  7453. clif_send(buf, packet_len_table[0x9c], bl, AREA_WOS);
  7454. if (disguised(bl)) {
  7455. WBUFL(buf,2) = -bl->id;
  7456. WBUFW(buf,6) = 0;
  7457. clif_send(buf, packet_len_table[0x9c], bl, SELF);
  7458. }
  7459. return;
  7460. }
  7461. /*==========================================
  7462. *
  7463. *------------------------------------------
  7464. */
  7465. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7466. unsigned char headdir, dir;
  7467. RFIFOHEAD(fd);
  7468. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7469. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7470. pc_setdir(sd, dir, headdir);
  7471. clif_changed_dir(&sd->bl);
  7472. return;
  7473. }
  7474. /*==========================================
  7475. *
  7476. *------------------------------------------
  7477. */
  7478. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7479. unsigned char buf[64];
  7480. RFIFOHEAD(fd);
  7481. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7482. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7483. clif_skill_fail(sd, 1, 0, 1);
  7484. return;
  7485. }
  7486. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7487. if (sd->emotionlasttime >= time(NULL)) {
  7488. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7489. clif_skill_fail(sd, 1, 0, 1);
  7490. return;
  7491. }
  7492. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7493. WBUFW(buf,0) = 0xc0;
  7494. WBUFL(buf,2) = sd->bl.id;
  7495. WBUFB(buf,6) = RFIFOB(fd,2);
  7496. clif_send(buf, packet_len_table[0xc0], &sd->bl, AREA);
  7497. } else
  7498. clif_skill_fail(sd, 1, 0, 1);
  7499. }
  7500. /*==========================================
  7501. *
  7502. *------------------------------------------
  7503. */
  7504. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7505. WFIFOHEAD(fd,packet_len_table[0xc2]);
  7506. WFIFOW(fd,0) = 0xc2;
  7507. WFIFOL(fd,2) = map_getusers();
  7508. WFIFOSET(fd,packet_len_table[0xc2]);
  7509. }
  7510. /*==========================================
  7511. *
  7512. *------------------------------------------
  7513. */
  7514. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  7515. unsigned int tick;
  7516. unsigned char buf[64];
  7517. int action_type, target_id;
  7518. RFIFOHEAD(fd);
  7519. if (pc_isdead(sd)) {
  7520. clif_clearchar_area(&sd->bl, 1);
  7521. return;
  7522. }
  7523. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7524. return;
  7525. if (sd->sc.count &&
  7526. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7527. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7528. sd->sc.data[SC_BLADESTOP].timer != -1))
  7529. return;
  7530. tick = gettick();
  7531. pc_stop_walking(sd, 1);
  7532. pc_stop_attack(sd);
  7533. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7534. action_type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7535. //Regardless of what they have to do, they have just requested an action, no longer idle. [Skotlex]
  7536. sd->idletime = last_tick;
  7537. if(target_id<0) // for disguises [Valaris]
  7538. target_id-=(target_id*2);
  7539. switch(action_type) {
  7540. case 0x00: // once attack
  7541. case 0x07: // continuous attack
  7542. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  7543. return;
  7544. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7545. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7546. clif_skill_fail(sd, 1, 4, 0);
  7547. return;
  7548. }
  7549. }
  7550. if (sd->invincible_timer != -1)
  7551. pc_delinvincibletimer(sd);
  7552. unit_attack(&sd->bl, target_id, action_type != 0);
  7553. break;
  7554. case 0x02: // sitdown
  7555. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 3) {
  7556. if (sd->ud.skilltimer != -1) //No sitting while casting :P
  7557. break;
  7558. if (sd->sc.count && (
  7559. sd->sc.data[SC_DANCING].timer != -1 ||
  7560. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7561. )) //No sitting during these states neither.
  7562. break;
  7563. pc_setsit(sd);
  7564. skill_gangsterparadise(sd, 1); // ギャングスターパラダイス設定 fixed Valaris
  7565. skill_rest(sd, 1); // TK_HPTIME sitting down mode [Dralnu]
  7566. clif_sitting(sd);
  7567. } else
  7568. clif_skill_fail(sd, 1, 0, 2);
  7569. break;
  7570. case 0x03: // standup
  7571. pc_setstand(sd);
  7572. skill_gangsterparadise(sd, 0); // ギャングスターパラダイス解除 fixed Valaris
  7573. skill_rest(sd, 0); // TK_HPTIME standing up mode [Dralnu]
  7574. WBUFW(buf, 0) = 0x8a;
  7575. WBUFL(buf, 2) = sd->bl.id;
  7576. WBUFB(buf,26) = 3;
  7577. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  7578. break;
  7579. }
  7580. }
  7581. /*==========================================
  7582. *
  7583. *------------------------------------------
  7584. */
  7585. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  7586. RFIFOHEAD(fd);
  7587. switch(RFIFOB(fd,2)) {
  7588. case 0x00:
  7589. if (pc_isdead(sd)) {
  7590. pc_setstand(sd);
  7591. pc_setrestartvalue(sd, 3);
  7592. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  7593. }
  7594. // in case the player's status somehow wasn't updated yet [Celest]
  7595. else if (sd->status.hp <= 0)
  7596. pc_setdead(sd);
  7597. break;
  7598. case 0x01:
  7599. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7600. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7601. {
  7602. //map_quit(sd); //A clif_quitsave is sent inmediately after this, so no need to quit yet. [Skotlex]
  7603. chrif_charselectreq(sd);
  7604. } else {
  7605. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7606. WFIFOW(fd,0)=0x18b;
  7607. WFIFOW(fd,2)=1;
  7608. WFIFOSET(fd,packet_len_table[0x018b]);
  7609. }
  7610. break;
  7611. }
  7612. }
  7613. /*==========================================
  7614. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7615. *------------------------------------------
  7616. */
  7617. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  7618. char *gm_command;
  7619. struct map_session_data *dstsd;
  7620. int i=0;
  7621. struct npc_data *npc;
  7622. char split_data[10][50];
  7623. int j=0,k=0;
  7624. char *whisper_tmp;
  7625. char output[256];
  7626. RFIFOHEAD(fd);
  7627. //printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28));
  7628. gm_command = (char*)aCallocA(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)
  7629. sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28));
  7630. if ((is_charcommand(fd, sd, gm_command, 0) != CharCommand_None) ||
  7631. (is_atcommand(fd, sd, gm_command, 0) != AtCommand_None)) {
  7632. if(gm_command) aFree(gm_command);
  7633. return;
  7634. }
  7635. if(gm_command) aFree(gm_command);
  7636. if (sd->sc.count &&
  7637. (sd->sc.data[SC_BERSERK].timer!=-1 || sd->sc.data[SC_NOCHAT].timer != -1))
  7638. return;
  7639. //Chat Logging type 'W' / Whisper
  7640. if(log_config.chat&1 //we log everything then
  7641. || ( log_config.chat&2 //if Whisper bit is on
  7642. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  7643. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, (char*)RFIFOP(fd, 4), (char*)RFIFOP(fd, 28));
  7644. //-------------------------------------------------------//
  7645. // Lordalfa - Paperboy - To whisper NPC commands //
  7646. //-------------------------------------------------------//
  7647. whisper_tmp = (char*) RFIFOP(fd,4);
  7648. if (whisper_tmp[0] && (strncasecmp(whisper_tmp,"NPC:",4) == 0) && (strlen(whisper_tmp) >4)) {
  7649. whisper_tmp += 4; //Skip the NPC: string part.
  7650. if ((npc = npc_name2id(whisper_tmp)))
  7651. {
  7652. whisper_tmp=(char *)aCallocA(strlen((char *)(RFIFOP(fd,28)))+1,sizeof(char));
  7653. whisper_tmp[0]=0;
  7654. sprintf(whisper_tmp, "%s", (const char*)RFIFOP(fd,28));
  7655. for( j=0;whisper_tmp[j]!='\0';j++)
  7656. {
  7657. if(whisper_tmp[j]!='#')
  7658. {
  7659. split_data[i][j-k]=whisper_tmp[j];
  7660. }
  7661. else
  7662. {
  7663. split_data[i][j-k]='\0';
  7664. k=j+1;
  7665. i++;
  7666. }
  7667. } // Splits the message using '#' as separators
  7668. split_data[i][j-k]='\0';
  7669. aFree(whisper_tmp);
  7670. whisper_tmp=(char *)aCallocA(15,sizeof(char));
  7671. whisper_tmp[0]=0;
  7672. for (j=0;j<=10;j++)
  7673. {
  7674. sprintf(whisper_tmp, "@whispervar%d$", j);
  7675. set_var(sd,whisper_tmp,(char *) split_data[j]);
  7676. }//You don't need to zero them, just reset them [Kevin]
  7677. aFree(whisper_tmp);
  7678. whisper_tmp=(char *)aCallocA(strlen(npc->name)+18,sizeof(char));
  7679. whisper_tmp[0]=0;
  7680. sprintf(whisper_tmp, "%s::OnWhisperGlobal", npc->name);
  7681. npc_event(sd,whisper_tmp,0); // Calls the NPC label
  7682. aFree(whisper_tmp); //I rewrote it a little to use memory allocation, a bit more stable =P [Kevin]
  7683. return;
  7684. } //should have just removed the one below that was a my bad =P
  7685. }
  7686. // Main chat [LuzZza]
  7687. if(strcmpi((const char*)RFIFOP(fd,4), main_chat_nick) == 0) {
  7688. if(!sd->state.mainchat) {
  7689. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7690. return;
  7691. }
  7692. if (sd->sc.data[SC_NOCHAT].timer != -1) {
  7693. clif_displaymessage(fd, msg_txt(387));
  7694. return;
  7695. }
  7696. sprintf(output, msg_txt(386), sd->status.name, (char *)RFIFOP(fd,28));
  7697. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7698. return;
  7699. }
  7700. // searching destination character
  7701. dstsd = map_nick2sd((char*)RFIFOP(fd,4));
  7702. // player is not on this map-server
  7703. if (dstsd == NULL ||
  7704. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7705. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7706. // and if we ask for 'Test', we must not contact 'test' player
  7707. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7708. strcmp(dstsd->status.name, (const char*)RFIFOP(fd,4)) != 0) // not exactly same name
  7709. // send message to inter-server
  7710. intif_wis_message(sd, (char*)RFIFOP(fd,4), (char*)RFIFOP(fd,28), RFIFOW(fd,2)-28);
  7711. // player is on this map-server
  7712. else {
  7713. // if you send to your self, don't send anything to others
  7714. if (dstsd->fd == fd) // but, normaly, it's impossible!
  7715. clif_wis_message(fd, wisp_server_name, "You can not page yourself. Sorry.", strlen("You can not page yourself. Sorry.") + 1);
  7716. // otherwise, send message and answer immediatly
  7717. else {
  7718. if (dstsd->ignoreAll == 1) {
  7719. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7720. clif_wis_end(fd, 1); // 1: target character is not loged in
  7721. else
  7722. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7723. } else {
  7724. // if player ignore the source character
  7725. for(i = 0; i < MAX_IGNORE_LIST; i++)
  7726. if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0) {
  7727. clif_wis_end(fd, 2); // 2: ignored by target
  7728. break;
  7729. }
  7730. // if source player not found in ignore list
  7731. if (i == MAX_IGNORE_LIST) {
  7732. if(strlen(dstsd->away_message) > 0) { // Send away automessage [LuzZza]
  7733. //(Automessage has been sent)
  7734. sprintf(output, "%s %s", (char*)RFIFOP(fd,28),msg_txt(543));
  7735. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7736. clif_wis_end(fd, 0); // 0: success to send wisper
  7737. if(dstsd->state.autotrade)
  7738. //"Away [AT] - \"%s\""
  7739. sprintf(output, msg_txt(544), dstsd->away_message);
  7740. else
  7741. //"Away - \"%s\""
  7742. sprintf(output, msg_txt(545), dstsd->away_message);
  7743. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7744. } else { // Normal message
  7745. clif_wis_message(dstsd->fd, sd->status.name, (char*)RFIFOP(fd,28), RFIFOW(fd,2) - 28);
  7746. clif_wis_end(fd, 0); // 0: success to send wisper
  7747. }
  7748. }
  7749. }
  7750. }
  7751. }
  7752. return;
  7753. }
  7754. /*==========================================
  7755. *
  7756. *------------------------------------------
  7757. */
  7758. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  7759. // /b
  7760. RFIFOHEAD(fd);
  7761. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7762. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast)))
  7763. intif_GMmessage((char*)RFIFOP(fd,4), RFIFOW(fd,2)-4, 0);
  7764. }
  7765. /*==========================================
  7766. *
  7767. *------------------------------------------
  7768. */
  7769. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  7770. struct flooritem_data *fitem;
  7771. int map_object_id;
  7772. RFIFOHEAD(fd);
  7773. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7774. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7775. if (pc_isdead(sd)) {
  7776. clif_clearchar_area(&sd->bl, 1);
  7777. return;
  7778. }
  7779. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7780. return;
  7781. if (clif_cant_act(sd))
  7782. return;
  7783. if(pc_iscloaking(sd) || pc_ischasewalk(sd)) //Disable cloaking/chasewalking characters from looting [Skotlex]
  7784. return;
  7785. if(sd->sc.count && (
  7786. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  7787. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  7788. sd->sc.data[SC_NOCHAT].timer!=-1 ) //会話禁止
  7789. ) {
  7790. clif_additem(sd,0,0,6); // send fail packet! [Valaris]
  7791. return;
  7792. }
  7793. pc_takeitem(sd, fitem);
  7794. }
  7795. /*==========================================
  7796. *
  7797. *------------------------------------------
  7798. */
  7799. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  7800. int item_index, item_amount;
  7801. RFIFOHEAD(fd);
  7802. if (pc_isdead(sd)) {
  7803. clif_clearchar_area(&sd->bl, 1);
  7804. return;
  7805. }
  7806. if (clif_cant_act(sd))
  7807. return;
  7808. if (sd->sc.count && (
  7809. sd->sc.data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
  7810. sd->sc.data[SC_BLADESTOP].timer != -1//白刃取り
  7811. ))
  7812. return;
  7813. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7814. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7815. if (!pc_dropitem(sd, item_index, item_amount))
  7816. //Because the client does not likes being ignored.
  7817. clif_delitem(sd, item_index,0);
  7818. }
  7819. /*==========================================
  7820. *
  7821. *------------------------------------------
  7822. */
  7823. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  7824. int n;
  7825. RFIFOHEAD(fd);
  7826. if (pc_isdead(sd)) {
  7827. clif_clearchar_area(&sd->bl, 1);
  7828. return;
  7829. }
  7830. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7831. return;
  7832. //This flag enables you to use items while in an NPC. [Skotlex]
  7833. if (sd->npc_id) {
  7834. if (sd->npc_id != sd->npc_item_flag)
  7835. return;
  7836. } else
  7837. if (clif_trading(sd))
  7838. return;
  7839. if (sd->sc.count && (
  7840. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  7841. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  7842. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク
  7843. sd->sc.data[SC_NOCHAT].timer!=-1 ||
  7844. sd->sc.data[SC_GRAVITATION].timer!=-1 //会話禁止
  7845. ))
  7846. return;
  7847. if (sd->invincible_timer != -1)
  7848. pc_delinvincibletimer(sd);
  7849. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7850. sd->idletime = last_tick;
  7851. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7852. if(n <0 || n >= MAX_INVENTORY)
  7853. return;
  7854. if (!pc_useitem(sd,n))
  7855. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7856. }
  7857. /*==========================================
  7858. *
  7859. *------------------------------------------
  7860. */
  7861. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7862. {
  7863. int index;
  7864. RFIFOHEAD(fd);
  7865. if(pc_isdead(sd)) {
  7866. clif_clearchar_area(&sd->bl,1);
  7867. return;
  7868. }
  7869. index = RFIFOW(fd,2)-2;
  7870. if (index < 0 || index >= MAX_INVENTORY)
  7871. return; //Out of bounds check.
  7872. if(sd->npc_id) {
  7873. if (sd->npc_id != sd->npc_item_flag)
  7874. return;
  7875. } else if (clif_cant_act(sd))
  7876. return;
  7877. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  7878. return;
  7879. if(sd->status.inventory[index].identify != 1) { // 未鑑定
  7880. clif_equipitemack(sd,index,0,0); // fail
  7881. return;
  7882. }
  7883. //ペット用装備であるかないか
  7884. if(sd->inventory_data[index]) {
  7885. if(sd->inventory_data[index]->type != 8){
  7886. if(sd->inventory_data[index]->type == 10)
  7887. RFIFOW(fd,4)=0x8000; // 矢を無理やり装備できるように(--;
  7888. pc_equipitem(sd,index,RFIFOW(fd,4));
  7889. } else
  7890. pet_equipitem(sd,index);
  7891. }
  7892. }
  7893. /*==========================================
  7894. *
  7895. *------------------------------------------
  7896. */
  7897. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7898. {
  7899. int index;
  7900. RFIFOHEAD(fd);
  7901. if(pc_isdead(sd)) {
  7902. clif_clearchar_area(&sd->bl,1);
  7903. return;
  7904. }
  7905. if (clif_cant_act(sd))
  7906. return;
  7907. index = RFIFOW(fd,2)-2;
  7908. pc_unequipitem(sd,index,1);
  7909. }
  7910. /*==========================================
  7911. *
  7912. *------------------------------------------
  7913. */
  7914. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7915. {
  7916. RFIFOHEAD(fd);
  7917. if(pc_isdead(sd)) {
  7918. clif_clearchar_area(&sd->bl,1);
  7919. return;
  7920. }
  7921. if (clif_cant_act(sd))
  7922. return;
  7923. //Clicked on a negative ID? Player disguised as NPC! [Skotlex]
  7924. if (RFIFOL(fd,2) < 0)
  7925. return;
  7926. npc_click(sd,RFIFOL(fd,2));
  7927. }
  7928. /*==========================================
  7929. *
  7930. *------------------------------------------
  7931. */
  7932. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7933. {
  7934. RFIFOHEAD(fd);
  7935. if (sd->trade_partner != 0)
  7936. return;
  7937. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7938. }
  7939. /*==========================================
  7940. *
  7941. *------------------------------------------
  7942. */
  7943. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  7944. {
  7945. int fail=0,n, i;
  7946. unsigned short *item_list;
  7947. unsigned char npc_ev[51];
  7948. struct npc_data *nd;
  7949. RFIFOHEAD(fd);
  7950. n = (RFIFOW(fd,2)-4) /4;
  7951. item_list = (unsigned short*)RFIFOP(fd,4);
  7952. if (sd->trade_partner || !sd->npc_shopid){
  7953. fail = 1;
  7954. }else{
  7955. if((nd = ((struct npc_data *)map_id2bl(sd->npc_shopid))->master_nd)){
  7956. sprintf(npc_ev, "%s::OnBuyItem", nd->exname);
  7957. for(i=0;i<n;i++){
  7958. setd_sub(sd, "@bought_nameid", i, (void *)((int)item_list[i*2+1]));
  7959. setd_sub(sd, "@bought_quantity", i, (void *)((int)item_list[i*2]));
  7960. }
  7961. npc_event(sd, npc_ev, 0);
  7962. fail = 0;
  7963. }else{
  7964. fail = npc_buylist(sd,n,item_list);
  7965. }
  7966. }
  7967. sd->npc_shopid = 0; //Clear shop data.
  7968. WFIFOHEAD(fd,packet_len_table[0xca]);
  7969. WFIFOW(fd,0)=0xca;
  7970. WFIFOB(fd,2)=fail;
  7971. WFIFOSET(fd,packet_len_table[0xca]);
  7972. }
  7973. /*==========================================
  7974. *
  7975. *------------------------------------------
  7976. */
  7977. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7978. {
  7979. int fail=0,n,i;
  7980. unsigned short *item_list;
  7981. unsigned char npc_ev[51];
  7982. struct npc_data *nd;
  7983. RFIFOHEAD(fd);
  7984. n = (RFIFOW(fd,2)-4) /4;
  7985. item_list = (unsigned short*)RFIFOP(fd,4);
  7986. if (sd->trade_partner || !sd->npc_shopid){
  7987. fail = 1;
  7988. }else{
  7989. if((nd = ((struct npc_data *)map_id2bl(sd->npc_shopid))->master_nd)){
  7990. sprintf(npc_ev, "%s::OnSellItem", nd->exname);
  7991. for(i=0;i<n;i++){
  7992. setd_sub(sd, "@sold_nameid", i, (void *)((int)sd->status.inventory[item_list[i*2]-2].nameid));
  7993. setd_sub(sd, "@sold_quantity", i, (void *)((int)item_list[i*2+1]));
  7994. }
  7995. npc_event(sd, npc_ev, 0);
  7996. fail = 0;
  7997. }else{
  7998. fail = npc_selllist(sd,n,item_list);
  7999. }
  8000. }
  8001. sd->npc_shopid = 0; //Clear shop data.
  8002. WFIFOHEAD(fd,packet_len_table[0xcb]);
  8003. WFIFOW(fd,0)=0xcb;
  8004. WFIFOB(fd,2)=fail;
  8005. WFIFOSET(fd,packet_len_table[0xcb]);
  8006. }
  8007. /*==========================================
  8008. *
  8009. *------------------------------------------
  8010. */
  8011. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8012. {
  8013. RFIFOHEAD(fd);
  8014. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8015. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8016. } else
  8017. clif_skill_fail(sd,1,0,3);
  8018. }
  8019. /*==========================================
  8020. *
  8021. *------------------------------------------
  8022. */
  8023. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8024. {
  8025. RFIFOHEAD(fd);
  8026. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8027. }
  8028. /*==========================================
  8029. *
  8030. *------------------------------------------
  8031. */
  8032. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8033. {
  8034. RFIFOHEAD(fd);
  8035. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8036. }
  8037. /*==========================================
  8038. *
  8039. *------------------------------------------
  8040. */
  8041. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8042. {
  8043. RFIFOHEAD(fd);
  8044. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8045. }
  8046. /*==========================================
  8047. *
  8048. *------------------------------------------
  8049. */
  8050. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8051. {
  8052. RFIFOHEAD(fd);
  8053. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8054. }
  8055. /*==========================================
  8056. *
  8057. *------------------------------------------
  8058. */
  8059. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8060. {
  8061. chat_leavechat(sd);
  8062. }
  8063. /*==========================================
  8064. * 取引要請を相手に送る
  8065. *------------------------------------------
  8066. */
  8067. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8068. {
  8069. RFIFOHEAD(fd);
  8070. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8071. trade_traderequest(sd,RFIFOL(sd->fd,2));
  8072. } else
  8073. clif_skill_fail(sd,1,0,0);
  8074. }
  8075. /*==========================================
  8076. * 取引要請
  8077. *------------------------------------------
  8078. */
  8079. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8080. {
  8081. RFIFOHEAD(fd);
  8082. trade_tradeack(sd,RFIFOB(sd->fd,2));
  8083. }
  8084. /*==========================================
  8085. * アイテム追加
  8086. *------------------------------------------
  8087. */
  8088. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8089. {
  8090. RFIFOHEAD(fd);
  8091. trade_tradeadditem(sd,RFIFOW(sd->fd,2),RFIFOL(sd->fd,4));
  8092. }
  8093. /*==========================================
  8094. * アイテム追加完了(ok押し)
  8095. *------------------------------------------
  8096. */
  8097. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8098. {
  8099. trade_tradeok(sd);
  8100. }
  8101. /*==========================================
  8102. * 取引キャンセル
  8103. *------------------------------------------
  8104. */
  8105. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8106. {
  8107. trade_tradecancel(sd);
  8108. }
  8109. /*==========================================
  8110. * 取引許諾(trade押し)
  8111. *------------------------------------------
  8112. */
  8113. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8114. {
  8115. trade_tradecommit(sd);
  8116. }
  8117. /*==========================================
  8118. *
  8119. *------------------------------------------
  8120. */
  8121. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8122. {
  8123. pc_stop_attack(sd);
  8124. }
  8125. /*==========================================
  8126. * カートへアイテムを移す
  8127. *------------------------------------------
  8128. */
  8129. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8130. {
  8131. RFIFOHEAD(fd);
  8132. if (clif_trading(sd))
  8133. return;
  8134. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8135. }
  8136. /*==========================================
  8137. * カートからアイテムを出す
  8138. *------------------------------------------
  8139. */
  8140. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8141. {
  8142. RFIFOHEAD(fd);
  8143. if (clif_trading(sd))
  8144. return;
  8145. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8146. }
  8147. /*==========================================
  8148. * 付属品(鷹,ペコ,カート)をはずす
  8149. *------------------------------------------
  8150. */
  8151. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8152. {
  8153. pc_setoption(sd,0);
  8154. }
  8155. /*==========================================
  8156. * チェンジカート
  8157. *------------------------------------------
  8158. */
  8159. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8160. {
  8161. RFIFOHEAD(fd);
  8162. pc_setcart(sd,RFIFOW(fd,2));
  8163. }
  8164. /*==========================================
  8165. * ステータスアップ
  8166. *------------------------------------------
  8167. */
  8168. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8169. {
  8170. RFIFOHEAD(fd);
  8171. pc_statusup(sd,RFIFOW(fd,2));
  8172. }
  8173. /*==========================================
  8174. * スキルレベルアップ
  8175. *------------------------------------------
  8176. */
  8177. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8178. {
  8179. RFIFOHEAD(fd);
  8180. pc_skillup(sd,RFIFOW(fd,2));
  8181. }
  8182. /*==========================================
  8183. * スキル使用(ID指定)
  8184. *------------------------------------------
  8185. */
  8186. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8187. int skillnum, skilllv, lv, target_id;
  8188. unsigned int tick = gettick();
  8189. RFIFOHEAD(fd);
  8190. if (clif_cant_act(sd))
  8191. return;
  8192. if (pc_issit(sd))
  8193. return;
  8194. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8195. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8196. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8197. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8198. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8199. sd->idletime = last_tick;
  8200. if (skillnotok(skillnum, sd))
  8201. return;
  8202. if (sd->bl.id != target_id &&
  8203. !sd->state.skill_flag &&
  8204. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8205. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8206. if (sd->ud.skilltimer != -1) {
  8207. if (skillnum != SA_CASTCANCEL)
  8208. return;
  8209. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0 &&
  8210. // allow monk combos to ignore this delay [celest]
  8211. !(sd->sc.count && sd->sc.data[SC_COMBO].timer!=-1 &&
  8212. (skillnum == MO_EXTREMITYFIST ||
  8213. skillnum == MO_CHAINCOMBO ||
  8214. skillnum == MO_COMBOFINISH ||
  8215. skillnum == CH_PALMSTRIKE ||
  8216. skillnum == CH_TIGERFIST ||
  8217. skillnum == CH_CHAINCRUSH))) {
  8218. clif_skill_fail(sd, skillnum, 4, 0);
  8219. return;
  8220. }
  8221. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8222. return;
  8223. if (sd->invincible_timer != -1)
  8224. pc_delinvincibletimer(sd);
  8225. if(target_id<0) // for disguises [Valaris]
  8226. target_id*=-1;
  8227. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8228. if (skilllv != sd->skillitemlv)
  8229. skilllv = sd->skillitemlv;
  8230. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8231. } else {
  8232. sd->skillitem = sd->skillitemlv = -1;
  8233. if (skillnum == MO_EXTREMITYFIST) {
  8234. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8235. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8236. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8237. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8238. if (!sd->state.skill_flag ) {
  8239. sd->state.skill_flag = 1;
  8240. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8241. return;
  8242. } else if (sd->bl.id == target_id) {
  8243. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8244. return;
  8245. }
  8246. }
  8247. }
  8248. if (skillnum == TK_JUMPKICK) {
  8249. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8250. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8251. if (!sd->state.skill_flag ) {
  8252. sd->state.skill_flag = 1;
  8253. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8254. return;
  8255. } else if (sd->bl.id == target_id) {
  8256. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8257. return;
  8258. }
  8259. }
  8260. }
  8261. if (skillnum >= GD_SKILLBASE && sd->state.gmaster_flag)
  8262. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8263. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8264. if (skilllv > lv)
  8265. skilllv = lv;
  8266. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8267. if (sd->state.skill_flag)
  8268. sd->state.skill_flag = 0;
  8269. }
  8270. }
  8271. }
  8272. /*==========================================
  8273. * スキル使用(場所指定)
  8274. *------------------------------------------
  8275. */
  8276. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8277. {
  8278. int lv;
  8279. unsigned int tick = gettick();
  8280. RFIFOHEAD(fd);
  8281. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8282. sd->idletime = last_tick;
  8283. if (skillnotok(skillnum, sd))
  8284. return;
  8285. if (skillmoreinfo != -1) {
  8286. if (pc_issit(sd)) {
  8287. clif_skill_fail(sd, skillnum, 0, 0);
  8288. return;
  8289. }
  8290. memcpy(talkie_mes, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8291. talkie_mes[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8292. }
  8293. if (sd->ud.skilltimer != -1)
  8294. return;
  8295. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8296. {
  8297. clif_skill_fail(sd, skillnum, 4, 0);
  8298. return;
  8299. }
  8300. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8301. return;
  8302. if (sd->invincible_timer != -1)
  8303. pc_delinvincibletimer(sd);
  8304. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8305. if (skilllv != sd->skillitemlv)
  8306. skilllv = sd->skillitemlv;
  8307. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8308. } else {
  8309. sd->skillitem = sd->skillitemlv = -1;
  8310. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8311. if (skilllv > lv)
  8312. skilllv = lv;
  8313. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8314. }
  8315. }
  8316. }
  8317. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8318. RFIFOHEAD(fd);
  8319. if (clif_cant_act(sd))
  8320. return;
  8321. if (pc_issit(sd))
  8322. return;
  8323. clif_parse_UseSkillToPosSub(fd, sd,
  8324. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8325. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8326. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8327. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8328. -1 //Skill more info.
  8329. );
  8330. }
  8331. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8332. RFIFOHEAD(fd);
  8333. if (clif_cant_act(sd))
  8334. return;
  8335. if (pc_issit(sd))
  8336. return;
  8337. clif_parse_UseSkillToPosSub(fd, sd,
  8338. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8339. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8340. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8341. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8342. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8343. );
  8344. }
  8345. /*==========================================
  8346. * スキル使用(map指定)
  8347. *------------------------------------------
  8348. */
  8349. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8350. {
  8351. RFIFOHEAD(fd);
  8352. if (clif_cant_act(sd))
  8353. return;
  8354. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8355. return;
  8356. if(sd->invincible_timer != -1)
  8357. pc_delinvincibletimer(sd);
  8358. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8359. }
  8360. /*==========================================
  8361. * メモ要求
  8362. *------------------------------------------
  8363. */
  8364. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8365. {
  8366. if (!pc_isdead(sd))
  8367. pc_memo(sd,-1);
  8368. }
  8369. /*==========================================
  8370. * アイテム合成
  8371. *------------------------------------------
  8372. */
  8373. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8374. {
  8375. RFIFOHEAD(fd);
  8376. if (sd->menuskill_id != AM_PHARMACY)
  8377. return;
  8378. if (clif_trading(sd)) {
  8379. //Make it fail to avoid shop exploits where you sell something different than you see.
  8380. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8381. sd->menuskill_lv = sd->menuskill_id = 0;
  8382. return;
  8383. }
  8384. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8385. sd->menuskill_lv = sd->menuskill_id = 0;
  8386. }
  8387. /*==========================================
  8388. * 武器修理
  8389. *------------------------------------------
  8390. */
  8391. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8392. {
  8393. RFIFOHEAD(fd);
  8394. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8395. return;
  8396. if (clif_trading(sd)) {
  8397. //Make it fail to avoid shop exploits where you sell something different than you see.
  8398. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8399. sd->menuskill_lv = sd->menuskill_id = 0;
  8400. return;
  8401. }
  8402. skill_repairweapon(sd,RFIFOW(fd,2));
  8403. sd->menuskill_lv = sd->menuskill_id = 0;
  8404. }
  8405. /*==========================================
  8406. *
  8407. *------------------------------------------
  8408. */
  8409. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8410. int idx;
  8411. RFIFOHEAD(fd);
  8412. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8413. return;
  8414. if (clif_trading(sd)) {
  8415. //Make it fail to avoid shop exploits where you sell something different than you see.
  8416. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8417. sd->menuskill_lv = sd->menuskill_id = 0;
  8418. return;
  8419. }
  8420. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8421. skill_weaponrefine(sd, idx-2);
  8422. sd->menuskill_lv = sd->menuskill_id = 0;
  8423. }
  8424. /*==========================================
  8425. *
  8426. *------------------------------------------
  8427. */
  8428. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8429. {
  8430. RFIFOHEAD(fd);
  8431. sd->npc_menu=RFIFOB(fd,6);
  8432. npc_scriptcont(sd,RFIFOL(fd,2));
  8433. }
  8434. /*==========================================
  8435. *
  8436. *------------------------------------------
  8437. */
  8438. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8439. {
  8440. RFIFOHEAD(fd);
  8441. #ifdef __WIN32
  8442. //For some extraordinarily eerie reason that noone has figured out yet,
  8443. //windows native compiles NEED this nullpo_retv or the function is not found!
  8444. nullpo_retv(sd);
  8445. #endif
  8446. npc_scriptcont(sd,RFIFOL(fd,2));
  8447. }
  8448. /*==========================================
  8449. *
  8450. *------------------------------------------
  8451. */
  8452. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8453. {
  8454. RFIFOHEAD(fd);
  8455. #define RFIFOL_(fd,pos) (*(int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos)))
  8456. //Input Value overflow Exploit FIX
  8457. sd->npc_amount=RFIFOL_(fd,6); //fixed by Lupus. npc_amount is (int) but was RFIFOL changing it to (unsigned int)
  8458. #undef RFIFOL_
  8459. npc_scriptcont(sd,RFIFOL(fd,2));
  8460. }
  8461. /*==========================================
  8462. *
  8463. *------------------------------------------
  8464. */
  8465. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8466. {
  8467. RFIFOHEAD(fd);
  8468. if(RFIFOW(fd,2)-7 >= sizeof(sd->npc_str)){
  8469. ShowWarning("clif: input string too long !\n");
  8470. memcpy(sd->npc_str,RFIFOP(fd,8),sizeof(sd->npc_str));
  8471. sd->npc_str[sizeof(sd->npc_str)-1]=0;
  8472. } else
  8473. strcpy(sd->npc_str,(char*)RFIFOP(fd,8));
  8474. npc_scriptcont(sd,RFIFOL(fd,4));
  8475. }
  8476. /*==========================================
  8477. *
  8478. *------------------------------------------
  8479. */
  8480. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8481. {
  8482. RFIFOHEAD(fd);
  8483. if (sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8484. npc_scriptcont(sd,RFIFOL(fd,2));
  8485. }
  8486. /*==========================================
  8487. * アイテム鑑定
  8488. *------------------------------------------
  8489. */
  8490. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8491. {
  8492. RFIFOHEAD(fd);
  8493. if (sd->menuskill_id != MC_IDENTIFY)
  8494. return;
  8495. skill_identify(sd,RFIFOW(fd,2)-2);
  8496. sd->menuskill_lv = sd->menuskill_id = 0;
  8497. }
  8498. /*==========================================
  8499. * 矢作成
  8500. *------------------------------------------
  8501. */
  8502. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8503. {
  8504. RFIFOHEAD(fd);
  8505. if (sd->menuskill_id != AC_MAKINGARROW)
  8506. return;
  8507. if (clif_trading(sd)) {
  8508. //Make it fail to avoid shop exploits where you sell something different than you see.
  8509. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8510. sd->menuskill_lv = sd->menuskill_id = 0;
  8511. return;
  8512. }
  8513. skill_arrow_create(sd,RFIFOW(fd,2));
  8514. sd->menuskill_lv = sd->menuskill_id = 0;
  8515. }
  8516. /*==========================================
  8517. * オートスペル受信
  8518. *------------------------------------------
  8519. */
  8520. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8521. {
  8522. RFIFOHEAD(fd);
  8523. if (sd->menuskill_id != SA_AUTOSPELL)
  8524. return;
  8525. skill_autospell(sd,RFIFOW(fd,2));
  8526. sd->menuskill_lv = sd->menuskill_id = 0;
  8527. }
  8528. /*==========================================
  8529. * カード使用
  8530. *------------------------------------------
  8531. */
  8532. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8533. {
  8534. RFIFOHEAD(fd);
  8535. if (sd->trade_partner != 0)
  8536. return;
  8537. clif_use_card(sd,RFIFOW(fd,2)-2);
  8538. }
  8539. /*==========================================
  8540. * カード挿入装備選択
  8541. *------------------------------------------
  8542. */
  8543. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8544. {
  8545. RFIFOHEAD(fd);
  8546. if (sd->trade_partner != 0)
  8547. return;
  8548. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8549. }
  8550. /*==========================================
  8551. * 0193 キャラID名前引き
  8552. *------------------------------------------
  8553. */
  8554. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8555. int char_id;
  8556. RFIFOHEAD(fd);
  8557. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8558. clif_solved_charname(sd, char_id);
  8559. }
  8560. /*==========================================
  8561. * 0197 /resetskill /resetstate
  8562. *------------------------------------------
  8563. */
  8564. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8565. RFIFOHEAD(fd);
  8566. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8567. pc_isGM(sd) >= get_atcommand_level(AtCommand_ResetState)) {
  8568. switch(RFIFOW(fd,2)){
  8569. case 0:
  8570. pc_resetstate(sd);
  8571. break;
  8572. case 1:
  8573. pc_resetskill(sd,1);
  8574. break;
  8575. }
  8576. }
  8577. }
  8578. /*==========================================
  8579. * 019c /lb等
  8580. *------------------------------------------
  8581. */
  8582. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  8583. unsigned char buf[512];
  8584. RFIFOHEAD(fd);
  8585. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8586. (pc_isGM(sd) >= get_atcommand_level(AtCommand_LocalBroadcast))) {
  8587. WBUFW(buf,0) = 0x9a;
  8588. WBUFW(buf,2) = RFIFOW(fd,2);
  8589. memcpy(WBUFP(buf,4), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  8590. clif_send(buf, RFIFOW(fd,2), &sd->bl, ALL_SAMEMAP);
  8591. }
  8592. }
  8593. /*==========================================
  8594. * カプラ倉庫へ入れる
  8595. *------------------------------------------
  8596. */
  8597. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  8598. int item_index, item_amount;
  8599. RFIFOHEAD(fd);
  8600. if (clif_trading(sd))
  8601. return;
  8602. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8603. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8604. if (item_index < 0 || item_index >= MAX_INVENTORY)
  8605. return;
  8606. if (sd->state.storage_flag == 1)
  8607. storage_storageadd(sd, item_index, item_amount);
  8608. else if (sd->state.storage_flag == 2)
  8609. storage_guild_storageadd(sd, item_index, item_amount);
  8610. }
  8611. /*==========================================
  8612. * カプラ倉庫から出す
  8613. *------------------------------------------
  8614. */
  8615. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  8616. int item_index, item_amount;
  8617. RFIFOHEAD(fd);
  8618. if (clif_trading(sd))
  8619. return;
  8620. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8621. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8622. if (sd->state.storage_flag == 1)
  8623. storage_storageget(sd, item_index, item_amount);
  8624. else if(sd->state.storage_flag == 2)
  8625. storage_guild_storageget(sd, item_index, item_amount);
  8626. }
  8627. /*==========================================
  8628. * カプラ倉庫へカートから入れる
  8629. *------------------------------------------
  8630. */
  8631. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  8632. RFIFOHEAD(fd);
  8633. if (clif_trading(sd))
  8634. return;
  8635. if (sd->state.storage_flag == 1)
  8636. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8637. else if (sd->state.storage_flag == 2)
  8638. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8639. }
  8640. /*==========================================
  8641. * カプラ倉庫から出す
  8642. *------------------------------------------
  8643. */
  8644. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  8645. RFIFOHEAD(fd);
  8646. if (clif_trading(sd))
  8647. return;
  8648. if (sd->state.storage_flag == 1)
  8649. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8650. else if (sd->state.storage_flag == 2)
  8651. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8652. }
  8653. /*==========================================
  8654. * カプラ倉庫を閉じる
  8655. *------------------------------------------
  8656. */
  8657. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  8658. if (sd->state.storage_flag == 1)
  8659. storage_storageclose(sd);
  8660. else if (sd->state.storage_flag == 2)
  8661. storage_guild_storageclose(sd);
  8662. }
  8663. /*==========================================
  8664. * パーティを作る
  8665. *------------------------------------------
  8666. */
  8667. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  8668. RFIFOHEAD(fd);
  8669. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8670. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8671. } else
  8672. clif_skill_fail(sd,1,0,4);
  8673. }
  8674. /*==========================================
  8675. * パーティを作る
  8676. *------------------------------------------
  8677. */
  8678. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  8679. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  8680. RFIFOHEAD(fd);
  8681. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8682. } else
  8683. clif_skill_fail(sd,1,0,4);
  8684. }
  8685. /*==========================================
  8686. * パーティに勧誘
  8687. *------------------------------------------
  8688. */
  8689. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  8690. RFIFOHEAD(fd);
  8691. party_invite(sd, RFIFOL(fd,2));
  8692. }
  8693. /*==========================================
  8694. * パーティ勧誘返答
  8695. *------------------------------------------
  8696. */
  8697. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  8698. RFIFOHEAD(fd);
  8699. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8700. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8701. } else {
  8702. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8703. clif_skill_fail(sd,1,0,4);
  8704. }
  8705. }
  8706. /*==========================================
  8707. * パーティ脱退要求
  8708. *------------------------------------------
  8709. */
  8710. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  8711. party_leave(sd);
  8712. }
  8713. /*==========================================
  8714. * パーティ除名要求
  8715. *------------------------------------------
  8716. */
  8717. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  8718. RFIFOHEAD(fd);
  8719. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8720. }
  8721. /*==========================================
  8722. * パーティ設定変更要求
  8723. *------------------------------------------
  8724. */
  8725. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  8726. RFIFOHEAD(fd);
  8727. party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8728. }
  8729. /*==========================================
  8730. * パーティメッセージ送信要求
  8731. *------------------------------------------
  8732. */
  8733. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  8734. RFIFOHEAD(fd);
  8735. if (is_charcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != CharCommand_None ||
  8736. is_atcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != AtCommand_None)
  8737. return;
  8738. if (sd->sc.count && (
  8739. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  8740. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  8741. ))
  8742. return;
  8743. party_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  8744. }
  8745. /*==========================================
  8746. * 露店閉鎖
  8747. *------------------------------------------
  8748. */
  8749. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  8750. vending_closevending(sd);
  8751. }
  8752. /*==========================================
  8753. * 露店アイテムリスト要求
  8754. *------------------------------------------
  8755. */
  8756. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  8757. RFIFOHEAD(fd);
  8758. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8759. if(sd->npc_id)
  8760. npc_event_dequeue(sd);
  8761. }
  8762. /*==========================================
  8763. * 露店アイテム購入
  8764. *------------------------------------------
  8765. */
  8766. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  8767. RFIFOHEAD(fd);
  8768. if (clif_trading(sd))
  8769. return;
  8770. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  8771. }
  8772. /*==========================================
  8773. * 露店開設
  8774. *------------------------------------------
  8775. */
  8776. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  8777. RFIFOHEAD(fd);
  8778. if (clif_trading(sd))
  8779. return;
  8780. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  8781. }
  8782. /*==========================================
  8783. * ギルドを作る
  8784. *------------------------------------------
  8785. */
  8786. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  8787. RFIFOHEAD(fd);
  8788. guild_create(sd, (char*)RFIFOP(fd,6));
  8789. }
  8790. /*==========================================
  8791. * ギルドマスターかどうか確認
  8792. *------------------------------------------
  8793. */
  8794. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  8795. clif_guild_masterormember(sd);
  8796. }
  8797. /*==========================================
  8798. * ギルド情報要求
  8799. *------------------------------------------
  8800. */
  8801. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  8802. RFIFOHEAD(fd);
  8803. switch(RFIFOL(fd,2)){
  8804. case 0: // ギルド基本情報、同盟敵対情報
  8805. clif_guild_basicinfo(sd);
  8806. clif_guild_allianceinfo(sd);
  8807. break;
  8808. case 1: // メンバーリスト、役職名リスト
  8809. clif_guild_positionnamelist(sd);
  8810. clif_guild_memberlist(sd);
  8811. break;
  8812. case 2: // 役職名リスト、役職情報リスト
  8813. clif_guild_positionnamelist(sd);
  8814. clif_guild_positioninfolist(sd);
  8815. break;
  8816. case 3: // スキルリスト
  8817. clif_guild_skillinfo(sd);
  8818. break;
  8819. case 4: // 追放リスト
  8820. clif_guild_explusionlist(sd);
  8821. break;
  8822. default:
  8823. if (battle_config.error_log)
  8824. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8825. break;
  8826. }
  8827. }
  8828. /*==========================================
  8829. * ギルド役職変更
  8830. *------------------------------------------
  8831. */
  8832. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  8833. int i;
  8834. RFIFOHEAD(fd);
  8835. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8836. guild_change_position(sd, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8837. }
  8838. }
  8839. /*==========================================
  8840. * ギルドメンバ役職変更
  8841. *------------------------------------------
  8842. */
  8843. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  8844. int i;
  8845. RFIFOHEAD(fd);
  8846. for(i=4;i<RFIFOW(fd,2);i+=12){
  8847. guild_change_memberposition(sd->status.guild_id,
  8848. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8849. }
  8850. }
  8851. /*==========================================
  8852. * ギルドエンブレム要求
  8853. *------------------------------------------
  8854. */
  8855. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  8856. struct guild *g;
  8857. RFIFOHEAD(fd);
  8858. g=guild_search(RFIFOL(fd,2));
  8859. if(g!=NULL)
  8860. clif_guild_emblem(sd,g);
  8861. }
  8862. /*==========================================
  8863. * ギルドエンブレム変更
  8864. *------------------------------------------
  8865. */
  8866. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  8867. RFIFOHEAD(fd);
  8868. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8869. }
  8870. /*==========================================
  8871. * ギルド告知変更
  8872. *------------------------------------------
  8873. */
  8874. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  8875. RFIFOHEAD(fd);
  8876. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  8877. }
  8878. /*==========================================
  8879. * ギルド勧誘
  8880. *------------------------------------------
  8881. */
  8882. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  8883. RFIFOHEAD(fd);
  8884. guild_invite(sd,RFIFOL(fd,2));
  8885. }
  8886. /*==========================================
  8887. * ギルド勧誘返信
  8888. *------------------------------------------
  8889. */
  8890. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  8891. RFIFOHEAD(fd);
  8892. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8893. }
  8894. /*==========================================
  8895. * ギルド脱退
  8896. *------------------------------------------
  8897. */
  8898. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  8899. RFIFOHEAD(fd);
  8900. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8901. }
  8902. /*==========================================
  8903. * ギルド追放
  8904. *------------------------------------------
  8905. */
  8906. void clif_parse_GuildExplusion(int fd,struct map_session_data *sd) {
  8907. RFIFOHEAD(fd);
  8908. guild_explusion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8909. }
  8910. /*==========================================
  8911. * ギルド会話
  8912. *------------------------------------------
  8913. */
  8914. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  8915. RFIFOHEAD(fd);
  8916. if (is_charcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != CharCommand_None ||
  8917. is_atcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != AtCommand_None)
  8918. return;
  8919. if (sd->sc.count && (
  8920. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  8921. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  8922. ))
  8923. return;
  8924. guild_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  8925. }
  8926. /*==========================================
  8927. * ギルド同盟要求
  8928. *------------------------------------------
  8929. */
  8930. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  8931. RFIFOHEAD(fd);
  8932. guild_reqalliance(sd,RFIFOL(fd,2));
  8933. }
  8934. /*==========================================
  8935. * ギルド同盟要求返信
  8936. *------------------------------------------
  8937. */
  8938. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  8939. RFIFOHEAD(fd);
  8940. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8941. }
  8942. /*==========================================
  8943. * ギルド関係解消
  8944. *------------------------------------------
  8945. */
  8946. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  8947. RFIFOHEAD(fd);
  8948. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8949. }
  8950. /*==========================================
  8951. * ギルド敵対
  8952. *------------------------------------------
  8953. */
  8954. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  8955. RFIFOHEAD(fd);
  8956. guild_opposition(sd,RFIFOL(fd,2));
  8957. }
  8958. /*==========================================
  8959. * ギルド解散
  8960. *------------------------------------------
  8961. */
  8962. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  8963. RFIFOHEAD(fd);
  8964. guild_break(sd,(char*)RFIFOP(fd,2));
  8965. }
  8966. // pet
  8967. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  8968. RFIFOHEAD(fd);
  8969. pet_menu(sd,RFIFOB(fd,2));
  8970. }
  8971. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  8972. RFIFOHEAD(fd);
  8973. pet_catch_process2(sd,RFIFOL(fd,2));
  8974. }
  8975. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  8976. RFIFOHEAD(fd);
  8977. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  8978. return;
  8979. pet_select_egg(sd,RFIFOW(fd,2)-2);
  8980. sd->menuskill_lv = sd->menuskill_id = 0;
  8981. }
  8982. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  8983. if(sd->pd) {
  8984. RFIFOHEAD(fd);
  8985. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  8986. }
  8987. }
  8988. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  8989. RFIFOHEAD(fd);
  8990. pet_change_name(sd,(char*)RFIFOP(fd,2));
  8991. }
  8992. // Kick (right click menu for GM "(name) force to quit")
  8993. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  8994. struct block_list *target;
  8995. int tid;
  8996. RFIFOHEAD(fd);
  8997. tid = RFIFOL(fd,2);
  8998. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8999. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Kick))) {
  9000. target = map_id2bl(tid);
  9001. if (target) {
  9002. if (target->type == BL_PC) {
  9003. struct map_session_data *tsd = (struct map_session_data *)target;
  9004. if (pc_isGM(sd) > pc_isGM(tsd))
  9005. clif_GM_kick(sd, tsd, 1);
  9006. else
  9007. clif_GM_kickack(sd, 0);
  9008. } else if (target->type == BL_MOB) {
  9009. struct mob_data *md = (struct mob_data *)target;
  9010. sd->state.attack_type = 0;
  9011. mob_damage(&sd->bl, md, md->hp, 2);
  9012. } else
  9013. clif_GM_kickack(sd, 0);
  9014. } else
  9015. clif_GM_kickack(sd, 0);
  9016. }
  9017. }
  9018. /*==========================================
  9019. * /shift
  9020. *------------------------------------------
  9021. */
  9022. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9023. char player_name[NAME_LENGTH+1];
  9024. memset(player_name, '\0', sizeof(player_name));
  9025. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9026. (pc_isGM(sd) >= get_atcommand_level(AtCommand_JumpTo))) {
  9027. RFIFOHEAD(fd);
  9028. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9029. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9030. }
  9031. return;
  9032. }
  9033. /*==========================================
  9034. * /recall
  9035. *------------------------------------------
  9036. */
  9037. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9038. char player_name[25];
  9039. memset(player_name, '\0', sizeof(player_name));
  9040. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9041. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Recall))) {
  9042. RFIFOHEAD(fd);
  9043. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9044. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9045. }
  9046. return;
  9047. }
  9048. /*==========================================
  9049. * /monster /item rewriten by [Yor]
  9050. *------------------------------------------
  9051. */
  9052. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9053. char monster_item_name[NAME_LENGTH+10]; //Additional space is for logging, eg: "@monster Poring"
  9054. int level;
  9055. memset(monster_item_name, '\0', sizeof(monster_item_name));
  9056. if (battle_config.atc_gmonly == 0 || pc_isGM(sd)) {
  9057. RFIFOHEAD(fd);
  9058. memcpy(monster_item_name, RFIFOP(fd,2), NAME_LENGTH);
  9059. if (mobdb_searchname(monster_item_name) != 0) {
  9060. if (pc_isGM(sd) >= (level =get_atcommand_level(AtCommand_Monster)))
  9061. {
  9062. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9063. if(log_config.gm && level >= log_config.gm)
  9064. { //Log action. [Skotlex]
  9065. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@spawn %s", RFIFOP(fd,2));
  9066. log_atcommand(sd, monster_item_name);
  9067. }
  9068. }
  9069. } else if (itemdb_searchname(monster_item_name) != NULL) {
  9070. if (pc_isGM(sd) >= (level = get_atcommand_level(AtCommand_Item)))
  9071. {
  9072. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9073. if(log_config.gm && level >= log_config.gm)
  9074. { //Log action. [Skotlex]
  9075. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@item %s", RFIFOP(fd,2));
  9076. log_atcommand(sd, monster_item_name);
  9077. }
  9078. }
  9079. }
  9080. }
  9081. }
  9082. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9083. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9084. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) {
  9085. if (sd->sc.option & OPTION_INVISIBLE) {
  9086. sd->sc.option &= ~OPTION_INVISIBLE;
  9087. if (sd->disguise)
  9088. status_set_viewdata(&sd->bl, sd->disguise);
  9089. else
  9090. status_set_viewdata(&sd->bl, sd->status.class_);
  9091. clif_displaymessage(fd, "Invisible: Off.");
  9092. } else {
  9093. sd->sc.option |= OPTION_INVISIBLE;
  9094. //Experimental hidden mode, changes your view class to invisible [Skotlex]
  9095. sd->vd.class_ = INVISIBLE_CLASS;
  9096. clif_displaymessage(fd, "Invisible: On.");
  9097. }
  9098. clif_changeoption(&sd->bl);
  9099. }
  9100. }
  9101. /*==========================================
  9102. * GMによるチャット禁止時間付与
  9103. *------------------------------------------
  9104. */
  9105. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9106. {
  9107. int type, limit, level;
  9108. struct block_list *bl;
  9109. struct map_session_data *dstsd;
  9110. if(!battle_config.muting_players) {
  9111. clif_displaymessage(fd, "Muting is disabled.");
  9112. return;
  9113. }
  9114. RFIFOHEAD(fd);
  9115. bl = map_id2bl(RFIFOL(fd,2));
  9116. if (!bl || bl->type != BL_PC)
  9117. return;
  9118. nullpo_retv(dstsd =(struct map_session_data *)bl);
  9119. type = RFIFOB(fd,6);
  9120. limit = RFIFOW(fd,7);
  9121. if (type == 0)
  9122. limit = 0 - limit;
  9123. //Temporarily disable chars from muting themselves due to the mysterious "DON'T USE BOT!" message. [Skotlex]
  9124. //Also, if type is 2 and the ids don't match, this is a crafted hacked packet!
  9125. //So for now, type 2is just totally disabled.
  9126. if (type == 2/*&& sd->bl.id != dstsd->bl.id*/)
  9127. return;
  9128. if (
  9129. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9130. || (type == 2 && !level)) {
  9131. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9132. if (battle_config.manner_system)
  9133. {
  9134. dstsd->status.manner -= limit;
  9135. if(dstsd->status.manner < 0)
  9136. sc_start(bl,SC_NOCHAT,100,0,0);
  9137. else
  9138. {
  9139. dstsd->status.manner = 0;
  9140. status_change_end(bl,SC_NOCHAT,-1);
  9141. }
  9142. }
  9143. ShowDebug("GMReqNoChat: name:%s type:%d limit:%d manner:%d\n", dstsd->status.name, type, limit, dstsd->status.manner);
  9144. }
  9145. return;
  9146. }
  9147. /*==========================================
  9148. * GMによるチャット禁止時間参照(?)
  9149. *------------------------------------------
  9150. */
  9151. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9152. {
  9153. int tid;
  9154. RFIFOHEAD(fd);
  9155. tid = RFIFOL(fd,2);
  9156. WFIFOHEAD(fd,packet_len_table[0x1e0]);
  9157. WFIFOW(fd,0) = 0x1e0;
  9158. WFIFOL(fd,2) = tid;
  9159. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9160. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9161. WFIFOSET(fd, packet_len_table[0x1e0]);
  9162. return;
  9163. }
  9164. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9165. char output[512];
  9166. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9167. int i, pos;
  9168. RFIFOHEAD(fd);
  9169. memset(output, '\0', sizeof(output));
  9170. nick = (char*)RFIFOP(fd,2); // speed up
  9171. RFIFOB(fd,NAME_LENGTH+1) = '\0'; // to be sure that the player name have at maximum 23 characters (nick range: [2]->[26])
  9172. //printf("Ignore: char '%s' state: %d\n", nick, RFIFOB(fd,26));
  9173. WFIFOHEAD(fd,packet_len_table[0xd1]);
  9174. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9175. WFIFOB(fd,2) = RFIFOB(fd,26);
  9176. // do nothing only if nick can not exist
  9177. if (strlen(nick) < 4) {
  9178. WFIFOB(fd,3) = 1; // fail
  9179. WFIFOSET(fd, packet_len_table[0x0d1]);
  9180. if (RFIFOB(fd,26) == 0) // type
  9181. clif_wis_message(fd, wisp_server_name, "It's impossible to block this player.", strlen("It's impossible to block this player.") + 1);
  9182. else
  9183. clif_wis_message(fd, wisp_server_name, "It's impossible to unblock this player.", strlen("It's impossible to unblock this player.") + 1);
  9184. return;
  9185. // name can exist
  9186. } else {
  9187. // deny action (we add nick only if it's not already exist
  9188. if (RFIFOB(fd,26) == 0) { // type
  9189. pos = -1;
  9190. for(i = 0; i < MAX_IGNORE_LIST; i++) {
  9191. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9192. WFIFOB(fd,3) = 1; // fail
  9193. WFIFOSET(fd, packet_len_table[0x0d1]);
  9194. clif_wis_message(fd, wisp_server_name, "This player is already blocked.", strlen("This player is already blocked.") + 1);
  9195. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9196. 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);
  9197. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9198. }
  9199. return;
  9200. } else if (pos == -1 && sd->ignore[i].name[0] == '\0')
  9201. pos = i;
  9202. }
  9203. // if a position is found and name not found, we add it in the list
  9204. if (pos != -1) {
  9205. memcpy(sd->ignore[pos].name, nick, NAME_LENGTH-1);
  9206. WFIFOB(fd,3) = 0; // success
  9207. WFIFOSET(fd, packet_len_table[0x0d1]);
  9208. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9209. 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);
  9210. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9211. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9212. 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);
  9213. }
  9214. } else {
  9215. WFIFOB(fd,3) = 1; // fail
  9216. WFIFOSET(fd, packet_len_table[0x0d1]);
  9217. clif_wis_message(fd, wisp_server_name, "You can not block more people.", strlen("You can not block more people.") + 1);
  9218. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9219. 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);
  9220. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9221. }
  9222. }
  9223. // allow action (we remove all same nicks if they exist)
  9224. } else {
  9225. pos = -1;
  9226. for(i = 0; i < MAX_IGNORE_LIST; i++)
  9227. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9228. memset(sd->ignore[i].name, 0, sizeof(sd->ignore[i].name));
  9229. if (pos == -1) {
  9230. WFIFOB(fd,3) = 0; // success
  9231. WFIFOSET(fd, packet_len_table[0x0d1]);
  9232. pos = i; // don't break, to remove ALL same nick
  9233. }
  9234. }
  9235. if (pos == -1) {
  9236. WFIFOB(fd,3) = 1; // fail
  9237. WFIFOSET(fd, packet_len_table[0x0d1]);
  9238. clif_wis_message(fd, wisp_server_name, "This player is not blocked by you.", strlen("This player is not blocked by you.") + 1);
  9239. }
  9240. }
  9241. }
  9242. // for(i = 0; i < MAX_IGNORE_LIST; i++) // for debug only
  9243. // if (sd->ignore[i].name[0] != '\0')
  9244. // printf("Ignored player: '%s'\n", sd->ignore[i].name);
  9245. return;
  9246. }
  9247. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9248. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9249. RFIFOHEAD(fd);
  9250. if (RFIFOB(fd,2) == 0) {// S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9251. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9252. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9253. WFIFOB(fd,2) = 0;
  9254. if (sd->ignoreAll == 0) {
  9255. sd->ignoreAll = 1;
  9256. WFIFOB(fd,3) = 0; // success
  9257. WFIFOSET(fd, packet_len_table[0x0d2]);
  9258. } else {
  9259. WFIFOB(fd,3) = 1; // fail
  9260. WFIFOSET(fd, packet_len_table[0x0d2]);
  9261. clif_wis_message(fd, wisp_server_name, "You already block everyone.", strlen("You already block everyone.") + 1);
  9262. }
  9263. } else {
  9264. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9265. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9266. WFIFOB(fd,2) = 1;
  9267. if (sd->ignoreAll == 1) {
  9268. sd->ignoreAll = 0;
  9269. WFIFOB(fd,3) = 0; // success
  9270. WFIFOSET(fd, packet_len_table[0x0d2]);
  9271. } else {
  9272. WFIFOB(fd,3) = 1; // fail
  9273. WFIFOSET(fd, packet_len_table[0x0d2]);
  9274. clif_wis_message(fd, wisp_server_name, "You already allow everyone.", strlen("You already allow everyone.") + 1);
  9275. }
  9276. }
  9277. return;
  9278. }
  9279. /*==========================================
  9280. * Wis拒否リスト
  9281. *------------------------------------------
  9282. */
  9283. int pstrcmp(const void *a, const void *b)
  9284. {
  9285. return strcmp((char *)a, (char *)b);
  9286. }
  9287. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9288. {
  9289. int i,j=0,count=0;
  9290. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9291. for(i = 0; i < MAX_IGNORE_LIST; i++){ //中身があるのを数える
  9292. if(sd->ignore[i].name[0] != 0)
  9293. count++;
  9294. }
  9295. WFIFOHEAD(fd, 4 + (NAME_LENGTH * count));
  9296. WFIFOW(fd,0) = 0xd4;
  9297. WFIFOW(fd,2) = 4 + (NAME_LENGTH * count);
  9298. for(i = 0; i < MAX_IGNORE_LIST; i++){
  9299. if(sd->ignore[i].name[0] != 0){
  9300. memcpy(WFIFOP(fd, 4 + j * 24),sd->ignore[i].name, NAME_LENGTH);
  9301. j++;
  9302. }
  9303. }
  9304. WFIFOSET(fd, WFIFOW(fd,2));
  9305. if(count >= MAX_IGNORE_LIST) //満タンなら最後の1個を消す
  9306. sd->ignore[MAX_IGNORE_LIST - 1].name[0] = 0;
  9307. return;
  9308. }
  9309. /*==========================================
  9310. * スパノビの/doridoriによるSPR2倍
  9311. *------------------------------------------
  9312. */
  9313. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9314. int level;
  9315. sd->doridori_counter = 1;
  9316. if ((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON
  9317. && sd->state.rest && (level = pc_checkskill(sd,TK_SPTIME)))
  9318. sc_start(&sd->bl,SkillStatusChangeTable[TK_SPTIME],100,level,skill_get_time(TK_SPTIME, level));
  9319. return;
  9320. }
  9321. /*==========================================
  9322. * スパノビの爆裂波動
  9323. *------------------------------------------
  9324. */
  9325. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9326. {
  9327. if(sd){
  9328. int nextbaseexp=pc_nextbaseexp(sd);
  9329. if (battle_config.etc_log){
  9330. if(nextbaseexp != 0)
  9331. 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));
  9332. else
  9333. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9334. }
  9335. 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){
  9336. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9337. sc_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  9338. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9339. }
  9340. }
  9341. return;
  9342. }
  9343. // random notes:
  9344. // 0x214: monster/player info ?
  9345. /*==========================================
  9346. * Friends List
  9347. *------------------------------------------
  9348. */
  9349. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9350. { //Toggles a single friend online/offline [Skotlex]
  9351. int i;
  9352. //Seek friend.
  9353. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9354. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9355. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9356. return; //Not found
  9357. WFIFOHEAD(sd->fd,packet_len_table[0x206]);
  9358. WFIFOW(sd->fd, 0) = 0x206;
  9359. WFIFOL(sd->fd, 2) = sd->status.friends[i].account_id;
  9360. WFIFOL(sd->fd, 6) = sd->status.friends[i].char_id;
  9361. WFIFOB(sd->fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9362. WFIFOSET(sd->fd, packet_len_table[0x206]);
  9363. }
  9364. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9365. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9366. {
  9367. int account_id, char_id, online;
  9368. account_id = va_arg(ap, int);
  9369. char_id = va_arg(ap, int);
  9370. online = va_arg(ap, int);
  9371. clif_friendslist_toggle(sd, account_id, char_id, online);
  9372. return 0;
  9373. }
  9374. //For sending the whole friends list.
  9375. void clif_friendslist_send(struct map_session_data *sd) {
  9376. int i = 0, n;
  9377. // Send friends list
  9378. WFIFOHEAD(sd->fd, MAX_FRIENDS * 32 + 4);
  9379. WFIFOW(sd->fd, 0) = 0x201;
  9380. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9381. {
  9382. WFIFOL(sd->fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9383. WFIFOL(sd->fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9384. memcpy(WFIFOP(sd->fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9385. }
  9386. if (i) {
  9387. WFIFOW(sd->fd,2) = 4 + 32 * i;
  9388. WFIFOSET(sd->fd, WFIFOW(sd->fd,2));
  9389. }
  9390. for (n = 0; n < i; n++)
  9391. { //Sending the online players
  9392. if (map_charid2sd(sd->status.friends[n].char_id))
  9393. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9394. }
  9395. }
  9396. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9397. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9398. {
  9399. int fd;
  9400. nullpo_retv(sd);
  9401. fd = sd->fd;
  9402. WFIFOHEAD(fd,packet_len_table[0x209]);
  9403. WFIFOW(fd,0) = 0x209;
  9404. WFIFOW(fd,2) = type;
  9405. if (f_sd)
  9406. {
  9407. WFIFOW(fd,4) = f_sd->status.account_id;
  9408. WFIFOW(fd,8) = f_sd->status.char_id;
  9409. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9410. }
  9411. WFIFOSET(fd, packet_len_table[0x209]);
  9412. }
  9413. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9414. struct map_session_data *f_sd;
  9415. int i, f_fd;
  9416. RFIFOHEAD(fd);
  9417. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9418. // Friend doesn't exist (no player with this name)
  9419. if (f_sd == NULL) {
  9420. clif_displaymessage(fd, msg_txt(3));
  9421. return;
  9422. }
  9423. // Friend already exists
  9424. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9425. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9426. clif_displaymessage(fd, "Friend already exists.");
  9427. return;
  9428. }
  9429. }
  9430. if (i == MAX_FRIENDS) {
  9431. //No space, list full.
  9432. clif_friendslist_reqack(sd, f_sd, 2);
  9433. return;
  9434. }
  9435. f_fd = f_sd->fd;
  9436. WFIFOHEAD(fd,packet_len_table[0x207]);
  9437. WFIFOW(f_fd,0) = 0x207;
  9438. WFIFOL(f_fd,2) = sd->status.account_id;
  9439. WFIFOL(f_fd,6) = sd->status.char_id;
  9440. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9441. WFIFOSET(f_fd, packet_len_table[0x207]);
  9442. return;
  9443. }
  9444. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9445. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9446. struct map_session_data *f_sd;
  9447. int char_id, account_id;
  9448. char reply;
  9449. RFIFOHEAD(fd);
  9450. account_id = RFIFOL(fd,2);
  9451. char_id = RFIFOL(fd,6);
  9452. reply = RFIFOB(fd,10);
  9453. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9454. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9455. if (f_sd == NULL)
  9456. return;
  9457. if (reply == 0)
  9458. clif_friendslist_reqack(f_sd, sd, 1);
  9459. else {
  9460. int i;
  9461. // Find an empty slot
  9462. for (i = 0; i < MAX_FRIENDS; i++)
  9463. if (f_sd->status.friends[i].char_id == 0)
  9464. break;
  9465. if (i == MAX_FRIENDS) {
  9466. clif_friendslist_reqack(f_sd, sd, 2);
  9467. return;
  9468. }
  9469. f_sd->status.friends[i].account_id = sd->status.account_id;
  9470. f_sd->status.friends[i].char_id = sd->status.char_id;
  9471. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9472. clif_friendslist_reqack(f_sd, sd, 0);
  9473. // clif_friendslist_send(sd); //This is not needed anymore.
  9474. }
  9475. return;
  9476. }
  9477. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9478. // 0x203 </o> <ID to be removed W 4B>
  9479. int account_id, char_id;
  9480. int i, j;
  9481. RFIFOHEAD(fd);
  9482. account_id = RFIFOL(fd,2);
  9483. char_id = RFIFOL(fd,6);
  9484. // Search friend
  9485. for (i = 0; i < MAX_FRIENDS &&
  9486. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9487. if (i == MAX_FRIENDS) {
  9488. clif_displaymessage(fd, "Name not found in list.");
  9489. return;
  9490. }
  9491. // move all chars down
  9492. for(j = i + 1; j < MAX_FRIENDS; j++)
  9493. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9494. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9495. clif_displaymessage(fd, "Friend removed");
  9496. WFIFOHEAD(fd,packet_len_table[0x20a]);
  9497. WFIFOW(fd,0) = 0x20a;
  9498. WFIFOL(fd,2) = account_id;
  9499. WFIFOL(fd,6) = char_id;
  9500. WFIFOSET(fd, packet_len_table[0x20a]);
  9501. // clif_friendslist_send(sd); //This is not needed anymore.
  9502. return;
  9503. }
  9504. /*==========================================
  9505. * /killall
  9506. *------------------------------------------
  9507. */
  9508. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  9509. {
  9510. char message[50];
  9511. strncpy(message,sd->status.name, NAME_LENGTH);
  9512. is_atcommand(fd, sd, strcat(message," : @kickall"),0);
  9513. return;
  9514. }
  9515. /*==========================================
  9516. * /pvpinfo
  9517. *------------------------------------------
  9518. */
  9519. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9520. {
  9521. WFIFOHEAD(fd,packet_len_table[0x210]);
  9522. WFIFOW(fd,0) = 0x210;
  9523. //WFIFOL(fd,2) = 0; // not sure what for yet
  9524. //WFIFOL(fd,6) = 0;
  9525. WFIFOL(fd,10) = sd->pvp_won; // times won
  9526. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9527. WFIFOL(fd,18) = sd->pvp_point;
  9528. WFIFOSET(fd, packet_len_table[0x210]);
  9529. return;
  9530. }
  9531. /*==========================================
  9532. * /blacksmith
  9533. *------------------------------------------
  9534. */
  9535. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9536. {
  9537. int i;
  9538. char *name;
  9539. WFIFOHEAD(fd,packet_len_table[0x219]);
  9540. WFIFOW(fd,0) = 0x219;
  9541. //Packet size limits this list to 10 elements. [Skotlex]
  9542. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9543. if (smith_fame_list[i].id > 0) {
  9544. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9545. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9546. {
  9547. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9548. } else
  9549. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9550. } else
  9551. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9552. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9553. }
  9554. for(;i < 10; i++) { //In case the MAX is less than 10.
  9555. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9556. WFIFOL(fd, 242 + i * 4) = 0;
  9557. }
  9558. WFIFOSET(fd, packet_len_table[0x219]);
  9559. }
  9560. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9561. {
  9562. int fd = sd->fd;
  9563. WFIFOHEAD(fd,packet_len_table[0x21b]);
  9564. WFIFOW(fd,0) = 0x21b;
  9565. WFIFOL(fd,2) = points;
  9566. WFIFOL(fd,6) = sd->status.fame;
  9567. WFIFOSET(fd, packet_len_table[0x21b]);
  9568. return 0;
  9569. }
  9570. /*==========================================
  9571. * /alchemist
  9572. *------------------------------------------
  9573. */
  9574. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9575. {
  9576. int i;
  9577. char *name;
  9578. WFIFOHEAD(fd,packet_len_table[0x21a]);
  9579. WFIFOW(fd,0) = 0x21a;
  9580. //Packet size limits this list to 10 elements. [Skotlex]
  9581. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9582. if (chemist_fame_list[i].id > 0) {
  9583. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9584. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9585. {
  9586. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9587. } else
  9588. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9589. } else
  9590. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9591. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9592. }
  9593. for(;i < 10; i++) { //In case the MAX is less than 10.
  9594. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9595. WFIFOL(fd, 242 + i * 4) = 0;
  9596. }
  9597. WFIFOSET(fd, packet_len_table[0x21a]);
  9598. }
  9599. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9600. {
  9601. int fd = sd->fd;
  9602. WFIFOHEAD(fd,packet_len_table[0x21c]);
  9603. WFIFOW(fd,0) = 0x21c;
  9604. WFIFOL(fd,2) = points;
  9605. WFIFOL(fd,6) = sd->status.fame;
  9606. WFIFOSET(fd, packet_len_table[0x21c]);
  9607. return 0;
  9608. }
  9609. /*==========================================
  9610. * /taekwon
  9611. *------------------------------------------
  9612. */
  9613. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9614. {
  9615. int i;
  9616. char *name;
  9617. WFIFOHEAD(fd,packet_len_table[0x226]);
  9618. WFIFOW(fd,0) = 0x226;
  9619. //Packet size limits this list to 10 elements. [Skotlex]
  9620. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9621. if (taekwon_fame_list[i].id > 0) {
  9622. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9623. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9624. {
  9625. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9626. } else
  9627. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9628. } else
  9629. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9630. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9631. }
  9632. for(;i < 10; i++) { //In case the MAX is less than 10.
  9633. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9634. WFIFOL(fd, 242 + i * 4) = 0;
  9635. }
  9636. WFIFOSET(fd, packet_len_table[0x226]);
  9637. }
  9638. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9639. {
  9640. int fd = sd->fd;
  9641. WFIFOHEAD(fd,packet_len_table[0x224]);
  9642. WFIFOW(fd,0) = 0x224;
  9643. WFIFOL(fd,2) = points;
  9644. WFIFOL(fd,6) = sd->status.fame;
  9645. WFIFOSET(fd, packet_len_table[0x224]);
  9646. return 0;
  9647. }
  9648. /*==========================================
  9649. * PK Ranking table?
  9650. *------------------------------------------
  9651. */
  9652. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9653. {
  9654. int i;
  9655. WFIFOHEAD(fd,packet_len_table[0x238]);
  9656. WFIFOW(fd,0) = 0x238;
  9657. for(i=0;i<10;i++){
  9658. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9659. WFIFOL(fd,i*4+242) = 0;
  9660. }
  9661. WFIFOSET(fd, packet_len_table[0x238]);
  9662. return;
  9663. }
  9664. /*==========================================
  9665. * SG Feel save OK [Komurka]
  9666. *------------------------------------------
  9667. */
  9668. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9669. {
  9670. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  9671. int i;
  9672. if (sd->menuskill_id != SG_FEEL)
  9673. return;
  9674. i = sd->menuskill_lv-1;
  9675. if (i<0 || i > 2) return; //Bug?
  9676. sd->feel_map[i].index = map[sd->bl.m].index;
  9677. sd->feel_map[i].m = sd->bl.m;
  9678. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  9679. WFIFOHEAD(fd,packet_len_table[0x20e]);
  9680. WFIFOW(fd,0)=0x20e;
  9681. memcpy(WFIFOP(fd,2),map[sd->bl.m].name, MAP_NAME_LENGTH);
  9682. WFIFOL(fd,26)=sd->bl.id;
  9683. WFIFOW(fd,30)=i;
  9684. WFIFOSET(fd, packet_len_table[0x20e]);
  9685. if (sd->bl.m == sd->feel_map[i].m &&
  9686. (i = pc_checkskill(sd,SG_KNOWLEDGE)) > 0)
  9687. sc_start(&sd->bl, SC_KNOWLEDGE, 100, i, skill_get_time(SG_KNOWLEDGE, i));
  9688. sd->menuskill_lv = sd->menuskill_id = 0;
  9689. }
  9690. /*==========================================
  9691. * Question about Star Glaldiator save map [Komurka]
  9692. *------------------------------------------
  9693. */
  9694. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  9695. WFIFOHEAD(fd,packet_len_table[0x253]);
  9696. WFIFOW(fd,0)=0x253;
  9697. WFIFOSET(fd, packet_len_table[0x253]);
  9698. sd->menuskill_id=SG_FEEL;
  9699. sd->menuskill_lv=skilllv;
  9700. }
  9701. /*==========================================
  9702. * パケットデバッグ
  9703. *------------------------------------------
  9704. */
  9705. void clif_parse_debug(int fd,struct map_session_data *sd)
  9706. {
  9707. int i, cmd, len;
  9708. RFIFOHEAD(fd);
  9709. cmd = RFIFOW(fd,0);
  9710. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  9711. ShowDebug("packet debug 0x%4X\n",cmd);
  9712. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9713. for(i=0;i<len;i++){
  9714. if((i&15)==0)
  9715. printf("\n%04X ",i);
  9716. printf("%02X ",RFIFOB(fd,i));
  9717. }
  9718. printf("\n");
  9719. }
  9720. /*==========================================
  9721. * クライアントからのパケット解析
  9722. * socket.cのdo_parsepacketから呼び出される
  9723. *------------------------------------------
  9724. */
  9725. int clif_parse(int fd) {
  9726. int packet_len = 0, cmd, packet_ver, dump = 0;
  9727. struct map_session_data *sd;
  9728. RFIFOHEAD(fd);
  9729. if (fd <= 0)
  9730. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  9731. ShowError("clif_parse: Received invalid session %d\n", fd);
  9732. return 0;
  9733. }
  9734. sd = (struct map_session_data*)session[fd]->session_data;
  9735. // 接続が切れてるので後始末
  9736. if (!chrif_isconnect() && kick_on_disconnect)
  9737. {
  9738. ShowInfo("Closing session #%d (Not connected to Char server)\n", fd);
  9739. if (sd && sd->state.auth)
  9740. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  9741. do_close(fd);
  9742. return 0;
  9743. } else
  9744. if (session[fd]->eof) {
  9745. if (sd && sd->state.autotrade) {
  9746. //Disassociate character from the socket connection.
  9747. session[fd]->session_data = NULL;
  9748. sd->fd = 0;
  9749. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  9750. } else if (sd && sd->state.auth) {
  9751. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  9752. if (sd->status.name != NULL)
  9753. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  9754. else
  9755. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id); // Player logout display [Yor]
  9756. } else {
  9757. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  9758. 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]);
  9759. }
  9760. do_close(fd);
  9761. return 0;
  9762. }
  9763. if (RFIFOREST(fd) < 2)
  9764. return 0;
  9765. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  9766. cmd = RFIFOW(fd,0);
  9767. // 管理用パケット処理
  9768. if (cmd >= 30000) {
  9769. switch(cmd) {
  9770. case 0x7530: { //Why are we letting people know which version we are running?
  9771. WFIFOHEAD(fd, 10);
  9772. WFIFOW(fd,0) = 0x7531;
  9773. WFIFOB(fd,2) = ATHENA_MAJOR_VERSION;
  9774. WFIFOB(fd,3) = ATHENA_MINOR_VERSION;
  9775. WFIFOB(fd,4) = ATHENA_REVISION;
  9776. WFIFOB(fd,5) = ATHENA_RELEASE_FLAG;
  9777. WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG;
  9778. WFIFOB(fd,7) = ATHENA_SERVER_MAP;
  9779. WFIFOW(fd,8) = ATHENA_MOD_VERSION;
  9780. WFIFOSET(fd,10);
  9781. RFIFOSKIP(fd,2);
  9782. break;
  9783. }
  9784. case 0x7532: // 接続の切断
  9785. ShowWarning("clif_parse: session #%d disconnected for sending packet 0x04%x\n", fd, cmd);
  9786. session[fd]->eof=1;
  9787. break;
  9788. default:
  9789. ShowWarning("Unknown incoming packet (command: 0x%04x, session: %d), disconnecting.\n", cmd, fd);
  9790. session[fd]->eof=1;
  9791. break;
  9792. }
  9793. return 0;
  9794. }
  9795. // get packet version before to parse
  9796. packet_ver = 0;
  9797. if (sd) {
  9798. packet_ver = sd->packet_ver;
  9799. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  9800. session[fd]->eof = 1;
  9801. return 0;
  9802. }
  9803. } else {
  9804. // check authentification packet to know packet version
  9805. packet_ver = clif_guess_PacketVer(fd, 0);
  9806. // check if version is accepted
  9807. if (packet_ver < 5 || // reject really old client versions
  9808. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  9809. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
  9810. packet_ver > MAX_PACKET_VER) // no packet version support yet
  9811. {
  9812. ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
  9813. WFIFOHEAD(fd, 23);
  9814. WFIFOW(fd,0) = 0x6a;
  9815. WFIFOB(fd,2) = 5; // 05 = Game's EXE is not the latest version
  9816. WFIFOSET(fd,23);
  9817. packet_len = RFIFOREST(fd);
  9818. RFIFOSKIP(fd, packet_len);
  9819. clif_setwaitclose(fd);
  9820. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  9821. session[fd]->func_send(fd);
  9822. return 0;
  9823. }
  9824. }
  9825. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  9826. 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
  9827. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  9828. session[fd]->eof = 1;
  9829. return 0;
  9830. }
  9831. // パケット長を計算
  9832. packet_len = packet_db[packet_ver][cmd].len;
  9833. if (packet_len == -1) {
  9834. if (RFIFOREST(fd) < 4)
  9835. return 0; // 可変長パケットで長さの所までデータが来てない
  9836. packet_len = RFIFOW(fd,2);
  9837. if (packet_len < 4 || packet_len > 32768) {
  9838. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  9839. session[fd]->eof =1;
  9840. return 0;
  9841. }
  9842. }
  9843. if ((int)RFIFOREST(fd) < packet_len)
  9844. return 0; // まだ1パケット分データが揃ってない
  9845. #if DUMP_ALL_PACKETS
  9846. dump = 1;
  9847. #endif
  9848. if (sd && sd->state.auth == 1 && sd->state.waitingdisconnect == 1) { // 切断待ちの場合パケットを処理しない
  9849. } else if (packet_db[packet_ver][cmd].func) {
  9850. if (sd
  9851. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  9852. || packet_db[packet_ver][cmd].func == clif_parse_debug
  9853. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  9854. packet_db[packet_ver][cmd].func(fd, sd);
  9855. } else {
  9856. // 不明なパケット
  9857. if (battle_config.error_log) {
  9858. #if DUMP_UNKNOWN_PACKET
  9859. {
  9860. int i;
  9861. FILE *fp;
  9862. char packet_txt[256] = "save/packet.txt";
  9863. time_t now;
  9864. dump = 1;
  9865. if ((fp = fopen(packet_txt, "a")) == NULL) {
  9866. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  9867. return 1;
  9868. } else {
  9869. time(&now);
  9870. if (sd && sd->state.auth) {
  9871. if (sd->status.name != NULL)
  9872. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  9873. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  9874. else
  9875. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  9876. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  9877. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  9878. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9879. for(i = 0; i < packet_len; i++) {
  9880. if ((i & 15) == 0)
  9881. fprintf(fp, "\n\t%04X ", i);
  9882. fprintf(fp, "%02X ", RFIFOB(fd,i));
  9883. }
  9884. fprintf(fp, "\n\n");
  9885. fclose(fp);
  9886. }
  9887. }
  9888. #endif
  9889. }
  9890. }
  9891. if (dump) {
  9892. int i;
  9893. if (fd)
  9894. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  9895. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9896. for(i = 0; i < packet_len; i++) {
  9897. if ((i & 15) == 0)
  9898. printf("\n%04X ",i);
  9899. printf("%02X ", RFIFOB(fd,i));
  9900. }
  9901. printf("\n");
  9902. if (sd && sd->state.auth) {
  9903. if (sd->status.name != NULL)
  9904. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  9905. sd->status.account_id, sd->status.char_id, sd->status.name);
  9906. else
  9907. printf("\nAccount ID %d.\n", sd->bl.id);
  9908. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  9909. printf("\nAccount ID %d.\n", sd->bl.id);
  9910. }
  9911. RFIFOSKIP(fd, packet_len);
  9912. return 0;
  9913. }
  9914. /*==========================================
  9915. * パケットデータベース読み込み
  9916. *------------------------------------------
  9917. */
  9918. static int packetdb_readdb(void)
  9919. {
  9920. FILE *fp;
  9921. char line[1024];
  9922. int ln=0;
  9923. int cmd,i,j,k,packet_ver;
  9924. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  9925. struct {
  9926. void (*func)(int, struct map_session_data *);
  9927. char *name;
  9928. } clif_parse_func[]={
  9929. {clif_parse_WantToConnection,"wanttoconnection"},
  9930. {clif_parse_LoadEndAck,"loadendack"},
  9931. {clif_parse_TickSend,"ticksend"},
  9932. {clif_parse_WalkToXY,"walktoxy"},
  9933. {clif_parse_QuitGame,"quitgame"},
  9934. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  9935. {clif_parse_GlobalMessage,"globalmessage"},
  9936. {clif_parse_MapMove,"mapmove"},
  9937. {clif_parse_ChangeDir,"changedir"},
  9938. {clif_parse_Emotion,"emotion"},
  9939. {clif_parse_HowManyConnections,"howmanyconnections"},
  9940. {clif_parse_ActionRequest,"actionrequest"},
  9941. {clif_parse_Restart,"restart"},
  9942. {clif_parse_Wis,"wis"},
  9943. {clif_parse_GMmessage,"gmmessage"},
  9944. {clif_parse_TakeItem,"takeitem"},
  9945. {clif_parse_DropItem,"dropitem"},
  9946. {clif_parse_UseItem,"useitem"},
  9947. {clif_parse_EquipItem,"equipitem"},
  9948. {clif_parse_UnequipItem,"unequipitem"},
  9949. {clif_parse_NpcClicked,"npcclicked"},
  9950. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  9951. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  9952. {clif_parse_NpcSellListSend,"npcselllistsend"},
  9953. {clif_parse_CreateChatRoom,"createchatroom"},
  9954. {clif_parse_ChatAddMember,"chataddmember"},
  9955. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  9956. {clif_parse_ChangeChatOwner,"changechatowner"},
  9957. {clif_parse_KickFromChat,"kickfromchat"},
  9958. {clif_parse_ChatLeave,"chatleave"},
  9959. {clif_parse_TradeRequest,"traderequest"},
  9960. {clif_parse_TradeAck,"tradeack"},
  9961. {clif_parse_TradeAddItem,"tradeadditem"},
  9962. {clif_parse_TradeOk,"tradeok"},
  9963. {clif_parse_TradeCancel,"tradecancel"},
  9964. {clif_parse_TradeCommit,"tradecommit"},
  9965. {clif_parse_StopAttack,"stopattack"},
  9966. {clif_parse_PutItemToCart,"putitemtocart"},
  9967. {clif_parse_GetItemFromCart,"getitemfromcart"},
  9968. {clif_parse_RemoveOption,"removeoption"},
  9969. {clif_parse_ChangeCart,"changecart"},
  9970. {clif_parse_StatusUp,"statusup"},
  9971. {clif_parse_SkillUp,"skillup"},
  9972. {clif_parse_UseSkillToId,"useskilltoid"},
  9973. {clif_parse_UseSkillToPos,"useskilltopos"},
  9974. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  9975. {clif_parse_UseSkillMap,"useskillmap"},
  9976. {clif_parse_RequestMemo,"requestmemo"},
  9977. {clif_parse_ProduceMix,"producemix"},
  9978. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  9979. {clif_parse_NpcNextClicked,"npcnextclicked"},
  9980. {clif_parse_NpcAmountInput,"npcamountinput"},
  9981. {clif_parse_NpcStringInput,"npcstringinput"},
  9982. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  9983. {clif_parse_ItemIdentify,"itemidentify"},
  9984. {clif_parse_SelectArrow,"selectarrow"},
  9985. {clif_parse_AutoSpell,"autospell"},
  9986. {clif_parse_UseCard,"usecard"},
  9987. {clif_parse_InsertCard,"insertcard"},
  9988. {clif_parse_RepairItem,"repairitem"},
  9989. {clif_parse_WeaponRefine,"weaponrefine"},
  9990. {clif_parse_SolveCharName,"solvecharname"},
  9991. {clif_parse_ResetChar,"resetchar"},
  9992. {clif_parse_LGMmessage,"lgmmessage"},
  9993. {clif_parse_MoveToKafra,"movetokafra"},
  9994. {clif_parse_MoveFromKafra,"movefromkafra"},
  9995. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  9996. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  9997. {clif_parse_CloseKafra,"closekafra"},
  9998. {clif_parse_CreateParty,"createparty"},
  9999. {clif_parse_CreateParty2,"createparty2"},
  10000. {clif_parse_PartyInvite,"partyinvite"},
  10001. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10002. {clif_parse_LeaveParty,"leaveparty"},
  10003. {clif_parse_RemovePartyMember,"removepartymember"},
  10004. {clif_parse_PartyChangeOption,"partychangeoption"},
  10005. {clif_parse_PartyMessage,"partymessage"},
  10006. {clif_parse_CloseVending,"closevending"},
  10007. {clif_parse_VendingListReq,"vendinglistreq"},
  10008. {clif_parse_PurchaseReq,"purchasereq"},
  10009. {clif_parse_OpenVending,"openvending"},
  10010. {clif_parse_CreateGuild,"createguild"},
  10011. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10012. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10013. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10014. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10015. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10016. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10017. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10018. {clif_parse_GuildInvite,"guildinvite"},
  10019. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10020. {clif_parse_GuildLeave,"guildleave"},
  10021. {clif_parse_GuildExplusion,"guildexplusion"},
  10022. {clif_parse_GuildMessage,"guildmessage"},
  10023. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10024. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10025. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10026. {clif_parse_GuildOpposition,"guildopposition"},
  10027. {clif_parse_GuildBreak,"guildbreak"},
  10028. {clif_parse_PetMenu,"petmenu"},
  10029. {clif_parse_CatchPet,"catchpet"},
  10030. {clif_parse_SelectEgg,"selectegg"},
  10031. {clif_parse_SendEmotion,"sendemotion"},
  10032. {clif_parse_ChangePetName,"changepetname"},
  10033. {clif_parse_GMKick,"gmkick"},
  10034. {clif_parse_GMHide,"gmhide"},
  10035. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10036. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10037. {clif_parse_NoviceDoriDori,"sndoridori"},
  10038. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10039. {clif_parse_PMIgnore,"wisexin"},
  10040. {clif_parse_PMIgnoreList,"wisexlist"},
  10041. {clif_parse_PMIgnoreAll,"wisall"},
  10042. {clif_parse_FriendsListAdd,"friendslistadd"},
  10043. {clif_parse_FriendsListRemove,"friendslistremove"},
  10044. {clif_parse_FriendsListReply,"friendslistreply"},
  10045. {clif_parse_GMKillAll,"killall"},
  10046. {clif_parse_Recall,"summon"},
  10047. {clif_parse_GM_Monster_Item,"itemmonster"},
  10048. {clif_parse_Shift,"shift"},
  10049. {clif_parse_Blacksmith,"blacksmith"},
  10050. {clif_parse_Alchemist,"alchemist"},
  10051. {clif_parse_Taekwon,"taekwon"},
  10052. {clif_parse_RankingPk,"rankingpk"},
  10053. {clif_parse_FeelSaveOk,"feelsaveok"},
  10054. {clif_parse_debug,"debug"},
  10055. {NULL,NULL}
  10056. };
  10057. sprintf(line, "%s/packet_db.txt", db_path);
  10058. if( (fp=fopen(line,"r"))==NULL ){
  10059. ShowFatalError("can't read %s\n", line);
  10060. exit(1);
  10061. }
  10062. clif_config.packet_db_ver = MAX_PACKET_VER;
  10063. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10064. while(fgets(line,1020,fp)){
  10065. if(line[0]=='/' && line[1]=='/')
  10066. continue;
  10067. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10068. if(strcmpi(w1,"packet_ver")==0) {
  10069. int prev_ver = packet_ver;
  10070. packet_ver = atoi(w2);
  10071. if (packet_ver > MAX_PACKET_VER)
  10072. { //Check to avoid overflowing. [Skotlex]
  10073. ShowWarning("The packet_db table only has support up to version %d\n", MAX_PACKET_VER);
  10074. break;
  10075. }
  10076. // copy from previous version into new version and continue
  10077. // - indicating all following packets should be read into the newer version
  10078. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10079. continue;
  10080. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10081. //This is the preferred version.
  10082. if(strcmpi(w2,"default")==0)
  10083. clif_config.packet_db_ver = MAX_PACKET_VER;
  10084. else {
  10085. // to manually set the packet DB version
  10086. clif_config.packet_db_ver = atoi(w2);
  10087. // check for invalid version
  10088. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10089. clif_config.packet_db_ver < 0)
  10090. clif_config.packet_db_ver = MAX_PACKET_VER;
  10091. }
  10092. continue;
  10093. }
  10094. }
  10095. memset(str,0,sizeof(str));
  10096. for(j=0,p=line;j<4 && p;j++){
  10097. str[j]=p;
  10098. p=strchr(p,',');
  10099. if(p) *p++=0;
  10100. }
  10101. if(str[0]==NULL)
  10102. continue;
  10103. cmd=strtol(str[0],(char **)NULL,0);
  10104. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10105. continue;
  10106. if(str[1]==NULL){
  10107. ShowError("packet_db: packet len error\n");
  10108. continue;
  10109. }
  10110. k = atoi(str[1]);
  10111. packet_db[packet_ver][cmd].len = k;
  10112. if(str[2]==NULL){
  10113. packet_db[packet_ver][cmd].func = NULL;
  10114. ln++;
  10115. continue;
  10116. }
  10117. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10118. if(clif_parse_func[j].name != NULL &&
  10119. strcmp(str[2],clif_parse_func[j].name)==0)
  10120. {
  10121. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10122. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10123. for(i=0;i<MAX_PACKET_DB;i++){
  10124. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10125. {
  10126. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10127. break;
  10128. }
  10129. }
  10130. }
  10131. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10132. break;
  10133. }
  10134. }
  10135. // set the identifying cmd for the packet_db version
  10136. if (strcmp(str[2],"wanttoconnection")==0)
  10137. clif_config.connect_cmd[packet_ver] = cmd;
  10138. if(str[3]==NULL){
  10139. ShowError("packet_db: packet error\n");
  10140. exit(1);
  10141. }
  10142. for(j=0,p2=str[3];p2;j++){
  10143. str2[j]=p2;
  10144. p2=strchr(p2,':');
  10145. if(p2) *p2++=0;
  10146. k = atoi(str2[j]);
  10147. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10148. packet_db[packet_ver][cmd].pos[j] = k;
  10149. }
  10150. ln++;
  10151. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10152. // 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);
  10153. }
  10154. fclose(fp);
  10155. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10156. { //Locate the nearest version that we still support. [Skotlex]
  10157. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10158. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10159. }
  10160. 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);
  10161. return 0;
  10162. }
  10163. /*==========================================
  10164. *
  10165. *------------------------------------------
  10166. */
  10167. int do_init_clif(void) {
  10168. #ifndef __WIN32
  10169. int i;
  10170. #endif
  10171. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10172. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10173. memset(packet_db,0,sizeof(packet_db));
  10174. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10175. packetdb_readdb();
  10176. set_defaultparse(clif_parse);
  10177. #ifdef __WIN32
  10178. //if (!make_listen_port(map_port)) {
  10179. if (!make_listen_bind(bind_ip,map_port)) {
  10180. ShowFatalError("cant bind game port\n");
  10181. exit(1);
  10182. }
  10183. #else
  10184. for(i = 0; i < 10; i++) {
  10185. //if (make_listen_port(map_port))
  10186. if (make_listen_bind(bind_ip,map_port))
  10187. break;
  10188. sleep(20);
  10189. }
  10190. if (i == 10) {
  10191. ShowFatalError("cant bind game port\n");
  10192. exit(1);
  10193. }
  10194. #endif
  10195. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10196. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10197. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10198. add_timer_func_list(clif_nighttimer, "clif_nighttimer");
  10199. return 0;
  10200. }