clif.c 344 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/malloc.h"
  7. #include "../common/version.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/showmsg.h"
  10. #include "../common/strlib.h"
  11. #include "../common/utils.h"
  12. #include "map.h"
  13. #include "chrif.h"
  14. #include "pc.h"
  15. #include "status.h"
  16. #include "npc.h"
  17. #include "itemdb.h"
  18. #include "chat.h"
  19. #include "trade.h"
  20. #include "storage.h"
  21. #include "script.h"
  22. #include "skill.h"
  23. #include "atcommand.h"
  24. #include "charcommand.h"
  25. #include "intif.h"
  26. #include "battle.h"
  27. #include "mob.h"
  28. #include "party.h"
  29. #include "unit.h"
  30. #include "guild.h"
  31. #include "vending.h"
  32. #include "pet.h"
  33. #include "mercenary.h" //[orn]
  34. #include "log.h"
  35. #include "clif.h"
  36. #include "mail.h"
  37. #include "quest.h"
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdarg.h>
  42. #include <time.h>
  43. #define DUMP_UNKNOWN_PACKET 0
  44. struct Clif_Config {
  45. int packet_db_ver; //Preferred packet version.
  46. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  47. } clif_config;
  48. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  49. //Converts item type in case of pet eggs.
  50. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  51. #define WBUFPOS(p,pos,x,y,dir) \
  52. do { \
  53. uint8 *__p = (p); \
  54. __p+=(pos); \
  55. __p[0] = (uint8)((x)>>2); \
  56. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  57. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  58. } while(0)
  59. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  60. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  61. do { \
  62. uint8 *__p = (p); \
  63. __p+=(pos); \
  64. __p[0]=(uint8)((x0)>>2); \
  65. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  66. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  67. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  68. __p[4]=(uint8)(y1); \
  69. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  70. } while(0)
  71. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  72. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  73. //To idenfity disguised characters.
  74. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  75. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  76. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  77. static char map_ip_str[128];
  78. static uint32 map_ip;
  79. static uint32 bind_ip = INADDR_ANY;
  80. static uint16 map_port = 5121;
  81. int map_fd;
  82. int clif_parse (int fd);
  83. /*==========================================
  84. * map鯖のip設定
  85. *------------------------------------------*/
  86. int clif_setip(const char* ip)
  87. {
  88. char ip_str[16];
  89. map_ip = host2ip(ip);
  90. if (!map_ip) {
  91. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  92. return 0;
  93. }
  94. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  95. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  96. return 1;
  97. }
  98. void clif_setbindip(const char* ip)
  99. {
  100. char ip_str[16];
  101. bind_ip = host2ip(ip);
  102. if (bind_ip) {
  103. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  104. } else {
  105. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  106. }
  107. }
  108. /*==========================================
  109. * map鯖のport設定
  110. *------------------------------------------*/
  111. void clif_setport(uint16 port)
  112. {
  113. map_port = port;
  114. }
  115. /*==========================================
  116. * map鯖のip読み出し
  117. *------------------------------------------*/
  118. uint32 clif_getip(void)
  119. {
  120. return map_ip;
  121. }
  122. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  123. uint32 clif_refresh_ip(void)
  124. {
  125. uint32 new_ip;
  126. new_ip = host2ip(map_ip_str);
  127. if (new_ip && new_ip != map_ip) {
  128. map_ip = new_ip;
  129. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  130. return map_ip;
  131. }
  132. return 0;
  133. }
  134. /*==========================================
  135. * map鯖のport読み出し
  136. *------------------------------------------*/
  137. uint16 clif_getport(void)
  138. {
  139. return map_port;
  140. }
  141. /*==========================================
  142. * clif_sendでAREA*指定時用
  143. *------------------------------------------*/
  144. int clif_send_sub(struct block_list *bl, va_list ap)
  145. {
  146. struct block_list *src_bl;
  147. struct map_session_data *sd;
  148. unsigned char *buf;
  149. int len, type, fd;
  150. nullpo_retr(0, bl);
  151. nullpo_retr(0, ap);
  152. nullpo_retr(0, sd = (struct map_session_data *)bl);
  153. fd = sd->fd;
  154. if (!fd) //Don't send to disconnected clients.
  155. return 0;
  156. buf = va_arg(ap,unsigned char*);
  157. len = va_arg(ap,int);
  158. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  159. type = va_arg(ap,int);
  160. switch(type)
  161. {
  162. case AREA_WOS:
  163. if (bl == src_bl)
  164. return 0;
  165. break;
  166. case AREA_WOC:
  167. if (sd->chatID || bl == src_bl)
  168. return 0;
  169. break;
  170. case AREA_WOSC:
  171. {
  172. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  173. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  174. return 0;
  175. }
  176. break;
  177. }
  178. if (session[fd] == NULL)
  179. return 0;
  180. WFIFOHEAD(fd, len);
  181. if (WFIFOP(fd,0) == buf) {
  182. ShowError("WARNING: Invalid use of clif_send function\n");
  183. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  184. ShowError(" Please correct your code.\n");
  185. // don't send to not move the pointer of the packet for next sessions in the loop
  186. //WFIFOSET(fd,0);//## TODO is this ok?
  187. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  188. return 0;
  189. }
  190. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  191. memcpy(WFIFOP(fd,0), buf, len);
  192. WFIFOSET(fd,len);
  193. }
  194. return 0;
  195. }
  196. /*==========================================
  197. *
  198. *------------------------------------------*/
  199. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  200. {
  201. int i;
  202. struct map_session_data *sd;
  203. struct party_data *p = NULL;
  204. struct guild *g = NULL;
  205. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  206. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  207. nullpo_retr(0, bl);
  208. sd = BL_CAST(BL_PC, bl);
  209. switch(type) {
  210. case ALL_CLIENT: //All player clients.
  211. for (i = 0; i < fd_max; i++) {
  212. if (session[i] && session[i]->func_parse == clif_parse &&
  213. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  214. sd->state.active &&
  215. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  216. { // packet must exist for the client version
  217. WFIFOHEAD(i, len);
  218. memcpy(WFIFOP(i,0), buf, len);
  219. WFIFOSET(i,len);
  220. }
  221. }
  222. break;
  223. case ALL_SAMEMAP: //All players on the same map
  224. for(i = 0; i < fd_max; i++) {
  225. if (session[i] && session[i]->func_parse == clif_parse &&
  226. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  227. sd->state.active && sd->bl.m == bl->m &&
  228. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  229. { // packet must exist for the client version
  230. WFIFOHEAD(i,len);
  231. memcpy(WFIFOP(i,0), buf, len);
  232. WFIFOSET(i,len);
  233. }
  234. }
  235. break;
  236. case AREA:
  237. case AREA_WOSC:
  238. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  239. clif_send (buf, len, bl, SELF);
  240. case AREA_WOC:
  241. case AREA_WOS:
  242. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  243. BL_PC, buf, len, bl, type);
  244. break;
  245. case AREA_CHAT_WOC:
  246. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  247. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  248. break;
  249. case CHAT:
  250. case CHAT_WOS:
  251. {
  252. struct chat_data *cd;
  253. if (sd) {
  254. cd = (struct chat_data*)map_id2bl(sd->chatID);
  255. } else if (bl->type == BL_CHAT) {
  256. cd = (struct chat_data*)bl;
  257. } else break;
  258. if (cd == NULL)
  259. break;
  260. for(i = 0; i < cd->users; i++) {
  261. if (type == CHAT_WOS && cd->usersd[i] == sd)
  262. continue;
  263. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  264. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  265. {
  266. WFIFOHEAD(fd,len);
  267. memcpy(WFIFOP(fd,0), buf, len);
  268. WFIFOSET(fd,len);
  269. }
  270. }
  271. }
  272. }
  273. break;
  274. case CHAT_MAINCHAT: //[LuzZza]
  275. for(i=1; i<fd_max; i++) {
  276. if (session[i] && session[i]->func_parse == clif_parse &&
  277. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  278. sd->state.active && sd->state.mainchat && !sd->chatID)
  279. {
  280. WFIFOHEAD(i,len);
  281. memcpy(WFIFOP(i,0), buf, len);
  282. WFIFOSET(i, len);
  283. }
  284. }
  285. break;
  286. case PARTY_AREA:
  287. case PARTY_AREA_WOS:
  288. x0 = bl->x - AREA_SIZE;
  289. y0 = bl->y - AREA_SIZE;
  290. x1 = bl->x + AREA_SIZE;
  291. y1 = bl->y + AREA_SIZE;
  292. case PARTY:
  293. case PARTY_WOS:
  294. case PARTY_SAMEMAP:
  295. case PARTY_SAMEMAP_WOS:
  296. if (sd && sd->status.party_id)
  297. p = party_search(sd->status.party_id);
  298. if (p) {
  299. for(i=0;i<MAX_PARTY;i++){
  300. if( (sd = p->data[i].sd) == NULL )
  301. continue;
  302. if( !(fd=sd->fd) )
  303. continue;
  304. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  305. continue;
  306. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  307. continue;
  308. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  309. continue;
  310. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  311. { // packet must exist for the client version
  312. WFIFOHEAD(fd,len);
  313. memcpy(WFIFOP(fd,0), buf, len);
  314. WFIFOSET(fd,len);
  315. }
  316. }
  317. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  318. break;
  319. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  320. if (session[i] && session[i]->func_parse == clif_parse &&
  321. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  322. sd->state.active && sd->partyspy == p->party.party_id &&
  323. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  324. { // packet must exist for the client version
  325. WFIFOHEAD(i,len);
  326. memcpy(WFIFOP(i,0), buf, len);
  327. WFIFOSET(i,len);
  328. }
  329. }
  330. }
  331. break;
  332. case DUEL:
  333. case DUEL_WOS:
  334. if (!sd || !sd->duel_group) break; //Invalid usage.
  335. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  336. for (i = 0; i < fd_max; i++) {
  337. if (session[i] && session[i]->func_parse == clif_parse &&
  338. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  339. sd->state.active && sd->duel_group == x0) {
  340. if (type == DUEL_WOS && bl->id == sd->bl.id)
  341. continue;
  342. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  343. WFIFOHEAD(i, len);
  344. memcpy(WFIFOP(i,0), buf, len);
  345. WFIFOSET(i,len);
  346. }
  347. }
  348. }
  349. break;
  350. case SELF:
  351. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  352. WFIFOHEAD(fd,len);
  353. memcpy(WFIFOP(fd,0), buf, len);
  354. WFIFOSET(fd,len);
  355. }
  356. break;
  357. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  358. case GUILD_AREA:
  359. case GUILD_AREA_WOS:
  360. x0 = bl->x - AREA_SIZE;
  361. y0 = bl->y - AREA_SIZE;
  362. x1 = bl->x + AREA_SIZE;
  363. y1 = bl->y + AREA_SIZE;
  364. case GUILD_SAMEMAP:
  365. case GUILD_SAMEMAP_WOS:
  366. case GUILD:
  367. case GUILD_WOS:
  368. if (sd && sd->status.guild_id)
  369. g = guild_search(sd->status.guild_id);
  370. if (g) {
  371. for(i = 0; i < g->max_member; i++) {
  372. if( (sd = g->member[i].sd) != NULL )
  373. {
  374. if( !(fd=sd->fd) )
  375. continue;
  376. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  377. continue;
  378. if( type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m )
  379. continue;
  380. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  381. continue;
  382. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  383. { // packet must exist for the client version
  384. WFIFOHEAD(fd,len);
  385. memcpy(WFIFOP(fd,0), buf, len);
  386. WFIFOSET(fd,len);
  387. }
  388. }
  389. }
  390. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  391. break;
  392. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  393. if (session[i] && session[i]->func_parse == clif_parse &&
  394. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  395. sd->state.active && sd->guildspy == g->guild_id &&
  396. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  397. { // packet must exist for the client version
  398. WFIFOHEAD(i,len);
  399. memcpy(WFIFOP(i,0), buf, len);
  400. WFIFOSET(i,len);
  401. }
  402. }
  403. }
  404. break;
  405. default:
  406. ShowError("clif_send: Unrecognized type %d\n",type);
  407. return -1;
  408. }
  409. return 0;
  410. }
  411. //
  412. // パケット作って送信
  413. //
  414. /*==========================================
  415. *
  416. *------------------------------------------*/
  417. int clif_authok(struct map_session_data *sd)
  418. {
  419. int fd;
  420. if (!sd->fd)
  421. return 0;
  422. fd = sd->fd;
  423. WFIFOHEAD(fd, packet_len(0x73));
  424. WFIFOW(fd, 0) = 0x73;
  425. WFIFOL(fd, 2) = gettick();
  426. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  427. WFIFOB(fd, 9) = 5; // ignored
  428. WFIFOB(fd,10) = 5; // ignored
  429. WFIFOSET(fd,packet_len(0x73));
  430. return 0;
  431. }
  432. /*==========================================
  433. * Authentication failed/disconnect client.
  434. *------------------------------------------
  435. * The client closes it's socket and displays a message according to type:
  436. * 1 - server closed -> MsgStringTable[4]
  437. * 2 - ID already logged in -> MsgStringTable[5]
  438. * 3 - timeout/too much lag -> MsgStringTable[241]
  439. * 4 - server full -> MsgStringTable[264]
  440. * 5 - underaged -> MsgStringTable[305]
  441. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  442. * 9 - too many connections from this ip -> MsgStringTable[529]
  443. * 10 - out of available time paid for -> MsgStringTable[530]
  444. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  445. * other - disconnected -> MsgStringTable[3]
  446. */
  447. int clif_authfail_fd(int fd, int type)
  448. {
  449. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  450. return 0;
  451. WFIFOHEAD(fd, packet_len(0x81));
  452. WFIFOW(fd,0) = 0x81;
  453. WFIFOB(fd,2) = type;
  454. WFIFOSET(fd,packet_len(0x81));
  455. set_eof(fd);
  456. return 0;
  457. }
  458. /*==========================================
  459. *
  460. *------------------------------------------*/
  461. int clif_charselectok(int id)
  462. {
  463. struct map_session_data* sd;
  464. int fd;
  465. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  466. return 1;
  467. fd = sd->fd;
  468. WFIFOHEAD(fd,packet_len(0xb3));
  469. WFIFOW(fd,0) = 0xb3;
  470. WFIFOB(fd,2) = 1;
  471. WFIFOSET(fd,packet_len(0xb3));
  472. return 0;
  473. }
  474. /*==========================================
  475. * Makes an item appear on the ground
  476. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  477. *------------------------------------------*/
  478. int clif_dropflooritem(struct flooritem_data* fitem)
  479. {
  480. uint8 buf[17];
  481. int view;
  482. nullpo_retr(0, fitem);
  483. if (fitem->item_data.nameid <= 0)
  484. return 0;
  485. WBUFW(buf, 0) = 0x9e;
  486. WBUFL(buf, 2) = fitem->bl.id;
  487. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  488. WBUFB(buf, 8) = fitem->item_data.identify;
  489. WBUFW(buf, 9) = fitem->bl.x;
  490. WBUFW(buf,11) = fitem->bl.y;
  491. WBUFB(buf,13) = fitem->subx;
  492. WBUFB(buf,14) = fitem->suby;
  493. WBUFW(buf,15) = fitem->item_data.amount;
  494. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  495. return 0;
  496. }
  497. /*==========================================
  498. *
  499. *------------------------------------------*/
  500. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  501. {
  502. unsigned char buf[16];
  503. nullpo_retr(0, fitem);
  504. WBUFW(buf,0) = 0xa1;
  505. WBUFL(buf,2) = fitem->bl.id;
  506. if (fd == 0) {
  507. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  508. } else {
  509. WFIFOHEAD(fd,packet_len(0xa1));
  510. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  511. WFIFOSET(fd,packet_len(0xa1));
  512. }
  513. return 0;
  514. }
  515. /*==========================================
  516. * make a unit (char, npc, mob, homun) disappear to one client
  517. * id : the id of the unit
  518. * type: 0 - moved out of sight
  519. * 1 - died
  520. * 2 - respawned
  521. * 3 - teleported / logged out
  522. * fd : the target client
  523. *------------------------------------------*/
  524. int clif_clearunit_single(int id, uint8 type, int fd)
  525. {
  526. WFIFOHEAD(fd, packet_len(0x80));
  527. WFIFOW(fd,0) = 0x80;
  528. WFIFOL(fd,2) = id;
  529. WFIFOB(fd,6) = type;
  530. WFIFOSET(fd, packet_len(0x80));
  531. return 0;
  532. }
  533. /*==========================================
  534. * make a unit (char, npc, mob, homun) disappear to all clients in area
  535. * type: 0 - moved out of sight
  536. * 1 - died
  537. * 2 - respawned
  538. * 3 - teleported / logged out
  539. *------------------------------------------*/
  540. int clif_clearunit_area(struct block_list* bl, uint8 type)
  541. {
  542. unsigned char buf[16];
  543. nullpo_retr(0, bl);
  544. WBUFW(buf,0) = 0x80;
  545. WBUFL(buf,2) = bl->id;
  546. WBUFB(buf,6) = type;
  547. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  548. if(disguised(bl)) {
  549. WBUFL(buf,2) = -bl->id;
  550. clif_send(buf, packet_len(0x80), bl, SELF);
  551. }
  552. return 0;
  553. }
  554. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr data)
  555. {
  556. struct block_list *bl = (struct block_list *)id;
  557. clif_clearunit_area(bl, 0);
  558. aFree(bl);
  559. return 0;
  560. }
  561. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  562. {
  563. struct block_list *tbl;
  564. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  565. memcpy (tbl, bl, sizeof (struct block_list));
  566. add_timer(tick, clif_clearunit_delayed_sub, (int)tbl, 0);
  567. return 0;
  568. }
  569. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  570. {
  571. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  572. {
  573. *rhand = *lhand = 0;
  574. return;
  575. }
  576. #if PACKETVER < 4
  577. *rhand = sd->status.weapon;
  578. *lhand = sd->status.shield;
  579. #else
  580. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  581. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  582. {
  583. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  584. if (id->view_id > 0)
  585. *rhand = id->view_id;
  586. else
  587. *rhand = id->nameid;
  588. } else
  589. *rhand = 0;
  590. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  591. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  592. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  593. {
  594. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  595. if (id->view_id > 0)
  596. *lhand = id->view_id;
  597. else
  598. *lhand = id->nameid;
  599. } else
  600. *lhand = 0;
  601. #endif
  602. }
  603. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  604. static int clif_setlevel(int lv)
  605. {
  606. if( lv < battle_config.max_lv )
  607. return lv;
  608. if( lv < battle_config.aura_lv )
  609. return battle_config.max_lv - 1;
  610. return battle_config.max_lv;
  611. }
  612. /*==========================================
  613. * Prepares 'unit standing/spawning' packet
  614. *------------------------------------------*/
  615. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  616. {
  617. struct map_session_data* sd;
  618. struct status_change* sc = status_get_sc(bl);
  619. struct view_data* vd = status_get_viewdata(bl);
  620. unsigned char *buf = WBUFP(buffer,0);
  621. bool type = !pcdb_checkid(vd->class_);
  622. #if PACKETVER >= 7
  623. unsigned short offset = 0;
  624. #endif
  625. sd = BL_CAST(BL_PC, bl);
  626. if(type)
  627. WBUFW(buf,0) = spawn?0x7c:0x78;
  628. else
  629. #if PACKETVER < 4
  630. WBUFW(buf,0) = spawn?0x79:0x78;
  631. #elif PACKETVER < 7
  632. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  633. #else
  634. WBUFW(buf,0) = spawn?0x22b:0x22a;
  635. #endif
  636. #if PACKETVER >= 20071106
  637. if (type) {
  638. // shift payload 1 byte to the right for mob packets
  639. WBUFB(buf,2) = 0; // padding?
  640. offset++;
  641. buf = WBUFP(buffer,offset);
  642. }
  643. #endif
  644. WBUFL(buf, 2) = bl->id;
  645. WBUFW(buf, 6) = status_get_speed(bl);
  646. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  647. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  648. if (type&&spawn) { //uses an older and different packet structure
  649. WBUFW(buf,12) = (sc)? sc->option : 0;
  650. WBUFW(buf,14) = vd->hair_style;
  651. WBUFW(buf,16) = vd->weapon;
  652. WBUFW(buf,18) = vd->head_bottom;
  653. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  654. WBUFW(buf,22) = vd->shield;
  655. } else {
  656. #if PACKETVER >= 7
  657. if (!type) {
  658. WBUFL(buf,12) = (sc)? sc->option : 0;
  659. offset+=2;
  660. buf = WBUFP(buffer,offset); //Shift 2 bytes to the right for the rest of fields
  661. } else
  662. #endif
  663. WBUFW(buf,12) = (sc)? sc->option : 0;
  664. WBUFW(buf,14) = vd->class_;
  665. WBUFW(buf,16) = vd->hair_style;
  666. WBUFW(buf,18) = vd->weapon;
  667. #if PACKETVER < 4
  668. WBUFW(buf,20) = vd->head_bottom;
  669. WBUFW(buf,22) = vd->shield;
  670. #else
  671. WBUFW(buf,20) = vd->shield;
  672. WBUFW(buf,22) = vd->head_bottom;
  673. #endif
  674. }
  675. WBUFW(buf,24) = vd->head_top;
  676. WBUFW(buf,26) = vd->head_mid;
  677. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  678. { //The hell, why flags work like this?
  679. WBUFL(buf,22) = status_get_emblem_id(bl);
  680. WBUFL(buf,26) = status_get_guild_id(bl);
  681. }
  682. WBUFW(buf,28) = vd->hair_color;
  683. WBUFW(buf,30) = vd->cloth_color;
  684. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  685. if (type&&spawn) { //End of packet 0x7c
  686. WBUFB(buf,34) = 0; // karma
  687. WBUFB(buf,35) = vd->sex;
  688. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  689. WBUFB(buf,39) = 0;
  690. WBUFB(buf,40) = 0;
  691. return packet_len(0x7c);
  692. }
  693. WBUFL(buf,34) = status_get_guild_id(bl);
  694. WBUFW(buf,38) = status_get_emblem_id(bl);
  695. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  696. #if PACKETVER >= 7
  697. if (!type) {
  698. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  699. offset+=2;
  700. buf = WBUFP(buffer,offset); //Shift additional 2 bytes...
  701. } else
  702. #endif
  703. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  704. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  705. WBUFB(buf,45) = vd->sex;
  706. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  707. WBUFB(buf,49) = (sd)? 5 : 0;
  708. WBUFB(buf,50) = (sd)? 5 : 0;
  709. if (spawn) {
  710. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  711. } else {
  712. WBUFB(buf,51) = vd->dead_sit;
  713. WBUFW(buf,52) = clif_setlevel(status_get_lv(bl));
  714. }
  715. return packet_len(WBUFW(buffer,0));
  716. }
  717. /*==========================================
  718. * Prepares 'unit walking' packet
  719. *------------------------------------------*/
  720. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  721. {
  722. struct map_session_data* sd;
  723. struct status_change* sc = status_get_sc(bl);
  724. struct view_data* vd = status_get_viewdata(bl);
  725. unsigned char* buf = WBUFP(buffer,0);
  726. #if PACKETVER >= 7
  727. unsigned short offset = 0;
  728. #endif
  729. sd = BL_CAST(BL_PC, bl);
  730. #if PACKETVER < 4
  731. WBUFW(buf, 0) = 0x7b;
  732. #elif PACKETVER < 7
  733. WBUFW(buf, 0) = 0x1da;
  734. #else
  735. WBUFW(buf, 0) = 0x22c;
  736. #endif
  737. #if PACKETVER >= 20071106
  738. WBUFB(buf, 2) = 0; // padding?
  739. offset++;
  740. buf = WBUFP(buf,offset);
  741. #endif
  742. WBUFL(buf, 2) = bl->id;
  743. WBUFW(buf, 6) = status_get_speed(bl);
  744. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  745. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  746. #if PACKETVER < 7
  747. WBUFW(buf,12) = (sc)? sc->option : 0;
  748. #else
  749. WBUFL(buf,12) = (sc)? sc->option : 0;
  750. offset+=2; //Shift the rest of elements by 2 bytes.
  751. buf = WBUFP(buffer,offset);
  752. #endif
  753. WBUFW(buf,14) = vd->class_;
  754. WBUFW(buf,16) = vd->hair_style;
  755. WBUFW(buf,18) = vd->weapon;
  756. #if PACKETVER < 4
  757. WBUFW(buf,20) = vd->head_bottom;
  758. WBUFL(buf,22) = gettick();
  759. WBUFW(buf,26) = vd->shield;
  760. #else
  761. WBUFW(buf,20) = vd->shield;
  762. WBUFW(buf,22) = vd->head_bottom;
  763. WBUFL(buf,24) = gettick();
  764. #endif
  765. WBUFW(buf,28) = vd->head_top;
  766. WBUFW(buf,30) = vd->head_mid;
  767. WBUFW(buf,32) = vd->hair_color;
  768. WBUFW(buf,34) = vd->cloth_color;
  769. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  770. WBUFL(buf,38) = status_get_guild_id(bl);
  771. WBUFW(buf,42) = status_get_emblem_id(bl);
  772. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  773. #if PACKETVER < 7
  774. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  775. #else
  776. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  777. offset+=2; //Shift the rest of elements by 2 bytes.
  778. buf = WBUFP(buffer,offset);
  779. #endif
  780. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  781. WBUFB(buf,49) = vd->sex;
  782. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  783. WBUFB(buf,56) = (sd)? 5 : 0;
  784. WBUFB(buf,57) = (sd)? 5 : 0;
  785. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  786. return packet_len(WBUFW(buffer,0));
  787. }
  788. //Modifies the buffer for disguise characters and sends it to self.
  789. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  790. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  791. {
  792. #if PACKETVER >= 20071106
  793. WBUFL(buf,3)=-bl->id;
  794. #else
  795. WBUFL(buf,2)=-bl->id;
  796. #endif
  797. clif_send(buf, len, bl, SELF);
  798. }
  799. /*==========================================
  800. * クラスチェンジ typeはMobの場合は1で他は0?
  801. *------------------------------------------*/
  802. int clif_class_change(struct block_list *bl,int class_,int type)
  803. {
  804. unsigned char buf[16];
  805. nullpo_retr(0, bl);
  806. if(!pcdb_checkid(class_)) {
  807. WBUFW(buf,0)=0x1b0;
  808. WBUFL(buf,2)=bl->id;
  809. WBUFB(buf,6)=type;
  810. WBUFL(buf,7)=class_;
  811. clif_send(buf,packet_len(0x1b0),bl,AREA);
  812. }
  813. return 0;
  814. }
  815. /*==========================================
  816. *
  817. *------------------------------------------*/
  818. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  819. {
  820. WFIFOHEAD(fd, packet_len(0x1e1));
  821. WFIFOW(fd,0)=0x1e1;
  822. WFIFOL(fd,2)=sd->bl.id;
  823. WFIFOW(fd,6)=sd->spiritball;
  824. WFIFOSET(fd, packet_len(0x1e1));
  825. }
  826. // new and improved weather display [Valaris]
  827. static void clif_weather_sub(int fd, int id, int type)
  828. {
  829. WFIFOHEAD(fd,packet_len(0x1f3));
  830. WFIFOW(fd,0) = 0x1f3;
  831. WFIFOL(fd,2) = id;
  832. WFIFOL(fd,6) = type;
  833. WFIFOSET(fd,packet_len(0x1f3));
  834. }
  835. /*==========================================
  836. *
  837. *------------------------------------------*/
  838. static void clif_weather_check(struct map_session_data *sd)
  839. {
  840. int m = sd->bl.m, fd = sd->fd;
  841. if (map[m].flag.snow
  842. || map[m].flag.clouds
  843. || map[m].flag.fog
  844. || map[m].flag.fireworks
  845. || map[m].flag.sakura
  846. || map[m].flag.leaves
  847. || map[m].flag.rain
  848. || map[m].flag.clouds2)
  849. {
  850. if (map[m].flag.snow)
  851. clif_weather_sub(fd, sd->bl.id, 162);
  852. if (map[m].flag.clouds)
  853. clif_weather_sub(fd, sd->bl.id, 233);
  854. if (map[m].flag.clouds2)
  855. clif_weather_sub(fd, sd->bl.id, 516);
  856. if (map[m].flag.fog)
  857. clif_weather_sub(fd, sd->bl.id, 515);
  858. if (map[m].flag.fireworks) {
  859. clif_weather_sub(fd, sd->bl.id, 297);
  860. clif_weather_sub(fd, sd->bl.id, 299);
  861. clif_weather_sub(fd, sd->bl.id, 301);
  862. }
  863. if (map[m].flag.sakura)
  864. clif_weather_sub(fd, sd->bl.id, 163);
  865. if (map[m].flag.leaves)
  866. clif_weather_sub(fd, sd->bl.id, 333);
  867. if (map[m].flag.rain)
  868. clif_weather_sub(fd, sd->bl.id, 161);
  869. }
  870. }
  871. void clif_weather(int m)
  872. {
  873. struct s_mapiterator* iter;
  874. struct map_session_data *sd=NULL;
  875. iter = mapit_getallusers();
  876. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  877. {
  878. if( sd->bl.m == m )
  879. clif_weather_check(sd);
  880. }
  881. mapit_free(iter);
  882. }
  883. int clif_spawn(struct block_list *bl)
  884. {
  885. unsigned char buf[128];
  886. struct view_data *vd;
  887. int len;
  888. vd = status_get_viewdata(bl);
  889. if( !vd || vd->class_ == INVISIBLE_CLASS )
  890. return 0;
  891. len = clif_set_unit_idle(bl, buf,true);
  892. clif_send(buf, len, bl, AREA_WOS);
  893. if (disguised(bl))
  894. clif_setdisguise(bl, buf, len);
  895. if (vd->cloth_color)
  896. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  897. switch (bl->type)
  898. {
  899. case BL_PC:
  900. {
  901. TBL_PC *sd = ((TBL_PC*)bl);
  902. if (sd->spiritball > 0)
  903. clif_spiritball(sd);
  904. if(sd->state.size==2) // tiny/big players [Valaris]
  905. clif_specialeffect(bl,423,AREA);
  906. else if(sd->state.size==1)
  907. clif_specialeffect(bl,421,AREA);
  908. }
  909. break;
  910. case BL_MOB:
  911. {
  912. TBL_MOB *md = ((TBL_MOB*)bl);
  913. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  914. clif_specialeffect(&md->bl,423,AREA);
  915. else if(md->special_state.size==1)
  916. clif_specialeffect(&md->bl,421,AREA);
  917. }
  918. break;
  919. case BL_NPC:
  920. {
  921. TBL_NPC *nd = ((TBL_NPC*)bl);
  922. if( nd->size == 2 )
  923. clif_specialeffect(&nd->bl,423,AREA);
  924. else if( nd->size == 1 )
  925. clif_specialeffect(&nd->bl,421,AREA);
  926. }
  927. break;
  928. case BL_PET:
  929. if (vd->head_bottom)
  930. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  931. break;
  932. }
  933. return 0;
  934. }
  935. //[orn]
  936. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  937. {
  938. struct status_data *status;
  939. unsigned char buf[128];
  940. nullpo_retr(0, hd);
  941. status = &hd->battle_status;
  942. memset(buf,0,packet_len(0x22e));
  943. WBUFW(buf,0)=0x22e;
  944. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  945. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  946. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  947. WBUFW(buf,27)=hd->homunculus.level;
  948. WBUFW(buf,29)=hd->homunculus.hunger;
  949. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  950. WBUFW(buf,33)=0; // equip id
  951. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  952. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  953. WBUFW(buf,39)=status->hit;
  954. if (battle_config.hom_setting&0x10)
  955. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  956. else
  957. WBUFW(buf,41)=status->cri/10;
  958. WBUFW(buf,43)=status->def + status->vit ;
  959. WBUFW(buf,45)=status->mdef;
  960. WBUFW(buf,47)=status->flee;
  961. WBUFW(buf,49)=(flag)?0:status->amotion;
  962. if (status->max_hp > SHRT_MAX) {
  963. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  964. WBUFW(buf,53) = 100;
  965. } else {
  966. WBUFW(buf,51)=status->hp;
  967. WBUFW(buf,53)=status->max_hp;
  968. }
  969. if (status->max_sp > SHRT_MAX) {
  970. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  971. WBUFW(buf,57) = 100;
  972. } else {
  973. WBUFW(buf,55)=status->sp;
  974. WBUFW(buf,57)=status->max_sp;
  975. }
  976. WBUFL(buf,59)=hd->homunculus.exp;
  977. WBUFL(buf,63)=hd->exp_next;
  978. WBUFW(buf,67)=hd->homunculus.skillpts;
  979. WBUFW(buf,69)=2; // FIXME: undocumented flag, seems to be '2' all the time [ultramage]
  980. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  981. return 0;
  982. }
  983. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  984. { //[orn]
  985. int fd = sd->fd;
  986. WFIFOHEAD(fd, packet_len(0x230));
  987. nullpo_retv(sd->hd);
  988. WFIFOW(fd,0)=0x230;
  989. WFIFOW(fd,2)=type;
  990. WFIFOL(fd,4)=sd->hd->bl.id;
  991. WFIFOL(fd,8)=param;
  992. WFIFOSET(fd,packet_len(0x230));
  993. return;
  994. }
  995. int clif_homskillinfoblock(struct map_session_data *sd)
  996. { //[orn]
  997. struct homun_data *hd;
  998. int fd = sd->fd;
  999. int i,j,len=4,id;
  1000. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1001. hd = sd->hd;
  1002. if ( !hd )
  1003. return 0 ;
  1004. WFIFOW(fd,0)=0x235;
  1005. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1006. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1007. j = id - HM_SKILLBASE ;
  1008. WFIFOW(fd,len ) = id ;
  1009. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1010. WFIFOW(fd,len+4) = 0 ;
  1011. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1012. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1013. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1014. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1015. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1016. len+=37;
  1017. }
  1018. }
  1019. WFIFOW(fd,2)=len;
  1020. WFIFOSET(fd,len);
  1021. return 0;
  1022. }
  1023. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1024. { //[orn]
  1025. struct homun_data *hd;
  1026. int fd=sd->fd, skillid;
  1027. WFIFOHEAD(fd, packet_len(0x239));
  1028. nullpo_retv(sd);
  1029. skillid = skill_num - HM_SKILLBASE;
  1030. hd=sd->hd;
  1031. WFIFOW(fd,0) = 0x239;
  1032. WFIFOW(fd,2) = skill_num;
  1033. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1034. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1035. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1036. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1037. WFIFOSET(fd,packet_len(0x239));
  1038. return;
  1039. }
  1040. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1041. {
  1042. int fd=sd->fd;
  1043. WFIFOHEAD(fd,packet_len(0x22f));
  1044. WFIFOW(fd,0)=0x22f;
  1045. WFIFOB(fd,2)=fail;
  1046. WFIFOW(fd,3)=foodid;
  1047. WFIFOSET(fd,packet_len(0x22f));
  1048. return 0;
  1049. }
  1050. /*==========================================
  1051. *
  1052. *------------------------------------------*/
  1053. int clif_walkok(struct map_session_data *sd)
  1054. {
  1055. int fd=sd->fd;
  1056. WFIFOHEAD(fd, packet_len(0x87));
  1057. WFIFOW(fd,0)=0x87;
  1058. WFIFOL(fd,2)=gettick();
  1059. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1060. WFIFOSET(fd,packet_len(0x87));
  1061. return 0;
  1062. }
  1063. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1064. {
  1065. uint8 buf[128];
  1066. int len;
  1067. len = clif_set_unit_walking(bl,ud,buf);
  1068. clif_send(buf,len,bl,AREA_WOS);
  1069. if (disguised(bl))
  1070. clif_setdisguise(bl, buf, len);
  1071. if(vd->cloth_color)
  1072. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1073. switch(bl->type)
  1074. {
  1075. case BL_PC:
  1076. {
  1077. TBL_PC *sd = ((TBL_PC*)bl);
  1078. // clif_movepc(sd);
  1079. if(sd->state.size==2) // tiny/big players [Valaris]
  1080. clif_specialeffect(&sd->bl,423,AREA);
  1081. else if(sd->state.size==1)
  1082. clif_specialeffect(&sd->bl,421,AREA);
  1083. }
  1084. break;
  1085. case BL_MOB:
  1086. {
  1087. TBL_MOB *md = ((TBL_MOB*)bl);
  1088. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1089. clif_specialeffect(&md->bl,423,AREA);
  1090. else if(md->special_state.size==1)
  1091. clif_specialeffect(&md->bl,421,AREA);
  1092. }
  1093. break;
  1094. }
  1095. return;
  1096. }
  1097. /// Move the unit (does nothing if the client has no info about the unit)
  1098. /// Note: unit must not be self
  1099. void clif_move(struct unit_data *ud)
  1100. {
  1101. unsigned char buf[16];
  1102. struct view_data* vd;
  1103. struct block_list* bl = ud->bl;
  1104. vd = status_get_viewdata(bl);
  1105. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1106. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1107. if (ud->state.speed_changed) {
  1108. // Since we don't know how to update the speed of other objects,
  1109. // use the old walk packet to update the data.
  1110. ud->state.speed_changed = 0;
  1111. clif_move2(bl, vd, ud);
  1112. return;
  1113. }
  1114. WBUFW(buf,0)=0x86;
  1115. WBUFL(buf,2)=bl->id;
  1116. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1117. WBUFL(buf,12)=gettick();
  1118. clif_send(buf, 16, bl, AREA_WOS);
  1119. if (disguised(bl))
  1120. {
  1121. WBUFL(buf,2)=-bl->id;
  1122. clif_send(buf, 16, bl, SELF);
  1123. }
  1124. }
  1125. /*==========================================
  1126. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1127. *------------------------------------------*/
  1128. static int clif_delayquit(int tid, unsigned int tick, int id, intptr data)
  1129. {
  1130. struct map_session_data *sd = NULL;
  1131. //Remove player from map server
  1132. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1133. map_quit(sd);
  1134. return 0;
  1135. }
  1136. /*==========================================
  1137. *
  1138. *------------------------------------------*/
  1139. void clif_quitsave(int fd,struct map_session_data *sd)
  1140. {
  1141. if (!battle_config.prevent_logout ||
  1142. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1143. map_quit(sd);
  1144. else if (sd->fd)
  1145. { //Disassociate session from player (session is deleted after this function was called)
  1146. //And set a timer to make him quit later.
  1147. session[sd->fd]->session_data = NULL;
  1148. sd->fd = 0;
  1149. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1150. }
  1151. }
  1152. /*==========================================
  1153. *
  1154. *------------------------------------------*/
  1155. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1156. {
  1157. int fd;
  1158. nullpo_retv(sd);
  1159. fd = sd->fd;
  1160. WFIFOHEAD(fd,packet_len(0x91));
  1161. WFIFOW(fd,0) = 0x91;
  1162. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1163. WFIFOW(fd,18) = x;
  1164. WFIFOW(fd,20) = y;
  1165. WFIFOSET(fd,packet_len(0x91));
  1166. }
  1167. /*==========================================
  1168. * Tells the client to connect to another map-server
  1169. *------------------------------------------*/
  1170. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1171. {
  1172. int fd;
  1173. nullpo_retv(sd);
  1174. fd = sd->fd;
  1175. WFIFOHEAD(fd,packet_len(0x92));
  1176. WFIFOW(fd,0) = 0x92;
  1177. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1178. WFIFOW(fd,18) = x;
  1179. WFIFOW(fd,20) = y;
  1180. WFIFOL(fd,22) = htonl(ip);
  1181. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1182. WFIFOSET(fd,packet_len(0x92));
  1183. }
  1184. int clif_blown(struct block_list *bl)
  1185. {
  1186. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1187. // return clif_fixpos(bl);
  1188. return clif_slide(bl, bl->x, bl->y);
  1189. }
  1190. /*==========================================
  1191. *
  1192. *------------------------------------------*/
  1193. int clif_fixpos(struct block_list *bl)
  1194. {
  1195. unsigned char buf[16];
  1196. nullpo_retr(0, bl);
  1197. WBUFW(buf,0)=0x88;
  1198. WBUFL(buf,2)=bl->id;
  1199. WBUFW(buf,6)=bl->x;
  1200. WBUFW(buf,8)=bl->y;
  1201. clif_send(buf, packet_len(0x88), bl, AREA);
  1202. if (disguised(bl)) {
  1203. WBUFL(buf,2)=-bl->id;
  1204. clif_send(buf, packet_len(0x88), bl, SELF);
  1205. }
  1206. return 0;
  1207. }
  1208. /*==========================================
  1209. *
  1210. *------------------------------------------*/
  1211. int clif_npcbuysell(struct map_session_data* sd, int id)
  1212. {
  1213. int fd;
  1214. nullpo_retr(0, sd);
  1215. fd=sd->fd;
  1216. WFIFOHEAD(fd, packet_len(0xc4));
  1217. WFIFOW(fd,0)=0xc4;
  1218. WFIFOL(fd,2)=id;
  1219. WFIFOSET(fd,packet_len(0xc4));
  1220. return 0;
  1221. }
  1222. /*==========================================
  1223. *
  1224. *------------------------------------------*/
  1225. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1226. {
  1227. int fd,i,c;
  1228. nullpo_retr(0, sd);
  1229. nullpo_retr(0, nd);
  1230. fd = sd->fd;
  1231. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1232. WFIFOW(fd,0) = 0xc6;
  1233. c = 0;
  1234. for( i = 0; i < nd->u.shop.count; i++ )
  1235. {
  1236. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1237. int val = nd->u.shop.shop_item[i].value;
  1238. if( id == NULL )
  1239. continue;
  1240. WFIFOL(fd, 4+c*11) = val;
  1241. if (!id->flag.value_notdc)
  1242. val = pc_modifybuyvalue(sd,val);
  1243. WFIFOL(fd, 8+c*11) = val;
  1244. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1245. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1246. c++;
  1247. }
  1248. WFIFOW(fd,2) = 4 + c*11;
  1249. WFIFOSET(fd,WFIFOW(fd,2));
  1250. return 0;
  1251. }
  1252. /*==========================================
  1253. *
  1254. *------------------------------------------*/
  1255. int clif_selllist(struct map_session_data *sd)
  1256. {
  1257. int fd,i,c=0,val;
  1258. nullpo_retr(0, sd);
  1259. fd=sd->fd;
  1260. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1261. WFIFOW(fd,0)=0xc7;
  1262. for(i=0;i<MAX_INVENTORY;i++) {
  1263. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1264. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1265. continue;
  1266. val=sd->inventory_data[i]->value_sell;
  1267. if (val < 0)
  1268. continue;
  1269. WFIFOW(fd,4+c*10)=i+2;
  1270. WFIFOL(fd,6+c*10)=val;
  1271. if (!sd->inventory_data[i]->flag.value_notoc)
  1272. val=pc_modifysellvalue(sd,val);
  1273. WFIFOL(fd,10+c*10)=val;
  1274. c++;
  1275. }
  1276. }
  1277. WFIFOW(fd,2)=c*10+4;
  1278. WFIFOSET(fd,WFIFOW(fd,2));
  1279. return 0;
  1280. }
  1281. /*==========================================
  1282. *
  1283. *------------------------------------------*/
  1284. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1285. {
  1286. int fd = sd->fd;
  1287. int slen = strlen(mes) + 9;
  1288. WFIFOHEAD(fd, slen);
  1289. WFIFOW(fd,0)=0xb4;
  1290. WFIFOW(fd,2)=slen;
  1291. WFIFOL(fd,4)=npcid;
  1292. strcpy((char*)WFIFOP(fd,8),mes);
  1293. WFIFOSET(fd,WFIFOW(fd,2));
  1294. return 0;
  1295. }
  1296. /*==========================================
  1297. *
  1298. *------------------------------------------*/
  1299. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1300. {
  1301. int fd;
  1302. nullpo_retr(0, sd);
  1303. fd=sd->fd;
  1304. WFIFOHEAD(fd, packet_len(0xb5));
  1305. WFIFOW(fd,0)=0xb5;
  1306. WFIFOL(fd,2)=npcid;
  1307. WFIFOSET(fd,packet_len(0xb5));
  1308. return 0;
  1309. }
  1310. /*==========================================
  1311. *
  1312. *------------------------------------------*/
  1313. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1314. {
  1315. int fd;
  1316. nullpo_retr(0, sd);
  1317. fd=sd->fd;
  1318. WFIFOHEAD(fd, packet_len(0xb6));
  1319. WFIFOW(fd,0)=0xb6;
  1320. WFIFOL(fd,2)=npcid;
  1321. WFIFOSET(fd,packet_len(0xb6));
  1322. return 0;
  1323. }
  1324. /*==========================================
  1325. *
  1326. *------------------------------------------*/
  1327. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1328. {
  1329. unsigned char *buf;
  1330. int fd = sd->fd;
  1331. sd->state.using_fake_npc = 1;
  1332. WFIFOHEAD(fd, packet_len(0x78));
  1333. buf = WFIFOP(fd,0);
  1334. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1335. WBUFW(buf,0)=0x78;
  1336. #if PACKETVER >= 20071106
  1337. WBUFB(buf,2) = 0; //Unknown bit
  1338. buf = WFIFOP(fd,1);
  1339. #endif
  1340. WBUFL(buf,2)=npcid;
  1341. WBUFW(buf,14)=111;
  1342. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1343. WBUFB(buf,49)=5;
  1344. WBUFB(buf,50)=5;
  1345. WFIFOSET(fd, packet_len(0x78));
  1346. return;
  1347. }
  1348. /*==========================================
  1349. *
  1350. *------------------------------------------*/
  1351. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1352. {
  1353. int fd = sd->fd;
  1354. int slen = strlen(mes) + 8;
  1355. struct block_list *bl = NULL;
  1356. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1357. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1358. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1359. clif_sendfakenpc(sd, npcid);
  1360. WFIFOHEAD(fd, slen);
  1361. WFIFOW(fd,0)=0xb7;
  1362. WFIFOW(fd,2)=slen;
  1363. WFIFOL(fd,4)=npcid;
  1364. strcpy((char*)WFIFOP(fd,8),mes);
  1365. WFIFOSET(fd,WFIFOW(fd,2));
  1366. return 0;
  1367. }
  1368. /*==========================================
  1369. *
  1370. *------------------------------------------*/
  1371. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1372. {
  1373. int fd;
  1374. struct block_list *bl = NULL;
  1375. nullpo_retr(0, sd);
  1376. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1377. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1378. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1379. clif_sendfakenpc(sd, npcid);
  1380. fd=sd->fd;
  1381. WFIFOHEAD(fd, packet_len(0x142));
  1382. WFIFOW(fd,0)=0x142;
  1383. WFIFOL(fd,2)=npcid;
  1384. WFIFOSET(fd,packet_len(0x142));
  1385. return 0;
  1386. }
  1387. /*==========================================
  1388. *
  1389. *------------------------------------------*/
  1390. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1391. {
  1392. int fd;
  1393. struct block_list *bl = NULL;
  1394. nullpo_retr(0, sd);
  1395. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1396. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1397. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1398. clif_sendfakenpc(sd, npcid);
  1399. fd=sd->fd;
  1400. WFIFOHEAD(fd, packet_len(0x1d4));
  1401. WFIFOW(fd,0)=0x1d4;
  1402. WFIFOL(fd,2)=npcid;
  1403. WFIFOSET(fd,packet_len(0x1d4));
  1404. return 0;
  1405. }
  1406. /// npc_id is ignored in the client
  1407. /// type=2 : Remove viewpoint
  1408. /// type=other : Show viewpoint
  1409. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1410. {
  1411. int fd;
  1412. nullpo_retr(0, sd);
  1413. fd=sd->fd;
  1414. WFIFOHEAD(fd, packet_len(0x144));
  1415. WFIFOW(fd,0)=0x144;
  1416. WFIFOL(fd,2)=npc_id;
  1417. WFIFOL(fd,6)=type;
  1418. WFIFOL(fd,10)=x;
  1419. WFIFOL(fd,14)=y;
  1420. WFIFOB(fd,18)=id;
  1421. WFIFOL(fd,19)=color;
  1422. WFIFOSET(fd,packet_len(0x144));
  1423. return 0;
  1424. }
  1425. /*==========================================
  1426. *
  1427. *------------------------------------------*/
  1428. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1429. {
  1430. int fd;
  1431. nullpo_retr(0, sd);
  1432. fd=sd->fd;
  1433. WFIFOHEAD(fd, packet_len(0x1b3));
  1434. WFIFOW(fd,0)=0x1b3;
  1435. strncpy((char*)WFIFOP(fd,2),image,64);
  1436. WFIFOB(fd,66)=type;
  1437. WFIFOSET(fd,packet_len(0x1b3));
  1438. return 0;
  1439. }
  1440. /*==========================================
  1441. * Fills in card data from the given item and into the buffer. [Skotlex]
  1442. *------------------------------------------*/
  1443. static void clif_addcards(unsigned char* buf, struct item* item)
  1444. {
  1445. int i=0,j;
  1446. if( item == NULL ) { //Blank data
  1447. WBUFW(buf,0) = 0;
  1448. WBUFW(buf,2) = 0;
  1449. WBUFW(buf,4) = 0;
  1450. WBUFW(buf,6) = 0;
  1451. return;
  1452. }
  1453. if( item->card[0] == CARD0_PET ) { //pet eggs
  1454. WBUFW(buf,0) = 0;
  1455. WBUFW(buf,2) = 0;
  1456. WBUFW(buf,4) = 0;
  1457. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1458. return;
  1459. }
  1460. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1461. WBUFW(buf,0) = item->card[0];
  1462. WBUFW(buf,2) = item->card[1];
  1463. WBUFW(buf,4) = item->card[2];
  1464. WBUFW(buf,6) = item->card[3];
  1465. return;
  1466. }
  1467. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1468. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1469. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1470. //Normal items.
  1471. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1472. WBUFW(buf,0) = j;
  1473. else
  1474. WBUFW(buf,0) = item->card[i];
  1475. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1476. WBUFW(buf,2) = j;
  1477. else
  1478. WBUFW(buf,2) = item->card[i];
  1479. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1480. WBUFW(buf,4) = j;
  1481. else
  1482. WBUFW(buf,4) = item->card[i];
  1483. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1484. WBUFW(buf,6) = j;
  1485. else
  1486. WBUFW(buf,6) = item->card[i];
  1487. }
  1488. /*==========================================
  1489. *
  1490. *------------------------------------------*/
  1491. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1492. {
  1493. int fd;
  1494. nullpo_retr(0, sd);
  1495. fd = sd->fd;
  1496. if (!session_isActive(fd)) //Sasuke-
  1497. return 0;
  1498. WFIFOHEAD(fd,packet_len(0xa0));
  1499. if(fail) {
  1500. WFIFOW(fd,0)=0xa0;
  1501. WFIFOW(fd,2)=n+2;
  1502. WFIFOW(fd,4)=amount;
  1503. WFIFOW(fd,6)=0;
  1504. WFIFOB(fd,8)=0;
  1505. WFIFOB(fd,9)=0;
  1506. WFIFOB(fd,10)=0;
  1507. WFIFOW(fd,11)=0;
  1508. WFIFOW(fd,13)=0;
  1509. WFIFOW(fd,15)=0;
  1510. WFIFOW(fd,17)=0;
  1511. WFIFOW(fd,19)=0;
  1512. WFIFOB(fd,21)=0;
  1513. WFIFOB(fd,22)=fail;
  1514. } else {
  1515. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1516. return 1;
  1517. WFIFOW(fd,0)=0xa0;
  1518. WFIFOW(fd,2)=n+2;
  1519. WFIFOW(fd,4)=amount;
  1520. if (sd->inventory_data[n]->view_id > 0)
  1521. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1522. else
  1523. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1524. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1525. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1526. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1527. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1528. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1529. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1530. WFIFOB(fd,22)=fail;
  1531. }
  1532. WFIFOSET(fd,packet_len(0xa0));
  1533. return 0;
  1534. }
  1535. /*==========================================
  1536. *
  1537. *------------------------------------------*/
  1538. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1539. {
  1540. int fd;
  1541. nullpo_retr(0, sd);
  1542. fd=sd->fd;
  1543. WFIFOHEAD(fd, packet_len(0xaf));
  1544. WFIFOW(fd,0)=0xaf;
  1545. WFIFOW(fd,2)=n+2;
  1546. WFIFOW(fd,4)=amount;
  1547. WFIFOSET(fd,packet_len(0xaf));
  1548. return 0;
  1549. }
  1550. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1551. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1552. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1553. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1554. {
  1555. if (id->view_id > 0)
  1556. WBUFW(buf,n)=id->view_id;
  1557. else
  1558. WBUFW(buf,n)=i->nameid;
  1559. WBUFB(buf,n+2)=itemtype(id->type);
  1560. WBUFB(buf,n+3)=i->identify;
  1561. if (equip >= 0) { //Equippable item
  1562. WBUFW(buf,n+4)=equip;
  1563. WBUFW(buf,n+6)=i->equip;
  1564. WBUFB(buf,n+8)=i->attribute;
  1565. WBUFB(buf,n+9)=i->refine;
  1566. } else { //Stackable item.
  1567. WBUFW(buf,n+4)=i->amount;
  1568. if (equip == -2 && id->equip == EQP_AMMO)
  1569. WBUFW(buf,n+6)=EQP_AMMO;
  1570. else
  1571. WBUFW(buf,n+6)=0;
  1572. }
  1573. }
  1574. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1575. void clif_inventorylist(struct map_session_data *sd)
  1576. {
  1577. int i,n,ne,fd = sd->fd,arrow=-1;
  1578. unsigned char *buf;
  1579. unsigned char bufe[MAX_INVENTORY*20+4];
  1580. #if PACKETVER < 5
  1581. const int s = 10; //Entry size.
  1582. #else
  1583. const int s = 18;
  1584. #endif
  1585. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1586. buf = WFIFOP(fd,0);
  1587. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1588. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1589. continue;
  1590. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1591. { //Non-stackable (Equippable)
  1592. WBUFW(bufe,ne*20+4)=i+2;
  1593. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1594. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1595. ne++;
  1596. } else { //Stackable.
  1597. WBUFW(buf,n*s+4)=i+2;
  1598. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1599. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1600. sd->status.inventory[i].equip)
  1601. arrow=i;
  1602. #if PACKETVER >= 5
  1603. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1604. #endif
  1605. n++;
  1606. }
  1607. }
  1608. if (n) {
  1609. #if PACKETVER < 5
  1610. WBUFW(buf,0)=0xa3;
  1611. #else
  1612. WBUFW(buf,0)=0x1ee;
  1613. #endif
  1614. WBUFW(buf,2)=4+n*s;
  1615. WFIFOSET(fd,WFIFOW(fd,2));
  1616. }
  1617. if(arrow >= 0)
  1618. clif_arrowequip(sd,arrow);
  1619. if(ne){
  1620. WBUFW(bufe,0)=0xa4;
  1621. WBUFW(bufe,2)=4+ne*20;
  1622. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1623. }
  1624. }
  1625. //Required when items break/get-repaired. Only sends equippable item list.
  1626. void clif_equiplist(struct map_session_data *sd)
  1627. {
  1628. int i,n,fd = sd->fd;
  1629. unsigned char *buf;
  1630. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1631. buf = WFIFOP(fd,0);
  1632. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1633. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1634. continue;
  1635. if(itemdb_isstackable2(sd->inventory_data[i]))
  1636. continue;
  1637. //Equippable
  1638. WBUFW(buf,n*20+4)=i+2;
  1639. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1640. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1641. n++;
  1642. }
  1643. if (n) {
  1644. WBUFW(buf,0)=0xa4;
  1645. WBUFW(buf,2)=4+n*20;
  1646. WFIFOSET(fd,WFIFOW(fd,2));
  1647. }
  1648. }
  1649. void clif_storagelist(struct map_session_data* sd, struct storage_data* stor)
  1650. {
  1651. struct item_data *id;
  1652. int i,n,ne,fd=sd->fd;
  1653. unsigned char *buf;
  1654. unsigned char bufe[MAX_STORAGE*20+4];
  1655. #if PACKETVER < 5
  1656. const int s = 10; //Entry size.
  1657. #else
  1658. const int s = 18;
  1659. #endif
  1660. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1661. buf = WFIFOP(fd,0);
  1662. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1663. if(stor->items[i].nameid<=0)
  1664. continue;
  1665. id = itemdb_search(stor->items[i].nameid);
  1666. if(!itemdb_isstackable2(id))
  1667. { //Equippable
  1668. WBUFW(bufe,ne*20+4)=i+1;
  1669. clif_item_sub(bufe, ne*20+6, &stor->items[i], id, id->equip);
  1670. clif_addcards(WBUFP(bufe, ne*20+16), &stor->items[i]);
  1671. ne++;
  1672. } else { //Stackable
  1673. WBUFW(buf,n*s+4)=i+1;
  1674. clif_item_sub(buf, n*s+6, &stor->items[i], id,-1);
  1675. #if PACKETVER >= 5
  1676. clif_addcards(WBUFP(buf,n*s+14), &stor->items[i]);
  1677. #endif
  1678. n++;
  1679. }
  1680. }
  1681. if(n){
  1682. #if PACKETVER < 5
  1683. WBUFW(buf,0)=0xa5;
  1684. #else
  1685. WBUFW(buf,0)=0x1f0;
  1686. #endif
  1687. WBUFW(buf,2)=4+n*s;
  1688. WFIFOSET(fd,WFIFOW(fd,2));
  1689. }
  1690. if(ne){
  1691. WBUFW(bufe,0)=0xa6;
  1692. WBUFW(bufe,2)=4+ne*20;
  1693. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1694. }
  1695. }
  1696. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1697. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1698. {
  1699. struct item_data *id;
  1700. int i,n,ne,fd=sd->fd;
  1701. unsigned char *buf;
  1702. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1703. #if PACKETVER < 5
  1704. const int s = 10; //Entry size.
  1705. #else
  1706. const int s = 18;
  1707. #endif
  1708. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1709. buf = WFIFOP(fd,0);
  1710. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1711. if(stor->storage_[i].nameid<=0)
  1712. continue;
  1713. id = itemdb_search(stor->storage_[i].nameid);
  1714. if(!itemdb_isstackable2(id))
  1715. { //Equippable
  1716. WBUFW(bufe,ne*20+4)=i+1;
  1717. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1718. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1719. ne++;
  1720. } else { //Stackable
  1721. WBUFW(buf,n*s+4)=i+1;
  1722. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1723. #if PACKETVER >= 5
  1724. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1725. #endif
  1726. n++;
  1727. }
  1728. }
  1729. if(n){
  1730. #if PACKETVER < 5
  1731. WBUFW(buf,0)=0xa5;
  1732. #else
  1733. WBUFW(buf,0)=0x1f0;
  1734. #endif
  1735. WBUFW(buf,2)=4+n*s;
  1736. WFIFOSET(fd,WFIFOW(fd,2));
  1737. }
  1738. if(ne){
  1739. WBUFW(bufe,0)=0xa6;
  1740. WBUFW(bufe,2)=4+ne*20;
  1741. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1742. }
  1743. }
  1744. void clif_cartlist(struct map_session_data *sd)
  1745. {
  1746. struct item_data *id;
  1747. int i,n,ne,fd=sd->fd;
  1748. unsigned char *buf;
  1749. unsigned char bufe[MAX_CART*20+4];
  1750. #if PACKETVER < 5
  1751. const int s = 10; //Entry size.
  1752. #else
  1753. const int s = 18;
  1754. #endif
  1755. WFIFOHEAD(fd, MAX_CART * s + 4);
  1756. buf = WFIFOP(fd,0);
  1757. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  1758. if(sd->status.cart[i].nameid<=0)
  1759. continue;
  1760. id = itemdb_search(sd->status.cart[i].nameid);
  1761. if(!itemdb_isstackable2(id))
  1762. { //Equippable
  1763. WBUFW(bufe,ne*20+4)=i+2;
  1764. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  1765. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  1766. ne++;
  1767. } else { //Stackable
  1768. WBUFW(buf,n*s+4)=i+2;
  1769. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  1770. #if PACKETVER >= 5
  1771. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  1772. #endif
  1773. n++;
  1774. }
  1775. }
  1776. if(n){
  1777. #if PACKETVER < 5
  1778. WBUFW(buf,0)=0x123;
  1779. #else
  1780. WBUFW(buf,0)=0x1ef;
  1781. #endif
  1782. WBUFW(buf,2)=4+n*s;
  1783. WFIFOSET(fd,WFIFOW(fd,2));
  1784. }
  1785. if(ne){
  1786. WBUFW(bufe,0)=0x122;
  1787. WBUFW(bufe,2)=4+ne*20;
  1788. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1789. }
  1790. return;
  1791. }
  1792. /// Client behaviour:
  1793. /// Closes the cart storage and removes all it's items from memory.
  1794. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  1795. void clif_clearcart(int fd)
  1796. {
  1797. WFIFOHEAD(fd, packet_len(0x12b));
  1798. WFIFOW(fd,0) = 0x12b;
  1799. }
  1800. // Guild XY locators [Valaris]
  1801. int clif_guild_xy(struct map_session_data *sd)
  1802. {
  1803. unsigned char buf[10];
  1804. nullpo_retr(0, sd);
  1805. WBUFW(buf,0)=0x1eb;
  1806. WBUFL(buf,2)=sd->status.account_id;
  1807. WBUFW(buf,6)=sd->bl.x;
  1808. WBUFW(buf,8)=sd->bl.y;
  1809. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1810. return 0;
  1811. }
  1812. /*==========================================
  1813. * Sends x/y dot to a single fd. [Skotlex]
  1814. *------------------------------------------*/
  1815. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  1816. {
  1817. WFIFOHEAD(fd,packet_len(0x1eb));
  1818. WFIFOW(fd,0)=0x1eb;
  1819. WFIFOL(fd,2)=sd->status.account_id;
  1820. WFIFOW(fd,6)=sd->bl.x;
  1821. WFIFOW(fd,8)=sd->bl.y;
  1822. WFIFOSET(fd,packet_len(0x1eb));
  1823. return 0;
  1824. }
  1825. // Guild XY locators [Valaris]
  1826. int clif_guild_xy_remove(struct map_session_data *sd)
  1827. {
  1828. unsigned char buf[10];
  1829. nullpo_retr(0, sd);
  1830. WBUFW(buf,0)=0x1eb;
  1831. WBUFL(buf,2)=sd->status.account_id;
  1832. WBUFW(buf,6)=-1;
  1833. WBUFW(buf,8)=-1;
  1834. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1835. return 0;
  1836. }
  1837. /*==========================================
  1838. * ステータスを送りつける
  1839. * 表示専用数字はこの中で計算して送る
  1840. *------------------------------------------*/
  1841. int clif_updatestatus(struct map_session_data *sd,int type)
  1842. {
  1843. int fd,len=8;
  1844. nullpo_retr(0, sd);
  1845. fd=sd->fd;
  1846. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  1847. return 0;
  1848. WFIFOHEAD(fd, 14);
  1849. WFIFOW(fd,0)=0xb0;
  1850. WFIFOW(fd,2)=type;
  1851. switch(type){
  1852. // 00b0
  1853. case SP_WEIGHT:
  1854. pc_updateweightstatus(sd);
  1855. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  1856. WFIFOW(fd,2)=type;
  1857. WFIFOL(fd,4)=sd->weight;
  1858. break;
  1859. case SP_MAXWEIGHT:
  1860. WFIFOL(fd,4)=sd->max_weight;
  1861. break;
  1862. case SP_SPEED:
  1863. WFIFOL(fd,4)=sd->battle_status.speed;
  1864. break;
  1865. case SP_BASELEVEL:
  1866. WFIFOL(fd,4)=sd->status.base_level;
  1867. break;
  1868. case SP_JOBLEVEL:
  1869. WFIFOL(fd,4)=sd->status.job_level;
  1870. break;
  1871. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  1872. WFIFOL(fd,4)=sd->status.karma;
  1873. break;
  1874. case SP_MANNER:
  1875. WFIFOL(fd,4)=sd->status.manner;
  1876. break;
  1877. case SP_STATUSPOINT:
  1878. WFIFOL(fd,4)=sd->status.status_point;
  1879. break;
  1880. case SP_SKILLPOINT:
  1881. WFIFOL(fd,4)=sd->status.skill_point;
  1882. break;
  1883. case SP_HIT:
  1884. WFIFOL(fd,4)=sd->battle_status.hit;
  1885. break;
  1886. case SP_FLEE1:
  1887. WFIFOL(fd,4)=sd->battle_status.flee;
  1888. break;
  1889. case SP_FLEE2:
  1890. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  1891. break;
  1892. case SP_MAXHP:
  1893. WFIFOL(fd,4)=sd->battle_status.max_hp;
  1894. break;
  1895. case SP_MAXSP:
  1896. WFIFOL(fd,4)=sd->battle_status.max_sp;
  1897. break;
  1898. case SP_HP:
  1899. WFIFOL(fd,4)=sd->battle_status.hp;
  1900. if (battle_config.disp_hpmeter)
  1901. clif_hpmeter(sd);
  1902. if (!battle_config.party_hp_mode && sd->status.party_id)
  1903. clif_party_hp(sd);
  1904. break;
  1905. case SP_SP:
  1906. WFIFOL(fd,4)=sd->battle_status.sp;
  1907. break;
  1908. case SP_ASPD:
  1909. WFIFOL(fd,4)=sd->battle_status.amotion;
  1910. break;
  1911. case SP_ATK1:
  1912. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  1913. break;
  1914. case SP_DEF1:
  1915. WFIFOL(fd,4)=sd->battle_status.def;
  1916. break;
  1917. case SP_MDEF1:
  1918. WFIFOL(fd,4)=sd->battle_status.mdef;
  1919. break;
  1920. case SP_ATK2:
  1921. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  1922. break;
  1923. case SP_DEF2:
  1924. WFIFOL(fd,4)=sd->battle_status.def2;
  1925. break;
  1926. case SP_MDEF2:
  1927. //negative check (in case you have something like Berserk active)
  1928. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  1929. if (len < 0) len = 0;
  1930. WFIFOL(fd,4)= len;
  1931. len = 8;
  1932. break;
  1933. case SP_CRITICAL:
  1934. WFIFOL(fd,4)=sd->battle_status.cri/10;
  1935. break;
  1936. case SP_MATK1:
  1937. WFIFOL(fd,4)=sd->battle_status.matk_max;
  1938. break;
  1939. case SP_MATK2:
  1940. WFIFOL(fd,4)=sd->battle_status.matk_min;
  1941. break;
  1942. case SP_ZENY:
  1943. WFIFOW(fd,0)=0xb1;
  1944. WFIFOL(fd,4)=sd->status.zeny;
  1945. break;
  1946. case SP_BASEEXP:
  1947. WFIFOW(fd,0)=0xb1;
  1948. WFIFOL(fd,4)=sd->status.base_exp;
  1949. break;
  1950. case SP_JOBEXP:
  1951. WFIFOW(fd,0)=0xb1;
  1952. WFIFOL(fd,4)=sd->status.job_exp;
  1953. break;
  1954. case SP_NEXTBASEEXP:
  1955. WFIFOW(fd,0)=0xb1;
  1956. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  1957. break;
  1958. case SP_NEXTJOBEXP:
  1959. WFIFOW(fd,0)=0xb1;
  1960. WFIFOL(fd,4)=pc_nextjobexp(sd);
  1961. break;
  1962. // 00be 終了
  1963. case SP_USTR:
  1964. case SP_UAGI:
  1965. case SP_UVIT:
  1966. case SP_UINT:
  1967. case SP_UDEX:
  1968. case SP_ULUK:
  1969. WFIFOW(fd,0)=0xbe;
  1970. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  1971. len=5;
  1972. break;
  1973. // 013a 終了
  1974. case SP_ATTACKRANGE:
  1975. WFIFOW(fd,0)=0x13a;
  1976. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  1977. len=4;
  1978. break;
  1979. // 0141 終了
  1980. case SP_STR:
  1981. WFIFOW(fd,0)=0x141;
  1982. WFIFOL(fd,2)=type;
  1983. WFIFOL(fd,6)=sd->status.str;
  1984. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  1985. len=14;
  1986. break;
  1987. case SP_AGI:
  1988. WFIFOW(fd,0)=0x141;
  1989. WFIFOL(fd,2)=type;
  1990. WFIFOL(fd,6)=sd->status.agi;
  1991. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  1992. len=14;
  1993. break;
  1994. case SP_VIT:
  1995. WFIFOW(fd,0)=0x141;
  1996. WFIFOL(fd,2)=type;
  1997. WFIFOL(fd,6)=sd->status.vit;
  1998. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  1999. len=14;
  2000. break;
  2001. case SP_INT:
  2002. WFIFOW(fd,0)=0x141;
  2003. WFIFOL(fd,2)=type;
  2004. WFIFOL(fd,6)=sd->status.int_;
  2005. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2006. len=14;
  2007. break;
  2008. case SP_DEX:
  2009. WFIFOW(fd,0)=0x141;
  2010. WFIFOL(fd,2)=type;
  2011. WFIFOL(fd,6)=sd->status.dex;
  2012. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2013. len=14;
  2014. break;
  2015. case SP_LUK:
  2016. WFIFOW(fd,0)=0x141;
  2017. WFIFOL(fd,2)=type;
  2018. WFIFOL(fd,6)=sd->status.luk;
  2019. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2020. len=14;
  2021. break;
  2022. case SP_CARTINFO:
  2023. WFIFOW(fd,0)=0x121;
  2024. WFIFOW(fd,2)=sd->cart_num;
  2025. WFIFOW(fd,4)=MAX_CART;
  2026. WFIFOL(fd,6)=sd->cart_weight;
  2027. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2028. len=14;
  2029. break;
  2030. default:
  2031. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2032. return 1;
  2033. }
  2034. WFIFOSET(fd,len);
  2035. return 0;
  2036. }
  2037. int clif_changestatus(struct block_list *bl,int type,int val)
  2038. {
  2039. unsigned char buf[12];
  2040. struct map_session_data *sd = NULL;
  2041. nullpo_retr(0, bl);
  2042. if(bl->type == BL_PC)
  2043. sd = (struct map_session_data *)bl;
  2044. if(sd){
  2045. WBUFW(buf,0)=0x1ab;
  2046. WBUFL(buf,2)=bl->id;
  2047. WBUFW(buf,6)=type;
  2048. switch(type){
  2049. case SP_MANNER:
  2050. WBUFL(buf,8)=val;
  2051. break;
  2052. default:
  2053. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2054. return 1;
  2055. }
  2056. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2057. }
  2058. return 0;
  2059. }
  2060. /*==========================================
  2061. *
  2062. *------------------------------------------*/
  2063. void clif_changelook(struct block_list *bl,int type,int val)
  2064. {
  2065. unsigned char buf[16];
  2066. struct map_session_data* sd = NULL;
  2067. struct view_data* vd;
  2068. nullpo_retv(bl);
  2069. sd = BL_CAST(BL_PC, bl);
  2070. vd = status_get_viewdata(bl);
  2071. //nullpo_ret(vd);
  2072. if( vd ) //temp hack to let Warp Portal change appearance
  2073. switch(type)
  2074. {
  2075. case LOOK_WEAPON:
  2076. if (sd)
  2077. {
  2078. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2079. val = vd->weapon;
  2080. }
  2081. else vd->weapon = val;
  2082. break;
  2083. case LOOK_SHIELD:
  2084. if (sd)
  2085. {
  2086. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2087. val = vd->shield;
  2088. }
  2089. else vd->shield = val;
  2090. break;
  2091. case LOOK_BASE:
  2092. vd->class_ = val;
  2093. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2094. vd->weapon = vd->shield = 0;
  2095. if (vd->cloth_color && (
  2096. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2097. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2098. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2099. ))
  2100. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2101. break;
  2102. case LOOK_HAIR:
  2103. vd->hair_style = val;
  2104. break;
  2105. case LOOK_HEAD_BOTTOM:
  2106. vd->head_bottom = val;
  2107. break;
  2108. case LOOK_HEAD_TOP:
  2109. vd->head_top = val;
  2110. break;
  2111. case LOOK_HEAD_MID:
  2112. vd->head_mid = val;
  2113. break;
  2114. case LOOK_HAIR_COLOR:
  2115. vd->hair_color = val;
  2116. break;
  2117. case LOOK_CLOTHES_COLOR:
  2118. if (val && (
  2119. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2120. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2121. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2122. ))
  2123. val = 0;
  2124. vd->cloth_color = val;
  2125. break;
  2126. case LOOK_SHOES:
  2127. #if PACKETVER > 3
  2128. if (sd) {
  2129. int n;
  2130. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2131. if(sd->inventory_data[n]->view_id > 0)
  2132. val = sd->inventory_data[n]->view_id;
  2133. else
  2134. val = sd->status.inventory[n].nameid;
  2135. }
  2136. val = 0;
  2137. }
  2138. #endif
  2139. //Shoes? No packet uses this....
  2140. break;
  2141. }
  2142. #if PACKETVER < 4
  2143. WBUFW(buf,0)=0xc3;
  2144. WBUFL(buf,2)=bl->id;
  2145. WBUFB(buf,6)=type;
  2146. WBUFB(buf,7)=val;
  2147. clif_send(buf,packet_len(0xc3),bl,AREA);
  2148. #else
  2149. WBUFW(buf,0)=0x1d7;
  2150. WBUFL(buf,2)=bl->id;
  2151. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2152. WBUFB(buf,6)=LOOK_WEAPON;
  2153. WBUFW(buf,7)=vd->weapon;
  2154. WBUFW(buf,9)=vd->shield;
  2155. } else {
  2156. WBUFB(buf,6)=type;
  2157. WBUFW(buf,7)=val;
  2158. WBUFW(buf,9)=0;
  2159. }
  2160. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2161. #endif
  2162. }
  2163. //Sends a change-base-look packet required for traps as they are triggered.
  2164. void clif_changetraplook(struct block_list *bl,int val)
  2165. {
  2166. unsigned char buf[32];
  2167. #if PACKETVER < 4
  2168. WBUFW(buf,0)=0xc3;
  2169. WBUFL(buf,2)=bl->id;
  2170. WBUFB(buf,6)=LOOK_BASE;
  2171. WBUFB(buf,7)=val;
  2172. clif_send(buf,packet_len(0xc3),bl,AREA);
  2173. #else
  2174. WBUFW(buf,0)=0x1d7;
  2175. WBUFL(buf,2)=bl->id;
  2176. WBUFB(buf,6)=LOOK_BASE;
  2177. WBUFW(buf,7)=val;
  2178. WBUFW(buf,9)=0;
  2179. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2180. #endif
  2181. }
  2182. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2183. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2184. {
  2185. unsigned char buf[32];
  2186. #if PACKETVER < 4
  2187. WBUFW(buf,0)=0xc3;
  2188. WBUFL(buf,2)=id;
  2189. WBUFB(buf,6)=type;
  2190. WBUFB(buf,7)=val;
  2191. clif_send(buf,packet_len(0xc3),bl,target);
  2192. #else
  2193. WBUFW(buf,0)=0x1d7;
  2194. WBUFL(buf,2)=id;
  2195. WBUFB(buf,6)=type;
  2196. WBUFW(buf,7)=val;
  2197. WBUFW(buf,9)=0;
  2198. clif_send(buf,packet_len(0x1d7),bl,target);
  2199. #endif
  2200. return;
  2201. }
  2202. /*==========================================
  2203. *
  2204. *------------------------------------------*/
  2205. int clif_initialstatus(struct map_session_data *sd)
  2206. {
  2207. int fd;
  2208. unsigned char *buf;
  2209. nullpo_retr(0, sd);
  2210. fd=sd->fd;
  2211. WFIFOHEAD(fd,packet_len(0xbd));
  2212. buf=WFIFOP(fd,0);
  2213. WBUFW(buf,0)=0xbd;
  2214. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2215. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2216. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2217. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2218. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2219. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2220. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2221. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2222. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2223. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2224. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2225. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2226. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2227. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2228. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2229. WBUFW(buf,20) = sd->battle_status.matk_max;
  2230. WBUFW(buf,22) = sd->battle_status.matk_min;
  2231. WBUFW(buf,24) = sd->battle_status.def; // def
  2232. WBUFW(buf,26) = sd->battle_status.def2;
  2233. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2234. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2235. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2236. WBUFW(buf,30) = fd;
  2237. fd = sd->fd;
  2238. WBUFW(buf,32) = sd->battle_status.hit;
  2239. WBUFW(buf,34) = sd->battle_status.flee;
  2240. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2241. WBUFW(buf,38) = sd->battle_status.cri/10;
  2242. WBUFW(buf,40) = sd->status.karma;
  2243. WBUFW(buf,42) = sd->status.manner;
  2244. WFIFOSET(fd,packet_len(0xbd));
  2245. clif_updatestatus(sd,SP_STR);
  2246. clif_updatestatus(sd,SP_AGI);
  2247. clif_updatestatus(sd,SP_VIT);
  2248. clif_updatestatus(sd,SP_INT);
  2249. clif_updatestatus(sd,SP_DEX);
  2250. clif_updatestatus(sd,SP_LUK);
  2251. clif_updatestatus(sd,SP_ATTACKRANGE);
  2252. clif_updatestatus(sd,SP_ASPD);
  2253. return 0;
  2254. }
  2255. /*==========================================
  2256. *矢装備
  2257. *------------------------------------------*/
  2258. int clif_arrowequip(struct map_session_data *sd,int val)
  2259. {
  2260. int fd;
  2261. nullpo_retr(0, sd);
  2262. pc_stop_attack(sd); // [Valaris]
  2263. fd=sd->fd;
  2264. WFIFOHEAD(fd, packet_len(0x013c));
  2265. WFIFOW(fd,0)=0x013c;
  2266. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2267. WFIFOSET(fd,packet_len(0x013c));
  2268. return 0;
  2269. }
  2270. /// Ammunition action message.
  2271. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2272. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2273. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2274. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2275. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2276. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2277. int clif_arrow_fail(struct map_session_data *sd,int type)
  2278. {
  2279. int fd;
  2280. nullpo_retr(0, sd);
  2281. fd=sd->fd;
  2282. WFIFOHEAD(fd, packet_len(0x013b));
  2283. WFIFOW(fd,0)=0x013b;
  2284. WFIFOW(fd,2)=type;
  2285. WFIFOSET(fd,packet_len(0x013b));
  2286. return 0;
  2287. }
  2288. /*==========================================
  2289. * 作成可能 矢リスト送信
  2290. *------------------------------------------*/
  2291. int clif_arrow_create_list(struct map_session_data *sd)
  2292. {
  2293. int i, c, j;
  2294. int fd;
  2295. nullpo_retr(0, sd);
  2296. fd = sd->fd;
  2297. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2298. WFIFOW(fd,0) = 0x1ad;
  2299. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2300. if (skill_arrow_db[i].nameid > 0 &&
  2301. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2302. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2303. {
  2304. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2305. WFIFOW(fd,c*2+4) = j;
  2306. else
  2307. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2308. c++;
  2309. }
  2310. }
  2311. WFIFOW(fd,2) = c*2+4;
  2312. WFIFOSET(fd, WFIFOW(fd,2));
  2313. if (c > 0) {
  2314. sd->menuskill_id = AC_MAKINGARROW;
  2315. sd->menuskill_val = c;
  2316. }
  2317. return 0;
  2318. }
  2319. /*==========================================
  2320. *
  2321. *------------------------------------------*/
  2322. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2323. {
  2324. int fd;
  2325. nullpo_retr(0, sd);
  2326. fd=sd->fd;
  2327. WFIFOHEAD(fd,packet_len(0xbc));
  2328. WFIFOW(fd,0)=0xbc;
  2329. WFIFOW(fd,2)=type;
  2330. WFIFOB(fd,4)=ok;
  2331. WFIFOB(fd,5)=cap_value(val,0,UCHAR_MAX);
  2332. WFIFOSET(fd,packet_len(0xbc));
  2333. return 0;
  2334. }
  2335. /*==========================================
  2336. *
  2337. *------------------------------------------*/
  2338. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2339. {
  2340. int fd;
  2341. nullpo_retr(0, sd);
  2342. fd=sd->fd;
  2343. WFIFOHEAD(fd,packet_len(0xaa));
  2344. WFIFOW(fd,0)=0xaa;
  2345. WFIFOW(fd,2)=n+2;
  2346. WFIFOW(fd,4)=pos;
  2347. WFIFOB(fd,6)=ok;
  2348. WFIFOSET(fd,packet_len(0xaa));
  2349. return 0;
  2350. }
  2351. /*==========================================
  2352. *
  2353. *------------------------------------------*/
  2354. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2355. {
  2356. int fd;
  2357. nullpo_retr(0, sd);
  2358. fd=sd->fd;
  2359. WFIFOHEAD(fd,packet_len(0xac));
  2360. WFIFOW(fd,0)=0xac;
  2361. WFIFOW(fd,2)=n+2;
  2362. WFIFOW(fd,4)=pos;
  2363. WFIFOB(fd,6)=ok;
  2364. WFIFOSET(fd,packet_len(0xac));
  2365. return 0;
  2366. }
  2367. /*==========================================
  2368. *
  2369. *------------------------------------------*/
  2370. int clif_misceffect(struct block_list* bl,int type)
  2371. {
  2372. unsigned char buf[32];
  2373. nullpo_retr(0, bl);
  2374. WBUFW(buf,0) = 0x19b;
  2375. WBUFL(buf,2) = bl->id;
  2376. WBUFL(buf,6) = type;
  2377. clif_send(buf,packet_len(0x19b),bl,AREA);
  2378. return 0;
  2379. }
  2380. int clif_misceffect2(struct block_list *bl, int type)
  2381. {
  2382. unsigned char buf[24];
  2383. nullpo_retr(0, bl);
  2384. memset(buf, 0, packet_len(0x1f3));
  2385. WBUFW(buf,0) = 0x1f3;
  2386. WBUFL(buf,2) = bl->id;
  2387. WBUFL(buf,6) = type;
  2388. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2389. return 0;
  2390. }
  2391. /*==========================================
  2392. * 表示オプション変更
  2393. *------------------------------------------*/
  2394. int clif_changeoption(struct block_list* bl)
  2395. {
  2396. unsigned char buf[32];
  2397. struct status_change *sc;
  2398. nullpo_retr(0, bl);
  2399. sc = status_get_sc(bl);
  2400. if (!sc) return 0; //How can an option change if there's no sc?
  2401. #if PACKETVER >= 7
  2402. WBUFW(buf,0) = 0x229;
  2403. WBUFL(buf,2) = bl->id;
  2404. WBUFW(buf,6) = sc->opt1;
  2405. WBUFW(buf,8) = sc->opt2;
  2406. WBUFL(buf,10) = sc->option;
  2407. WBUFB(buf,14) = 0; // PK???
  2408. if(disguised(bl)) {
  2409. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2410. WBUFL(buf,2) = -bl->id;
  2411. clif_send(buf,packet_len(0x229),bl,SELF);
  2412. WBUFL(buf,2) = bl->id;
  2413. WBUFL(buf,10) = OPTION_INVISIBLE;
  2414. clif_send(buf,packet_len(0x229),bl,SELF);
  2415. } else
  2416. clif_send(buf,packet_len(0x229),bl,AREA);
  2417. #else
  2418. WBUFW(buf,0) = 0x119;
  2419. WBUFL(buf,2) = bl->id;
  2420. WBUFW(buf,6) = sc->opt1;
  2421. WBUFW(buf,8) = sc->opt2;
  2422. WBUFW(buf,10) = sc->option;
  2423. WBUFB(buf,12) = 0; // ??
  2424. if(disguised(bl)) {
  2425. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2426. WBUFL(buf,2) = -bl->id;
  2427. clif_send(buf,packet_len(0x119),bl,SELF);
  2428. WBUFL(buf,2) = bl->id;
  2429. WBUFW(buf,10) = OPTION_INVISIBLE;
  2430. clif_send(buf,packet_len(0x119),bl,SELF);
  2431. } else
  2432. clif_send(buf,packet_len(0x119),bl,AREA);
  2433. #endif
  2434. return 0;
  2435. }
  2436. int clif_changeoption2(struct block_list* bl)
  2437. {
  2438. unsigned char buf[20];
  2439. struct status_change *sc;
  2440. sc = status_get_sc(bl);
  2441. if (!sc) return 0; //How can an option change if there's no sc?
  2442. WBUFW(buf,0) = 0x28a;
  2443. WBUFL(buf,2) = bl->id;
  2444. WBUFL(buf,6) = sc->option;
  2445. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2446. WBUFL(buf,14) = sc->opt3;
  2447. if(disguised(bl)) {
  2448. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2449. WBUFL(buf,2) = -bl->id;
  2450. clif_send(buf,packet_len(0x28a),bl,SELF);
  2451. WBUFL(buf,2) = bl->id;
  2452. WBUFL(buf,6) = OPTION_INVISIBLE;
  2453. clif_send(buf,packet_len(0x28a),bl,SELF);
  2454. } else
  2455. clif_send(buf,packet_len(0x28a),bl,AREA);
  2456. return 0;
  2457. }
  2458. /*==========================================
  2459. *
  2460. *------------------------------------------*/
  2461. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2462. {
  2463. nullpo_retr(0, sd);
  2464. if(!ok) {
  2465. int fd=sd->fd;
  2466. WFIFOHEAD(fd,packet_len(0xa8));
  2467. WFIFOW(fd,0)=0xa8;
  2468. WFIFOW(fd,2)=index+2;
  2469. WFIFOW(fd,4)=amount;
  2470. WFIFOB(fd,6)=ok;
  2471. WFIFOSET(fd,packet_len(0xa8));
  2472. }
  2473. else {
  2474. #if PACKETVER < 3
  2475. int fd=sd->fd;
  2476. WFIFOHEAD(fd,packet_len(0xa8));
  2477. WFIFOW(fd,0)=0xa8;
  2478. WFIFOW(fd,2)=index+2;
  2479. WFIFOW(fd,4)=amount;
  2480. WFIFOB(fd,6)=ok;
  2481. WFIFOSET(fd,packet_len(0xa8));
  2482. #else
  2483. unsigned char buf[32];
  2484. WBUFW(buf,0)=0x1c8;
  2485. WBUFW(buf,2)=index+2;
  2486. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2487. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2488. else
  2489. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2490. WBUFL(buf,6)=sd->bl.id;
  2491. WBUFW(buf,10)=amount;
  2492. WBUFB(buf,12)=ok;
  2493. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2494. #endif
  2495. }
  2496. return 0;
  2497. }
  2498. /*==========================================
  2499. * Inform client whether chatroom creation was successful or not
  2500. * R 00d6 <fail>.B
  2501. *------------------------------------------*/
  2502. void clif_createchat(struct map_session_data* sd, int fail)
  2503. {
  2504. int fd;
  2505. nullpo_retv(sd);
  2506. fd = sd->fd;
  2507. WFIFOHEAD(fd,packet_len(0xd6));
  2508. WFIFOW(fd,0) = 0xd6;
  2509. WFIFOB(fd,2) = fail;
  2510. WFIFOSET(fd,packet_len(0xd6));
  2511. }
  2512. /*==========================================
  2513. * Display a chat above the owner
  2514. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2515. *------------------------------------------*/
  2516. int clif_dispchat(struct chat_data* cd, int fd)
  2517. {
  2518. unsigned char buf[128];
  2519. uint8 type;
  2520. if( cd == NULL || cd->owner == NULL )
  2521. return 1;
  2522. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2523. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2524. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2525. : 1;
  2526. WBUFW(buf, 0) = 0xd7;
  2527. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2528. WBUFL(buf, 4) = cd->owner->id;
  2529. WBUFL(buf, 8) = cd->bl.id;
  2530. WBUFW(buf,12) = cd->limit;
  2531. WBUFW(buf,14) = cd->users;
  2532. WBUFB(buf,16) = type;
  2533. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2534. if( fd ) {
  2535. WFIFOHEAD(fd,WBUFW(buf,2));
  2536. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2537. WFIFOSET(fd,WBUFW(buf,2));
  2538. } else {
  2539. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2540. }
  2541. return 0;
  2542. }
  2543. /*==========================================
  2544. * Chatroom properties adjustment
  2545. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2546. *------------------------------------------*/
  2547. int clif_changechatstatus(struct chat_data* cd)
  2548. {
  2549. unsigned char buf[128];
  2550. if( cd == NULL || cd->usersd[0] == NULL )
  2551. return 1;
  2552. WBUFW(buf, 0) = 0xdf;
  2553. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2554. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2555. WBUFL(buf, 8) = cd->bl.id;
  2556. WBUFW(buf,12) = cd->limit;
  2557. WBUFW(buf,14) = cd->users;
  2558. WBUFB(buf,16) = cd->pub;
  2559. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2560. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2561. return 0;
  2562. }
  2563. /*==========================================
  2564. *
  2565. *------------------------------------------*/
  2566. int clif_clearchat(struct chat_data *cd,int fd)
  2567. {
  2568. unsigned char buf[32];
  2569. nullpo_retr(0, cd);
  2570. WBUFW(buf,0) = 0xd8;
  2571. WBUFL(buf,2) = cd->bl.id;
  2572. if( fd ) {
  2573. WFIFOHEAD(fd,packet_len(0xd8));
  2574. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2575. WFIFOSET(fd,packet_len(0xd8));
  2576. } else {
  2577. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2578. }
  2579. return 0;
  2580. }
  2581. /*==========================================
  2582. *
  2583. *------------------------------------------*/
  2584. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2585. {
  2586. int fd;
  2587. nullpo_retr(0, sd);
  2588. fd = sd->fd;
  2589. WFIFOHEAD(fd,packet_len(0xda));
  2590. WFIFOW(fd,0) = 0xda;
  2591. WFIFOB(fd,2) = fail;
  2592. WFIFOSET(fd,packet_len(0xda));
  2593. return 0;
  2594. }
  2595. /*==========================================
  2596. *
  2597. *------------------------------------------*/
  2598. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2599. {
  2600. int fd;
  2601. int i;
  2602. nullpo_retr(0, sd);
  2603. nullpo_retr(0, cd);
  2604. fd = sd->fd;
  2605. if (!session_isActive(fd))
  2606. return 0;
  2607. WFIFOHEAD(fd, 8 + (28*cd->users));
  2608. WFIFOW(fd, 0) = 0xdb;
  2609. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2610. WFIFOL(fd, 4) = cd->bl.id;
  2611. for (i = 0; i < cd->users; i++) {
  2612. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2613. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2614. }
  2615. WFIFOSET(fd, WFIFOW(fd, 2));
  2616. return 0;
  2617. }
  2618. /*==========================================
  2619. *
  2620. *------------------------------------------*/
  2621. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2622. {
  2623. unsigned char buf[32];
  2624. nullpo_retr(0, sd);
  2625. nullpo_retr(0, cd);
  2626. WBUFW(buf, 0) = 0x0dc;
  2627. WBUFW(buf, 2) = cd->users;
  2628. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2629. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2630. return 0;
  2631. }
  2632. /*==========================================
  2633. * Announce the new owner
  2634. * R 00e1 <index>.l <nick>.24B
  2635. *------------------------------------------*/
  2636. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2637. {
  2638. unsigned char buf[64];
  2639. nullpo_retv(sd);
  2640. nullpo_retv(cd);
  2641. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2642. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2643. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2644. WBUFW(buf, 0) = 0xe1;
  2645. WBUFL(buf, 2) = 1;
  2646. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2647. WBUFW(buf,30) = 0xe1;
  2648. WBUFL(buf,32) = 0;
  2649. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2650. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2651. }
  2652. /*==========================================
  2653. * Notify about user leaving the chatroom
  2654. * R 00dd <index>.w <nick>.24B <flag>.B
  2655. *------------------------------------------*/
  2656. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2657. {
  2658. unsigned char buf[32];
  2659. nullpo_retv(sd);
  2660. nullpo_retv(cd);
  2661. WBUFW(buf, 0) = 0xdd;
  2662. WBUFW(buf, 2) = cd->users-1;
  2663. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2664. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2665. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2666. }
  2667. /*==========================================
  2668. * Opens a trade request window from char 'name'
  2669. * R 00e5 <nick>.24B
  2670. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2671. *------------------------------------------*/
  2672. void clif_traderequest(struct map_session_data* sd, const char* name)
  2673. {
  2674. int fd = sd->fd;
  2675. #if PACKETVER < 6
  2676. WFIFOHEAD(fd,packet_len(0xe5));
  2677. WFIFOW(fd,0) = 0xe5;
  2678. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2679. WFIFOSET(fd,packet_len(0xe5));
  2680. #else
  2681. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2682. if( !tsd ) return;
  2683. WFIFOHEAD(fd,packet_len(0x1f4));
  2684. WFIFOW(fd,0) = 0x1f4;
  2685. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2686. WFIFOL(fd,26) = tsd->status.char_id;
  2687. WFIFOW(fd,30) = clif_setlevel(tsd->status.base_level);
  2688. WFIFOSET(fd,packet_len(0x1f4));
  2689. #endif
  2690. }
  2691. /*==========================================
  2692. * Reply to a trade-request.
  2693. * R 00e7 <type>.B
  2694. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2695. * Type:
  2696. * 0: Char is too far
  2697. * 1: Character does not exist
  2698. * 2: Trade failed
  2699. * 3: Accept
  2700. * 4: Cancel
  2701. *------------------------------------------*/
  2702. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2703. {
  2704. int fd = sd->fd;
  2705. #if PACKETVER < 6
  2706. WFIFOHEAD(fd,packet_len(0xe7));
  2707. WFIFOW(fd,0) = 0xe7;
  2708. WFIFOB(fd,2) = type;
  2709. WFIFOSET(fd,packet_len(0xe7));
  2710. #else
  2711. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2712. if( !tsd ) return;
  2713. WFIFOHEAD(fd,packet_len(0x1f5));
  2714. WFIFOW(fd,0) = 0x1f5;
  2715. WFIFOB(fd,2) = type;
  2716. WFIFOL(fd,3) = tsd->status.char_id;
  2717. WFIFOW(fd,7) = clif_setlevel(tsd->status.base_level);
  2718. WFIFOSET(fd,packet_len(0x1f5));
  2719. #endif
  2720. }
  2721. /*==========================================
  2722. * 相手方からのアイテム追加
  2723. *------------------------------------------*/
  2724. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  2725. {
  2726. int fd;
  2727. nullpo_retv(sd);
  2728. nullpo_retv(tsd);
  2729. fd = tsd->fd;
  2730. WFIFOHEAD(fd,packet_len(0xe9));
  2731. WFIFOW(fd,0) = 0xe9;
  2732. WFIFOL(fd,2) = amount;
  2733. if( index == 0 )
  2734. {
  2735. WFIFOW(fd,6) = 0; // type id
  2736. WFIFOB(fd,8) = 0; //identify flag
  2737. WFIFOB(fd,9) = 0; // attribute
  2738. WFIFOB(fd,10)= 0; //refine
  2739. WFIFOW(fd,11)= 0; //card (4w)
  2740. WFIFOW(fd,13)= 0; //card (4w)
  2741. WFIFOW(fd,15)= 0; //card (4w)
  2742. WFIFOW(fd,17)= 0; //card (4w)
  2743. }
  2744. else
  2745. {
  2746. index -= 2; //index fix
  2747. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2748. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2749. else
  2750. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2751. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2752. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2753. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2754. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2755. }
  2756. WFIFOSET(fd,packet_len(0xe9));
  2757. }
  2758. /*==========================================
  2759. * アイテム追加成功/失敗
  2760. *------------------------------------------*/
  2761. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  2762. {
  2763. int fd;
  2764. nullpo_retv(sd);
  2765. fd = sd->fd;
  2766. WFIFOHEAD(fd,packet_len(0xea));
  2767. WFIFOW(fd,0) = 0xea;
  2768. WFIFOW(fd,2) = index;
  2769. WFIFOB(fd,4) = fail;
  2770. WFIFOSET(fd,packet_len(0xea));
  2771. }
  2772. /*==========================================
  2773. * 取り引きok押し
  2774. *------------------------------------------*/
  2775. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  2776. {
  2777. int fd;
  2778. nullpo_retv(sd);
  2779. fd = sd->fd;
  2780. WFIFOHEAD(fd,packet_len(0xec));
  2781. WFIFOW(fd,0) = 0xec;
  2782. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  2783. WFIFOSET(fd,packet_len(0xec));
  2784. }
  2785. /*==========================================
  2786. * 取り引きがキャンセルされました
  2787. *------------------------------------------*/
  2788. void clif_tradecancelled(struct map_session_data* sd)
  2789. {
  2790. int fd;
  2791. nullpo_retv(sd);
  2792. fd = sd->fd;
  2793. WFIFOHEAD(fd,packet_len(0xee));
  2794. WFIFOW(fd,0) = 0xee;
  2795. WFIFOSET(fd,packet_len(0xee));
  2796. }
  2797. /*==========================================
  2798. * 取り引き完了
  2799. *------------------------------------------*/
  2800. void clif_tradecompleted(struct map_session_data* sd, int fail)
  2801. {
  2802. int fd;
  2803. nullpo_retv(sd);
  2804. fd = sd->fd;
  2805. WFIFOHEAD(fd,packet_len(0xf0));
  2806. WFIFOW(fd,0) = 0xf0;
  2807. WFIFOB(fd,2) = fail;
  2808. WFIFOSET(fd,packet_len(0xf0));
  2809. }
  2810. /*==========================================
  2811. * カプラ倉庫のアイテム数を更新
  2812. *------------------------------------------*/
  2813. void clif_updatestorageamount(struct map_session_data* sd, int amount)
  2814. {
  2815. int fd;
  2816. nullpo_retv(sd);
  2817. fd=sd->fd;
  2818. WFIFOHEAD(fd,packet_len(0xf2));
  2819. WFIFOW(fd,0) = 0xf2; // update storage amount
  2820. WFIFOW(fd,2) = amount; //items
  2821. WFIFOW(fd,4) = MAX_STORAGE; //items max
  2822. WFIFOSET(fd,packet_len(0xf2));
  2823. }
  2824. /*==========================================
  2825. * カプラ倉庫にアイテムを追加する
  2826. *------------------------------------------*/
  2827. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2828. {
  2829. int view,fd;
  2830. nullpo_retv(sd);
  2831. nullpo_retv(i);
  2832. fd=sd->fd;
  2833. view = itemdb_viewid(i->nameid);
  2834. #if PACKETVER < 5
  2835. WFIFOHEAD(fd,packet_len(0xf4));
  2836. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2837. WFIFOW(fd, 2) = index+1; // index
  2838. WFIFOL(fd, 4) = amount; // amount
  2839. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2840. WFIFOB(fd,10) = i->identify; //identify flag
  2841. WFIFOB(fd,11) = i->attribute; // attribute
  2842. WFIFOB(fd,12) = i->refine; //refine
  2843. clif_addcards(WFIFOP(fd,13), i);
  2844. WFIFOSET(fd,packet_len(0xf4));
  2845. #else
  2846. WFIFOHEAD(fd,packet_len(0x1c4));
  2847. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  2848. WFIFOW(fd, 2) = index+1; // index
  2849. WFIFOL(fd, 4) = amount; // amount
  2850. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2851. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  2852. WFIFOB(fd,11) = i->identify; //identify flag
  2853. WFIFOB(fd,12) = i->attribute; // attribute
  2854. WFIFOB(fd,13) = i->refine; //refine
  2855. clif_addcards(WFIFOP(fd,14), i);
  2856. WFIFOSET(fd,packet_len(0x1c4));
  2857. #endif
  2858. }
  2859. /*==========================================
  2860. *
  2861. *------------------------------------------*/
  2862. void clif_updateguildstorageamount(struct map_session_data* sd, int amount)
  2863. {
  2864. int fd;
  2865. nullpo_retv(sd);
  2866. fd=sd->fd;
  2867. WFIFOHEAD(fd,packet_len(0xf2));
  2868. WFIFOW(fd,0) = 0xf2; // update storage amount
  2869. WFIFOW(fd,2) = amount; //items
  2870. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  2871. WFIFOSET(fd,packet_len(0xf2));
  2872. }
  2873. /*==========================================
  2874. *
  2875. *------------------------------------------*/
  2876. void clif_guildstorageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2877. {
  2878. int view,fd;
  2879. nullpo_retv(sd);
  2880. nullpo_retv(i);
  2881. fd=sd->fd;
  2882. view = itemdb_viewid(i->nameid);
  2883. WFIFOHEAD(fd,packet_len(0xf4));
  2884. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2885. WFIFOW(fd, 2) = index+1; // index
  2886. WFIFOL(fd, 4) = amount; // amount
  2887. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2888. WFIFOB(fd,10) = i->identify; //identify flag
  2889. WFIFOB(fd,11) = i->attribute; // attribute
  2890. WFIFOB(fd,12) = i->refine; //refine
  2891. clif_addcards(WFIFOP(fd,13), i);
  2892. WFIFOSET(fd,packet_len(0xf4));
  2893. }
  2894. /*==========================================
  2895. * カプラ倉庫からアイテムを取り去る
  2896. *------------------------------------------*/
  2897. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  2898. {
  2899. int fd;
  2900. nullpo_retv(sd);
  2901. fd=sd->fd;
  2902. WFIFOHEAD(fd,packet_len(0xf6));
  2903. WFIFOW(fd,0)=0xf6; // Storage item removed
  2904. WFIFOW(fd,2)=index+1;
  2905. WFIFOL(fd,4)=amount;
  2906. WFIFOSET(fd,packet_len(0xf6));
  2907. }
  2908. /*==========================================
  2909. * カプラ倉庫を閉じる
  2910. *------------------------------------------*/
  2911. void clif_storageclose(struct map_session_data* sd)
  2912. {
  2913. int fd;
  2914. nullpo_retv(sd);
  2915. fd=sd->fd;
  2916. WFIFOHEAD(fd,packet_len(0xf8));
  2917. WFIFOW(fd,0) = 0xf8; // Storage Closed
  2918. WFIFOSET(fd,packet_len(0xf8));
  2919. }
  2920. /*==========================================
  2921. * PC表示
  2922. *------------------------------------------*/
  2923. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  2924. {
  2925. struct map_session_data* tmpsd;
  2926. int gmlvl;
  2927. int i;
  2928. if(dstsd->chatID)
  2929. {
  2930. struct chat_data *cd;
  2931. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  2932. if(cd && cd->usersd[0]==dstsd)
  2933. clif_dispchat(cd,sd->fd);
  2934. }
  2935. if(dstsd->vender_id)
  2936. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  2937. if(dstsd->spiritball > 0)
  2938. clif_spiritball_single(sd->fd, dstsd);
  2939. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  2940. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd))
  2941. )
  2942. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  2943. // display link (sd - dstsd) to sd
  2944. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  2945. if( i < 5 ) clif_devotion(sd, sd);
  2946. // display links (dstsd - devotees) to sd
  2947. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  2948. if( i < 5 ) clif_devotion(dstsd, sd);
  2949. // display link (dstsd - crusader) to sd
  2950. if( dstsd->sc.data[SC_DEVOTION] && (tmpsd = map_id2sd(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  2951. clif_devotion(tmpsd, sd);
  2952. // pvp circle for duel [LuzZza]
  2953. //if(dstsd->duel_group)
  2954. // clif_specialeffect(&dstsd->bl, 159, 4);
  2955. }
  2956. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  2957. {
  2958. uint8 buf[128];
  2959. struct unit_data *ud;
  2960. struct view_data *vd;
  2961. int len;
  2962. vd = status_get_viewdata(bl);
  2963. if (!vd || vd->class_ == INVISIBLE_CLASS)
  2964. return;
  2965. ud = unit_bl2ud(bl);
  2966. len = ( ud && ud->walktimer != -1 ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  2967. clif_send(buf,len,&sd->bl,SELF);
  2968. if (vd->cloth_color)
  2969. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  2970. switch (bl->type)
  2971. {
  2972. case BL_PC:
  2973. {
  2974. TBL_PC* tsd = (TBL_PC*)bl;
  2975. clif_getareachar_pc(sd, tsd);
  2976. if(tsd->state.size==2) // tiny/big players [Valaris]
  2977. clif_specialeffect_single(bl,423,sd->fd);
  2978. else if(tsd->state.size==1)
  2979. clif_specialeffect_single(bl,421,sd->fd);
  2980. }
  2981. break;
  2982. case BL_NPC:
  2983. {
  2984. TBL_NPC* nd = (TBL_NPC*)bl;
  2985. if( nd->chat_id )
  2986. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  2987. if( nd->size == 2 )
  2988. clif_specialeffect_single(bl,423,sd->fd);
  2989. else if( nd->size == 1 )
  2990. clif_specialeffect_single(bl,421,sd->fd);
  2991. }
  2992. break;
  2993. case BL_MOB:
  2994. {
  2995. TBL_MOB* md = (TBL_MOB*)bl;
  2996. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  2997. clif_specialeffect_single(bl,423,sd->fd);
  2998. else if(md->special_state.size==1)
  2999. clif_specialeffect_single(bl,421,sd->fd);
  3000. }
  3001. break;
  3002. case BL_PET:
  3003. if (vd->head_bottom)
  3004. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3005. break;
  3006. }
  3007. }
  3008. //Modifies the type of damage according to status changes [Skotlex]
  3009. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3010. #define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
  3011. /*==========================================
  3012. * Estimates walk delay based on the damage criteria. [Skotlex]
  3013. *------------------------------------------*/
  3014. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3015. {
  3016. if (type == 4 || type == 9 || damage <=0)
  3017. return 0;
  3018. if (bl->type == BL_PC) {
  3019. if (battle_config.pc_walk_delay_rate != 100)
  3020. delay = delay*battle_config.pc_walk_delay_rate/100;
  3021. } else
  3022. if (battle_config.walk_delay_rate != 100)
  3023. delay = delay*battle_config.walk_delay_rate/100;
  3024. if (div_ > 1) //Multi-hit skills mean higher delays.
  3025. delay += battle_config.multihit_delay*(div_-1);
  3026. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3027. }
  3028. /*==========================================
  3029. * Sends a 'damage' packet (src performs action on dst)
  3030. * R 008a <src ID>.l <dst ID>.l <server tick>.l <src speed>.l <dst speed>.l <param1>.w <param2>.w <type>.B <param3>.w
  3031. *
  3032. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3033. * type=01 pick up item
  3034. * type=02 sit down
  3035. * type=03 stand up
  3036. * type=04 reflected/absorbed damage?
  3037. * type=08 double attack
  3038. * type=09 don't display flinch animation (endure)
  3039. * type=0a critical hit
  3040. * type=0b lucky dodge
  3041. *------------------------------------------*/
  3042. 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)
  3043. {
  3044. unsigned char buf[256];
  3045. struct status_change *sc;
  3046. nullpo_retr(0, src);
  3047. nullpo_retr(0, dst);
  3048. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3049. sc = status_get_sc(dst);
  3050. if(sc && sc->count) {
  3051. if(sc->data[SC_HALLUCINATION]) {
  3052. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3053. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3054. }
  3055. }
  3056. WBUFW(buf,0)=0x8a;
  3057. WBUFL(buf,2)=src->id;
  3058. WBUFL(buf,6)=dst->id;
  3059. WBUFL(buf,10)=tick;
  3060. WBUFL(buf,14)=sdelay;
  3061. WBUFL(buf,18)=ddelay;
  3062. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3063. WBUFW(buf,22)=damage?div:0;
  3064. WBUFW(buf,27)=damage2?div:0;
  3065. } else {
  3066. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3067. WBUFW(buf,27)=damage2;
  3068. }
  3069. WBUFW(buf,24)=div;
  3070. WBUFB(buf,26)=type;
  3071. if(disguised(dst)) {
  3072. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3073. WBUFL(buf,6) = -dst->id;
  3074. clif_send(buf,packet_len(0x8a),dst,SELF);
  3075. } else
  3076. clif_send(buf,packet_len(0x8a),dst,AREA);
  3077. if(disguised(src)) {
  3078. WBUFL(buf,2) = -src->id;
  3079. if (disguised(dst))
  3080. WBUFL(buf,6) = dst->id;
  3081. if(damage > 0) WBUFW(buf,22) = -1;
  3082. if(damage2 > 0) WBUFW(buf,27) = -1;
  3083. clif_send(buf,packet_len(0x8a),src,SELF);
  3084. }
  3085. //Return adjusted can't walk delay for further processing.
  3086. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3087. }
  3088. /*==========================================
  3089. * src picks up dst
  3090. *------------------------------------------*/
  3091. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3092. {
  3093. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3094. unsigned char buf[32];
  3095. nullpo_retv(src);
  3096. nullpo_retv(dst);
  3097. WBUFW(buf, 0) = 0x8a;
  3098. WBUFL(buf, 2) = src->id;
  3099. WBUFL(buf, 6) = dst->id;
  3100. WBUFB(buf,26) = 1;
  3101. clif_send(buf, packet_len(0x8a), src, AREA);
  3102. }
  3103. /*==========================================
  3104. * inform clients in area that `bl` is sitting
  3105. *------------------------------------------*/
  3106. void clif_sitting(struct block_list* bl)
  3107. {
  3108. unsigned char buf[32];
  3109. nullpo_retv(bl);
  3110. WBUFW(buf, 0) = 0x8a;
  3111. WBUFL(buf, 2) = bl->id;
  3112. WBUFB(buf,26) = 2;
  3113. clif_send(buf, packet_len(0x8a), bl, AREA);
  3114. if(disguised(bl)) {
  3115. WBUFL(buf, 2) = - bl->id;
  3116. clif_send(buf, packet_len(0x8a), bl, SELF);
  3117. }
  3118. }
  3119. /*==========================================
  3120. * inform clients in area that `bl` is standing
  3121. *------------------------------------------*/
  3122. void clif_standing(struct block_list* bl)
  3123. {
  3124. unsigned char buf[32];
  3125. nullpo_retv(bl);
  3126. WBUFW(buf, 0) = 0x8a;
  3127. WBUFL(buf, 2) = bl->id;
  3128. WBUFB(buf,26) = 3;
  3129. clif_send(buf, packet_len(0x8a), bl, AREA);
  3130. if(disguised(bl)) {
  3131. WBUFL(buf, 2) = - bl->id;
  3132. clif_send(buf, packet_len(0x8a), bl, SELF);
  3133. }
  3134. }
  3135. /*==========================================
  3136. * Inform client(s) about a map-cell change
  3137. *------------------------------------------*/
  3138. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3139. {
  3140. unsigned char buf[32];
  3141. WBUFW(buf,0) = 0x192;
  3142. WBUFW(buf,2) = x;
  3143. WBUFW(buf,4) = y;
  3144. WBUFW(buf,6) = type;
  3145. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3146. if( fd )
  3147. {
  3148. WFIFOHEAD(fd,packet_len(0x192));
  3149. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3150. WFIFOSET(fd,packet_len(0x192));
  3151. }
  3152. else
  3153. {
  3154. struct block_list dummy_bl;
  3155. dummy_bl.type = BL_NUL;
  3156. dummy_bl.x = x;
  3157. dummy_bl.y = y;
  3158. dummy_bl.m = m;
  3159. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3160. }
  3161. }
  3162. /*==========================================
  3163. *
  3164. *------------------------------------------*/
  3165. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3166. {
  3167. int view,fd;
  3168. fd=sd->fd;
  3169. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3170. WFIFOHEAD(fd,packet_len(0x9d));
  3171. WFIFOW(fd,0)=0x9d;
  3172. WFIFOL(fd,2)=fitem->bl.id;
  3173. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3174. WFIFOW(fd,6)=view;
  3175. else
  3176. WFIFOW(fd,6)=fitem->item_data.nameid;
  3177. WFIFOB(fd,8)=fitem->item_data.identify;
  3178. WFIFOW(fd,9)=fitem->bl.x;
  3179. WFIFOW(fd,11)=fitem->bl.y;
  3180. WFIFOW(fd,13)=fitem->item_data.amount;
  3181. WFIFOB(fd,15)=fitem->subx;
  3182. WFIFOB(fd,16)=fitem->suby;
  3183. WFIFOSET(fd,packet_len(0x9d));
  3184. }
  3185. /*==========================================
  3186. * 場所スキルエフェクトが視界に入る
  3187. *------------------------------------------*/
  3188. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3189. {
  3190. int fd = sd->fd;
  3191. #if PACKETVER >= 3
  3192. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3193. WFIFOHEAD(fd,packet_len(0x1c9));
  3194. WFIFOW(fd, 0)=0x1c9;
  3195. WFIFOL(fd, 2)=unit->bl.id;
  3196. WFIFOL(fd, 6)=unit->group->src_id;
  3197. WFIFOW(fd,10)=unit->bl.x;
  3198. WFIFOW(fd,12)=unit->bl.y;
  3199. WFIFOB(fd,14)=unit->group->unit_id;
  3200. WFIFOB(fd,15)=1;
  3201. WFIFOB(fd,16)=1;
  3202. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3203. WFIFOSET(fd,packet_len(0x1c9));
  3204. return;
  3205. }
  3206. #endif
  3207. WFIFOHEAD(fd,packet_len(0x11f));
  3208. WFIFOW(fd, 0)=0x11f;
  3209. WFIFOL(fd, 2)=unit->bl.id;
  3210. WFIFOL(fd, 6)=unit->group->src_id;
  3211. WFIFOW(fd,10)=unit->bl.x;
  3212. WFIFOW(fd,12)=unit->bl.y;
  3213. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3214. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3215. else
  3216. WFIFOB(fd,14)=unit->group->unit_id;
  3217. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3218. WFIFOSET(fd,packet_len(0x11f));
  3219. if(unit->group->skill_id == WZ_ICEWALL)
  3220. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3221. }
  3222. /*==========================================
  3223. * 場所スキルエフェクトが視界から消える
  3224. *------------------------------------------*/
  3225. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3226. {
  3227. nullpo_retv(unit);
  3228. WFIFOHEAD(fd,packet_len(0x120));
  3229. WFIFOW(fd, 0)=0x120;
  3230. WFIFOL(fd, 2)=unit->bl.id;
  3231. WFIFOSET(fd,packet_len(0x120));
  3232. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3233. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3234. }
  3235. /*==========================================
  3236. * 場所スキルエフェクト削除
  3237. *------------------------------------------*/
  3238. void clif_skill_delunit(struct skill_unit *unit)
  3239. {
  3240. unsigned char buf[16];
  3241. nullpo_retv(unit);
  3242. WBUFW(buf, 0)=0x120;
  3243. WBUFL(buf, 2)=unit->bl.id;
  3244. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3245. }
  3246. /*==========================================
  3247. * Unknown... trap related?
  3248. * Sent when an object gets ankle-snared
  3249. * Only affects units with class [139,153] client-side
  3250. * R 01ac <object id>.l
  3251. *------------------------------------------*/
  3252. void clif_01ac(struct block_list* bl)
  3253. {
  3254. unsigned char buf[6];
  3255. nullpo_retv(bl);
  3256. WBUFW(buf,0) = 0x1ac;
  3257. WBUFL(buf,2) = bl->id;
  3258. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3259. }
  3260. /*==========================================
  3261. *
  3262. *------------------------------------------*/
  3263. int clif_getareachar(struct block_list* bl,va_list ap)
  3264. {
  3265. struct map_session_data *sd;
  3266. nullpo_retr(0, bl);
  3267. nullpo_retr(0, ap);
  3268. sd=va_arg(ap,struct map_session_data*);
  3269. if (sd == NULL || !sd->fd)
  3270. return 0;
  3271. switch(bl->type){
  3272. case BL_ITEM:
  3273. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3274. break;
  3275. case BL_SKILL:
  3276. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3277. break;
  3278. default:
  3279. if(&sd->bl == bl)
  3280. break;
  3281. clif_getareachar_unit(sd,bl);
  3282. break;
  3283. }
  3284. return 0;
  3285. }
  3286. /*==========================================
  3287. * tbl has gone out of view-size of bl
  3288. *------------------------------------------*/
  3289. int clif_outsight(struct block_list *bl,va_list ap)
  3290. {
  3291. struct block_list *tbl;
  3292. struct view_data *vd;
  3293. TBL_PC *sd, *tsd;
  3294. tbl=va_arg(ap,struct block_list*);
  3295. if(bl == tbl) return 0;
  3296. sd = BL_CAST(BL_PC, bl);
  3297. tsd = BL_CAST(BL_PC, tbl);
  3298. if (tsd && tsd->fd)
  3299. { //tsd has lost sight of the bl object.
  3300. switch(bl->type){
  3301. case BL_PC:
  3302. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3303. clif_clearunit_single(bl->id,0,tsd->fd);
  3304. if(sd->chatID){
  3305. struct chat_data *cd;
  3306. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3307. if(cd->usersd[0]==sd)
  3308. clif_dispchat(cd,tsd->fd);
  3309. }
  3310. if(sd->vender_id)
  3311. clif_closevendingboard(bl,tsd->fd);
  3312. break;
  3313. case BL_ITEM:
  3314. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3315. break;
  3316. case BL_SKILL:
  3317. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3318. break;
  3319. default:
  3320. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3321. clif_clearunit_single(bl->id,0,tsd->fd);
  3322. break;
  3323. }
  3324. }
  3325. if (sd && sd->fd)
  3326. { //sd is watching tbl go out of view.
  3327. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3328. clif_clearunit_single(tbl->id,0,sd->fd);
  3329. }
  3330. return 0;
  3331. }
  3332. /*==========================================
  3333. * tbl has come into view of bl
  3334. *------------------------------------------*/
  3335. int clif_insight(struct block_list *bl,va_list ap)
  3336. {
  3337. struct block_list *tbl;
  3338. TBL_PC *sd, *tsd;
  3339. tbl=va_arg(ap,struct block_list*);
  3340. if (bl == tbl) return 0;
  3341. sd = BL_CAST(BL_PC, bl);
  3342. tsd = BL_CAST(BL_PC, tbl);
  3343. if (tsd && tsd->fd)
  3344. { //Tell tsd that bl entered into his view
  3345. switch(bl->type){
  3346. case BL_ITEM:
  3347. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3348. break;
  3349. case BL_SKILL:
  3350. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3351. break;
  3352. default:
  3353. clif_getareachar_unit(tsd,bl);
  3354. break;
  3355. }
  3356. }
  3357. if (sd && sd->fd)
  3358. { //Tell sd that tbl walked into his view
  3359. clif_getareachar_unit(sd,tbl);
  3360. }
  3361. return 0;
  3362. }
  3363. /*==========================================
  3364. *
  3365. *------------------------------------------*/
  3366. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3367. {
  3368. int fd,id;
  3369. nullpo_retr(0, sd);
  3370. fd=sd->fd;
  3371. if( (id=sd->status.skill[skillid].id) <= 0 )
  3372. return 0;
  3373. WFIFOHEAD(fd,packet_len(0x147));
  3374. WFIFOW(fd,0)=0x147;
  3375. WFIFOW(fd,2) = id;
  3376. if(type < 0)
  3377. WFIFOW(fd,4) = skill_get_inf(id);
  3378. else
  3379. WFIFOW(fd,4) = type;
  3380. WFIFOW(fd,6) = 0;
  3381. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3382. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3383. if(range < 0)
  3384. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3385. WFIFOW(fd,12)= range;
  3386. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3387. if(sd->status.skill[skillid].flag ==0)
  3388. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3389. else
  3390. WFIFOB(fd,38) = 0;
  3391. WFIFOSET(fd,packet_len(0x147));
  3392. return 0;
  3393. }
  3394. /*==========================================
  3395. * スキルリストを送信する
  3396. *------------------------------------------*/
  3397. int clif_skillinfoblock(struct map_session_data *sd)
  3398. {
  3399. int fd;
  3400. int i,c,len,id;
  3401. nullpo_retr(0, sd);
  3402. fd=sd->fd;
  3403. if (!fd) return 0;
  3404. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3405. WFIFOW(fd,0) = 0x10f;
  3406. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3407. {
  3408. if( (id = sd->status.skill[i].id) != 0 )
  3409. {
  3410. WFIFOW(fd,len) = id;
  3411. WFIFOW(fd,len+2) = skill_get_inf(id);
  3412. WFIFOW(fd,len+4) = 0;
  3413. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3414. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3415. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3416. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3417. if(sd->status.skill[i].flag == 0)
  3418. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3419. else
  3420. WFIFOB(fd,len+36) = 0;
  3421. len += 37;
  3422. c++;
  3423. }
  3424. }
  3425. WFIFOW(fd,2)=len;
  3426. WFIFOSET(fd,len);
  3427. return 1;
  3428. }
  3429. /*==========================================
  3430. * スキル割り振り通知
  3431. *------------------------------------------*/
  3432. int clif_skillup(struct map_session_data *sd,int skill_num)
  3433. {
  3434. int fd;
  3435. nullpo_retr(0, sd);
  3436. fd=sd->fd;
  3437. WFIFOHEAD(fd,packet_len(0x10e));
  3438. WFIFOW(fd,0) = 0x10e;
  3439. WFIFOW(fd,2) = skill_num;
  3440. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3441. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3442. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3443. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3444. WFIFOSET(fd,packet_len(0x10e));
  3445. return 0;
  3446. }
  3447. /*==========================================
  3448. * スキル詠唱エフェクトを送信する
  3449. *------------------------------------------*/
  3450. int clif_skillcasting(struct block_list* bl,
  3451. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3452. {
  3453. unsigned char buf[32];
  3454. WBUFW(buf,0) = 0x13e;
  3455. WBUFL(buf,2) = src_id;
  3456. WBUFL(buf,6) = dst_id;
  3457. WBUFW(buf,10) = dst_x;
  3458. WBUFW(buf,12) = dst_y;
  3459. WBUFW(buf,14) = skill_num;
  3460. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3461. WBUFL(buf,20) = casttime;
  3462. if (disguised(bl)) {
  3463. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3464. WBUFL(buf,2) = -src_id;
  3465. clif_send(buf,packet_len(0x13e), bl, SELF);
  3466. } else
  3467. clif_send(buf,packet_len(0x13e), bl, AREA);
  3468. return 0;
  3469. }
  3470. /*==========================================
  3471. *
  3472. *------------------------------------------*/
  3473. int clif_skillcastcancel(struct block_list* bl)
  3474. {
  3475. unsigned char buf[16];
  3476. nullpo_retr(0, bl);
  3477. WBUFW(buf,0) = 0x1b9;
  3478. WBUFL(buf,2) = bl->id;
  3479. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3480. return 0;
  3481. }
  3482. /// only when type==0:
  3483. /// if(skill_id==NV_BASIC)
  3484. /// btype==0 "skill failed" MsgStringTable[159]
  3485. /// btype==1 "no emotions" MsgStringTable[160]
  3486. /// btype==2 "no sit" MsgStringTable[161]
  3487. /// btype==3 "no chat" MsgStringTable[162]
  3488. /// btype==4 "no party" MsgStringTable[163]
  3489. /// btype==5 "no shout" MsgStringTable[164]
  3490. /// btype==6 "no PKing" MsgStringTable[165]
  3491. /// btype==7 "no alligning" MsgStringTable[383]
  3492. /// btype>=8: ignored
  3493. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3494. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3495. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3496. /// otherwise "skill failed" MsgStringTable[204]
  3497. /// btype irrelevant
  3498. /// type==1 "insufficient SP" MsgStringTable[202]
  3499. /// type==2 "insufficient HP" MsgStringTable[203]
  3500. /// type==3 "insufficient materials" MsgStringTable[808]
  3501. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3502. /// type==5 "insufficient zeny" MsgStringTable[233]
  3503. /// type==6 "wrong weapon" MsgStringTable[239]
  3504. /// type==7 "red gemstone needed" MsgStringTable[246]
  3505. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3506. /// type==9 "overweight" MsgStringTable[580]
  3507. /// type==10 "skill failed" MsgStringTable[285]
  3508. /// type>=11 ignored
  3509. ///
  3510. /// if(success!=0) doesn't display any of the previous messages
  3511. /// Note: when this packet is received an unknown flag is always set to 0,
  3512. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3513. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3514. {
  3515. int fd;
  3516. if (!sd) { //Since this is the most common nullpo....
  3517. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3518. return 0;
  3519. }
  3520. fd=sd->fd;
  3521. if (!fd) return 0;
  3522. if(battle_config.display_skill_fail&1)
  3523. return 0; //Disable all skill failed messages
  3524. if(type==0x4 && !sd->state.showdelay)
  3525. return 0; //Disable delay failed messages
  3526. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3527. return 0;
  3528. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3529. return 0;
  3530. WFIFOHEAD(fd,packet_len(0x110));
  3531. WFIFOW(fd,0) = 0x110;
  3532. WFIFOW(fd,2) = skill_id;
  3533. WFIFOL(fd,4) = btype;
  3534. WFIFOB(fd,8) = 0;// success?
  3535. WFIFOB(fd,9) = type;
  3536. WFIFOSET(fd,packet_len(0x110));
  3537. return 1;
  3538. }
  3539. /*==========================================
  3540. * skill attack effect and damage
  3541. * R 01de <skill ID>.w <src ID>.l <dst ID>.l <tick>.l <src delay>.l <dst delay>.l <damage>.l <skillv>.w <div>.w <type>.B
  3542. *------------------------------------------*/
  3543. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3544. {
  3545. unsigned char buf[64];
  3546. struct status_change *sc;
  3547. nullpo_retr(0, src);
  3548. nullpo_retr(0, dst);
  3549. type = clif_calc_delay(type,div,damage,ddelay);
  3550. sc = status_get_sc(dst);
  3551. if(sc && sc->count) {
  3552. if(sc->data[SC_HALLUCINATION] && damage)
  3553. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3554. }
  3555. #if PACKETVER < 3
  3556. WBUFW(buf,0)=0x114;
  3557. WBUFW(buf,2)=skill_id;
  3558. WBUFL(buf,4)=src->id;
  3559. WBUFL(buf,8)=dst->id;
  3560. WBUFL(buf,12)=tick;
  3561. WBUFL(buf,16)=sdelay;
  3562. WBUFL(buf,20)=ddelay;
  3563. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3564. WBUFW(buf,24)=damage?div:0;
  3565. } else {
  3566. WBUFW(buf,24)=damage;
  3567. }
  3568. WBUFW(buf,26)=skill_lv;
  3569. WBUFW(buf,28)=div;
  3570. WBUFB(buf,30)=type;
  3571. if (disguised(dst)) {
  3572. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3573. WBUFL(buf,8)=-dst->id;
  3574. clif_send(buf,packet_len(0x114),dst,SELF);
  3575. } else
  3576. clif_send(buf,packet_len(0x114),dst,AREA);
  3577. if(disguised(src)) {
  3578. WBUFL(buf,4)=-src->id;
  3579. if (disguised(dst))
  3580. WBUFL(buf,8)=dst->id;
  3581. if(damage > 0)
  3582. WBUFW(buf,24)=-1;
  3583. clif_send(buf,packet_len(0x114),src,SELF);
  3584. }
  3585. #else
  3586. WBUFW(buf,0)=0x1de;
  3587. WBUFW(buf,2)=skill_id;
  3588. WBUFL(buf,4)=src->id;
  3589. WBUFL(buf,8)=dst->id;
  3590. WBUFL(buf,12)=tick;
  3591. WBUFL(buf,16)=sdelay;
  3592. WBUFL(buf,20)=ddelay;
  3593. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3594. WBUFL(buf,24)=damage?div:0;
  3595. } else {
  3596. WBUFL(buf,24)=damage;
  3597. }
  3598. WBUFW(buf,28)=skill_lv;
  3599. WBUFW(buf,30)=div;
  3600. WBUFB(buf,32)=type;
  3601. if (disguised(dst)) {
  3602. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3603. WBUFL(buf,8)=-dst->id;
  3604. clif_send(buf,packet_len(0x1de),dst,SELF);
  3605. } else
  3606. clif_send(buf,packet_len(0x1de),dst,AREA);
  3607. if(disguised(src)) {
  3608. WBUFL(buf,4)=-src->id;
  3609. if (disguised(dst))
  3610. WBUFL(buf,8)=dst->id;
  3611. if(damage > 0)
  3612. WBUFL(buf,24)=-1;
  3613. clif_send(buf,packet_len(0x1de),src,SELF);
  3614. }
  3615. #endif
  3616. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3617. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3618. }
  3619. /*==========================================
  3620. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3621. *------------------------------------------*/
  3622. /*
  3623. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3624. {
  3625. unsigned char buf[64];
  3626. struct status_change *sc;
  3627. nullpo_retr(0, src);
  3628. nullpo_retr(0, dst);
  3629. type = (type>0)?type:skill_get_hit(skill_id);
  3630. type = clif_calc_delay(type,div,damage,ddelay);
  3631. sc = status_get_sc(dst);
  3632. if(sc && sc->count) {
  3633. if(sc->data[SC_HALLUCINATION] && damage)
  3634. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3635. }
  3636. WBUFW(buf,0)=0x115;
  3637. WBUFW(buf,2)=skill_id;
  3638. WBUFL(buf,4)=src->id;
  3639. WBUFL(buf,8)=dst->id;
  3640. WBUFL(buf,12)=tick;
  3641. WBUFL(buf,16)=sdelay;
  3642. WBUFL(buf,20)=ddelay;
  3643. WBUFW(buf,24)=dst->x;
  3644. WBUFW(buf,26)=dst->y;
  3645. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3646. WBUFW(buf,28)=damage?div:0;
  3647. } else {
  3648. WBUFW(buf,28)=damage;
  3649. }
  3650. WBUFW(buf,30)=skill_lv;
  3651. WBUFW(buf,32)=div;
  3652. WBUFB(buf,34)=type;
  3653. clif_send(buf,packet_len(0x115),src,AREA);
  3654. if(disguised(src)) {
  3655. WBUFL(buf,4)=-src->id;
  3656. if(damage > 0)
  3657. WBUFW(buf,28)=-1;
  3658. clif_send(buf,packet_len(0x115),src,SELF);
  3659. }
  3660. if (disguised(dst)) {
  3661. WBUFL(buf,8)=-dst->id;
  3662. if (disguised(src))
  3663. WBUFL(buf,4)=src->id;
  3664. else if(damage > 0)
  3665. WBUFW(buf,28)=-1;
  3666. clif_send(buf,packet_len(0x115),dst,SELF);
  3667. }
  3668. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3669. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3670. }
  3671. */
  3672. /*==========================================
  3673. * 支援/回復スキルエフェクト
  3674. *------------------------------------------*/
  3675. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3676. {
  3677. unsigned char buf[32];
  3678. nullpo_retr(0, dst);
  3679. WBUFW(buf,0)=0x11a;
  3680. WBUFW(buf,2)=skill_id;
  3681. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3682. WBUFL(buf,6)=dst->id;
  3683. WBUFL(buf,10)=src?src->id:0;
  3684. WBUFB(buf,14)=fail;
  3685. if (disguised(dst)) {
  3686. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  3687. WBUFL(buf,6)=-dst->id;
  3688. clif_send(buf,packet_len(0x11a),dst,SELF);
  3689. } else
  3690. clif_send(buf,packet_len(0x11a),dst,AREA);
  3691. if(src && disguised(src)) {
  3692. WBUFL(buf,10)=-src->id;
  3693. if (disguised(dst))
  3694. WBUFL(buf,6)=dst->id;
  3695. clif_send(buf,packet_len(0x11a),src,SELF);
  3696. }
  3697. return fail;
  3698. }
  3699. /*==========================================
  3700. * 場所スキルエフェクト
  3701. *------------------------------------------*/
  3702. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3703. {
  3704. unsigned char buf[32];
  3705. nullpo_retr(0, src);
  3706. WBUFW(buf,0)=0x117;
  3707. WBUFW(buf,2)=skill_id;
  3708. WBUFL(buf,4)=src->id;
  3709. WBUFW(buf,8)=val;
  3710. WBUFW(buf,10)=x;
  3711. WBUFW(buf,12)=y;
  3712. WBUFL(buf,14)=tick;
  3713. if(disguised(src)) {
  3714. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  3715. WBUFL(buf,4)=-src->id;
  3716. clif_send(buf,packet_len(0x117),src,SELF);
  3717. } else
  3718. clif_send(buf,packet_len(0x117),src,AREA);
  3719. return 0;
  3720. }
  3721. /*==========================================
  3722. * 場所スキルエフェクト表示
  3723. *------------------------------------------*/
  3724. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  3725. void clif_skill_setunit(struct skill_unit *unit)
  3726. {
  3727. unsigned char buf[128];
  3728. nullpo_retv(unit);
  3729. #if PACKETVER >= 3
  3730. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3731. WBUFW(buf, 0)=0x1c9;
  3732. WBUFL(buf, 2)=unit->bl.id;
  3733. WBUFL(buf, 6)=unit->group->src_id;
  3734. WBUFW(buf,10)=unit->bl.x;
  3735. WBUFW(buf,12)=unit->bl.y;
  3736. WBUFB(buf,14)=unit->group->unit_id;
  3737. WBUFB(buf,15)=1;
  3738. WBUFB(buf,16)=1;
  3739. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3740. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3741. return;
  3742. }
  3743. #endif
  3744. WBUFW(buf, 0)=0x11f;
  3745. WBUFL(buf, 2)=unit->bl.id;
  3746. WBUFL(buf, 6)=unit->group->src_id;
  3747. WBUFW(buf,10)=unit->bl.x;
  3748. WBUFW(buf,12)=unit->bl.y;
  3749. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  3750. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3751. else
  3752. WBUFB(buf,14)=unit->group->unit_id;
  3753. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  3754. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  3755. }
  3756. /*==========================================
  3757. * ワープ場所選択
  3758. *------------------------------------------*/
  3759. void clif_skill_warppoint(struct map_session_data* sd, short skill_num, short skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  3760. {
  3761. int fd;
  3762. nullpo_retv(sd);
  3763. fd = sd->fd;
  3764. WFIFOHEAD(fd,packet_len(0x11c));
  3765. WFIFOW(fd,0) = 0x11c;
  3766. WFIFOW(fd,2) = skill_num;
  3767. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  3768. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  3769. else // normal map name
  3770. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  3771. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  3772. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  3773. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  3774. WFIFOSET(fd,packet_len(0x11c));
  3775. sd->menuskill_id = skill_num;
  3776. if (skill_num == AL_WARP)
  3777. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  3778. else
  3779. sd->menuskill_val = skill_lv;
  3780. }
  3781. /// Memo message.
  3782. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  3783. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  3784. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  3785. ///
  3786. /// @param sd Who receives the message
  3787. /// @param type What message
  3788. void clif_skill_memomessage(struct map_session_data* sd, int type)
  3789. {
  3790. int fd;
  3791. nullpo_retv(sd);
  3792. fd=sd->fd;
  3793. WFIFOHEAD(fd,packet_len(0x11e));
  3794. WFIFOW(fd,0)=0x11e;
  3795. WFIFOB(fd,2)=type;
  3796. WFIFOSET(fd,packet_len(0x11e));
  3797. }
  3798. /// Teleport message.
  3799. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  3800. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  3801. ///
  3802. /// @param sd Who receives the message
  3803. /// @param type What message
  3804. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  3805. {
  3806. int fd;
  3807. nullpo_retv(sd);
  3808. fd=sd->fd;
  3809. WFIFOHEAD(fd,packet_len(0x189));
  3810. WFIFOW(fd,0)=0x189;
  3811. WFIFOW(fd,2)=type;
  3812. WFIFOSET(fd,packet_len(0x189));
  3813. }
  3814. /*==========================================
  3815. * モンスター情報
  3816. *------------------------------------------*/
  3817. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  3818. {
  3819. struct status_data *status;
  3820. unsigned char buf[64];
  3821. int i;//, fix;
  3822. nullpo_retr(0, sd);
  3823. nullpo_retr(0, dst);
  3824. if(dst->type!=BL_MOB )
  3825. return 0;
  3826. status = status_get_status_data(dst);
  3827. WBUFW(buf, 0)=0x18c;
  3828. WBUFW(buf, 2)=status_get_class(dst);
  3829. WBUFW(buf, 4)=status_get_lv(dst);
  3830. WBUFW(buf, 6)=status->size;
  3831. WBUFL(buf, 8)=status->hp;
  3832. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  3833. +(battle_config.estimation_type&2?status->def2:0);
  3834. WBUFW(buf,14)=status->race;
  3835. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  3836. +(battle_config.estimation_type&2?status->mdef2:0);
  3837. WBUFW(buf,18)= status->def_ele;
  3838. for(i=0;i<9;i++)
  3839. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  3840. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  3841. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  3842. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  3843. return 0;
  3844. }
  3845. /*==========================================
  3846. * アイテム合成可能リスト
  3847. *------------------------------------------*/
  3848. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  3849. {
  3850. int i,c,view,fd;
  3851. nullpo_retr(0, sd);
  3852. if(sd->menuskill_id == AM_PHARMACY)
  3853. return 0; //Avoid resending the menu twice or more times...
  3854. fd=sd->fd;
  3855. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  3856. WFIFOW(fd, 0)=0x18d;
  3857. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  3858. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  3859. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  3860. WFIFOW(fd,c*8+ 4)= view;
  3861. else
  3862. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  3863. WFIFOW(fd,c*8+ 6)= 0x0012;
  3864. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  3865. c++;
  3866. }
  3867. }
  3868. WFIFOW(fd, 2)=c*8+8;
  3869. WFIFOSET(fd,WFIFOW(fd,2));
  3870. if(c > 0) {
  3871. sd->menuskill_id = AM_PHARMACY;
  3872. sd->menuskill_val = trigger;
  3873. return 1;
  3874. }
  3875. return 0;
  3876. }
  3877. /*==========================================
  3878. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  3879. *------------------------------------------*/
  3880. int clif_status_load(struct block_list *bl,int type, int flag)
  3881. {
  3882. int fd;
  3883. if (type == SI_BLANK) //It shows nothing on the client...
  3884. return 0;
  3885. if (bl->type != BL_PC)
  3886. return 0;
  3887. fd = ((struct map_session_data*)bl)->fd;
  3888. WFIFOHEAD(fd,packet_len(0x196));
  3889. WFIFOW(fd,0)=0x0196;
  3890. WFIFOW(fd,2)=type;
  3891. WFIFOL(fd,4)=bl->id;
  3892. WFIFOB(fd,8)=flag; //Status start
  3893. WFIFOSET(fd, packet_len(0x196));
  3894. return 0;
  3895. }
  3896. /*==========================================
  3897. * 状態異常アイコン/メッセージ表示
  3898. *------------------------------------------*/
  3899. int clif_status_change(struct block_list *bl,int type,int flag)
  3900. {
  3901. unsigned char buf[16];
  3902. if (type == SI_BLANK) //It shows nothing on the client...
  3903. return 0;
  3904. nullpo_retr(0, bl);
  3905. WBUFW(buf,0)=0x0196;
  3906. WBUFW(buf,2)=type;
  3907. WBUFL(buf,4)=bl->id;
  3908. WBUFB(buf,8)=flag;
  3909. clif_send(buf,packet_len(0x196),bl,AREA);
  3910. return 0;
  3911. }
  3912. /*==========================================
  3913. * Send message (modified by [Yor])
  3914. *------------------------------------------*/
  3915. int clif_displaymessage(const int fd, const char* mes)
  3916. {
  3917. // invalid pointer?
  3918. nullpo_retr(-1, mes);
  3919. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  3920. if (fd == 0)
  3921. return 0;
  3922. else {
  3923. int len_mes = strlen(mes);
  3924. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  3925. WFIFOHEAD(fd, 5 + len_mes);
  3926. WFIFOW(fd,0) = 0x8e;
  3927. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  3928. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  3929. WFIFOSET(fd, 5 + len_mes);
  3930. }
  3931. }
  3932. return 0;
  3933. }
  3934. /*==========================================
  3935. * 天の声を送信する
  3936. *------------------------------------------*/
  3937. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  3938. {
  3939. unsigned char *buf;
  3940. int lp;
  3941. lp = (flag & 0x10) ? 8 : 4;
  3942. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  3943. WBUFW(buf,0) = 0x9a;
  3944. WBUFW(buf,2) = len + lp;
  3945. WBUFL(buf,4) = 0x65756c62; //"blue":
  3946. memcpy(WBUFP(buf,lp), mes, len);
  3947. flag &= 0x07;
  3948. clif_send(buf, WBUFW(buf,2), bl,
  3949. (flag == 1) ? ALL_SAMEMAP :
  3950. (flag == 2) ? AREA :
  3951. (flag == 3) ? SELF :
  3952. ALL_CLIENT);
  3953. if(buf) aFree(buf);
  3954. return 0;
  3955. }
  3956. /*==========================================
  3957. * グローバルメッセージ
  3958. *------------------------------------------*/
  3959. void clif_GlobalMessage(struct block_list* bl, const char* message)
  3960. {
  3961. char buf[100];
  3962. int len;
  3963. nullpo_retv(bl);
  3964. if(!message)
  3965. return;
  3966. len = strlen(message)+1;
  3967. WBUFW(buf,0)=0x8d;
  3968. WBUFW(buf,2)=len+8;
  3969. WBUFL(buf,4)=bl->id;
  3970. strncpy((char *) WBUFP(buf,8),message,len);
  3971. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  3972. }
  3973. /*==========================================
  3974. * Send main chat message [LuzZza]
  3975. *------------------------------------------*/
  3976. void clif_MainChatMessage(const char* message)
  3977. {
  3978. char buf[200];
  3979. int len;
  3980. if(!message)
  3981. return;
  3982. len = strlen(message)+1;
  3983. if (len+8 > sizeof(buf)) {
  3984. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  3985. len = sizeof(buf)-8;
  3986. }
  3987. WBUFW(buf,0)=0x8d;
  3988. WBUFW(buf,2)=len+8;
  3989. WBUFL(buf,4)=0;
  3990. strncpy((char *) WBUFP(buf,8),message,len);
  3991. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  3992. }
  3993. /*==========================================
  3994. * Does an announce message in the given color.
  3995. *------------------------------------------*/
  3996. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  3997. {
  3998. return clif_announce_ex(bl, mes, len, color, flag, 12);
  3999. }
  4000. int clif_announce_ex(struct block_list* bl, const char* mes, int len, unsigned long color, int flag, int size)
  4001. {
  4002. unsigned char *buf;
  4003. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4004. WBUFW(buf,0) = 0x1c3;
  4005. WBUFW(buf,2) = len + 16;
  4006. WBUFL(buf,4) = color;
  4007. WBUFW(buf,8) = 0x190; //Font style? Type?
  4008. WBUFW(buf,10) = size; // Font size
  4009. WBUFL(buf,12) = 0; //Unknown!
  4010. memcpy(WBUFP(buf,16), mes, len);
  4011. flag &= 0x07;
  4012. clif_send(buf, WBUFW(buf,2), bl,
  4013. (flag == 1) ? ALL_SAMEMAP :
  4014. (flag == 2) ? AREA :
  4015. (flag == 3) ? SELF :
  4016. ALL_CLIENT);
  4017. if(buf) aFree(buf);
  4018. return 0;
  4019. }
  4020. /*==========================================
  4021. * HPSP回復エフェクトを送信する
  4022. *------------------------------------------*/
  4023. int clif_heal(int fd,int type,int val)
  4024. {
  4025. WFIFOHEAD(fd,packet_len(0x13d));
  4026. WFIFOW(fd,0)=0x13d;
  4027. WFIFOW(fd,2)=type;
  4028. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4029. WFIFOSET(fd,packet_len(0x13d));
  4030. return 0;
  4031. }
  4032. /*==========================================
  4033. * 復活する
  4034. *------------------------------------------*/
  4035. int clif_resurrection(struct block_list *bl,int type)
  4036. {
  4037. unsigned char buf[16];
  4038. nullpo_retr(0, bl);
  4039. WBUFW(buf,0)=0x148;
  4040. WBUFL(buf,2)=bl->id;
  4041. WBUFW(buf,6)=type;
  4042. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4043. if (disguised(bl))
  4044. clif_spawn(bl);
  4045. return 0;
  4046. }
  4047. /// Sets the map mode.
  4048. ///
  4049. /// mode=1 : pvp mode
  4050. /// mode=2 : unknown mode (pk?)
  4051. /// mode=3 : gvg mode
  4052. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4053. /// mode=5 : pvp mode
  4054. /// mode=other : ?
  4055. void clif_set0199(struct map_session_data* sd, int mode)
  4056. {
  4057. int fd;
  4058. nullpo_retv(sd);
  4059. fd=sd->fd;
  4060. WFIFOHEAD(fd,packet_len(0x199));
  4061. WFIFOW(fd,0)=0x199;
  4062. WFIFOW(fd,2)=mode;
  4063. WFIFOSET(fd,packet_len(0x199));
  4064. }
  4065. #if 0
  4066. /// Set the map mode?
  4067. /// Differs from the behaviour of clif_set0199 with unknown consequences.
  4068. void clif_set01D6(struct map_session_data* sd, int mode)
  4069. {
  4070. int fd;
  4071. nullpo_retv(sd);
  4072. fd=sd->fd;
  4073. WFIFOHEAD(fd,packet_len(0x1D6));
  4074. WFIFOW(fd,0)=0x1D6;
  4075. WFIFOW(fd,2)=mode;
  4076. WFIFOSET(fd,packet_len(0x1D6));
  4077. }
  4078. #endif
  4079. /*==========================================
  4080. * PVP実装?(仮)
  4081. *------------------------------------------*/
  4082. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4083. {
  4084. if(type == 2) {
  4085. int fd = sd->fd;
  4086. WFIFOHEAD(fd,packet_len(0x19a));
  4087. WFIFOW(fd,0) = 0x19a;
  4088. WFIFOL(fd,2) = sd->bl.id;
  4089. WFIFOL(fd,6) = pvprank;
  4090. WFIFOL(fd,10) = pvpnum;
  4091. WFIFOSET(fd,packet_len(0x19a));
  4092. } else {
  4093. unsigned char buf[32];
  4094. WBUFW(buf,0) = 0x19a;
  4095. WBUFL(buf,2) = sd->bl.id;
  4096. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4097. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4098. else
  4099. WBUFL(buf,6) = pvprank;
  4100. WBUFL(buf,10) = pvpnum;
  4101. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4102. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4103. else if(!type)
  4104. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4105. else
  4106. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4107. }
  4108. return 0;
  4109. }
  4110. /*==========================================
  4111. *
  4112. *------------------------------------------*/
  4113. int clif_send0199(int map,int type)
  4114. {
  4115. struct block_list bl;
  4116. unsigned char buf[16];
  4117. bl.id = 0;
  4118. bl.type = BL_NUL;
  4119. bl.m = map;
  4120. WBUFW(buf,0)=0x199;
  4121. WBUFW(buf,2)=type;
  4122. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4123. return 0;
  4124. }
  4125. /*==========================================
  4126. * 精錬エフェクトを送信する
  4127. *------------------------------------------*/
  4128. void clif_refine(int fd, int fail, int index, int val)
  4129. {
  4130. WFIFOHEAD(fd,packet_len(0x188));
  4131. WFIFOW(fd,0)=0x188;
  4132. WFIFOW(fd,2)=fail;
  4133. WFIFOW(fd,4)=index+2;
  4134. WFIFOW(fd,6)=val;
  4135. WFIFOSET(fd,packet_len(0x188));
  4136. }
  4137. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4138. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4139. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4140. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4141. void clif_upgrademessage(int fd, int result, int item_id)
  4142. {
  4143. WFIFOHEAD(fd,packet_len(0x223));
  4144. WFIFOW(fd,0)=0x223;
  4145. WFIFOL(fd,2)=result;
  4146. WFIFOW(fd,6)=item_id;
  4147. WFIFOSET(fd,packet_len(0x223));
  4148. }
  4149. /*==========================================
  4150. * Wisp/page is transmitted to the destination player
  4151. * R 0097 <len>.w <nick>.24B <message>.?B
  4152. *------------------------------------------*/
  4153. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4154. {
  4155. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4156. WFIFOW(fd,0) = 0x97;
  4157. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4158. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4159. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4160. WFIFOSET(fd,WFIFOW(fd,2));
  4161. return 0;
  4162. }
  4163. /*==========================================
  4164. * Inform the player about the result of his whisper action
  4165. * R 0098 <type>.B
  4166. * 0: success to send wisper
  4167. * 1: target character is not loged in
  4168. * 2: ignored by target
  4169. * 3: everyone ignored by target
  4170. *------------------------------------------*/
  4171. int clif_wis_end(int fd, int flag)
  4172. {
  4173. WFIFOHEAD(fd,packet_len(0x98));
  4174. WFIFOW(fd,0) = 0x98;
  4175. WFIFOW(fd,2) = flag;
  4176. WFIFOSET(fd,packet_len(0x98));
  4177. return 0;
  4178. }
  4179. /*==========================================
  4180. * キャラID名前引き結果を送信する
  4181. *------------------------------------------*/
  4182. int clif_solved_charname(int fd, int charid, const char* name)
  4183. {
  4184. WFIFOHEAD(fd,packet_len(0x194));
  4185. WFIFOW(fd,0)=0x194;
  4186. WFIFOL(fd,2)=charid;
  4187. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4188. WFIFOSET(fd,packet_len(0x194));
  4189. return 0;
  4190. }
  4191. /*==========================================
  4192. * カードの挿入可能リストを返す
  4193. *------------------------------------------*/
  4194. int clif_use_card(struct map_session_data *sd,int idx)
  4195. {
  4196. int i,c,ep;
  4197. int fd=sd->fd;
  4198. nullpo_retr(0, sd);
  4199. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4200. return 0;
  4201. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4202. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4203. ep=sd->inventory_data[idx]->equip;
  4204. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4205. WFIFOW(fd,0)=0x017b;
  4206. for(i=c=0;i<MAX_INVENTORY;i++){
  4207. int j;
  4208. if(sd->inventory_data[i] == NULL)
  4209. continue;
  4210. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4211. continue;
  4212. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4213. continue;
  4214. if(sd->status.inventory[i].identify==0 ) //Not identified
  4215. continue;
  4216. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4217. continue;
  4218. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4219. continue;
  4220. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4221. if( sd->status.inventory[i].card[j]==0 )
  4222. break;
  4223. }
  4224. if(j==sd->inventory_data[i]->slot) // No room
  4225. continue;
  4226. WFIFOW(fd,4+c*2)=i+2;
  4227. c++;
  4228. }
  4229. WFIFOW(fd,2)=4+c*2;
  4230. WFIFOSET(fd,WFIFOW(fd,2));
  4231. return 0;
  4232. }
  4233. /*==========================================
  4234. * カードの挿入終了
  4235. *------------------------------------------*/
  4236. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4237. {
  4238. int fd;
  4239. nullpo_retr(0, sd);
  4240. fd=sd->fd;
  4241. WFIFOHEAD(fd,packet_len(0x17d));
  4242. WFIFOW(fd,0)=0x17d;
  4243. WFIFOW(fd,2)=idx_equip+2;
  4244. WFIFOW(fd,4)=idx_card+2;
  4245. WFIFOB(fd,6)=flag;
  4246. WFIFOSET(fd,packet_len(0x17d));
  4247. return 0;
  4248. }
  4249. /*==========================================
  4250. * 鑑定可能アイテムリスト送信
  4251. *------------------------------------------*/
  4252. int clif_item_identify_list(struct map_session_data *sd)
  4253. {
  4254. int i,c;
  4255. int fd;
  4256. nullpo_retr(0, sd);
  4257. fd=sd->fd;
  4258. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4259. WFIFOW(fd,0)=0x177;
  4260. for(i=c=0;i<MAX_INVENTORY;i++){
  4261. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4262. WFIFOW(fd,c*2+4)=i+2;
  4263. c++;
  4264. }
  4265. }
  4266. if(c > 0) {
  4267. WFIFOW(fd,2)=c*2+4;
  4268. WFIFOSET(fd,WFIFOW(fd,2));
  4269. sd->menuskill_id = MC_IDENTIFY;
  4270. sd->menuskill_val = c;
  4271. }
  4272. return 0;
  4273. }
  4274. /*==========================================
  4275. * 鑑定結果
  4276. *------------------------------------------*/
  4277. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4278. {
  4279. int fd;
  4280. nullpo_retr(0, sd);
  4281. fd=sd->fd;
  4282. WFIFOHEAD(fd,packet_len(0x179));
  4283. WFIFOW(fd, 0)=0x179;
  4284. WFIFOW(fd, 2)=idx+2;
  4285. WFIFOB(fd, 4)=flag;
  4286. WFIFOSET(fd,packet_len(0x179));
  4287. return 0;
  4288. }
  4289. /*==========================================
  4290. * 修理可能アイテムリスト送信
  4291. *------------------------------------------*/
  4292. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4293. {
  4294. int i,c;
  4295. int fd;
  4296. int nameid;
  4297. nullpo_retr(0, sd);
  4298. nullpo_retr(0, dstsd);
  4299. fd=sd->fd;
  4300. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4301. WFIFOW(fd,0)=0x1fc;
  4302. for(i=c=0;i<MAX_INVENTORY;i++){
  4303. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4304. WFIFOW(fd,c*13+4) = i;
  4305. WFIFOW(fd,c*13+6) = nameid;
  4306. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4307. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4308. WFIFOB(fd,c*13+16)= c;
  4309. c++;
  4310. }
  4311. }
  4312. if(c > 0) {
  4313. WFIFOW(fd,2)=c*13+4;
  4314. WFIFOSET(fd,WFIFOW(fd,2));
  4315. sd->menuskill_id = BS_REPAIRWEAPON;
  4316. sd->menuskill_val = dstsd->bl.id;
  4317. }else
  4318. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4319. return 0;
  4320. }
  4321. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4322. {
  4323. int view,fd;
  4324. nullpo_retr(0, sd);
  4325. fd=sd->fd;
  4326. WFIFOHEAD(fd,packet_len(0x1fe));
  4327. WFIFOW(fd, 0)=0x1fe;
  4328. if((view = itemdb_viewid(nameid)) > 0)
  4329. WFIFOW(fd, 2)=view;
  4330. else
  4331. WFIFOW(fd, 2)=nameid;
  4332. WFIFOB(fd, 4)=flag;
  4333. WFIFOSET(fd,packet_len(0x1fe));
  4334. return 0;
  4335. }
  4336. /*==========================================
  4337. * Weapon Refining - Taken from jAthena
  4338. *------------------------------------------*/
  4339. int clif_item_refine_list(struct map_session_data *sd)
  4340. {
  4341. int i,c;
  4342. int fd;
  4343. int skilllv;
  4344. int wlv;
  4345. int refine_item[5];
  4346. nullpo_retr(0, sd);
  4347. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4348. fd=sd->fd;
  4349. refine_item[0] = -1;
  4350. refine_item[1] = pc_search_inventory(sd,1010);
  4351. refine_item[2] = pc_search_inventory(sd,1011);
  4352. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4353. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4354. WFIFOW(fd,0)=0x221;
  4355. for(i=c=0;i<MAX_INVENTORY;i++){
  4356. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4357. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4358. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4359. WFIFOW(fd,c*13+ 4)=i+2;
  4360. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4361. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4362. WFIFOW(fd,c*13+10)=0;
  4363. WFIFOB(fd,c*13+12)=c;
  4364. c++;
  4365. }
  4366. }
  4367. WFIFOW(fd,2)=c*13+4;
  4368. WFIFOSET(fd,WFIFOW(fd,2));
  4369. if (c > 0) {
  4370. sd->menuskill_id = WS_WEAPONREFINE;
  4371. sd->menuskill_val = skilllv;
  4372. }
  4373. return 0;
  4374. }
  4375. /*==========================================
  4376. * アイテムによる一時的なスキル効果
  4377. *------------------------------------------*/
  4378. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4379. {
  4380. int fd;
  4381. nullpo_retr(0, sd);
  4382. fd=sd->fd;
  4383. WFIFOHEAD(fd,packet_len(0x147));
  4384. WFIFOW(fd, 0)=0x147;
  4385. WFIFOW(fd, 2)=skillid;
  4386. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4387. WFIFOW(fd, 6)=0;
  4388. WFIFOW(fd, 8)=skilllv;
  4389. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4390. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4391. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4392. WFIFOB(fd,38)=0;
  4393. WFIFOSET(fd,packet_len(0x147));
  4394. return 0;
  4395. }
  4396. /*==========================================
  4397. * カートにアイテム追加
  4398. *------------------------------------------*/
  4399. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4400. {
  4401. int view,fd;
  4402. unsigned char *buf;
  4403. nullpo_retr(0, sd);
  4404. fd=sd->fd;
  4405. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4406. return 1;
  4407. #if PACKETVER < 5
  4408. WFIFOHEAD(fd,packet_len(0x124));
  4409. buf=WFIFOP(fd,0);
  4410. WBUFW(buf,0)=0x124;
  4411. WBUFW(buf,2)=n+2;
  4412. WBUFL(buf,4)=amount;
  4413. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4414. WBUFW(buf,8)=view;
  4415. else
  4416. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4417. WBUFB(buf,10)=sd->status.cart[n].identify;
  4418. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4419. WBUFB(buf,12)=sd->status.cart[n].refine;
  4420. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4421. WFIFOSET(fd,packet_len(0x124));
  4422. #else
  4423. WFIFOHEAD(fd,packet_len(0x1c5));
  4424. buf=WFIFOP(fd,0);
  4425. WBUFW(buf,0)=0x1c5;
  4426. WBUFW(buf,2)=n+2;
  4427. WBUFL(buf,4)=amount;
  4428. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4429. WBUFW(buf,8)=view;
  4430. else
  4431. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4432. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4433. WBUFB(buf,11)=sd->status.cart[n].identify;
  4434. WBUFB(buf,12)=sd->status.cart[n].attribute;
  4435. WBUFB(buf,13)=sd->status.cart[n].refine;
  4436. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  4437. WFIFOSET(fd,packet_len(0x1c5));
  4438. #endif
  4439. return 0;
  4440. }
  4441. /*==========================================
  4442. * カートからアイテム削除
  4443. *------------------------------------------*/
  4444. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4445. {
  4446. int fd;
  4447. nullpo_retr(0, sd);
  4448. fd=sd->fd;
  4449. WFIFOHEAD(fd,packet_len(0x125));
  4450. WFIFOW(fd,0)=0x125;
  4451. WFIFOW(fd,2)=n+2;
  4452. WFIFOL(fd,4)=amount;
  4453. WFIFOSET(fd,packet_len(0x125));
  4454. return 0;
  4455. }
  4456. /*==========================================
  4457. * Opens the shop creation menu.
  4458. * R 012d <num>.w
  4459. * 'num' is the number of allowed item slots
  4460. *------------------------------------------*/
  4461. void clif_openvendingreq(struct map_session_data* sd, int num)
  4462. {
  4463. int fd;
  4464. nullpo_retv(sd);
  4465. fd = sd->fd;
  4466. WFIFOHEAD(fd,packet_len(0x12d));
  4467. WFIFOW(fd,0) = 0x12d;
  4468. WFIFOW(fd,2) = num;
  4469. WFIFOSET(fd,packet_len(0x12d));
  4470. }
  4471. /*==========================================
  4472. * Displays a vending board to target/area
  4473. * R 0131 <ID>.l <message>.80B
  4474. *------------------------------------------*/
  4475. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4476. {
  4477. unsigned char buf[128];
  4478. nullpo_retv(bl);
  4479. WBUFW(buf,0) = 0x131;
  4480. WBUFL(buf,2) = bl->id;
  4481. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4482. if( fd ) {
  4483. WFIFOHEAD(fd,packet_len(0x131));
  4484. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4485. WFIFOSET(fd,packet_len(0x131));
  4486. } else {
  4487. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4488. }
  4489. }
  4490. /*==========================================
  4491. * Removes a vending board from screen
  4492. *------------------------------------------*/
  4493. void clif_closevendingboard(struct block_list* bl, int fd)
  4494. {
  4495. unsigned char buf[16];
  4496. nullpo_retv(bl);
  4497. WBUFW(buf,0) = 0x132;
  4498. WBUFL(buf,2) = bl->id;
  4499. if( fd ) {
  4500. WFIFOHEAD(fd,packet_len(0x132));
  4501. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4502. WFIFOSET(fd,packet_len(0x132));
  4503. } else {
  4504. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4505. }
  4506. }
  4507. /*==========================================
  4508. * Sends a list of items in a shop
  4509. * R 0133 <len>.w <ID>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
  4510. *------------------------------------------*/
  4511. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4512. {
  4513. int i,fd;
  4514. int count;
  4515. struct map_session_data* vsd;
  4516. nullpo_retv(sd);
  4517. nullpo_retv(vending);
  4518. nullpo_retv(vsd=map_id2sd(id));
  4519. fd = sd->fd;
  4520. count = vsd->vend_num;
  4521. WFIFOHEAD(fd, 8+count*22);
  4522. WFIFOW(fd,0) = 0x133;
  4523. WFIFOW(fd,2) = 8+count*22;
  4524. WFIFOL(fd,4) = id;
  4525. for( i = 0; i < count; i++ )
  4526. {
  4527. int index = vending[i].index;
  4528. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4529. WFIFOL(fd, 8+i*22) = vending[i].value;
  4530. WFIFOW(fd,12+i*22) = vending[i].amount;
  4531. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4532. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4533. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4534. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4535. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4536. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4537. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4538. }
  4539. WFIFOSET(fd,WFIFOW(fd,2));
  4540. }
  4541. /*==========================================
  4542. * Shop purchase failure
  4543. * R 0135 <index>.w <amount>.w <fail>.B
  4544. * fail=1 - not enough zeny
  4545. * fail=2 - overweight
  4546. * fail=4 - out of stock
  4547. * fail=5 - "cannot use an npc shop while in a trade"
  4548. *------------------------------------------*/
  4549. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4550. {
  4551. int fd;
  4552. nullpo_retv(sd);
  4553. fd = sd->fd;
  4554. WFIFOHEAD(fd,packet_len(0x135));
  4555. WFIFOW(fd,0) = 0x135;
  4556. WFIFOW(fd,2) = index+2;
  4557. WFIFOW(fd,4) = amount;
  4558. WFIFOB(fd,6) = fail;
  4559. WFIFOSET(fd,packet_len(0x135));
  4560. }
  4561. /*==========================================
  4562. * Shop creation success
  4563. * R 0136 <len>.w <ID>.l {<value>.l <index>.w <amount>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B*
  4564. *------------------------------------------*/
  4565. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4566. {
  4567. int i,fd;
  4568. int count;
  4569. nullpo_retv(sd);
  4570. fd = sd->fd;
  4571. count = sd->vend_num;
  4572. WFIFOHEAD(fd, 8+count*22);
  4573. WFIFOW(fd,0) = 0x136;
  4574. WFIFOW(fd,2) = 8+count*22;
  4575. WFIFOL(fd,4) = id;
  4576. for( i = 0; i < count; i++ )
  4577. {
  4578. int index = vending[i].index;
  4579. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4580. WFIFOL(fd, 8+i*22) = vending[i].value;
  4581. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4582. WFIFOW(fd,14+i*22) = vending[i].amount;
  4583. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4584. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4585. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4586. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4587. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4588. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  4589. }
  4590. WFIFOSET(fd,WFIFOW(fd,2));
  4591. }
  4592. /*==========================================
  4593. * Inform merchant that someone has bought an item.
  4594. * R 0137 <index>.w <amount>.w
  4595. *------------------------------------------*/
  4596. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4597. {
  4598. int fd;
  4599. nullpo_retv(sd);
  4600. fd = sd->fd;
  4601. WFIFOHEAD(fd,packet_len(0x137));
  4602. WFIFOW(fd,0) = 0x137;
  4603. WFIFOW(fd,2) = index+2;
  4604. WFIFOW(fd,4) = amount;
  4605. WFIFOSET(fd,packet_len(0x137));
  4606. }
  4607. /// Result of organizing a party.
  4608. /// R 00FA <result>.B
  4609. ///
  4610. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4611. /// result=1 : MsgStringTable[78]="party name already exists"
  4612. /// result=2 : MsgStringTable[79]="already in a party"
  4613. /// result=other : nothing
  4614. int clif_party_created(struct map_session_data *sd,int result)
  4615. {
  4616. int fd;
  4617. nullpo_retr(0, sd);
  4618. fd=sd->fd;
  4619. WFIFOHEAD(fd,packet_len(0xfa));
  4620. WFIFOW(fd,0)=0xfa;
  4621. WFIFOB(fd,2)=result;
  4622. WFIFOSET(fd,packet_len(0xfa));
  4623. return 0;
  4624. }
  4625. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4626. {
  4627. unsigned char buf[96];
  4628. int i;
  4629. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4630. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  4631. } else {
  4632. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  4633. }
  4634. if (i >= MAX_PARTY) return 0; //Should never happen...
  4635. sd = p->data[i].sd;
  4636. WBUFW(buf, 0) = 0x1e9;
  4637. WBUFL(buf, 2) = sd->status.account_id;
  4638. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  4639. WBUFW(buf,10) = sd->bl.x;
  4640. WBUFW(buf,12) = sd->bl.y;
  4641. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  4642. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4643. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4644. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4645. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4646. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4647. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4648. return 1;
  4649. }
  4650. /*==========================================
  4651. * Sends party information
  4652. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4653. *------------------------------------------*/
  4654. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4655. {
  4656. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4657. struct map_session_data* party_sd = NULL;
  4658. int i, c;
  4659. nullpo_retr(0, p);
  4660. WBUFW(buf,0) = 0xfb;
  4661. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4662. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4663. {
  4664. struct party_member* m = &p->party.member[i];
  4665. if(!m->account_id) continue;
  4666. if(party_sd == NULL) party_sd = p->data[i].sd;
  4667. WBUFL(buf,28+c*46) = m->account_id;
  4668. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4669. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4670. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4671. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4672. c++;
  4673. }
  4674. WBUFW(buf,2) = 28+c*46;
  4675. if(sd) { // send only to self
  4676. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4677. } else if (party_sd) { // send to whole party
  4678. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4679. }
  4680. return 0;
  4681. }
  4682. /*==========================================
  4683. * パーティ勧誘
  4684. *------------------------------------------*/
  4685. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4686. {
  4687. int fd;
  4688. struct party_data *p;
  4689. nullpo_retr(0, sd);
  4690. nullpo_retr(0, tsd);
  4691. fd=tsd->fd;
  4692. if( (p=party_search(sd->status.party_id))==NULL )
  4693. return 0;
  4694. WFIFOHEAD(fd,packet_len(0xfe));
  4695. WFIFOW(fd,0)=0xfe;
  4696. WFIFOL(fd,2)=sd->status.account_id;
  4697. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4698. WFIFOSET(fd,packet_len(0xfe));
  4699. return 0;
  4700. }
  4701. /*==========================================
  4702. * Party invitation result.
  4703. * R 00fd <nick>.24S <flag>.B
  4704. * R 02c5 <nick>.24S <flag>.L
  4705. * Flag values are:
  4706. * 0 -> char is already in a party
  4707. * 1 -> party invite was rejected
  4708. * 2 -> party invite was accepted
  4709. * 3 -> party is full
  4710. * 4 -> char of the same account already joined the party
  4711. *------------------------------------------*/
  4712. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4713. {
  4714. int fd;
  4715. nullpo_retv(sd);
  4716. fd=sd->fd;
  4717. #if PACKETVER < 20070821
  4718. WFIFOHEAD(fd,packet_len(0xfd));
  4719. WFIFOW(fd,0) = 0xfd;
  4720. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4721. WFIFOB(fd,26) = flag;
  4722. WFIFOSET(fd,packet_len(0xfd));
  4723. #else
  4724. WFIFOHEAD(fd,packet_len(0x2c5));
  4725. WFIFOW(fd,0) = 0x2c5;
  4726. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4727. WFIFOL(fd,26) = flag;
  4728. WFIFOSET(fd,packet_len(0x2c5));
  4729. #endif
  4730. }
  4731. /*==========================================
  4732. * パーティ設定送信
  4733. * flag & 0x001=exp変更ミス
  4734. * 0x010=item変更ミス
  4735. * 0x100=一人にのみ送信
  4736. *------------------------------------------*/
  4737. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4738. {
  4739. unsigned char buf[16];
  4740. nullpo_retr(0, p);
  4741. if(!sd && flag==0){
  4742. int i;
  4743. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4744. if (i < MAX_PARTY)
  4745. sd = p->data[i].sd;
  4746. }
  4747. if(!sd) return 0;
  4748. WBUFW(buf,0)=0x101;
  4749. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4750. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4751. WBUFW(buf,4)=0;
  4752. if(flag==0)
  4753. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4754. else
  4755. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4756. return 0;
  4757. }
  4758. /*==========================================
  4759. * パーティ脱退(脱退前に呼ぶこと)
  4760. *------------------------------------------*/
  4761. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4762. {
  4763. unsigned char buf[64];
  4764. int i;
  4765. nullpo_retr(0, p);
  4766. if(!sd && (flag&0xf0)==0)
  4767. {
  4768. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4769. if (i < MAX_PARTY)
  4770. sd = p->data[i].sd;
  4771. }
  4772. if(!sd) return 0;
  4773. WBUFW(buf,0)=0x105;
  4774. WBUFL(buf,2)=account_id;
  4775. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4776. WBUFB(buf,30)=flag&0x0f;
  4777. if((flag&0xf0)==0)
  4778. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4779. else
  4780. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4781. return 0;
  4782. }
  4783. /*==========================================
  4784. * パーティメッセージ送信
  4785. *------------------------------------------*/
  4786. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  4787. {
  4788. struct map_session_data *sd;
  4789. int i;
  4790. nullpo_retr(0, p);
  4791. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  4792. if(i < MAX_PARTY){
  4793. unsigned char buf[1024];
  4794. sd = p->data[i].sd;
  4795. WBUFW(buf,0)=0x109;
  4796. WBUFW(buf,2)=len+8;
  4797. WBUFL(buf,4)=account_id;
  4798. memcpy(WBUFP(buf,8),mes,len);
  4799. clif_send(buf,len+8,&sd->bl,PARTY);
  4800. }
  4801. return 0;
  4802. }
  4803. /*==========================================
  4804. * パーティ座標通知
  4805. *------------------------------------------*/
  4806. int clif_party_xy(struct map_session_data *sd)
  4807. {
  4808. unsigned char buf[16];
  4809. nullpo_retr(0, sd);
  4810. WBUFW(buf,0)=0x107;
  4811. WBUFL(buf,2)=sd->status.account_id;
  4812. WBUFW(buf,6)=sd->bl.x;
  4813. WBUFW(buf,8)=sd->bl.y;
  4814. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  4815. return 0;
  4816. }
  4817. /*==========================================
  4818. * Sends x/y dot to a single fd. [Skotlex]
  4819. *------------------------------------------*/
  4820. int clif_party_xy_single(int fd, struct map_session_data *sd)
  4821. {
  4822. WFIFOHEAD(fd,packet_len(0x107));
  4823. WFIFOW(fd,0)=0x107;
  4824. WFIFOL(fd,2)=sd->status.account_id;
  4825. WFIFOW(fd,6)=sd->bl.x;
  4826. WFIFOW(fd,8)=sd->bl.y;
  4827. WFIFOSET(fd,packet_len(0x107));
  4828. return 0;
  4829. }
  4830. /*==========================================
  4831. * パーティHP通知
  4832. *------------------------------------------*/
  4833. int clif_party_hp(struct map_session_data *sd)
  4834. {
  4835. unsigned char buf[16];
  4836. nullpo_retr(0, sd);
  4837. WBUFW(buf,0)=0x106;
  4838. WBUFL(buf,2)=sd->status.account_id;
  4839. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4840. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4841. WBUFW(buf,8) = 100;
  4842. } else {
  4843. WBUFW(buf,6) = sd->battle_status.hp;
  4844. WBUFW(buf,8) = sd->battle_status.max_hp;
  4845. }
  4846. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  4847. return 0;
  4848. }
  4849. /*==========================================
  4850. * Sends HP bar to a single fd. [Skotlex]
  4851. *------------------------------------------*/
  4852. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  4853. {
  4854. WFIFOHEAD(fd,packet_len(0x106));
  4855. WFIFOW(fd,0) = 0x106;
  4856. WFIFOL(fd,2) = id;
  4857. if( maxhp > SHRT_MAX )
  4858. {// To correctly display the %hp bar. [Skotlex]
  4859. WFIFOW(fd,6) = hp/(maxhp/100);
  4860. WFIFOW(fd,8) = 100;
  4861. } else {
  4862. WFIFOW(fd,6) = hp;
  4863. WFIFOW(fd,8) = maxhp;
  4864. }
  4865. WFIFOSET(fd, packet_len(0x106));
  4866. }
  4867. /*==========================================
  4868. * GMへ場所とHP通知
  4869. *------------------------------------------*/
  4870. int clif_hpmeter(struct map_session_data *sd)
  4871. {
  4872. struct map_session_data *sd2;
  4873. unsigned char buf[16];
  4874. int i, x0, y0, x1, y1;
  4875. int level;
  4876. nullpo_retr(0, sd);
  4877. x0 = sd->bl.x - AREA_SIZE;
  4878. y0 = sd->bl.y - AREA_SIZE;
  4879. x1 = sd->bl.x + AREA_SIZE;
  4880. y1 = sd->bl.y + AREA_SIZE;
  4881. WBUFW(buf,0) = 0x106;
  4882. WBUFL(buf,2) = sd->status.account_id;
  4883. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4884. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4885. WBUFW(buf,8) = 100;
  4886. } else {
  4887. WBUFW(buf,6) = sd->battle_status.hp;
  4888. WBUFW(buf,8) = sd->battle_status.max_hp;
  4889. }
  4890. for (i = 0; i < fd_max; i++) {
  4891. if (session[i] && session[i]->func_parse == clif_parse &&
  4892. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  4893. sd != sd2 && sd2->state.active) {
  4894. if (sd2->bl.m != sd->bl.m ||
  4895. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  4896. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  4897. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  4898. level < pc_isGM(sd))
  4899. continue;
  4900. WFIFOHEAD (i, packet_len(0x106));
  4901. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  4902. WFIFOSET (i, packet_len(0x106));
  4903. }
  4904. }
  4905. return 0;
  4906. }
  4907. /*==========================================
  4908. * パーティ場所移動(未使用)
  4909. *------------------------------------------*/
  4910. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  4911. {
  4912. unsigned char buf[128];
  4913. nullpo_retv(sd);
  4914. nullpo_retv(p);
  4915. WBUFW(buf, 0) = 0x104;
  4916. WBUFL(buf, 2) = sd->status.account_id;
  4917. WBUFL(buf, 6) = 0;
  4918. WBUFW(buf,10) = sd->bl.x;
  4919. WBUFW(buf,12) = sd->bl.y;
  4920. WBUFB(buf,14) = !online;
  4921. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  4922. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  4923. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  4924. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  4925. }
  4926. /*==========================================
  4927. * 攻撃するために移動が必要
  4928. *------------------------------------------*/
  4929. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  4930. {
  4931. int fd;
  4932. nullpo_retr(0, sd);
  4933. nullpo_retr(0, bl);
  4934. fd=sd->fd;
  4935. WFIFOHEAD(fd,packet_len(0x139));
  4936. WFIFOW(fd, 0)=0x139;
  4937. WFIFOL(fd, 2)=bl->id;
  4938. WFIFOW(fd, 6)=bl->x;
  4939. WFIFOW(fd, 8)=bl->y;
  4940. WFIFOW(fd,10)=sd->bl.x;
  4941. WFIFOW(fd,12)=sd->bl.y;
  4942. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  4943. WFIFOSET(fd,packet_len(0x139));
  4944. return 0;
  4945. }
  4946. /*==========================================
  4947. * 製造エフェクト
  4948. *------------------------------------------*/
  4949. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  4950. {
  4951. int view,fd;
  4952. nullpo_retr(0, sd);
  4953. fd = sd->fd;
  4954. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  4955. WFIFOHEAD(fd,packet_len(0x18f));
  4956. WFIFOW(fd, 0)=0x18f;
  4957. WFIFOW(fd, 2)=flag;
  4958. if((view = itemdb_viewid(nameid)) > 0)
  4959. WFIFOW(fd, 4)=view;
  4960. else
  4961. WFIFOW(fd, 4)=nameid;
  4962. WFIFOSET(fd,packet_len(0x18f));
  4963. return 0;
  4964. }
  4965. // pet
  4966. int clif_catch_process(struct map_session_data *sd)
  4967. {
  4968. int fd;
  4969. nullpo_retr(0, sd);
  4970. fd=sd->fd;
  4971. WFIFOHEAD(fd,packet_len(0x19e));
  4972. WFIFOW(fd,0)=0x19e;
  4973. WFIFOSET(fd,packet_len(0x19e));
  4974. return 0;
  4975. }
  4976. int clif_pet_roulette(struct map_session_data *sd,int data)
  4977. {
  4978. int fd;
  4979. nullpo_retr(0, sd);
  4980. fd=sd->fd;
  4981. WFIFOHEAD(fd,packet_len(0x1a0));
  4982. WFIFOW(fd,0)=0x1a0;
  4983. WFIFOB(fd,2)=data;
  4984. WFIFOSET(fd,packet_len(0x1a0));
  4985. return 0;
  4986. }
  4987. /*==========================================
  4988. * pet卵リスト作成
  4989. *------------------------------------------*/
  4990. int clif_sendegg(struct map_session_data *sd)
  4991. {
  4992. //R 01a6 <len>.w <index>.w*
  4993. int i,n=0,fd;
  4994. nullpo_retr(0, sd);
  4995. fd=sd->fd;
  4996. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  4997. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  4998. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  4999. return 0;
  5000. }
  5001. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5002. WFIFOW(fd,0)=0x1a6;
  5003. if(sd->status.pet_id <= 0) {
  5004. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5005. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5006. sd->inventory_data[i]->type!=IT_PETEGG ||
  5007. sd->status.inventory[i].amount<=0)
  5008. continue;
  5009. WFIFOW(fd,n*2+4)=i+2;
  5010. n++;
  5011. }
  5012. }
  5013. WFIFOW(fd,2)=4+n*2;
  5014. WFIFOSET(fd,WFIFOW(fd,2));
  5015. sd->menuskill_id = SA_TAMINGMONSTER;
  5016. sd->menuskill_val = -1;
  5017. return 0;
  5018. }
  5019. /*==========================================
  5020. * Sends a specific pet data update.
  5021. * type = 0 -> param = 0 (initial data)
  5022. * type = 1 -> param = intimacy value
  5023. * type = 2 -> param = hungry value
  5024. * type = 3 -> param = accessory id
  5025. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5026. * type = 5 -> param = hairstyle number
  5027. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5028. *------------------------------------------*/
  5029. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5030. {
  5031. uint8 buf[16];
  5032. nullpo_retr(0, pd);
  5033. WBUFW(buf,0) = 0x1a4;
  5034. WBUFB(buf,2) = type;
  5035. WBUFL(buf,3) = pd->bl.id;
  5036. WBUFL(buf,7) = param;
  5037. if (sd)
  5038. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5039. else
  5040. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5041. return 0;
  5042. }
  5043. int clif_send_petstatus(struct map_session_data *sd)
  5044. {
  5045. int fd;
  5046. struct s_pet *pet;
  5047. nullpo_retr(0, sd);
  5048. nullpo_retr(0, sd->pd);
  5049. fd=sd->fd;
  5050. pet = &sd->pd->pet;
  5051. WFIFOHEAD(fd,packet_len(0x1a2));
  5052. WFIFOW(fd,0)=0x1a2;
  5053. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5054. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5055. WFIFOW(fd,27)=pet->level;
  5056. WFIFOW(fd,29)=pet->hungry;
  5057. WFIFOW(fd,31)=pet->intimate;
  5058. WFIFOW(fd,33)=pet->equip;
  5059. WFIFOSET(fd,packet_len(0x1a2));
  5060. return 0;
  5061. }
  5062. /*==========================================
  5063. *
  5064. *------------------------------------------*/
  5065. int clif_pet_emotion(struct pet_data *pd,int param)
  5066. {
  5067. unsigned char buf[16];
  5068. nullpo_retr(0, pd);
  5069. memset(buf,0,packet_len(0x1aa));
  5070. WBUFW(buf,0)=0x1aa;
  5071. WBUFL(buf,2)=pd->bl.id;
  5072. if(param >= 100 && pd->petDB->talk_convert_class) {
  5073. if(pd->petDB->talk_convert_class < 0)
  5074. return 0;
  5075. else if(pd->petDB->talk_convert_class > 0) {
  5076. param -= (pd->pet.class_ - 100)*100;
  5077. param += (pd->petDB->talk_convert_class - 100)*100;
  5078. }
  5079. }
  5080. WBUFL(buf,6)=param;
  5081. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5082. return 0;
  5083. }
  5084. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5085. {
  5086. int fd;
  5087. nullpo_retr(0, sd);
  5088. fd=sd->fd;
  5089. WFIFOHEAD(fd,packet_len(0x1a3));
  5090. WFIFOW(fd,0)=0x1a3;
  5091. WFIFOB(fd,2)=fail;
  5092. WFIFOW(fd,3)=foodid;
  5093. WFIFOSET(fd,packet_len(0x1a3));
  5094. return 0;
  5095. }
  5096. /*==========================================
  5097. * オートスペル リスト送信
  5098. *------------------------------------------*/
  5099. int clif_autospell(struct map_session_data *sd,int skilllv)
  5100. {
  5101. int fd;
  5102. nullpo_retr(0, sd);
  5103. fd=sd->fd;
  5104. WFIFOHEAD(fd,packet_len(0x1cd));
  5105. WFIFOW(fd, 0)=0x1cd;
  5106. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5107. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5108. else
  5109. WFIFOL(fd,2)= 0x00000000;
  5110. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5111. WFIFOL(fd,6)= MG_COLDBOLT;
  5112. else
  5113. WFIFOL(fd,6)= 0x00000000;
  5114. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5115. WFIFOL(fd,10)= MG_FIREBOLT;
  5116. else
  5117. WFIFOL(fd,10)= 0x00000000;
  5118. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5119. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5120. else
  5121. WFIFOL(fd,14)= 0x00000000;
  5122. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5123. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5124. else
  5125. WFIFOL(fd,18)= 0x00000000;
  5126. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5127. WFIFOL(fd,22)= MG_FIREBALL;
  5128. else
  5129. WFIFOL(fd,22)= 0x00000000;
  5130. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5131. WFIFOL(fd,26)= MG_FROSTDIVER;
  5132. else
  5133. WFIFOL(fd,26)= 0x00000000;
  5134. WFIFOSET(fd,packet_len(0x1cd));
  5135. sd->menuskill_id = SA_AUTOSPELL;
  5136. sd->menuskill_val = skilllv;
  5137. return 0;
  5138. }
  5139. /*==========================================
  5140. * Devotion's visual effect
  5141. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5142. *------------------------------------------*/
  5143. void clif_devotion(struct map_session_data *sd, struct map_session_data *tsd)
  5144. {
  5145. unsigned char buf[56];
  5146. int i;
  5147. nullpo_retv(sd);
  5148. WBUFW(buf,0) = 0x1cf;
  5149. WBUFL(buf,2) = sd->bl.id;
  5150. for( i = 0; i < 5; i++ )
  5151. WBUFL(buf,6+4*i) = sd->devotion[i];
  5152. WBUFW(buf,26) = skill_get_range2(&sd->bl,CR_DEVOTION,pc_checkskill(sd,CR_DEVOTION)); // ignored
  5153. if( tsd )
  5154. clif_send(buf,packet_len(0x1cf),&tsd->bl,SELF);
  5155. else
  5156. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5157. }
  5158. /*==========================================
  5159. * 氣球
  5160. *------------------------------------------*/
  5161. int clif_spiritball(struct map_session_data *sd)
  5162. {
  5163. unsigned char buf[16];
  5164. nullpo_retr(0, sd);
  5165. WBUFW(buf,0)=0x1d0;
  5166. WBUFL(buf,2)=sd->bl.id;
  5167. WBUFW(buf,6)=sd->spiritball;
  5168. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5169. return 0;
  5170. }
  5171. /*==========================================
  5172. *
  5173. *------------------------------------------*/
  5174. int clif_combo_delay(struct block_list *bl,int wait)
  5175. {
  5176. unsigned char buf[32];
  5177. nullpo_retr(0, bl);
  5178. WBUFW(buf,0)=0x1d2;
  5179. WBUFL(buf,2)=bl->id;
  5180. WBUFL(buf,6)=wait;
  5181. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5182. return 0;
  5183. }
  5184. /*==========================================
  5185. *白刃取り
  5186. *------------------------------------------*/
  5187. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5188. int _bool)
  5189. {
  5190. unsigned char buf[32];
  5191. nullpo_retr(0, src);
  5192. nullpo_retr(0, dst);
  5193. WBUFW(buf,0)=0x1d1;
  5194. WBUFL(buf,2)=src->id;
  5195. WBUFL(buf,6)=dst->id;
  5196. WBUFL(buf,10)=_bool;
  5197. clif_send(buf,packet_len(0x1d1),src,AREA);
  5198. return 0;
  5199. }
  5200. /*==========================================
  5201. * MVPエフェクト
  5202. *------------------------------------------*/
  5203. int clif_mvp_effect(struct map_session_data *sd)
  5204. {
  5205. unsigned char buf[16];
  5206. nullpo_retr(0, sd);
  5207. WBUFW(buf,0)=0x10c;
  5208. WBUFL(buf,2)=sd->bl.id;
  5209. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5210. return 0;
  5211. }
  5212. /*==========================================
  5213. * MVPアイテム所得
  5214. *------------------------------------------*/
  5215. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5216. {
  5217. int view,fd;
  5218. nullpo_retr(0, sd);
  5219. fd=sd->fd;
  5220. WFIFOHEAD(fd,packet_len(0x10a));
  5221. WFIFOW(fd,0)=0x10a;
  5222. if((view = itemdb_viewid(nameid)) > 0)
  5223. WFIFOW(fd,2)=view;
  5224. else
  5225. WFIFOW(fd,2)=nameid;
  5226. WFIFOSET(fd,packet_len(0x10a));
  5227. return 0;
  5228. }
  5229. /*==========================================
  5230. * MVP経験値所得
  5231. *------------------------------------------*/
  5232. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5233. {
  5234. int fd;
  5235. nullpo_retr(0, sd);
  5236. fd=sd->fd;
  5237. WFIFOHEAD(fd,packet_len(0x10b));
  5238. WFIFOW(fd,0)=0x10b;
  5239. WFIFOL(fd,2)=cap_value(exp,0,INT_MAX);
  5240. WFIFOSET(fd,packet_len(0x10b));
  5241. return 0;
  5242. }
  5243. /*==========================================
  5244. * Guild creation result
  5245. * R 0167 <flag>.B
  5246. * flag = 0 -> "Guild has been created."
  5247. * flag = 1 -> "You are already in a Guild."
  5248. * flag = 2 -> "That Guild Name already exists."
  5249. * flag = 3 -> "You need the neccessary item to create a Guild."
  5250. *------------------------------------------*/
  5251. int clif_guild_created(struct map_session_data *sd,int flag)
  5252. {
  5253. int fd;
  5254. nullpo_retr(0, sd);
  5255. fd=sd->fd;
  5256. WFIFOHEAD(fd,packet_len(0x167));
  5257. WFIFOW(fd,0)=0x167;
  5258. WFIFOB(fd,2)=flag;
  5259. WFIFOSET(fd,packet_len(0x167));
  5260. return 0;
  5261. }
  5262. /*==========================================
  5263. * ギルド所属通知
  5264. *------------------------------------------*/
  5265. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5266. {
  5267. int ps,fd;
  5268. nullpo_retr(0, sd);
  5269. nullpo_retr(0, g);
  5270. fd=sd->fd;
  5271. ps=guild_getposition(g,sd);
  5272. WFIFOHEAD(fd,packet_len(0x16c));
  5273. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5274. WFIFOW(fd,0)=0x16c;
  5275. WFIFOL(fd,2)=g->guild_id;
  5276. WFIFOL(fd,6)=g->emblem_id;
  5277. WFIFOL(fd,10)=g->position[ps].mode;
  5278. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5279. WFIFOSET(fd,packet_len(0x16c));
  5280. return 0;
  5281. }
  5282. /*==========================================
  5283. * ギルドメンバログイン通知
  5284. *------------------------------------------*/
  5285. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5286. {
  5287. unsigned char buf[64];
  5288. nullpo_retr(0, g);
  5289. WBUFW(buf, 0)=0x16d;
  5290. WBUFL(buf, 2)=g->member[idx].account_id;
  5291. WBUFL(buf, 6)=g->member[idx].char_id;
  5292. WBUFL(buf,10)=flag;
  5293. if(g->member[idx].sd==NULL){
  5294. struct map_session_data *sd=guild_getavailablesd(g);
  5295. if(sd!=NULL)
  5296. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5297. }else
  5298. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5299. return 0;
  5300. }
  5301. // Function `clif_guild_memberlogin_notice` sends info about
  5302. // logins and logouts of a guild member to the rest members.
  5303. // But at the 1st time (after a player login or map changing)
  5304. // the client won't show the message.
  5305. // So I suggest use this function for sending "first-time-info"
  5306. // to some player on entering the game or changing location.
  5307. // At next time the client would always show the message.
  5308. // The function sends all the statuses in the single packet
  5309. // to economize traffic. [LuzZza]
  5310. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5311. {
  5312. struct guild *g;
  5313. unsigned char buf[14*128];
  5314. int i, count=0, p_len;
  5315. nullpo_retr(0, sd);
  5316. p_len = packet_len(0x16d);
  5317. if(!(g = guild_search(sd->status.guild_id)))
  5318. return 0;
  5319. for(i=0; i<g->max_member; i++) {
  5320. if(g->member[i].account_id > 0 &&
  5321. g->member[i].account_id != sd->status.account_id) {
  5322. WBUFW(buf,count*p_len) = 0x16d;
  5323. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5324. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5325. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5326. count++;
  5327. }
  5328. }
  5329. clif_send(buf, p_len*count, &sd->bl, SELF);
  5330. return 0;
  5331. }
  5332. /*==========================================
  5333. * ギルドマスター通知(14dへの応答)
  5334. *------------------------------------------*/
  5335. int clif_guild_masterormember(struct map_session_data *sd)
  5336. {
  5337. int fd;
  5338. nullpo_retr(0, sd);
  5339. fd=sd->fd;
  5340. WFIFOHEAD(fd,packet_len(0x14e));
  5341. WFIFOW(fd,0) = 0x14e;
  5342. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5343. WFIFOSET(fd,packet_len(0x14e));
  5344. return 0;
  5345. }
  5346. /*==========================================
  5347. * Basic Info (Territories [Valaris])
  5348. *------------------------------------------*/
  5349. int clif_guild_basicinfo(struct map_session_data *sd)
  5350. {
  5351. int fd,i,t;
  5352. struct guild *g;
  5353. struct guild_castle *gc=NULL;
  5354. nullpo_retr(0, sd);
  5355. fd=sd->fd;
  5356. g=guild_search(sd->status.guild_id);
  5357. if(g==NULL)
  5358. return 0;
  5359. WFIFOHEAD(fd,packet_len(0x1b6));
  5360. WFIFOW(fd, 0)=0x1b6;//0x150;
  5361. WFIFOL(fd, 2)=g->guild_id;
  5362. WFIFOL(fd, 6)=g->guild_lv;
  5363. WFIFOL(fd,10)=g->connect_member;
  5364. WFIFOL(fd,14)=g->max_member;
  5365. WFIFOL(fd,18)=g->average_lv;
  5366. WFIFOL(fd,22)=g->exp;
  5367. WFIFOL(fd,26)=g->next_exp;
  5368. WFIFOL(fd,30)=0; // Tax Points
  5369. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5370. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5371. WFIFOL(fd,42)=g->emblem_id;
  5372. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5373. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5374. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5375. {
  5376. gc = guild_castle_search(i);
  5377. if(gc && g->guild_id == gc->guild_id)
  5378. t++;
  5379. }
  5380. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5381. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5382. return 0;
  5383. }
  5384. /*==========================================
  5385. * ギルド同盟/敵対情報
  5386. *------------------------------------------*/
  5387. int clif_guild_allianceinfo(struct map_session_data *sd)
  5388. {
  5389. int fd,i,c;
  5390. struct guild *g;
  5391. nullpo_retr(0, sd);
  5392. fd=sd->fd;
  5393. g=guild_search(sd->status.guild_id);
  5394. if(g==NULL)
  5395. return 0;
  5396. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5397. WFIFOW(fd, 0)=0x14c;
  5398. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5399. struct guild_alliance *a=&g->alliance[i];
  5400. if(a->guild_id>0){
  5401. WFIFOL(fd,c*32+4)=a->opposition;
  5402. WFIFOL(fd,c*32+8)=a->guild_id;
  5403. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5404. c++;
  5405. }
  5406. }
  5407. WFIFOW(fd, 2)=c*32+4;
  5408. WFIFOSET(fd,WFIFOW(fd,2));
  5409. return 0;
  5410. }
  5411. /*==========================================
  5412. * ギルドメンバーリスト
  5413. *------------------------------------------*/
  5414. int clif_guild_memberlist(struct map_session_data *sd)
  5415. {
  5416. int fd;
  5417. int i,c;
  5418. struct guild *g;
  5419. nullpo_retr(0, sd);
  5420. fd=sd->fd;
  5421. if (!fd)
  5422. return 0;
  5423. g=guild_search(sd->status.guild_id);
  5424. if(g==NULL)
  5425. return 0;
  5426. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5427. WFIFOW(fd, 0)=0x154;
  5428. for(i=0,c=0;i<g->max_member;i++){
  5429. struct guild_member *m=&g->member[i];
  5430. if(m->account_id==0)
  5431. continue;
  5432. WFIFOL(fd,c*104+ 4)=m->account_id;
  5433. WFIFOL(fd,c*104+ 8)=m->char_id;
  5434. WFIFOW(fd,c*104+12)=m->hair;
  5435. WFIFOW(fd,c*104+14)=m->hair_color;
  5436. WFIFOW(fd,c*104+16)=m->gender;
  5437. WFIFOW(fd,c*104+18)=m->class_;
  5438. WFIFOW(fd,c*104+20)=m->lv;
  5439. WFIFOL(fd,c*104+22)=m->exp;
  5440. WFIFOL(fd,c*104+26)=m->online;
  5441. WFIFOL(fd,c*104+30)=m->position;
  5442. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5443. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5444. c++;
  5445. }
  5446. WFIFOW(fd, 2)=c*104+4;
  5447. WFIFOSET(fd,WFIFOW(fd,2));
  5448. return 0;
  5449. }
  5450. /*==========================================
  5451. * ギルド役職名リスト
  5452. *------------------------------------------*/
  5453. int clif_guild_positionnamelist(struct map_session_data *sd)
  5454. {
  5455. int i,fd;
  5456. struct guild *g;
  5457. nullpo_retr(0, sd);
  5458. fd=sd->fd;
  5459. g=guild_search(sd->status.guild_id);
  5460. if(g==NULL)
  5461. return 0;
  5462. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5463. WFIFOW(fd, 0)=0x166;
  5464. for(i=0;i<MAX_GUILDPOSITION;i++){
  5465. WFIFOL(fd,i*28+4)=i;
  5466. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5467. }
  5468. WFIFOW(fd,2)=i*28+4;
  5469. WFIFOSET(fd,WFIFOW(fd,2));
  5470. return 0;
  5471. }
  5472. /*==========================================
  5473. * ギルド役職情報リスト
  5474. *------------------------------------------*/
  5475. int clif_guild_positioninfolist(struct map_session_data *sd)
  5476. {
  5477. int i,fd;
  5478. struct guild *g;
  5479. nullpo_retr(0, sd);
  5480. fd=sd->fd;
  5481. g=guild_search(sd->status.guild_id);
  5482. if(g==NULL)
  5483. return 0;
  5484. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5485. WFIFOW(fd, 0)=0x160;
  5486. for(i=0;i<MAX_GUILDPOSITION;i++){
  5487. struct guild_position *p=&g->position[i];
  5488. WFIFOL(fd,i*16+ 4)=i;
  5489. WFIFOL(fd,i*16+ 8)=p->mode;
  5490. WFIFOL(fd,i*16+12)=i;
  5491. WFIFOL(fd,i*16+16)=p->exp_mode;
  5492. }
  5493. WFIFOW(fd, 2)=i*16+4;
  5494. WFIFOSET(fd,WFIFOW(fd,2));
  5495. return 0;
  5496. }
  5497. /*==========================================
  5498. * ギルド役職変更通知
  5499. *------------------------------------------*/
  5500. int clif_guild_positionchanged(struct guild *g,int idx)
  5501. {
  5502. struct map_session_data *sd;
  5503. unsigned char buf[128];
  5504. nullpo_retr(0, g);
  5505. WBUFW(buf, 0)=0x174;
  5506. WBUFW(buf, 2)=44;
  5507. WBUFL(buf, 4)=idx;
  5508. WBUFL(buf, 8)=g->position[idx].mode;
  5509. WBUFL(buf,12)=idx;
  5510. WBUFL(buf,16)=g->position[idx].exp_mode;
  5511. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5512. if( (sd=guild_getavailablesd(g))!=NULL )
  5513. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5514. return 0;
  5515. }
  5516. /*==========================================
  5517. * ギルドメンバ変更通知
  5518. *------------------------------------------*/
  5519. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5520. {
  5521. struct map_session_data *sd;
  5522. unsigned char buf[64];
  5523. nullpo_retr(0, g);
  5524. WBUFW(buf, 0)=0x156;
  5525. WBUFW(buf, 2)=16;
  5526. WBUFL(buf, 4)=g->member[idx].account_id;
  5527. WBUFL(buf, 8)=g->member[idx].char_id;
  5528. WBUFL(buf,12)=g->member[idx].position;
  5529. if( (sd=guild_getavailablesd(g))!=NULL )
  5530. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5531. return 0;
  5532. }
  5533. /*==========================================
  5534. * ギルドエンブレム送信
  5535. *------------------------------------------*/
  5536. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5537. {
  5538. int fd;
  5539. nullpo_retr(0, sd);
  5540. nullpo_retr(0, g);
  5541. fd=sd->fd;
  5542. if(g->emblem_len<=0)
  5543. return 0;
  5544. WFIFOHEAD(fd,g->emblem_len+12);
  5545. WFIFOW(fd,0)=0x152;
  5546. WFIFOW(fd,2)=g->emblem_len+12;
  5547. WFIFOL(fd,4)=g->guild_id;
  5548. WFIFOL(fd,8)=g->emblem_id;
  5549. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5550. WFIFOSET(fd,WFIFOW(fd,2));
  5551. return 0;
  5552. }
  5553. /// Sends update of the guild id/emblem id to everyone in the area.
  5554. void clif_guild_emblem_area(struct block_list* bl)
  5555. {
  5556. uint8 buf[12];
  5557. nullpo_retv(bl);
  5558. // TODO this packet doesn't force the update of ui components that have the emblem visible
  5559. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  5560. WBUFW(buf,0) = 0x1B4;
  5561. WBUFL(buf,2) = bl->id;
  5562. WBUFL(buf,6) = status_get_guild_id(bl);
  5563. WBUFW(buf,10) = status_get_emblem_id(bl);
  5564. clif_send(buf, 12, bl, AREA_WOS);
  5565. }
  5566. /*==========================================
  5567. * Send guild skills
  5568. *------------------------------------------*/
  5569. int clif_guild_skillinfo(struct map_session_data* sd)
  5570. {
  5571. int fd;
  5572. struct guild* g;
  5573. int i,c;
  5574. nullpo_retr(0, sd);
  5575. fd = sd->fd;
  5576. g = guild_search(sd->status.guild_id);
  5577. if(g == NULL)
  5578. return 0;
  5579. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5580. WFIFOW(fd,0) = 0x0162;
  5581. WFIFOW(fd,4) = g->skill_point;
  5582. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5583. {
  5584. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5585. {
  5586. int id = g->skill[i].id;
  5587. int p = 6 + c*37;
  5588. WFIFOW(fd,p+0) = id;
  5589. WFIFOW(fd,p+2) = skill_get_inf(id);
  5590. WFIFOW(fd,p+4) = 0;
  5591. WFIFOW(fd,p+6) = g->skill[i].lv;
  5592. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5593. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5594. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5595. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5596. c++;
  5597. }
  5598. }
  5599. WFIFOW(fd,2) = 6 + c*37;
  5600. WFIFOSET(fd,WFIFOW(fd,2));
  5601. return 0;
  5602. }
  5603. /*==========================================
  5604. * Sends guild notice to client
  5605. * R 016f <str1z>.60B <str2z>.120B
  5606. *------------------------------------------*/
  5607. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5608. {
  5609. int fd;
  5610. nullpo_retr(0, sd);
  5611. nullpo_retr(0, g);
  5612. fd = sd->fd;
  5613. if ( !session_isActive(fd) )
  5614. return 0;
  5615. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5616. return 0;
  5617. WFIFOHEAD(fd,packet_len(0x16f));
  5618. WFIFOW(fd,0) = 0x16f;
  5619. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5620. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5621. WFIFOSET(fd,packet_len(0x16f));
  5622. return 0;
  5623. }
  5624. /*==========================================
  5625. * ギルドメンバ勧誘
  5626. *------------------------------------------*/
  5627. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5628. {
  5629. int fd;
  5630. nullpo_retr(0, sd);
  5631. nullpo_retr(0, g);
  5632. fd=sd->fd;
  5633. WFIFOHEAD(fd,packet_len(0x16a));
  5634. WFIFOW(fd,0)=0x16a;
  5635. WFIFOL(fd,2)=g->guild_id;
  5636. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5637. WFIFOSET(fd,packet_len(0x16a));
  5638. return 0;
  5639. }
  5640. /*==========================================
  5641. * ギルドメンバ勧誘結果
  5642. *------------------------------------------*/
  5643. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5644. {
  5645. int fd;
  5646. nullpo_retr(0, sd);
  5647. fd=sd->fd;
  5648. WFIFOHEAD(fd,packet_len(0x169));
  5649. WFIFOW(fd,0)=0x169;
  5650. WFIFOB(fd,2)=flag;
  5651. WFIFOSET(fd,packet_len(0x169));
  5652. return 0;
  5653. }
  5654. /*==========================================
  5655. * ギルドメンバ脱退通知
  5656. *------------------------------------------*/
  5657. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5658. {
  5659. unsigned char buf[128];
  5660. nullpo_retr(0, sd);
  5661. WBUFW(buf, 0)=0x15a;
  5662. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5663. memcpy(WBUFP(buf,26),mes,40);
  5664. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5665. return 0;
  5666. }
  5667. /*==========================================
  5668. * ギルドメンバ追放通知
  5669. *------------------------------------------*/
  5670. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  5671. {
  5672. unsigned char buf[128];
  5673. nullpo_retr(0, sd);
  5674. WBUFW(buf, 0)=0x15c;
  5675. safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
  5676. safestrncpy((char*)WBUFP(buf,26),mes,40);
  5677. safestrncpy((char*)WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  5678. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5679. return 0;
  5680. }
  5681. /*==========================================
  5682. * ギルド追放メンバリスト
  5683. *------------------------------------------*/
  5684. int clif_guild_expulsionlist(struct map_session_data *sd)
  5685. {
  5686. int fd;
  5687. int i,c;
  5688. struct guild *g;
  5689. nullpo_retr(0, sd);
  5690. fd=sd->fd;
  5691. g=guild_search(sd->status.guild_id);
  5692. if(g==NULL)
  5693. return 0;
  5694. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  5695. WFIFOW(fd,0)=0x163;
  5696. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5697. struct guild_expulsion *e=&g->expulsion[i];
  5698. if(e->account_id>0){
  5699. safestrncpy((char*)WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  5700. safestrncpy((char*)WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  5701. safestrncpy((char*)WFIFOP(fd,4 + c*88+48),e->mes,40);
  5702. c++;
  5703. }
  5704. }
  5705. WFIFOW(fd,2) = 4 + c*88;
  5706. WFIFOSET(fd,WFIFOW(fd,2));
  5707. return 0;
  5708. }
  5709. /*==========================================
  5710. * ギルド会話
  5711. *------------------------------------------*/
  5712. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5713. {
  5714. struct map_session_data *sd;
  5715. unsigned char *buf;
  5716. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5717. WBUFW(buf, 0) = 0x17f;
  5718. WBUFW(buf, 2) = len + 4;
  5719. memcpy(WBUFP(buf,4), mes, len);
  5720. if ((sd = guild_getavailablesd(g)) != NULL)
  5721. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5722. if(buf) aFree(buf);
  5723. return 0;
  5724. }
  5725. /*==========================================
  5726. * ギルドスキル割り振り通知
  5727. *------------------------------------------*/
  5728. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5729. {
  5730. int fd;
  5731. nullpo_retr(0, sd);
  5732. fd=sd->fd;
  5733. WFIFOHEAD(fd,11);
  5734. WFIFOW(fd,0) = 0x10e;
  5735. WFIFOW(fd,2) = skill_num;
  5736. WFIFOW(fd,4) = lv;
  5737. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5738. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5739. WFIFOB(fd,10) = 1;
  5740. WFIFOSET(fd,11);
  5741. return 0;
  5742. }
  5743. /*==========================================
  5744. * ギルド同盟要請
  5745. *------------------------------------------*/
  5746. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5747. {
  5748. int fd;
  5749. nullpo_retr(0, sd);
  5750. fd=sd->fd;
  5751. WFIFOHEAD(fd,packet_len(0x171));
  5752. WFIFOW(fd,0)=0x171;
  5753. WFIFOL(fd,2)=account_id;
  5754. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5755. WFIFOSET(fd,packet_len(0x171));
  5756. return 0;
  5757. }
  5758. /*==========================================
  5759. * Reply to alliance request.
  5760. * Flag values are:
  5761. * 0: Already allied.
  5762. * 1: You rejected the offer.
  5763. * 2: You accepted the offer.
  5764. * 3: They have too any alliances
  5765. * 4: You have too many alliances.
  5766. *------------------------------------------*/
  5767. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5768. {
  5769. int fd;
  5770. nullpo_retr(0, sd);
  5771. fd=sd->fd;
  5772. WFIFOHEAD(fd,packet_len(0x173));
  5773. WFIFOW(fd,0)=0x173;
  5774. WFIFOL(fd,2)=flag;
  5775. WFIFOSET(fd,packet_len(0x173));
  5776. return 0;
  5777. }
  5778. /*==========================================
  5779. * ギルド関係解消通知
  5780. *------------------------------------------*/
  5781. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5782. {
  5783. int fd;
  5784. nullpo_retr(0, sd);
  5785. fd = sd->fd;
  5786. if (fd <= 0)
  5787. return 0;
  5788. WFIFOHEAD(fd,packet_len(0x184));
  5789. WFIFOW(fd,0)=0x184;
  5790. WFIFOL(fd,2)=guild_id;
  5791. WFIFOL(fd,6)=flag;
  5792. WFIFOSET(fd,packet_len(0x184));
  5793. return 0;
  5794. }
  5795. /*==========================================
  5796. * ギルド敵対結果
  5797. *------------------------------------------*/
  5798. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  5799. {
  5800. int fd;
  5801. nullpo_retr(0, sd);
  5802. fd=sd->fd;
  5803. WFIFOHEAD(fd,packet_len(0x181));
  5804. WFIFOW(fd,0)=0x181;
  5805. WFIFOB(fd,2)=flag;
  5806. WFIFOSET(fd,packet_len(0x181));
  5807. return 0;
  5808. }
  5809. /*==========================================
  5810. * ギルド関係追加
  5811. *------------------------------------------*/
  5812. /*int clif_guild_allianceadded(struct guild *g,int idx)
  5813. {
  5814. unsigned char buf[64];
  5815. WBUFW(fd,0)=0x185;
  5816. WBUFL(fd,2)=g->alliance[idx].opposition;
  5817. WBUFL(fd,6)=g->alliance[idx].guild_id;
  5818. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  5819. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  5820. return 0;
  5821. }*/
  5822. /*==========================================
  5823. * ギルド解散通知
  5824. *------------------------------------------*/
  5825. int clif_guild_broken(struct map_session_data *sd,int flag)
  5826. {
  5827. int fd;
  5828. nullpo_retr(0, sd);
  5829. fd=sd->fd;
  5830. WFIFOHEAD(fd,packet_len(0x15e));
  5831. WFIFOW(fd,0)=0x15e;
  5832. WFIFOL(fd,2)=flag;
  5833. WFIFOSET(fd,packet_len(0x15e));
  5834. return 0;
  5835. }
  5836. /*==========================================
  5837. * エモーション
  5838. *------------------------------------------*/
  5839. void clif_emotion(struct block_list *bl,int type)
  5840. {
  5841. unsigned char buf[8];
  5842. nullpo_retv(bl);
  5843. WBUFW(buf,0)=0xc0;
  5844. WBUFL(buf,2)=bl->id;
  5845. WBUFB(buf,6)=type;
  5846. clif_send(buf,packet_len(0xc0),bl,AREA);
  5847. }
  5848. /*==========================================
  5849. * トーキーボックス
  5850. *------------------------------------------*/
  5851. void clif_talkiebox(struct block_list* bl, const char* talkie)
  5852. {
  5853. unsigned char buf[86];
  5854. nullpo_retv(bl);
  5855. WBUFW(buf,0) = 0x191;
  5856. WBUFL(buf,2) = bl->id;
  5857. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  5858. clif_send(buf,packet_len(0x191),bl,AREA);
  5859. }
  5860. /*==========================================
  5861. * 結婚エフェクト
  5862. *------------------------------------------*/
  5863. void clif_wedding_effect(struct block_list *bl)
  5864. {
  5865. unsigned char buf[6];
  5866. nullpo_retv(bl);
  5867. WBUFW(buf,0) = 0x1ea;
  5868. WBUFL(buf,2) = bl->id;
  5869. clif_send(buf, packet_len(0x1ea), bl, AREA);
  5870. }
  5871. /*==========================================
  5872. * � なたに逢いたい使用時名前叫び
  5873. *------------------------------------------
  5874. void clif_callpartner(struct map_session_data *sd)
  5875. {
  5876. unsigned char buf[26];
  5877. char *p;
  5878. nullpo_retv(sd);
  5879. if(sd->status.partner_id){
  5880. WBUFW(buf,0)=0x1e6;
  5881. p = map_charid2nick(sd->status.partner_id);
  5882. if(p){
  5883. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  5884. }else{
  5885. map_reqchariddb(sd,sd->status.partner_id);
  5886. chrif_searchcharid(sd->status.partner_id);
  5887. WBUFB(buf,2) = 0;
  5888. }
  5889. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  5890. }
  5891. return;
  5892. }
  5893. */
  5894. /*==========================================
  5895. * Marry [DracoRPG]
  5896. *------------------------------------------*/
  5897. void clif_marriage_process(struct map_session_data *sd)
  5898. {
  5899. int fd;
  5900. nullpo_retv(sd);
  5901. fd=sd->fd;
  5902. WFIFOHEAD(fd,packet_len(0x1e4));
  5903. WFIFOW(fd,0)=0x1e4;
  5904. WFIFOSET(fd,packet_len(0x1e4));
  5905. }
  5906. /*==========================================
  5907. * Notice of divorce
  5908. *------------------------------------------*/
  5909. void clif_divorced(struct map_session_data* sd, const char* name)
  5910. {
  5911. int fd;
  5912. nullpo_retv(sd);
  5913. fd=sd->fd;
  5914. WFIFOHEAD(fd,packet_len(0x205));
  5915. WFIFOW(fd,0)=0x205;
  5916. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  5917. WFIFOSET(fd, packet_len(0x205));
  5918. }
  5919. /*==========================================
  5920. *
  5921. *------------------------------------------*/
  5922. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  5923. {
  5924. nullpo_retv(sd);
  5925. WFIFOHEAD(fd,packet_len(0x1e2));
  5926. WFIFOW(fd,0)=0x1e2;
  5927. WFIFOSET(fd, packet_len(0x1e2));
  5928. }
  5929. /*==========================================
  5930. *
  5931. *------------------------------------------*/
  5932. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  5933. {
  5934. int fd;
  5935. nullpo_retr(0, sd);
  5936. fd = sd->fd;
  5937. if (!fd || !len) return 0; //Disconnected player.
  5938. WFIFOHEAD(fd, len+5);
  5939. WFIFOW(fd, 0) = 0x17f;
  5940. WFIFOW(fd, 2) = len + 5;
  5941. memcpy(WFIFOP(fd,4), mes, len);
  5942. WFIFOSET(fd, WFIFOW(fd,2));
  5943. return 1;
  5944. }
  5945. /*==========================================
  5946. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  5947. *------------------------------------------*/
  5948. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  5949. {
  5950. unsigned char buf[1024];
  5951. if (!len) return;
  5952. WBUFW(buf, 0) = 0x17f;
  5953. WBUFW(buf, 2) = len + 5;
  5954. memcpy(WBUFP(buf,4), mes, len);
  5955. clif_send(buf, WBUFW(buf,2), src, target);
  5956. return;
  5957. }
  5958. /*==========================================
  5959. *
  5960. *------------------------------------------*/
  5961. int clif_GM_kickack(struct map_session_data *sd, int id)
  5962. {
  5963. int fd;
  5964. nullpo_retr(0, sd);
  5965. fd = sd->fd;
  5966. WFIFOHEAD(fd,packet_len(0xcd));
  5967. WFIFOW(fd,0) = 0xcd;
  5968. WFIFOL(fd,2) = id;
  5969. WFIFOSET(fd, packet_len(0xcd));
  5970. return 0;
  5971. }
  5972. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  5973. {
  5974. int fd = tsd->fd;
  5975. if( fd > 0 )
  5976. clif_authfail_fd(fd, 15);
  5977. else
  5978. map_quit(tsd);
  5979. if( sd )
  5980. clif_GM_kickack(sd,tsd->status.account_id);
  5981. }
  5982. /// Displays various manner-related status messages
  5983. /// R 014a <type>.L
  5984. /// type: 0 - "A manner point has been successfully aligned."
  5985. /// 1 - ?
  5986. /// 2 - ?
  5987. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  5988. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  5989. /// 5 - "You got a good point from %s."
  5990. void clif_manner_message(struct map_session_data* sd, uint32 type)
  5991. {
  5992. int fd;
  5993. nullpo_retv(sd);
  5994. fd = sd->fd;
  5995. WFIFOHEAD(fd,packet_len(0x14a));
  5996. WFIFOW(fd,0) = 0x14a;
  5997. WFIFOL(fd,2) = type;
  5998. WFIFOSET(fd, packet_len(0x14a));
  5999. }
  6000. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6001. /// R 014b <type>.B <GM name>.24B
  6002. /// type: 0 - positive (unmute)
  6003. /// 1 - negative (mute)
  6004. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6005. {
  6006. int fd;
  6007. nullpo_retv(sd);
  6008. nullpo_retv(tsd);
  6009. fd = tsd->fd;
  6010. WFIFOHEAD(fd,packet_len(0x14b));
  6011. WFIFOW(fd,0) = 0x14b;
  6012. WFIFOB(fd,2) = type;
  6013. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6014. WFIFOSET(fd, packet_len(0x14b));
  6015. }
  6016. /*==========================================
  6017. * Wis拒否許可応答
  6018. *------------------------------------------*/
  6019. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6020. {
  6021. int fd;
  6022. nullpo_retr(0, sd);
  6023. fd=sd->fd;
  6024. WFIFOHEAD(fd,packet_len(0xd1));
  6025. WFIFOW(fd,0)=0xd1;
  6026. WFIFOB(fd,2)=type;
  6027. WFIFOB(fd,3)=flag;
  6028. WFIFOSET(fd,packet_len(0xd1));
  6029. return 0;
  6030. }
  6031. /*==========================================
  6032. * Wis全拒否許可応答
  6033. *------------------------------------------*/
  6034. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6035. {
  6036. int fd;
  6037. nullpo_retr(0, sd);
  6038. fd=sd->fd;
  6039. WFIFOHEAD(fd,packet_len(0xd2));
  6040. WFIFOW(fd,0)=0xd2;
  6041. WFIFOB(fd,2)=type;
  6042. WFIFOB(fd,3)=flag;
  6043. WFIFOSET(fd,packet_len(0xd2));
  6044. return 0;
  6045. }
  6046. /*==========================================
  6047. * サウンドエフェクト
  6048. *------------------------------------------*/
  6049. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6050. {
  6051. int fd;
  6052. nullpo_retv(sd);
  6053. nullpo_retv(bl);
  6054. fd = sd->fd;
  6055. WFIFOHEAD(fd,packet_len(0x1d3));
  6056. WFIFOW(fd,0) = 0x1d3;
  6057. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6058. WFIFOB(fd,26) = type;
  6059. WFIFOL(fd,27) = 0;
  6060. WFIFOL(fd,31) = bl->id;
  6061. WFIFOSET(fd,packet_len(0x1d3));
  6062. return;
  6063. }
  6064. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6065. {
  6066. unsigned char buf[40];
  6067. nullpo_retr(0, bl);
  6068. WBUFW(buf,0) = 0x1d3;
  6069. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6070. WBUFB(buf,26) = type;
  6071. WBUFL(buf,27) = 0;
  6072. WBUFL(buf,31) = bl->id;
  6073. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6074. return 0;
  6075. }
  6076. // displaying special effects (npcs, weather, etc) [Valaris]
  6077. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6078. {
  6079. unsigned char buf[24];
  6080. nullpo_retr(0, bl);
  6081. memset(buf, 0, packet_len(0x1f3));
  6082. WBUFW(buf,0) = 0x1f3;
  6083. WBUFL(buf,2) = bl->id;
  6084. WBUFL(buf,6) = type;
  6085. clif_send(buf, packet_len(0x1f3), bl, target);
  6086. if (disguised(bl)) {
  6087. WBUFL(buf,2) = -bl->id;
  6088. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6089. }
  6090. return 0;
  6091. }
  6092. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6093. {
  6094. WFIFOHEAD(fd,10);
  6095. WFIFOW(fd,0) = 0x1f3;
  6096. WFIFOL(fd,2) = bl->id;
  6097. WFIFOL(fd,6) = type;
  6098. WFIFOSET(fd,10);
  6099. }
  6100. // messages (from mobs/npcs) [Valaris]
  6101. int clif_message(struct block_list* bl, const char* msg)
  6102. {
  6103. unsigned short msg_len = strlen(msg) + 1;
  6104. uint8 buf[256];
  6105. nullpo_retr(0, bl);
  6106. WBUFW(buf,0) = 0x8d;
  6107. WBUFW(buf,2) = msg_len + 8;
  6108. WBUFL(buf,4) = bl->id;
  6109. memcpy(WBUFP(buf,8), msg, msg_len);
  6110. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6111. return 0;
  6112. }
  6113. // refresh the client's screen, getting rid of any effects
  6114. int clif_refresh(struct map_session_data *sd)
  6115. {
  6116. nullpo_retr(-1, sd);
  6117. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6118. clif_inventorylist(sd);
  6119. if(pc_iscarton(sd)) {
  6120. clif_cartlist(sd);
  6121. clif_updatestatus(sd,SP_CARTINFO);
  6122. }
  6123. clif_updatestatus(sd,SP_WEIGHT);
  6124. clif_updatestatus(sd,SP_MAXWEIGHT);
  6125. clif_updatestatus(sd,SP_STR);
  6126. clif_updatestatus(sd,SP_AGI);
  6127. clif_updatestatus(sd,SP_VIT);
  6128. clif_updatestatus(sd,SP_INT);
  6129. clif_updatestatus(sd,SP_DEX);
  6130. clif_updatestatus(sd,SP_LUK);
  6131. if (sd->spiritball)
  6132. clif_spiritball_single(sd->fd, sd);
  6133. if (sd->vd.cloth_color)
  6134. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6135. if(merc_is_hom_active(sd->hd))
  6136. clif_send_homdata(sd,0,0);
  6137. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6138. clif_weather_check(sd);
  6139. if( pc_issit(sd) )
  6140. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6141. if( pc_isdead(sd) ) //When you refresh, resend the death packet.
  6142. clif_clearunit_single(sd->bl.id,1,sd->fd);
  6143. #ifndef TXT_ONLY
  6144. mail_clear(sd);
  6145. #endif
  6146. return 0;
  6147. }
  6148. // updates the object's (bl) name on client
  6149. int clif_charnameack (int fd, struct block_list *bl)
  6150. {
  6151. unsigned char buf[103];
  6152. int cmd = 0x95;
  6153. nullpo_retr(0, bl);
  6154. WBUFW(buf,0) = cmd;
  6155. WBUFL(buf,2) = bl->id;
  6156. switch(bl->type) {
  6157. case BL_PC:
  6158. {
  6159. struct map_session_data *ssd = (struct map_session_data *)bl;
  6160. struct party_data *p = NULL;
  6161. struct guild *g = NULL;
  6162. //Requesting your own "shadow" name. [Skotlex]
  6163. if (ssd->fd == fd && ssd->disguise)
  6164. WBUFL(buf,2) = -bl->id;
  6165. if (strlen(ssd->fakename)>1) {
  6166. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6167. break;
  6168. }
  6169. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6170. if (ssd->status.party_id > 0)
  6171. p = party_search(ssd->status.party_id);
  6172. if (ssd->status.guild_id > 0)
  6173. g = guild_search(ssd->status.guild_id);
  6174. if (p == NULL && g == NULL)
  6175. break;
  6176. WBUFW(buf, 0) = cmd = 0x195;
  6177. if (p)
  6178. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6179. else
  6180. WBUFB(buf,30) = 0;
  6181. if (g)
  6182. {
  6183. int i, ps = -1;
  6184. for(i = 0; i < g->max_member; i++) {
  6185. if (g->member[i].account_id == ssd->status.account_id &&
  6186. g->member[i].char_id == ssd->status.char_id )
  6187. {
  6188. ps = g->member[i].position;
  6189. break;
  6190. }
  6191. }
  6192. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6193. {
  6194. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6195. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6196. } else { //Assume no guild.
  6197. WBUFB(buf,54) = 0;
  6198. WBUFB(buf,78) = 0;
  6199. }
  6200. } else {
  6201. WBUFB(buf,54) = 0;
  6202. WBUFB(buf,78) = 0;
  6203. }
  6204. }
  6205. break;
  6206. //[blackhole89]
  6207. case BL_HOM:
  6208. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6209. break;
  6210. case BL_PET:
  6211. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6212. break;
  6213. case BL_NPC:
  6214. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6215. break;
  6216. case BL_MOB:
  6217. {
  6218. struct mob_data *md = (struct mob_data *)bl;
  6219. nullpo_retr(0, md);
  6220. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6221. if (md->guardian_data && md->guardian_data->guild_id) {
  6222. WBUFW(buf, 0) = cmd = 0x195;
  6223. WBUFB(buf,30) = 0;
  6224. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6225. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6226. } else if (battle_config.show_mob_info) {
  6227. char mobhp[50], *str_p = mobhp;
  6228. WBUFW(buf, 0) = cmd = 0x195;
  6229. if (battle_config.show_mob_info&4)
  6230. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6231. if (battle_config.show_mob_info&1)
  6232. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6233. if (battle_config.show_mob_info&2)
  6234. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6235. //Even thought mobhp ain't a name, we send it as one so the client
  6236. //can parse it. [Skotlex]
  6237. if (str_p != mobhp) {
  6238. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6239. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6240. WBUFB(buf,54) = 0;
  6241. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6242. }
  6243. }
  6244. }
  6245. break;
  6246. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6247. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6248. // break;
  6249. return 0;
  6250. default:
  6251. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6252. return 0;
  6253. }
  6254. // if no receipient specified just update nearby clients
  6255. if (fd == 0)
  6256. clif_send(buf, packet_len(cmd), bl, AREA);
  6257. else {
  6258. WFIFOHEAD(fd, packet_len(cmd));
  6259. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6260. WFIFOSET(fd, packet_len(cmd));
  6261. }
  6262. return 0;
  6263. }
  6264. //Used to update when a char leaves a party/guild. [Skotlex]
  6265. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6266. int clif_charnameupdate (struct map_session_data *ssd)
  6267. {
  6268. unsigned char buf[103];
  6269. int cmd = 0x195;
  6270. struct party_data *p = NULL;
  6271. struct guild *g = NULL;
  6272. nullpo_retr(0, ssd);
  6273. if (strlen(ssd->fakename)>1)
  6274. return 0; //No need to update as the party/guild was not displayed anyway.
  6275. WBUFW(buf,0) = cmd;
  6276. WBUFL(buf,2) = ssd->bl.id;
  6277. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6278. if (ssd->status.party_id > 0)
  6279. p = party_search(ssd->status.party_id);
  6280. if (ssd->status.guild_id > 0)
  6281. g = guild_search(ssd->status.guild_id);
  6282. if (p)
  6283. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6284. else
  6285. WBUFB(buf,30) = 0;
  6286. if (g)
  6287. {
  6288. int i, ps = -1;
  6289. for(i = 0; i < g->max_member; i++) {
  6290. if (g->member[i].account_id == ssd->status.account_id &&
  6291. g->member[i].char_id == ssd->status.char_id )
  6292. {
  6293. ps = g->member[i].position;
  6294. break;
  6295. }
  6296. }
  6297. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6298. {
  6299. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6300. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6301. } else { //Assume no guild.
  6302. WBUFB(buf,54) = 0;
  6303. WBUFB(buf,78) = 0;
  6304. }
  6305. } else {
  6306. WBUFB(buf,54) = 0;
  6307. WBUFB(buf,78) = 0;
  6308. }
  6309. // Update nearby clients
  6310. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6311. return 0;
  6312. }
  6313. int clif_slide(struct block_list *bl, int x, int y){
  6314. unsigned char buf[10];
  6315. nullpo_retr(0, bl);
  6316. WBUFW(buf, 0) = 0x01ff;
  6317. WBUFL(buf, 2) = bl->id;
  6318. WBUFW(buf, 6) = x;
  6319. WBUFW(buf, 8) = y;
  6320. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6321. return 0;
  6322. }
  6323. /*------------------------------------------
  6324. * @me command by lordalfa, rewritten implementation by Skotlex
  6325. *------------------------------------------*/
  6326. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6327. {
  6328. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6329. int len_mes = strlen(mes)+1; //Account for \0
  6330. if (len_mes + 8 >= 256) {
  6331. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6332. len_mes = 247; //Trunk it to avoid problems.
  6333. }
  6334. // send message to others
  6335. WBUFW(buf,0) = 0x8d;
  6336. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6337. WBUFL(buf,4) = sd->bl.id;
  6338. memcpy(WBUFP(buf,8), mes, len_mes);
  6339. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6340. // send back message to the speaker
  6341. WBUFW(buf,0) = 0x8e;
  6342. WBUFW(buf, 2) = len_mes + 4;
  6343. memcpy(WBUFP(buf,4), mes, len_mes);
  6344. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6345. return 0;
  6346. }
  6347. /*==========================
  6348. * Minimap fix [Kevin]
  6349. * Remove dot from minimap
  6350. *--------------------------*/
  6351. int clif_party_xy_remove(struct map_session_data *sd)
  6352. {
  6353. unsigned char buf[16];
  6354. nullpo_retr(0, sd);
  6355. WBUFW(buf,0)=0x107;
  6356. WBUFL(buf,2)=sd->status.account_id;
  6357. WBUFW(buf,6)=-1;
  6358. WBUFW(buf,8)=-1;
  6359. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6360. return 0;
  6361. }
  6362. //Displays gospel-buff information (thanks to Rayce):
  6363. //Type determines message based on this table:
  6364. /*
  6365. 0x15 End all negative status
  6366. 0x16 Immunity to all status
  6367. 0x17 MaxHP +100%
  6368. 0x18 MaxSP +100%
  6369. 0x19 All stats +20
  6370. 0x1c Enchant weapon with Holy element
  6371. 0x1d Enchant armor with Holy element
  6372. 0x1e DEF +25%
  6373. 0x1f ATK +100%
  6374. 0x20 HIT/Flee +50
  6375. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6376. */
  6377. void clif_gospel_info(struct map_session_data *sd, int type)
  6378. {
  6379. int fd=sd->fd;
  6380. WFIFOHEAD(fd,packet_len(0x215));
  6381. WFIFOW(fd,0)=0x215;
  6382. WFIFOL(fd,2)=type;
  6383. WFIFOSET(fd, packet_len(0x215));
  6384. }
  6385. /*==========================================
  6386. * Info about Star Glaldiator save map [Komurka]
  6387. * type: 1: Information, 0: Map registered
  6388. *------------------------------------------*/
  6389. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6390. {
  6391. int fd=sd->fd;
  6392. WFIFOHEAD(fd,packet_len(0x20e));
  6393. WFIFOW(fd,0) = 0x20e;
  6394. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6395. WFIFOL(fd,26) = sd->bl.id;
  6396. WFIFOB(fd,30) = feel_level;
  6397. WFIFOB(fd,31) = type?1:0;
  6398. WFIFOSET(fd,packet_len(0x20e));
  6399. }
  6400. /*==========================================
  6401. * Info about Star Glaldiator hate mob [Komurka]
  6402. * type: 1: Register mob, 0: Information.
  6403. *------------------------------------------*/
  6404. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6405. {
  6406. int fd=sd->fd;
  6407. WFIFOHEAD(fd,packet_len(0x20e));
  6408. WFIFOW(fd,0)=0x20e;
  6409. if (pcdb_checkid(class_))
  6410. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6411. else if (mobdb_checkid(class_))
  6412. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6413. else //Really shouldn't happen...
  6414. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6415. WFIFOL(fd,26)=sd->bl.id;
  6416. WFIFOB(fd,30)=hate_level;
  6417. WFIFOB(fd,31)=type?10:11; //Register/Info
  6418. WFIFOSET(fd, packet_len(0x20e));
  6419. }
  6420. /*==========================================
  6421. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6422. *------------------------------------------*/
  6423. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6424. {
  6425. int fd=sd->fd;
  6426. WFIFOHEAD(fd,packet_len(0x20e));
  6427. WFIFOW(fd,0)=0x20e;
  6428. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6429. WFIFOL(fd,26)=mob_id;
  6430. WFIFOB(fd,30)=progress; //Message to display
  6431. WFIFOB(fd,31)=20;
  6432. WFIFOSET(fd, packet_len(0x20e));
  6433. }
  6434. /*==========================================
  6435. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6436. *------------------------------------------*/
  6437. void clif_feel_hate_reset(struct map_session_data *sd)
  6438. {
  6439. int fd=sd->fd;
  6440. WFIFOHEAD(fd,packet_len(0x20e));
  6441. WFIFOW(fd,0)=0x20e;
  6442. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6443. WFIFOL(fd,26)=sd->bl.id;
  6444. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6445. WFIFOB(fd,31)=30;
  6446. WFIFOSET(fd, packet_len(0x20e));
  6447. }
  6448. /*==========================================
  6449. * Equip window (un)tick ack
  6450. * R 02d9 <zero>.L <flag>.L
  6451. *------------------------------------------*/
  6452. void clif_equiptickack(struct map_session_data* sd, int flag)
  6453. {
  6454. int fd;
  6455. nullpo_retv(sd);
  6456. fd = sd->fd;
  6457. WFIFOHEAD(fd, packet_len(0x2d9));
  6458. WFIFOW(fd, 0) = 0x2d9;
  6459. WFIFOL(fd, 2) = 0;
  6460. WFIFOL(fd, 6) = flag;
  6461. WFIFOSET(fd, packet_len(0x2d9));
  6462. }
  6463. /*==========================================
  6464. * The player's 'view equip' state, sent during login
  6465. * R 02da <flag>.B
  6466. *------------------------------------------*/
  6467. void clif_equipcheckbox(struct map_session_data* sd)
  6468. {
  6469. int fd;
  6470. nullpo_retv(sd);
  6471. fd = sd->fd;
  6472. WFIFOHEAD(fd, packet_len(0x2da));
  6473. WFIFOW(fd, 0) = 0x2da;
  6474. WFIFOW(fd, 2) = (sd->status.show_equip ? 1 : 0);
  6475. WFIFOSET(fd, packet_len(0x2da));
  6476. }
  6477. /*==========================================
  6478. * Sends info about a player's equipped items
  6479. * R 002d7 <length>.W <name>.24B <class>.w <hairstyle>.w <up-viewid>.w <mid-viewid>.w <low-viewid>.w <haircolor>.w <cloth-dye>.w <gender>.1B {equip item}.26B*
  6480. *------------------------------------------*/
  6481. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  6482. {
  6483. int i, n, fd;
  6484. nullpo_retv(sd);
  6485. nullpo_retv(tsd);
  6486. fd = sd->fd;
  6487. WFIFOHEAD(fd, MAX_INVENTORY * 26 + 43);
  6488. WFIFOW(fd, 0) = 0x2d7;
  6489. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  6490. WFIFOW(fd,28) = tsd->status.class_;
  6491. WFIFOW(fd,30) = tsd->vd.hair_style;
  6492. WFIFOW(fd,32) = tsd->vd.head_top;
  6493. WFIFOW(fd,34) = tsd->vd.head_mid;
  6494. WFIFOW(fd,36) = tsd->vd.head_bottom;
  6495. WFIFOW(fd,38) = tsd->vd.hair_color;
  6496. WFIFOW(fd,40) = tsd->vd.cloth_color;
  6497. WFIFOB(fd,42) = tsd->vd.sex;
  6498. for(i=0,n=0; i < MAX_INVENTORY; i++)
  6499. {
  6500. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  6501. continue;
  6502. if (itemdb_isstackable2(tsd->inventory_data[i])) // Is not equippable
  6503. continue;
  6504. // Inventory position
  6505. WFIFOW(fd, n*26+43) = i + 2;
  6506. // Add refine, identify flag, element, etc.
  6507. clif_item_sub(WFIFOP(fd,0), n*26+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  6508. // Add cards
  6509. clif_addcards(WFIFOP(fd, n*26+55), &tsd->status.inventory[i]);
  6510. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  6511. memset(WFIFOP(fd, n*26+63), 0, 6);
  6512. n++;
  6513. }
  6514. WFIFOW(fd, 2) = 43 + n*26; // Set length
  6515. WFIFOSET(fd, WFIFOW(fd, 2));
  6516. }
  6517. /*==========================================
  6518. * View player equip request denied
  6519. * R 0291 <message>.W
  6520. * TODO: this looks like a general-purpose packet to print msgstringtable entries.
  6521. *------------------------------------------*/
  6522. void clif_viewequip_fail(struct map_session_data* sd)
  6523. {
  6524. int fd;
  6525. nullpo_retv(sd);
  6526. fd = sd->fd;
  6527. WFIFOHEAD(fd, packet_len(0x291));
  6528. WFIFOW(fd, 0) = 0x291;
  6529. WFIFOW(fd, 2) = 0x54d; // This controls which message is displayed. 0x54d is the correct one. Maybe it's used for something else too?
  6530. WFIFOSET(fd, packet_len(0x291));
  6531. }
  6532. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  6533. /// Returns true if the packet was parsed successfully.
  6534. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6535. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6536. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6537. {
  6538. char *text, *name, *message;
  6539. unsigned int packetlen, textlen, namelen, messagelen;
  6540. int fd = sd->fd;
  6541. *name_ = NULL;
  6542. *namelen_ = 0;
  6543. *message_ = NULL;
  6544. *messagelen_ = 0;
  6545. packetlen = RFIFOW(fd,2);
  6546. // basic structure checks
  6547. if( packetlen > RFIFOREST(fd) )
  6548. { // there has to be enough data to read
  6549. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6550. return false;
  6551. }
  6552. if( packetlen < 4 + 1 )
  6553. { // 4-byte header and at least an empty string is expected
  6554. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6555. return false;
  6556. }
  6557. text = (char*)RFIFOP(fd,4);
  6558. textlen = packetlen - 4;
  6559. // process <name> part of the packet
  6560. if( format == 0 )
  6561. {// name and message are separated by ' : '
  6562. // validate name
  6563. name = text;
  6564. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6565. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6566. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6567. {
  6568. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6569. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6570. set_eof(fd); // Just kick them out to correct it.
  6571. return false;
  6572. }
  6573. message = name + namelen + 3;
  6574. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6575. }
  6576. else
  6577. {// name has fixed width
  6578. if( textlen < NAME_LENGTH + 1 )
  6579. {
  6580. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6581. return false;
  6582. }
  6583. // validate name
  6584. name = text;
  6585. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6586. if( name[namelen] != '\0' )
  6587. { // only restriction is that the name must be zero-terminated
  6588. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6589. return false;
  6590. }
  6591. message = name + NAME_LENGTH;
  6592. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6593. }
  6594. if( messagelen != strnlen(message, messagelen)+1 )
  6595. { // the declared length must match real length
  6596. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6597. return false;
  6598. }
  6599. // verify <message> part of the packet
  6600. if( message[messagelen-1] != '\0' )
  6601. { // message must be zero-terminated
  6602. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6603. return false;
  6604. }
  6605. if( messagelen > CHAT_SIZE_MAX-1 )
  6606. { // messages mustn't be too long
  6607. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  6608. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  6609. // Neither the official client nor server place any restriction on the length of the data in the packet,
  6610. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  6611. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  6612. return false;
  6613. }
  6614. *name_ = name;
  6615. *namelen_ = namelen;
  6616. *message_ = message;
  6617. *messagelen_ = messagelen;
  6618. return true;
  6619. }
  6620. // ---------------------
  6621. // clif_guess_PacketVer
  6622. // ---------------------
  6623. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6624. // error codes:
  6625. // 0 - Success
  6626. // 1 - Unknown packet_ver
  6627. // 2 - Invalid account_id
  6628. // 3 - Invalid char_id
  6629. // 4 - Invalid login_id1 (reserved)
  6630. // 5 - Invalid client_tick (reserved)
  6631. // 6 - Invalid sex
  6632. // Only the first 'invalid' error that appears is used.
  6633. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6634. {
  6635. static int err = 1;
  6636. static int packet_ver = -1;
  6637. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6638. if (get_previous)
  6639. {//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]
  6640. if( error )
  6641. *error = err;
  6642. return packet_ver;
  6643. }
  6644. //By default, start searching on the default one.
  6645. err = 1;
  6646. packet_ver = clif_config.packet_db_ver;
  6647. cmd = RFIFOW(fd,0);
  6648. packet_len = RFIFOREST(fd);
  6649. #define SET_ERROR(n) \
  6650. if( err == 1 )\
  6651. err = n;\
  6652. //define SET_ERROR
  6653. #define CHECK_PACKET_VER() \
  6654. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6655. ;/* not wanttoconnection or wrong length */\
  6656. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  6657. { SET_ERROR(2); }/* invalid account_id */\
  6658. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  6659. { SET_ERROR(3); }/* invalid char_id */\
  6660. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6661. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6662. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6663. { SET_ERROR(6); }/* invalid sex */\
  6664. else\
  6665. {\
  6666. err = 0;\
  6667. if( error )\
  6668. *error = 0;\
  6669. return packet_ver;\
  6670. }\
  6671. //define CHECK_PACKET_VER
  6672. CHECK_PACKET_VER();//Default packet version found.
  6673. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6674. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6675. CHECK_PACKET_VER();
  6676. }
  6677. if( error )
  6678. *error = err;
  6679. packet_ver = -1;
  6680. return -1;
  6681. #undef SET_ERROR
  6682. #undef CHECK_PACKET_VER
  6683. }
  6684. // ------------
  6685. // clif_parse_*
  6686. // ------------
  6687. // パケット読み取って色々操作
  6688. /*==========================================
  6689. *
  6690. *------------------------------------------*/
  6691. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6692. {
  6693. struct block_list* bl;
  6694. struct auth_node* node;
  6695. int cmd, account_id, char_id, login_id1, sex;
  6696. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6697. 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])
  6698. if (sd) {
  6699. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  6700. return;
  6701. }
  6702. // Only valid packet version get here
  6703. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6704. cmd = RFIFOW(fd,0);
  6705. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6706. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6707. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6708. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6709. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6710. if( packet_ver < 5 || // reject really old client versions
  6711. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6712. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6713. {// packet version rejected
  6714. ShowInfo("Rejected connection attempt, forbidden packet version (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"', Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%s"CL_RESET"').\n", account_id, char_id, packet_ver, ip2str(session[fd]->client_addr, NULL));
  6715. WFIFOHEAD(fd,packet_len(0x6a));
  6716. WFIFOW(fd,0) = 0x6a;
  6717. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6718. WFIFOSET(fd,packet_len(0x6a));
  6719. set_eof(fd);
  6720. return;
  6721. }
  6722. //Check for double login.
  6723. bl = map_id2bl(account_id);
  6724. if(bl && bl->type != BL_PC) {
  6725. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6726. WFIFOHEAD(fd,packet_len(0x6a));
  6727. WFIFOW(fd,0) = 0x6a;
  6728. WFIFOB(fd,2) = 3; // Rejected by server
  6729. WFIFOSET(fd,packet_len(0x6a));
  6730. set_eof(fd);
  6731. return;
  6732. }
  6733. if (bl ||
  6734. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  6735. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN))) {
  6736. sd = BL_CAST(BL_PC, bl);
  6737. if (!sd)
  6738. ; //We have another char with the same account logging in/out.
  6739. else //Already connected player.
  6740. if (sd->fd)
  6741. clif_authfail_fd(sd->fd, 2); //someone else logged in
  6742. else
  6743. if(sd->state.autotrade)
  6744. map_quit(sd);// kick autotrading character
  6745. //Else do not kick character, it could be on its 10 sec penalty for Alt+F4
  6746. clif_authfail_fd(fd, 8); //Still recognizes last connection
  6747. return;
  6748. }
  6749. CREATE(sd, TBL_PC, 1);
  6750. sd->fd = fd;
  6751. sd->packet_ver = packet_ver;
  6752. session[fd]->session_data = sd;
  6753. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6754. #if PACKETVER < 20070521
  6755. WFIFOHEAD(fd,4);
  6756. WFIFOL(fd,0) = sd->bl.id;
  6757. WFIFOSET(fd,4);
  6758. #else
  6759. WFIFOHEAD(fd,packet_len(0x283));
  6760. WFIFOW(fd,0) = 0x283;
  6761. WFIFOL(fd,2) = sd->bl.id;
  6762. WFIFOSET(fd,packet_len(0x283));
  6763. #endif
  6764. chrif_authreq(sd);
  6765. return;
  6766. }
  6767. /*==========================================
  6768. * 007d クライアント側マップ読み込み完了
  6769. * map侵入時に必要なデータを全て送りつける
  6770. *------------------------------------------*/
  6771. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6772. {
  6773. if(sd->bl.prev != NULL)
  6774. return;
  6775. if (!sd->state.active)
  6776. { //Character loading is not complete yet!
  6777. //Let pc_reg_received reinvoke this when ready.
  6778. sd->state.connect_new = 0;
  6779. return;
  6780. }
  6781. if (sd->state.rewarp)
  6782. { //Rewarp player.
  6783. sd->state.rewarp = 0;
  6784. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6785. return;
  6786. }
  6787. // look
  6788. #if PACKETVER < 4
  6789. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6790. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6791. #else
  6792. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6793. #endif
  6794. if(sd->vd.cloth_color)
  6795. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6796. // item
  6797. pc_checkitem(sd);
  6798. clif_inventorylist(sd);
  6799. // cart
  6800. if(pc_iscarton(sd)) {
  6801. clif_cartlist(sd);
  6802. clif_updatestatus(sd,SP_CARTINFO);
  6803. }
  6804. // weight
  6805. clif_updatestatus(sd,SP_WEIGHT);
  6806. clif_updatestatus(sd,SP_MAXWEIGHT);
  6807. // guild
  6808. // (needs to go before clif_spawn() to show guild emblems correctly)
  6809. if(sd->status.guild_id)
  6810. guild_send_memberinfoshort(sd,1);
  6811. if(battle_config.pc_invincible_time > 0) {
  6812. if(map_flag_gvg(sd->bl.m))
  6813. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6814. else
  6815. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6816. }
  6817. if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
  6818. map_spawnmobs(sd->bl.m);
  6819. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  6820. map_addblock(&sd->bl);
  6821. clif_spawn(&sd->bl);
  6822. // Party
  6823. // (needs to go after clif_spawn() to show hp bars correctly)
  6824. if(sd->status.party_id) {
  6825. party_send_movemap(sd);
  6826. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6827. }
  6828. if(map[sd->bl.m].flag.pvp) {
  6829. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6830. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6831. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6832. sd->pvp_rank = 0;
  6833. sd->pvp_lastusers = 0;
  6834. sd->pvp_point = 5;
  6835. sd->pvp_won = 0;
  6836. sd->pvp_lost = 0;
  6837. }
  6838. clif_set0199(sd,1);
  6839. } else
  6840. // set flag, if it's a duel [LuzZza]
  6841. if(sd->duel_group)
  6842. clif_set0199(sd,1);
  6843. if (map[sd->bl.m].flag.gvg_dungeon)
  6844. {
  6845. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  6846. if (!sd->pvp_point)
  6847. {
  6848. sd->pvp_point = 5; //Need to die twice to be warped out.
  6849. sd->pvp_won = 0;
  6850. sd->pvp_lost = 0;
  6851. }
  6852. }
  6853. if(map_flag_gvg(sd->bl.m))
  6854. {
  6855. clif_set0199(sd,3);
  6856. if (battle_config.gvg_flee_penalty != 100)
  6857. status_calc_bl(&sd->bl, SCB_FLEE); //Apply flee penalty
  6858. }
  6859. // info about nearby objects
  6860. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  6861. 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);
  6862. //TODO: merge it with the code below
  6863. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
  6864. { //Return the pet to egg. [Skotlex]
  6865. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  6866. pet_menu(sd, 3); //Option 3 is return to egg.
  6867. }
  6868. // pet
  6869. if(sd->pd) {
  6870. map_addblock(&sd->pd->bl);
  6871. clif_spawn(&sd->pd->bl);
  6872. clif_send_petdata(sd,sd->pd,0,0);
  6873. clif_send_petstatus(sd);
  6874. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6875. }
  6876. //homunculus [blackhole89]
  6877. if(merc_is_hom_active(sd->hd)) {
  6878. map_addblock(&sd->hd->bl);
  6879. clif_spawn(&sd->hd->bl);
  6880. clif_send_homdata(sd,0,0);
  6881. clif_hominfo(sd,sd->hd,1);
  6882. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6883. clif_homskillinfoblock(sd);
  6884. if (battle_config.hom_setting&0x8)
  6885. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6886. if (!(battle_config.hom_setting&0x2))
  6887. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6888. }
  6889. if(sd->state.connect_new) {
  6890. int lv;
  6891. sd->state.connect_new = 0;
  6892. clif_skillinfoblock(sd);
  6893. clif_hotkeys_send(sd);
  6894. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6895. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6896. clif_updatestatus(sd,SP_SKILLPOINT);
  6897. clif_initialstatus(sd);
  6898. if (sd->sc.option&OPTION_FALCON)
  6899. clif_status_load(&sd->bl, SI_FALCON, 1);
  6900. if (sd->sc.option&OPTION_RIDING)
  6901. clif_status_load(&sd->bl, SI_RIDING, 1);
  6902. if(sd->status.manner < 0)
  6903. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  6904. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  6905. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  6906. if(sd->bl.m == sd->feel_map[0].m
  6907. || sd->bl.m == sd->feel_map[1].m
  6908. || sd->bl.m == sd->feel_map[2].m)
  6909. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  6910. }
  6911. if(sd->pd && sd->pd->pet.intimate > 900)
  6912. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  6913. if(merc_is_hom_active(sd->hd))
  6914. merc_hom_init_timers(sd->hd);
  6915. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6916. {
  6917. sd->state.night = 1;
  6918. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6919. }
  6920. #if PACKETVER >= 20070918
  6921. clif_equipcheckbox(sd);
  6922. #endif
  6923. // Notify everyone that this char logged in [Skotlex].
  6924. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  6925. //Login Event
  6926. npc_script_event(sd, NPCE_LOGIN);
  6927. mob_barricade_get(sd);
  6928. } else {
  6929. //For some reason the client "loses" these on warp/map-change.
  6930. clif_updatestatus(sd,SP_STR);
  6931. clif_updatestatus(sd,SP_AGI);
  6932. clif_updatestatus(sd,SP_VIT);
  6933. clif_updatestatus(sd,SP_INT);
  6934. clif_updatestatus(sd,SP_DEX);
  6935. clif_updatestatus(sd,SP_LUK);
  6936. // abort currently running script
  6937. sd->state.using_fake_npc = 0;
  6938. sd->state.menu_or_input = 0;
  6939. sd->npc_menu = 0;
  6940. if(sd->npc_id)
  6941. npc_event_dequeue(sd);
  6942. }
  6943. if( sd->state.changemap )
  6944. {// restore information that gets lost on map-change
  6945. if( night_flag && map[sd->bl.m].flag.nightenabled )
  6946. { //Display night.
  6947. if( !sd->state.night )
  6948. {
  6949. sd->state.night = 1;
  6950. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6951. }
  6952. }
  6953. else if( sd->state.night )
  6954. { //Clear night display.
  6955. sd->state.night = 0;
  6956. clif_status_load(&sd->bl, SI_NIGHT, 0);
  6957. }
  6958. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  6959. {
  6960. char output[128];
  6961. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  6962. clif_announce(&sd->bl, output, strlen(output) + 1, 0x00CC66, 3);
  6963. }
  6964. mob_barricade_get(sd);
  6965. sd->state.changemap = false;
  6966. }
  6967. #ifndef TXT_ONLY
  6968. mail_clear(sd);
  6969. #endif
  6970. quest_pc_login(sd);
  6971. if(map[sd->bl.m].flag.loadevent) // Lance
  6972. npc_script_event(sd, NPCE_LOADMAP);
  6973. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  6974. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  6975. if (sd->sc.opt2) //Client loses these on warp.
  6976. clif_changeoption(&sd->bl);
  6977. clif_weather_check(sd);
  6978. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  6979. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  6980. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  6981. else
  6982. sd->areanpc_id = 0;
  6983. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  6984. if(pc_isdead(sd))
  6985. clif_clearunit_area(&sd->bl, 1);
  6986. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  6987. // else
  6988. // clif_changed_dir(&sd->bl, SELF);
  6989. // Trigger skill effects if you appear standing on them
  6990. if(!battle_config.pc_invincible_time)
  6991. skill_unit_move(&sd->bl,gettick(),1);
  6992. }
  6993. /*==========================================
  6994. *
  6995. *------------------------------------------*/
  6996. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  6997. {
  6998. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  6999. WFIFOHEAD(fd, packet_len(0x7f));
  7000. WFIFOW(fd,0)=0x7f;
  7001. WFIFOL(fd,2)=gettick();
  7002. WFIFOSET(fd,packet_len(0x7f));
  7003. // removed until the socket problems are fixed. [FlavioJS]
  7004. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7005. return;
  7006. }
  7007. void clif_hotkeys_send(struct map_session_data *sd) {
  7008. #ifdef HOTKEY_SAVING
  7009. const int fd = sd->fd;
  7010. int i;
  7011. if (!fd) return;
  7012. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7013. WFIFOW(fd, 0) = 0x02b9;
  7014. for(i = 0; i < MAX_HOTKEYS; i++) {
  7015. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7016. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7017. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7018. }
  7019. WFIFOSET(fd, packet_len(0x02b9));
  7020. #endif
  7021. }
  7022. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7023. #ifdef HOTKEY_SAVING
  7024. unsigned short idx;
  7025. int cmd;
  7026. cmd = RFIFOW(fd, 0);
  7027. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7028. if (idx >= MAX_HOTKEYS) return;
  7029. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7030. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7031. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7032. return;
  7033. #endif
  7034. }
  7035. /*==========================================
  7036. *
  7037. *------------------------------------------*/
  7038. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7039. {
  7040. short x, y;
  7041. int cmd;
  7042. if (pc_isdead(sd)) {
  7043. clif_clearunit_area(&sd->bl, 1);
  7044. return;
  7045. }
  7046. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7047. ; //You CAN walk on this OPT1 value.
  7048. else if (pc_cant_act(sd))
  7049. return;
  7050. if(sd->sc.data[SC_RUN])
  7051. return;
  7052. pc_delinvincibletimer(sd);
  7053. cmd = RFIFOW(fd,0);
  7054. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7055. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7056. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7057. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7058. //Set last idle time... [Skotlex]
  7059. sd->idletime = last_tick;
  7060. unit_walktoxy(&sd->bl, x, y, 4);
  7061. }
  7062. /*==========================================
  7063. *
  7064. *------------------------------------------*/
  7065. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7066. {
  7067. WFIFOHEAD(fd,packet_len(0x18b));
  7068. WFIFOW(fd,0) = 0x18b;
  7069. /* Rovert's prevent logout option fixed [Valaris] */
  7070. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] &&
  7071. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7072. ) {
  7073. set_eof(fd);
  7074. WFIFOW(fd,2)=0;
  7075. } else {
  7076. WFIFOW(fd,2)=1;
  7077. }
  7078. WFIFOSET(fd,packet_len(0x18b));
  7079. }
  7080. /// Requesting unit's name
  7081. /// S 0094 <object id>.l
  7082. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7083. {
  7084. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7085. struct block_list* bl;
  7086. //struct status_change *sc;
  7087. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7088. id = sd->bl.id;
  7089. bl = map_id2bl(id);
  7090. if( bl == NULL )
  7091. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7092. // 'see people in GM hide' cheat detection
  7093. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7094. sc = status_get_sc(bl);
  7095. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7096. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7097. pc_isGM(sd) < battle_config.hack_info_GM_level
  7098. ) {
  7099. char gm_msg[256];
  7100. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target (id: %d).\n", sd->status.name, sd->status.account_id, id);
  7101. ShowWarning(gm_msg);
  7102. // information is sent to all online GMs
  7103. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7104. return;
  7105. }
  7106. */
  7107. clif_charnameack(fd, bl);
  7108. }
  7109. /*==========================================
  7110. * Validates and processes global messages
  7111. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7112. *------------------------------------------*/
  7113. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7114. {
  7115. const char* text = (char*)RFIFOP(fd,4);
  7116. int textlen = RFIFOW(fd,2) - 4;
  7117. char *name, *message;
  7118. int namelen, messagelen;
  7119. // validate packet and retrieve name and message
  7120. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7121. return;
  7122. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  7123. return;
  7124. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7125. return;
  7126. if( battle_config.min_chat_delay )
  7127. { //[Skotlex]
  7128. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7129. return;
  7130. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7131. }
  7132. // send message to others (using the send buffer for temp. storage)
  7133. WFIFOHEAD(fd, 8 + textlen);
  7134. WFIFOW(fd,0) = 0x8d;
  7135. WFIFOW(fd,2) = 8 + textlen;
  7136. WFIFOL(fd,4) = sd->bl.id;
  7137. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7138. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7139. // send back message to the speaker
  7140. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7141. WFIFOW(fd,0) = 0x8e;
  7142. WFIFOSET(fd, WFIFOW(fd,2));
  7143. #ifdef PCRE_SUPPORT
  7144. // trigger listening npcs
  7145. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7146. #endif
  7147. // check for special supernovice phrase
  7148. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7149. {
  7150. unsigned int next = pc_nextbaseexp(sd);
  7151. if( next == 0 ) next = pc_thisbaseexp(sd);
  7152. if( get_percentage(sd->status.base_exp, next)% 10 == 0 ) // 0%, 10%, 20%, ...
  7153. {
  7154. switch (sd->state.snovice_call_flag) {
  7155. case 0:
  7156. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7157. sd->state.snovice_call_flag++;
  7158. break;
  7159. case 1: {
  7160. char buf[256];
  7161. sprintf(buf, msg_txt(505), sd->status.name);
  7162. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7163. sd->state.snovice_call_flag++;
  7164. }
  7165. break;
  7166. case 2:
  7167. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7168. sd->state.snovice_call_flag++;
  7169. break;
  7170. case 3:
  7171. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7172. break; //Do not override the noskill mapflag. [Skotlex]
  7173. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7174. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  7175. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7176. sd->state.snovice_call_flag = 0;
  7177. break;
  7178. }
  7179. }
  7180. }
  7181. // Chat logging type 'O' / Global Chat
  7182. if( log_config.chat&1 || (log_config.chat&2 && !(agit_flag && log_config.chat&64)) )
  7183. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7184. return;
  7185. }
  7186. /*==========================================
  7187. * /mm /mapmove (as @rura GM command)
  7188. *------------------------------------------*/
  7189. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7190. {
  7191. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7192. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7193. char* map_name;
  7194. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7195. return;
  7196. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7197. return;
  7198. map_name = (char*)RFIFOP(fd,2);
  7199. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7200. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7201. atcommand_mapmove(fd, sd, "@mapmove", output);
  7202. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7203. {
  7204. sprintf(message, "/mm %s", output);
  7205. log_atcommand(sd, message);
  7206. }
  7207. return;
  7208. }
  7209. /*==========================================
  7210. *
  7211. *------------------------------------------*/
  7212. void clif_changed_dir(struct block_list *bl, enum send_target target)
  7213. {
  7214. unsigned char buf[64];
  7215. WBUFW(buf,0) = 0x9c;
  7216. WBUFL(buf,2) = bl->id;
  7217. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7218. WBUFB(buf,8) = unit_getdir(bl);
  7219. clif_send(buf, packet_len(0x9c), bl, target);
  7220. if (disguised(bl)) {
  7221. WBUFL(buf,2) = -bl->id;
  7222. WBUFW(buf,6) = 0;
  7223. clif_send(buf, packet_len(0x9c), bl, SELF);
  7224. }
  7225. return;
  7226. }
  7227. /*==========================================
  7228. *
  7229. *------------------------------------------*/
  7230. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7231. {
  7232. unsigned char headdir, dir;
  7233. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7234. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7235. pc_setdir(sd, dir, headdir);
  7236. clif_changed_dir(&sd->bl, AREA_WOS);
  7237. return;
  7238. }
  7239. /*==========================================
  7240. *
  7241. *------------------------------------------*/
  7242. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7243. {
  7244. unsigned char buf[64];
  7245. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7246. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7247. clif_skill_fail(sd, 1, 0, 1);
  7248. return;
  7249. }
  7250. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7251. if (sd->emotionlasttime >= time(NULL)) {
  7252. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7253. clif_skill_fail(sd, 1, 0, 1);
  7254. return;
  7255. }
  7256. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7257. WBUFW(buf,0) = 0xc0;
  7258. WBUFL(buf,2) = sd->bl.id;
  7259. WBUFB(buf,6) = RFIFOB(fd,2);
  7260. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7261. } else
  7262. clif_skill_fail(sd, 1, 0, 1);
  7263. }
  7264. /*==========================================
  7265. *
  7266. *------------------------------------------*/
  7267. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7268. {
  7269. WFIFOHEAD(fd,packet_len(0xc2));
  7270. WFIFOW(fd,0) = 0xc2;
  7271. WFIFOL(fd,2) = map_getusers();
  7272. WFIFOSET(fd,packet_len(0xc2));
  7273. }
  7274. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7275. {
  7276. if (pc_isdead(sd)) {
  7277. clif_clearunit_area(&sd->bl, 1);
  7278. return;
  7279. }
  7280. if (sd->sc.count &&
  7281. (sd->sc.data[SC_TRICKDEAD] ||
  7282. sd->sc.data[SC_AUTOCOUNTER] ||
  7283. sd->sc.data[SC_BLADESTOP]))
  7284. return;
  7285. pc_stop_walking(sd, 1);
  7286. pc_stop_attack(sd);
  7287. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7288. target_id = sd->bl.id;
  7289. switch(action_type)
  7290. {
  7291. case 0x00: // once attack
  7292. case 0x07: // continuous attack
  7293. if (pc_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7294. return;
  7295. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7296. return;
  7297. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7298. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7299. clif_skill_fail(sd, 1, 4, 0);
  7300. return;
  7301. }
  7302. }
  7303. pc_delinvincibletimer(sd);
  7304. sd->idletime = last_tick;
  7305. unit_attack(&sd->bl, target_id, action_type != 0);
  7306. break;
  7307. case 0x02: // sitdown
  7308. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7309. clif_skill_fail(sd, 1, 0, 2);
  7310. break;
  7311. }
  7312. if(pc_issit(sd)) {
  7313. //Bugged client? Just refresh them.
  7314. clif_sitting(&sd->bl);
  7315. return;
  7316. }
  7317. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7318. break;
  7319. if (sd->sc.count && (
  7320. sd->sc.data[SC_DANCING] ||
  7321. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7322. )) //No sitting during these states either.
  7323. break;
  7324. pc_setsit(sd);
  7325. skill_sit(sd,1);
  7326. clif_sitting(&sd->bl);
  7327. break;
  7328. case 0x03: // standup
  7329. if (!pc_issit(sd)) {
  7330. //Bugged client? Just refresh them.
  7331. clif_standing(&sd->bl);
  7332. return;
  7333. }
  7334. pc_setstand(sd);
  7335. skill_sit(sd,0);
  7336. clif_standing(&sd->bl);
  7337. break;
  7338. }
  7339. }
  7340. /*==========================================
  7341. *
  7342. *------------------------------------------*/
  7343. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7344. {
  7345. clif_parse_ActionRequest_sub(sd,
  7346. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7347. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7348. gettick()
  7349. );
  7350. }
  7351. /*==========================================
  7352. *
  7353. *------------------------------------------*/
  7354. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7355. {
  7356. switch(RFIFOB(fd,2)) {
  7357. case 0x00:
  7358. pc_respawn(sd,2);
  7359. break;
  7360. case 0x01:
  7361. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7362. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7363. { //Send to char-server for character selection.
  7364. chrif_charselectreq(sd, session[fd]->client_addr);
  7365. } else {
  7366. WFIFOHEAD(fd,packet_len(0x18b));
  7367. WFIFOW(fd,0)=0x18b;
  7368. WFIFOW(fd,2)=1;
  7369. WFIFOSET(fd,packet_len(0x018b));
  7370. }
  7371. break;
  7372. }
  7373. }
  7374. /*==========================================
  7375. * Validates and processes whispered messages
  7376. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7377. *------------------------------------------*/
  7378. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7379. {
  7380. struct map_session_data* dstsd;
  7381. int i;
  7382. char *target, *message;
  7383. int namelen, messagelen;
  7384. // validate packet and retrieve name and message
  7385. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7386. return;
  7387. if (is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  7388. return;
  7389. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7390. return;
  7391. if (battle_config.min_chat_delay)
  7392. { //[Skotlex]
  7393. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7394. return;
  7395. }
  7396. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7397. }
  7398. // Chat logging type 'W' / Whisper
  7399. if( log_config.chat&1 || (log_config.chat&4 && !(agit_flag && log_config.chat&64)) )
  7400. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7401. //-------------------------------------------------------//
  7402. // Lordalfa - Paperboy - To whisper NPC commands //
  7403. //-------------------------------------------------------//
  7404. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7405. {
  7406. char* str = target+4; //Skip the NPC: string part.
  7407. struct npc_data* npc;
  7408. if ((npc = npc_name2id(str)))
  7409. {
  7410. char split_data[10][50];
  7411. char *split;
  7412. char output[256];
  7413. str = message;
  7414. for( i = 0; i < 10; ++i )
  7415. {// Splits the message using '#' as separators
  7416. split = strchr(str,'#');
  7417. if( split == NULL )
  7418. { // use the remaining string
  7419. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7420. for( ++i; i < 10; ++i )
  7421. split_data[i][0] = '\0';
  7422. break;
  7423. }
  7424. *split = '\0';
  7425. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7426. str = split+1;
  7427. }
  7428. for( i = 0; i < 10; ++i )
  7429. {
  7430. sprintf(output, "@whispervar%d$", i);
  7431. set_var(sd,output,(char *) split_data[i]);
  7432. }
  7433. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7434. npc_event(sd,output,0); // Calls the NPC label
  7435. return;
  7436. }
  7437. }
  7438. // Main chat [LuzZza]
  7439. if(strcmpi(target, main_chat_nick) == 0)
  7440. {
  7441. if(!sd->state.mainchat)
  7442. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7443. else {
  7444. char output[256];
  7445. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7446. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7447. }
  7448. // Chat logging type 'M' / Main Chat
  7449. if( log_config.chat&1 || (log_config.chat&32 && !(agit_flag && log_config.chat&64)) )
  7450. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7451. return;
  7452. }
  7453. // searching destination character
  7454. dstsd = map_nick2sd(target);
  7455. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7456. {
  7457. // player is not on this map-server
  7458. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7459. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7460. // and if we ask for 'Test', we must not contact 'test' player
  7461. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7462. intif_wis_message(sd, target, message, messagelen);
  7463. return;
  7464. }
  7465. // if player ignores everyone
  7466. if (dstsd->state.ignoreAll)
  7467. {
  7468. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7469. clif_wis_end(fd, 1); // 1: target character is not loged in
  7470. else
  7471. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7472. return;
  7473. }
  7474. // if player ignores the source character
  7475. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7476. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7477. { // source char present in ignore list
  7478. clif_wis_end(fd, 2); // 2: ignored by target
  7479. return;
  7480. }
  7481. // if player is autotrading
  7482. if( dstsd->state.autotrade == 1 )
  7483. {
  7484. char output[256];
  7485. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  7486. clif_wis_message(fd, sd->status.name, output, strlen(output) + 1);
  7487. return;
  7488. }
  7489. // notify sender of success
  7490. clif_wis_end(fd, 0); // 0: success to send wisper
  7491. // if player has an auto-away message
  7492. if(dstsd->away_message[0] != '\0')
  7493. {
  7494. char output[256];
  7495. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7496. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7497. if(dstsd->state.autotrade)
  7498. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7499. else
  7500. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7501. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7502. return;
  7503. }
  7504. // Normal message
  7505. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7506. return;
  7507. }
  7508. /*==========================================
  7509. * /b /nb
  7510. * S 0099 <packet len>.w <text>.?B 00
  7511. *------------------------------------------*/
  7512. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7513. {
  7514. char* msg = (char*)RFIFOP(fd,4);
  7515. unsigned int len = RFIFOW(fd,2)-4;
  7516. int lv;
  7517. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  7518. return;
  7519. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  7520. return;
  7521. // as the length varies depending on the command used, just block unreasonably long strings
  7522. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7523. intif_GMmessage(msg, len, 0);
  7524. if(log_config.gm && lv >= log_config.gm) {
  7525. char logmsg[CHAT_SIZE_MAX+4];
  7526. sprintf(logmsg, "/b %s", msg);
  7527. log_atcommand(sd, logmsg);
  7528. }
  7529. }
  7530. /*==========================================
  7531. *
  7532. *------------------------------------------*/
  7533. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7534. {
  7535. struct flooritem_data *fitem;
  7536. int map_object_id;
  7537. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7538. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7539. do {
  7540. if (pc_isdead(sd)) {
  7541. clif_clearunit_area(&sd->bl, 1);
  7542. break;
  7543. }
  7544. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7545. break;
  7546. if (pc_cant_act(sd))
  7547. break;
  7548. if(sd->sc.count && (
  7549. sd->sc.data[SC_HIDING] ||
  7550. sd->sc.data[SC_CLOAKING] ||
  7551. sd->sc.data[SC_TRICKDEAD] ||
  7552. sd->sc.data[SC_BLADESTOP] ||
  7553. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  7554. )
  7555. break;
  7556. if (!pc_takeitem(sd, fitem))
  7557. break;
  7558. return;
  7559. } while (0);
  7560. // Client REQUIRES a fail packet or you can no longer pick items.
  7561. clif_additem(sd,0,0,6);
  7562. }
  7563. /*==========================================
  7564. *
  7565. *------------------------------------------*/
  7566. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7567. {
  7568. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7569. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7570. do {
  7571. if (pc_isdead(sd))
  7572. break;
  7573. if (pc_cant_act(sd))
  7574. break;
  7575. if (sd->sc.count && (
  7576. sd->sc.data[SC_HIDING] ||
  7577. sd->sc.data[SC_AUTOCOUNTER] ||
  7578. sd->sc.data[SC_BLADESTOP] ||
  7579. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  7580. ))
  7581. break;
  7582. if (!pc_dropitem(sd, item_index, item_amount))
  7583. break;
  7584. return;
  7585. } while (0);
  7586. //Because the client does not like being ignored.
  7587. clif_delitem(sd, item_index,0);
  7588. }
  7589. /*==========================================
  7590. *
  7591. *------------------------------------------*/
  7592. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7593. {
  7594. int n;
  7595. if (pc_isdead(sd)) {
  7596. clif_clearunit_area(&sd->bl, 1);
  7597. return;
  7598. }
  7599. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7600. return;
  7601. //This flag enables you to use items while in an NPC. [Skotlex]
  7602. if (sd->npc_id) {
  7603. if (sd->npc_id != sd->npc_item_flag)
  7604. return;
  7605. } else
  7606. if (pc_istrading(sd))
  7607. return;
  7608. pc_delinvincibletimer(sd);
  7609. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7610. sd->idletime = last_tick;
  7611. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7612. if(n <0 || n >= MAX_INVENTORY)
  7613. return;
  7614. if (!pc_useitem(sd,n))
  7615. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7616. }
  7617. /*==========================================
  7618. *
  7619. *------------------------------------------*/
  7620. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7621. {
  7622. int index;
  7623. if(pc_isdead(sd)) {
  7624. clif_clearunit_area(&sd->bl,1);
  7625. return;
  7626. }
  7627. index = RFIFOW(fd,2)-2;
  7628. if (index < 0 || index >= MAX_INVENTORY)
  7629. return; //Out of bounds check.
  7630. if(sd->npc_id) {
  7631. if (sd->npc_id != sd->npc_item_flag)
  7632. return;
  7633. } else if (sd->state.storage_flag || sd->sc.opt1)
  7634. ; //You can equip/unequip stuff while storage is open/under status changes
  7635. else if (pc_cant_act(sd))
  7636. return;
  7637. if(!sd->status.inventory[index].identify) {
  7638. clif_equipitemack(sd,index,0,0); // fail
  7639. return;
  7640. }
  7641. if(!sd->inventory_data[index])
  7642. return;
  7643. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7644. pet_equipitem(sd,index);
  7645. return;
  7646. }
  7647. //Client doesn't send the position for ammo.
  7648. if(sd->inventory_data[index]->type == IT_AMMO)
  7649. pc_equipitem(sd,index,EQP_AMMO);
  7650. else
  7651. pc_equipitem(sd,index,RFIFOW(fd,4));
  7652. }
  7653. /*==========================================
  7654. *
  7655. *------------------------------------------*/
  7656. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7657. {
  7658. int index;
  7659. if(pc_isdead(sd)) {
  7660. clif_clearunit_area(&sd->bl,1);
  7661. return;
  7662. }
  7663. if (sd->state.storage_flag)
  7664. ; //You can equip/unequip stuff while storage is open.
  7665. else if (pc_cant_act(sd))
  7666. return;
  7667. index = RFIFOW(fd,2)-2;
  7668. pc_unequipitem(sd,index,1);
  7669. }
  7670. /*==========================================
  7671. *
  7672. *------------------------------------------*/
  7673. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7674. {
  7675. struct block_list *bl;
  7676. if(pc_isdead(sd)) {
  7677. clif_clearunit_area(&sd->bl,1);
  7678. return;
  7679. }
  7680. if (pc_cant_act(sd))
  7681. return;
  7682. bl = map_id2bl(RFIFOL(fd,2));
  7683. if (!bl) return;
  7684. switch (bl->type) {
  7685. case BL_MOB:
  7686. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7687. break;
  7688. case BL_PC:
  7689. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7690. break;
  7691. case BL_NPC:
  7692. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  7693. npc_click(sd,(TBL_NPC*)bl);
  7694. break;
  7695. }
  7696. return;
  7697. }
  7698. /*==========================================
  7699. *
  7700. *------------------------------------------*/
  7701. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7702. {
  7703. if (sd->state.trading)
  7704. return;
  7705. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7706. }
  7707. /// Request to buy chosen items from npc shop
  7708. /// S 00c8 <length>.w {<amount>.w <itemid>.w).4b*
  7709. /// R 00ca <result>.b
  7710. /// result = 00 -> "The deal has successfully completed."
  7711. /// result = 01 -> "You do not have enough zeny."
  7712. /// result = 02 -> "You are over your Weight Limit."
  7713. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  7714. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  7715. {
  7716. int n = (RFIFOW(fd,2)-4) /4;
  7717. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  7718. int result;
  7719. if( sd->state.trading || !sd->npc_shopid )
  7720. result = 1;
  7721. else
  7722. result = npc_buylist(sd,n,item_list);
  7723. sd->npc_shopid = 0; //Clear shop data.
  7724. WFIFOHEAD(fd,packet_len(0xca));
  7725. WFIFOW(fd,0) = 0xca;
  7726. WFIFOB(fd,2) = result;
  7727. WFIFOSET(fd,packet_len(0xca));
  7728. }
  7729. /*==========================================
  7730. *
  7731. *------------------------------------------*/
  7732. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7733. {
  7734. int fail=0,n;
  7735. unsigned short *item_list;
  7736. n = (RFIFOW(fd,2)-4) /4;
  7737. item_list = (unsigned short*)RFIFOP(fd,4);
  7738. if (sd->state.trading || !sd->npc_shopid)
  7739. fail = 1;
  7740. else
  7741. fail = npc_selllist(sd,n,item_list);
  7742. sd->npc_shopid = 0; //Clear shop data.
  7743. WFIFOHEAD(fd,packet_len(0xcb));
  7744. WFIFOW(fd,0)=0xcb;
  7745. WFIFOB(fd,2)=fail;
  7746. WFIFOSET(fd,packet_len(0xcb));
  7747. }
  7748. /*==========================================
  7749. * Chatroom creation request
  7750. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7751. *------------------------------------------*/
  7752. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7753. {
  7754. int len = RFIFOW(fd,2)-15;
  7755. int limit = RFIFOW(fd,4);
  7756. bool pub = (RFIFOB(fd,6) != 0);
  7757. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7758. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7759. char s_title[CHATROOM_TITLE_SIZE];
  7760. char s_password[CHATROOM_PASS_SIZE];
  7761. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  7762. return;
  7763. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7764. clif_skill_fail(sd,1,0,3);
  7765. return;
  7766. }
  7767. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7768. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7769. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7770. }
  7771. /*==========================================
  7772. * Chatroom join request
  7773. * S 00d9 <chat ID>.l <passwd>.8B
  7774. *------------------------------------------*/
  7775. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7776. {
  7777. int chatid = RFIFOL(fd,2);
  7778. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7779. chat_joinchat(sd,chatid,password);
  7780. }
  7781. /*==========================================
  7782. * Chatroom properties adjustment request
  7783. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7784. *------------------------------------------*/
  7785. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7786. {
  7787. int len = RFIFOW(fd,2)-15;
  7788. int limit = RFIFOW(fd,4);
  7789. bool pub = (RFIFOB(fd,6) != 0);
  7790. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7791. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7792. char s_title[CHATROOM_TITLE_SIZE];
  7793. char s_password[CHATROOM_PASS_SIZE];
  7794. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7795. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7796. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7797. }
  7798. /*==========================================
  7799. * S 00e0 ?.l <nick>.24B
  7800. *------------------------------------------*/
  7801. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7802. {
  7803. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7804. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7805. }
  7806. /*==========================================
  7807. *
  7808. *------------------------------------------*/
  7809. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7810. {
  7811. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7812. }
  7813. /*==========================================
  7814. * Request to leave the current chatroom
  7815. * S 00e3
  7816. *------------------------------------------*/
  7817. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7818. {
  7819. chat_leavechat(sd,0);
  7820. }
  7821. //Handles notifying asker and rejecter of what has just ocurred.
  7822. //Type is used to determine the correct msg_txt to use:
  7823. //0:
  7824. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7825. {
  7826. char *msg, output[256];
  7827. // Your request has been rejected by autoreject option.
  7828. msg = msg_txt(392);
  7829. clif_disp_onlyself(src, msg, strlen(msg));
  7830. //Notice that a request was rejected.
  7831. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7832. clif_disp_onlyself(target, output, strlen(output));
  7833. }
  7834. /*==========================================
  7835. * 取引要請を相手に送る
  7836. *------------------------------------------*/
  7837. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7838. {
  7839. struct map_session_data *t_sd;
  7840. t_sd = map_id2sd(RFIFOL(fd,2));
  7841. if(!sd->chatID && pc_cant_act(sd))
  7842. return; //You can trade while in a chatroom.
  7843. // @noask [LuzZza]
  7844. if(t_sd && t_sd->state.noask) {
  7845. clif_noask_sub(sd, t_sd, 0);
  7846. return;
  7847. }
  7848. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  7849. {
  7850. clif_skill_fail(sd,1,0,0);
  7851. return;
  7852. }
  7853. trade_traderequest(sd,t_sd);
  7854. }
  7855. /*==========================================
  7856. * 取引要請
  7857. *------------------------------------------*/
  7858. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7859. {
  7860. trade_tradeack(sd,RFIFOB(fd,2));
  7861. }
  7862. /*==========================================
  7863. * アイテム追加
  7864. *------------------------------------------*/
  7865. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7866. {
  7867. short index = RFIFOW(fd,2);
  7868. int amount = RFIFOL(fd,4);
  7869. if( index == 0 )
  7870. trade_tradeaddzeny(sd, amount);
  7871. else
  7872. trade_tradeadditem(sd, index, (short)amount);
  7873. }
  7874. /*==========================================
  7875. * アイテム追加完了(ok押し)
  7876. *------------------------------------------*/
  7877. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7878. {
  7879. trade_tradeok(sd);
  7880. }
  7881. /*==========================================
  7882. * 取引キャンセル
  7883. *------------------------------------------*/
  7884. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7885. {
  7886. trade_tradecancel(sd);
  7887. }
  7888. /*==========================================
  7889. * 取引許諾(trade押し)
  7890. *------------------------------------------*/
  7891. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7892. {
  7893. trade_tradecommit(sd);
  7894. }
  7895. /*==========================================
  7896. *
  7897. *------------------------------------------*/
  7898. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7899. {
  7900. pc_stop_attack(sd);
  7901. }
  7902. /*==========================================
  7903. * カートへアイテムを移す
  7904. *------------------------------------------*/
  7905. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  7906. {
  7907. if (pc_istrading(sd))
  7908. return;
  7909. if (!pc_iscarton(sd))
  7910. return;
  7911. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7912. }
  7913. /*==========================================
  7914. * カートからアイテムを出す
  7915. *------------------------------------------*/
  7916. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  7917. {
  7918. if (!pc_iscarton(sd))
  7919. return;
  7920. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7921. }
  7922. /*==========================================
  7923. * 付属品(鷹,ペコ,カート)をはずす
  7924. *------------------------------------------*/
  7925. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  7926. {
  7927. //Can only remove Cart/Riding/Falcon.
  7928. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  7929. }
  7930. /*==========================================
  7931. * チェンジカート
  7932. *------------------------------------------*/
  7933. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  7934. {
  7935. int type;
  7936. type = (int)RFIFOW(fd,2);
  7937. if( (type == 5 && sd->status.base_level > 90) ||
  7938. (type == 4 && sd->status.base_level > 80) ||
  7939. (type == 3 && sd->status.base_level > 65) ||
  7940. (type == 2 && sd->status.base_level > 40) )
  7941. pc_setcart(sd,type);
  7942. }
  7943. /*==========================================
  7944. * ステータスアップ
  7945. *------------------------------------------*/
  7946. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  7947. {
  7948. pc_statusup(sd,RFIFOW(fd,2));
  7949. }
  7950. /*==========================================
  7951. * スキルレベルアップ
  7952. *------------------------------------------*/
  7953. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  7954. {
  7955. pc_skillup(sd,RFIFOW(fd,2));
  7956. }
  7957. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  7958. {
  7959. int lv;
  7960. if (!hd)
  7961. return;
  7962. if (skillnotok_hom(skillnum, hd)) //[orn]
  7963. return;
  7964. if (hd->bl.id != target_id &&
  7965. skill_get_inf(skillnum)&INF_SELF_SKILL)
  7966. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  7967. if (hd->ud.skilltimer != -1) {
  7968. if (skillnum != SA_CASTCANCEL)
  7969. return;
  7970. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  7971. return;
  7972. lv = merc_hom_checkskill(hd, skillnum);
  7973. if (skilllv > lv)
  7974. skilllv = lv;
  7975. if (skilllv)
  7976. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  7977. }
  7978. /*==========================================
  7979. * スキル使用(ID指定)
  7980. *------------------------------------------*/
  7981. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  7982. {
  7983. short skillnum, skilllv;
  7984. int tmp, target_id;
  7985. unsigned int tick = gettick();
  7986. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7987. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7988. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  7989. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  7990. tmp = skill_get_inf(skillnum);
  7991. if (tmp&INF_GROUND_SKILL || !tmp)
  7992. return; //Using a ground/passive skill on a target? WRONG.
  7993. if (skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE+MAX_HOMUNSKILL) {
  7994. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  7995. return;
  7996. }
  7997. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  7998. sd->idletime = last_tick;
  7999. if (pc_cant_act(sd))
  8000. return;
  8001. if (pc_issit(sd))
  8002. return;
  8003. if (skillnotok(skillnum, sd))
  8004. return;
  8005. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8006. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8007. if (sd->ud.skilltimer != -1) {
  8008. if (skillnum != SA_CASTCANCEL)
  8009. return;
  8010. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8011. clif_skill_fail(sd, skillnum, 4, 0);
  8012. return;
  8013. }
  8014. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8015. return;
  8016. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8017. target_id = sd->bl.id;
  8018. if(sd->menuskill_id)
  8019. {
  8020. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8021. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8022. else
  8023. if (sd->menuskill_id != SA_AUTOSPELL)
  8024. return; //Can't use skills while a menu is open.
  8025. }
  8026. if (sd->skillitem == skillnum) {
  8027. if (skilllv != sd->skillitemlv)
  8028. skilllv = sd->skillitemlv;
  8029. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8030. return;
  8031. }
  8032. sd->skillitem = sd->skillitemlv = 0;
  8033. if (skillnum == MO_EXTREMITYFIST) {
  8034. if ((!sd->sc.data[SC_COMBO] ||
  8035. (sd->sc.data[SC_COMBO]->val1 != MO_COMBOFINISH &&
  8036. sd->sc.data[SC_COMBO]->val1 != CH_TIGERFIST &&
  8037. sd->sc.data[SC_COMBO]->val1 != CH_CHAINCRUSH))) {
  8038. if (!sd->state.skill_flag ) {
  8039. sd->state.skill_flag = 1;
  8040. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8041. return;
  8042. } else if (sd->bl.id == target_id) {
  8043. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8044. return;
  8045. }
  8046. }
  8047. }
  8048. if (skillnum == TK_JUMPKICK) {
  8049. if (!sd->sc.data[SC_COMBO] || sd->sc.data[SC_COMBO]->val1 != TK_JUMPKICK) {
  8050. if (!sd->state.skill_flag ) {
  8051. sd->state.skill_flag = 1;
  8052. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8053. return;
  8054. } else if (sd->bl.id == target_id) {
  8055. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8056. return;
  8057. }
  8058. }
  8059. }
  8060. if (skillnum >= GD_SKILLBASE) {
  8061. if (sd->state.gmaster_flag)
  8062. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8063. else
  8064. skilllv = 0;
  8065. } else {
  8066. tmp = pc_checkskill(sd, skillnum);
  8067. if (skilllv > tmp)
  8068. skilllv = tmp;
  8069. }
  8070. pc_delinvincibletimer(sd);
  8071. if (skilllv)
  8072. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8073. if (sd->state.skill_flag)
  8074. sd->state.skill_flag = 0;
  8075. }
  8076. /*==========================================
  8077. * スキル使用(場所指定)
  8078. *------------------------------------------*/
  8079. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8080. {
  8081. int lv;
  8082. unsigned int tick = gettick();
  8083. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8084. sd->idletime = last_tick;
  8085. if (skillnotok(skillnum, sd))
  8086. return;
  8087. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8088. return; //Using a target skill on the ground? WRONG.
  8089. if (skillmoreinfo != -1) {
  8090. if (pc_issit(sd)) {
  8091. clif_skill_fail(sd, skillnum, 0, 0);
  8092. return;
  8093. }
  8094. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8095. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8096. }
  8097. if (sd->ud.skilltimer != -1)
  8098. return;
  8099. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8100. {
  8101. clif_skill_fail(sd, skillnum, 4, 0);
  8102. return;
  8103. }
  8104. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8105. return;
  8106. if(sd->menuskill_id)
  8107. {
  8108. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8109. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8110. else
  8111. if (sd->menuskill_id != SA_AUTOSPELL)
  8112. return; //Can't use skills while a menu is open.
  8113. }
  8114. pc_delinvincibletimer(sd);
  8115. if (sd->skillitem == skillnum) {
  8116. if (skilllv != sd->skillitemlv)
  8117. skilllv = sd->skillitemlv;
  8118. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8119. } else {
  8120. sd->skillitem = sd->skillitemlv = 0;
  8121. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8122. if (skilllv > lv)
  8123. skilllv = lv;
  8124. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8125. }
  8126. }
  8127. }
  8128. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8129. {
  8130. if (pc_cant_act(sd))
  8131. return;
  8132. if (pc_issit(sd))
  8133. return;
  8134. clif_parse_UseSkillToPosSub(fd, sd,
  8135. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8136. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8137. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8138. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8139. -1 //Skill more info.
  8140. );
  8141. }
  8142. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8143. {
  8144. if (pc_cant_act(sd))
  8145. return;
  8146. if (pc_issit(sd))
  8147. return;
  8148. clif_parse_UseSkillToPosSub(fd, sd,
  8149. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8150. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8151. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8152. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8153. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8154. );
  8155. }
  8156. /*==========================================
  8157. * スキル使用(map指定)
  8158. *------------------------------------------*/
  8159. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8160. {
  8161. short skill_num = RFIFOW(fd,2);
  8162. char map_name[MAP_NAME_LENGTH];
  8163. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8164. if(skill_num != sd->menuskill_id)
  8165. return;
  8166. if (pc_cant_act(sd))
  8167. {
  8168. sd->menuskill_id = sd->menuskill_val = 0;
  8169. return;
  8170. }
  8171. pc_delinvincibletimer(sd);
  8172. skill_castend_map(sd,skill_num,map_name);
  8173. }
  8174. /*==========================================
  8175. * メモ要求
  8176. *------------------------------------------*/
  8177. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8178. {
  8179. if (!pc_isdead(sd))
  8180. pc_memo(sd,-1);
  8181. }
  8182. /*==========================================
  8183. * アイテム合成
  8184. *------------------------------------------*/
  8185. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8186. {
  8187. if (sd->menuskill_id != AM_PHARMACY)
  8188. return;
  8189. if (pc_istrading(sd)) {
  8190. //Make it fail to avoid shop exploits where you sell something different than you see.
  8191. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8192. sd->menuskill_val = sd->menuskill_id = 0;
  8193. return;
  8194. }
  8195. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8196. sd->menuskill_val = sd->menuskill_id = 0;
  8197. }
  8198. /*==========================================
  8199. * 武器修理
  8200. *------------------------------------------*/
  8201. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8202. {
  8203. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8204. return;
  8205. if (pc_istrading(sd)) {
  8206. //Make it fail to avoid shop exploits where you sell something different than you see.
  8207. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8208. sd->menuskill_val = sd->menuskill_id = 0;
  8209. return;
  8210. }
  8211. skill_repairweapon(sd,RFIFOW(fd,2));
  8212. sd->menuskill_val = sd->menuskill_id = 0;
  8213. }
  8214. /*==========================================
  8215. *
  8216. *------------------------------------------*/
  8217. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8218. {
  8219. int idx;
  8220. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8221. return;
  8222. if (pc_istrading(sd)) {
  8223. //Make it fail to avoid shop exploits where you sell something different than you see.
  8224. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8225. sd->menuskill_val = sd->menuskill_id = 0;
  8226. return;
  8227. }
  8228. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8229. skill_weaponrefine(sd, idx-2);
  8230. sd->menuskill_val = sd->menuskill_id = 0;
  8231. }
  8232. /*==========================================
  8233. *
  8234. *------------------------------------------*/
  8235. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8236. {
  8237. uint8 select;
  8238. select = RFIFOB(fd,6);
  8239. if((select > sd->npc_menu && select != 0xff) || !select){
  8240. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8241. clif_GM_kick(NULL,sd);
  8242. } else {
  8243. sd->npc_menu=select;
  8244. npc_scriptcont(sd,RFIFOL(fd,2));
  8245. }
  8246. }
  8247. /*==========================================
  8248. *
  8249. *------------------------------------------*/
  8250. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8251. {
  8252. npc_scriptcont(sd,RFIFOL(fd,2));
  8253. }
  8254. /*==========================================
  8255. * Value entered into a NPC input box.
  8256. * S 0143 <npcID>.l <amount>.l
  8257. *------------------------------------------*/
  8258. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8259. {
  8260. int npcid = RFIFOL(fd,2);
  8261. int amount = (int)RFIFOL(fd,6);
  8262. sd->npc_amount = amount;
  8263. npc_scriptcont(sd, npcid);
  8264. }
  8265. /*==========================================
  8266. * Text entered into a NPC input box.
  8267. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8268. *------------------------------------------*/
  8269. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8270. {
  8271. int message_len = RFIFOW(fd,2)-8;
  8272. int npcid = RFIFOL(fd,4);
  8273. const char* message = (char*)RFIFOP(fd,8);
  8274. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8275. npc_scriptcont(sd, npcid);
  8276. }
  8277. /*==========================================
  8278. *
  8279. *------------------------------------------*/
  8280. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8281. {
  8282. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8283. return;
  8284. npc_scriptcont(sd,RFIFOL(fd,2));
  8285. }
  8286. /*==========================================
  8287. * アイテム鑑定
  8288. *------------------------------------------*/
  8289. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8290. {
  8291. if (sd->menuskill_id != MC_IDENTIFY)
  8292. return;
  8293. skill_identify(sd,RFIFOW(fd,2)-2);
  8294. sd->menuskill_val = sd->menuskill_id = 0;
  8295. }
  8296. /*==========================================
  8297. * 矢作成
  8298. *------------------------------------------*/
  8299. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8300. {
  8301. if (sd->menuskill_id != AC_MAKINGARROW)
  8302. return;
  8303. if (pc_istrading(sd)) {
  8304. //Make it fail to avoid shop exploits where you sell something different than you see.
  8305. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8306. sd->menuskill_val = sd->menuskill_id = 0;
  8307. return;
  8308. }
  8309. skill_arrow_create(sd,RFIFOW(fd,2));
  8310. sd->menuskill_val = sd->menuskill_id = 0;
  8311. }
  8312. /*==========================================
  8313. * オートスペル受信
  8314. *------------------------------------------*/
  8315. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8316. {
  8317. if (sd->menuskill_id != SA_AUTOSPELL)
  8318. return;
  8319. skill_autospell(sd,RFIFOW(fd,2));
  8320. sd->menuskill_val = sd->menuskill_id = 0;
  8321. }
  8322. /*==========================================
  8323. * カード使用
  8324. *------------------------------------------*/
  8325. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8326. {
  8327. if (sd->state.trading != 0)
  8328. return;
  8329. clif_use_card(sd,RFIFOW(fd,2)-2);
  8330. }
  8331. /*==========================================
  8332. * カード挿入装備選択
  8333. *------------------------------------------*/
  8334. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8335. {
  8336. if (sd->state.trading != 0)
  8337. return;
  8338. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8339. }
  8340. /*==========================================
  8341. * 0193 キャラID名前引き
  8342. *------------------------------------------*/
  8343. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8344. {
  8345. int charid;
  8346. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8347. map_reqnickdb(sd, charid);
  8348. }
  8349. /*==========================================
  8350. * 0197 /resetskill /resetstate
  8351. *------------------------------------------*/
  8352. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8353. {
  8354. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8355. return;
  8356. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  8357. return;
  8358. if( RFIFOW(fd,2) )
  8359. pc_resetskill(sd,1);
  8360. else
  8361. pc_resetstate(sd);
  8362. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  8363. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8364. }
  8365. /*==========================================
  8366. * /lb /nlb
  8367. * S 019c <packet len>.w <text>.?B 00
  8368. *------------------------------------------*/
  8369. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8370. {
  8371. char* msg = (char*)RFIFOP(fd,4);
  8372. unsigned int len = RFIFOW(fd,2)-4;
  8373. int lv;
  8374. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8375. return;
  8376. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  8377. return;
  8378. // as the length varies depending on the command used, just block unreasonably long strings
  8379. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8380. clif_GMmessage(&sd->bl, msg, len, 1);
  8381. if( log_config.gm && lv >= log_config.gm ) {
  8382. char logmsg[CHAT_SIZE_MAX+5];
  8383. sprintf(logmsg, "/lb %s", msg);
  8384. log_atcommand(sd, logmsg);
  8385. }
  8386. }
  8387. /*==========================================
  8388. * カプラ倉庫へ入れる
  8389. *------------------------------------------*/
  8390. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8391. {
  8392. int item_index, item_amount;
  8393. if (pc_istrading(sd))
  8394. return;
  8395. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8396. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8397. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8398. return;
  8399. if (sd->state.storage_flag == 1)
  8400. storage_storageadd(sd, item_index, item_amount);
  8401. else
  8402. if (sd->state.storage_flag == 2)
  8403. storage_guild_storageadd(sd, item_index, item_amount);
  8404. }
  8405. /*==========================================
  8406. * カプラ倉庫から出す
  8407. *------------------------------------------*/
  8408. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8409. {
  8410. int item_index, item_amount;
  8411. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8412. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8413. if (sd->state.storage_flag == 1)
  8414. storage_storageget(sd, item_index, item_amount);
  8415. else
  8416. if(sd->state.storage_flag == 2)
  8417. storage_guild_storageget(sd, item_index, item_amount);
  8418. }
  8419. /*==========================================
  8420. * カプラ倉庫へカートから入れる
  8421. *------------------------------------------*/
  8422. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8423. {
  8424. if(sd->vender_id)
  8425. return;
  8426. if (!pc_iscarton(sd))
  8427. return;
  8428. if (sd->state.storage_flag == 1)
  8429. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8430. else
  8431. if (sd->state.storage_flag == 2)
  8432. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8433. }
  8434. /*==========================================
  8435. * カプラ倉庫から出す
  8436. *------------------------------------------*/
  8437. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8438. {
  8439. if (sd->vender_id)
  8440. return;
  8441. if (!pc_iscarton(sd))
  8442. return;
  8443. if (sd->state.storage_flag == 1)
  8444. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8445. else
  8446. if (sd->state.storage_flag == 2)
  8447. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8448. }
  8449. /*==========================================
  8450. * カプラ倉庫を閉じる
  8451. *------------------------------------------*/
  8452. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8453. {
  8454. if( sd->state.storage_flag == 1 )
  8455. storage_storageclose(sd);
  8456. else
  8457. if( sd->state.storage_flag == 2 )
  8458. storage_guild_storageclose(sd);
  8459. }
  8460. /*==========================================
  8461. * Kafra storage protection password system
  8462. *------------------------------------------*/
  8463. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8464. {
  8465. //TODO
  8466. }
  8467. /*==========================================
  8468. * Party creation request
  8469. * S 00f9 <party name>.24S
  8470. * S 01e8 <party name>.24S <item1>.B <item2>.B
  8471. *------------------------------------------*/
  8472. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8473. {
  8474. char* name = (char*)RFIFOP(fd,2);
  8475. name[NAME_LENGTH-1] = '\0';
  8476. if( map[sd->bl.m].flag.partylock )
  8477. {// Party locked.
  8478. clif_displaymessage(fd, msg_txt(227));
  8479. return;
  8480. }
  8481. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8482. {
  8483. clif_skill_fail(sd,1,0,4);
  8484. return;
  8485. }
  8486. party_create(sd,name,0,0);
  8487. }
  8488. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8489. {
  8490. char* name = (char*)RFIFOP(fd,2);
  8491. int item1 = RFIFOB(fd,26);
  8492. int item2 = RFIFOB(fd,27);
  8493. name[NAME_LENGTH-1] = '\0';
  8494. if( map[sd->bl.m].flag.partylock )
  8495. {// Party locked.
  8496. clif_displaymessage(fd, msg_txt(227));
  8497. return;
  8498. }
  8499. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8500. {
  8501. clif_skill_fail(sd,1,0,4);
  8502. return;
  8503. }
  8504. party_create(sd,name,item1,item2);
  8505. }
  8506. /*==========================================
  8507. * Party invitation request
  8508. * S 00fc <account ID>.L
  8509. * S 02c4 <char name>.24S
  8510. *------------------------------------------*/
  8511. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8512. {
  8513. struct map_session_data *t_sd;
  8514. if(map[sd->bl.m].flag.partylock)
  8515. {// Party locked.
  8516. clif_displaymessage(fd, msg_txt(227));
  8517. return;
  8518. }
  8519. t_sd = map_id2sd(RFIFOL(fd,2));
  8520. if(t_sd && t_sd->state.noask)
  8521. {// @noask [LuzZza]
  8522. clif_noask_sub(sd, t_sd, 1);
  8523. return;
  8524. }
  8525. party_invite(sd, t_sd);
  8526. }
  8527. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8528. {
  8529. struct map_session_data *t_sd;
  8530. char *name = (char*)RFIFOP(fd,2);
  8531. name[NAME_LENGTH-1] = '\0';
  8532. if(map[sd->bl.m].flag.partylock)
  8533. {// Party locked.
  8534. clif_displaymessage(fd, msg_txt(227));
  8535. return;
  8536. }
  8537. t_sd = map_nick2sd(name);
  8538. if(t_sd && t_sd->state.noask)
  8539. {// @noask [LuzZza]
  8540. clif_noask_sub(sd, t_sd, 1);
  8541. return;
  8542. }
  8543. party_invite(sd, t_sd);
  8544. }
  8545. /*==========================================
  8546. * Party invitation reply
  8547. * S 00ff <account ID>.L <flag>.L
  8548. * S 02c7 <account ID>.L <flag>.B
  8549. * flag: 0-reject, 1-accept
  8550. *------------------------------------------*/
  8551. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8552. {
  8553. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 5 )
  8554. {
  8555. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8556. clif_skill_fail(sd,1,0,4);
  8557. return;
  8558. }
  8559. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8560. }
  8561. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8562. {
  8563. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 5 )
  8564. {
  8565. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8566. clif_skill_fail(sd,1,0,4);
  8567. return;
  8568. }
  8569. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8570. }
  8571. /*==========================================
  8572. * パーティ脱退要求
  8573. *------------------------------------------*/
  8574. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8575. {
  8576. if(map[sd->bl.m].flag.partylock)
  8577. { //Guild locked.
  8578. clif_displaymessage(fd, msg_txt(227));
  8579. return;
  8580. }
  8581. party_leave(sd);
  8582. }
  8583. /*==========================================
  8584. * パーティ除名要求
  8585. *------------------------------------------*/
  8586. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8587. {
  8588. if(map[sd->bl.m].flag.partylock)
  8589. { //Guild locked.
  8590. clif_displaymessage(fd, msg_txt(227));
  8591. return;
  8592. }
  8593. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8594. }
  8595. /*==========================================
  8596. * パーティ設定変更要求
  8597. *------------------------------------------*/
  8598. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8599. {
  8600. struct party_data *p;
  8601. int i;
  8602. if( !sd->status.party_id )
  8603. return;
  8604. p = party_search(sd->status.party_id);
  8605. if( p == NULL )
  8606. return;
  8607. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  8608. if( i == MAX_PARTY )
  8609. return; //Shouldn't happen
  8610. if( !p->party.member[i].leader )
  8611. return;
  8612. //The client no longer can change the item-field, therefore it always
  8613. //comes as zero. Here, resend the item data as it is.
  8614. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8615. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8616. }
  8617. /*==========================================
  8618. * Validates and processes party messages
  8619. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8620. *------------------------------------------*/
  8621. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8622. {
  8623. const char* text = (char*)RFIFOP(fd,4);
  8624. int textlen = RFIFOW(fd,2) - 4;
  8625. char *name, *message;
  8626. int namelen, messagelen;
  8627. // validate packet and retrieve name and message
  8628. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8629. return;
  8630. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  8631. return;
  8632. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8633. return;
  8634. if( battle_config.min_chat_delay )
  8635. { //[Skotlex]
  8636. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8637. return;
  8638. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8639. }
  8640. party_send_message(sd, text, textlen);
  8641. }
  8642. /*==========================================
  8643. * 露店閉鎖
  8644. *------------------------------------------*/
  8645. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8646. {
  8647. vending_closevending(sd);
  8648. }
  8649. /*==========================================
  8650. * 露店アイテムリスト要求
  8651. *------------------------------------------*/
  8652. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8653. {
  8654. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8655. if( sd->npc_id )
  8656. npc_event_dequeue(sd);
  8657. }
  8658. /*==========================================
  8659. * Shop item(s) purchase request
  8660. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8661. *------------------------------------------*/
  8662. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8663. {
  8664. int len = (int)RFIFOW(fd,2) - 8;
  8665. int id = (int)RFIFOL(fd,4);
  8666. const uint8* data = (uint8*)RFIFOP(fd,8);
  8667. vending_purchasereq(sd, id, data, len/4);
  8668. }
  8669. /*==========================================
  8670. * Confirm or cancel the shop preparation window
  8671. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8672. * flag: 0=cancel, 1=confirm
  8673. *------------------------------------------*/
  8674. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8675. {
  8676. short len = (short)RFIFOW(fd,2) - 85;
  8677. const char* message = (char*)RFIFOP(fd,4);
  8678. bool flag = (bool)RFIFOB(fd,84);
  8679. const uint8* data = (uint8*)RFIFOP(fd,85);
  8680. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  8681. return;
  8682. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  8683. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open shop on this map"
  8684. return;
  8685. }
  8686. if( message[0] == '\0' ) // invalid input
  8687. return;
  8688. vending_openvending(sd, message, flag, data, len/8);
  8689. }
  8690. /*==========================================
  8691. * Guild creation request
  8692. * S 0165 <account id>.L <guild name>.24S
  8693. *------------------------------------------*/
  8694. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8695. {
  8696. char* name = (char*)RFIFOP(fd,6);
  8697. name[NAME_LENGTH-1] = '\0';
  8698. if(map[sd->bl.m].flag.guildlock)
  8699. { //Guild locked.
  8700. clif_displaymessage(fd, msg_txt(228));
  8701. return;
  8702. }
  8703. guild_create(sd, name);
  8704. }
  8705. /*==========================================
  8706. * ギルドマスターかどうか確認
  8707. *------------------------------------------*/
  8708. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8709. {
  8710. clif_guild_masterormember(sd);
  8711. }
  8712. /*==========================================
  8713. * ギルド情報要求
  8714. *------------------------------------------*/
  8715. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8716. {
  8717. if (!sd->status.guild_id)
  8718. return;
  8719. switch(RFIFOL(fd,2)){
  8720. case 0: // ギルド基本情報、同盟敵対情報
  8721. clif_guild_basicinfo(sd);
  8722. clif_guild_allianceinfo(sd);
  8723. break;
  8724. case 1: // メンバーリスト、役職名リスト
  8725. clif_guild_positionnamelist(sd);
  8726. clif_guild_memberlist(sd);
  8727. break;
  8728. case 2: // 役職名リスト、役職情報リスト
  8729. clif_guild_positionnamelist(sd);
  8730. clif_guild_positioninfolist(sd);
  8731. break;
  8732. case 3: // スキルリスト
  8733. clif_guild_skillinfo(sd);
  8734. break;
  8735. case 4: // 追放リスト
  8736. clif_guild_expulsionlist(sd);
  8737. break;
  8738. default:
  8739. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8740. break;
  8741. }
  8742. }
  8743. /*==========================================
  8744. * ギルド役職変更
  8745. *------------------------------------------*/
  8746. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8747. {
  8748. int i;
  8749. if(!sd->state.gmaster_flag)
  8750. return;
  8751. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8752. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8753. }
  8754. }
  8755. /*==========================================
  8756. * ギルドメンバ役職変更
  8757. *------------------------------------------*/
  8758. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8759. {
  8760. int i;
  8761. if(!sd->state.gmaster_flag)
  8762. return;
  8763. for(i=4;i<RFIFOW(fd,2);i+=12){
  8764. guild_change_memberposition(sd->status.guild_id,
  8765. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8766. }
  8767. }
  8768. /*==========================================
  8769. * ギルドエンブレム要求
  8770. *------------------------------------------*/
  8771. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8772. {
  8773. struct guild* g = guild_search(RFIFOL(fd,2));
  8774. if(g!=NULL)
  8775. clif_guild_emblem(sd,g);
  8776. }
  8777. /*==========================================
  8778. * ギルドエンブレム変更
  8779. *------------------------------------------*/
  8780. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8781. {
  8782. if(!sd->state.gmaster_flag)
  8783. return;
  8784. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8785. }
  8786. /*==========================================
  8787. * Guild notice update request
  8788. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8789. *------------------------------------------*/
  8790. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8791. {
  8792. int guild_id = RFIFOL(fd,2);
  8793. char* msg1 = (char*)RFIFOP(fd,6);
  8794. char* msg2 = (char*)RFIFOP(fd,66);
  8795. if(!sd->state.gmaster_flag)
  8796. return;
  8797. // compensate for some client defects when using multilanguage mode
  8798. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8799. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8800. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8801. guild_change_notice(sd, guild_id, msg1, msg2);
  8802. }
  8803. /*==========================================
  8804. * ギルド勧誘
  8805. *------------------------------------------*/
  8806. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8807. {
  8808. struct map_session_data *t_sd;
  8809. if(map[sd->bl.m].flag.guildlock)
  8810. { //Guild locked.
  8811. clif_displaymessage(fd, msg_txt(228));
  8812. return;
  8813. }
  8814. t_sd = map_id2sd(RFIFOL(fd,2));
  8815. // @noask [LuzZza]
  8816. if(t_sd && t_sd->state.noask) {
  8817. clif_noask_sub(sd, t_sd, 2);
  8818. return;
  8819. }
  8820. guild_invite(sd,t_sd);
  8821. }
  8822. /*==========================================
  8823. * ギルド勧誘返信
  8824. *------------------------------------------*/
  8825. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8826. {
  8827. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8828. }
  8829. /*==========================================
  8830. * ギルド脱退
  8831. *------------------------------------------*/
  8832. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8833. {
  8834. if(map[sd->bl.m].flag.guildlock)
  8835. { //Guild locked.
  8836. clif_displaymessage(fd, msg_txt(228));
  8837. return;
  8838. }
  8839. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8840. }
  8841. /*==========================================
  8842. * Request to expel a member of a guild
  8843. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.39B 00
  8844. *------------------------------------------*/
  8845. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8846. {
  8847. if(map[sd->bl.m].flag.guildlock)
  8848. { //Guild locked.
  8849. clif_displaymessage(fd, msg_txt(228));
  8850. return;
  8851. }
  8852. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8853. }
  8854. /*==========================================
  8855. * Validates and processes guild messages
  8856. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  8857. *------------------------------------------*/
  8858. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  8859. {
  8860. const char* text = (char*)RFIFOP(fd,4);
  8861. int textlen = RFIFOW(fd,2) - 4;
  8862. char *name, *message;
  8863. int namelen, messagelen;
  8864. // validate packet and retrieve name and message
  8865. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8866. return;
  8867. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  8868. return;
  8869. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8870. return;
  8871. if( battle_config.min_chat_delay )
  8872. { //[Skotlex]
  8873. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8874. return;
  8875. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8876. }
  8877. guild_send_message(sd, text, textlen);
  8878. }
  8879. /*==========================================
  8880. * ギルド同盟要求
  8881. *------------------------------------------*/
  8882. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  8883. {
  8884. struct map_session_data *t_sd;
  8885. if(!sd->state.gmaster_flag)
  8886. return;
  8887. if(map[sd->bl.m].flag.guildlock)
  8888. { //Guild locked.
  8889. clif_displaymessage(fd, msg_txt(228));
  8890. return;
  8891. }
  8892. t_sd = map_id2sd(RFIFOL(fd,2));
  8893. // @noask [LuzZza]
  8894. if(t_sd && t_sd->state.noask) {
  8895. clif_noask_sub(sd, t_sd, 3);
  8896. return;
  8897. }
  8898. guild_reqalliance(sd,t_sd);
  8899. }
  8900. /*==========================================
  8901. * ギルド同盟要求返信
  8902. *------------------------------------------*/
  8903. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  8904. {
  8905. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8906. }
  8907. /*==========================================
  8908. * ギルド関係解消
  8909. *------------------------------------------*/
  8910. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  8911. {
  8912. if(!sd->state.gmaster_flag)
  8913. return;
  8914. if(map[sd->bl.m].flag.guildlock)
  8915. { //Guild locked.
  8916. clif_displaymessage(fd, msg_txt(228));
  8917. return;
  8918. }
  8919. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8920. }
  8921. /*==========================================
  8922. * ギルド敵対
  8923. *------------------------------------------*/
  8924. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  8925. {
  8926. struct map_session_data *t_sd;
  8927. if(!sd->state.gmaster_flag)
  8928. return;
  8929. if(map[sd->bl.m].flag.guildlock)
  8930. { //Guild locked.
  8931. clif_displaymessage(fd, msg_txt(228));
  8932. return;
  8933. }
  8934. t_sd = map_id2sd(RFIFOL(fd,2));
  8935. // @noask [LuzZza]
  8936. if(t_sd && t_sd->state.noask) {
  8937. clif_noask_sub(sd, t_sd, 4);
  8938. return;
  8939. }
  8940. guild_opposition(sd,t_sd);
  8941. }
  8942. /*==========================================
  8943. * ギルド解散
  8944. *------------------------------------------*/
  8945. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  8946. {
  8947. if(map[sd->bl.m].flag.guildlock)
  8948. { //Guild locked.
  8949. clif_displaymessage(fd, msg_txt(228));
  8950. return;
  8951. }
  8952. guild_break(sd,(char*)RFIFOP(fd,2));
  8953. }
  8954. // pet
  8955. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  8956. {
  8957. pet_menu(sd,RFIFOB(fd,2));
  8958. }
  8959. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  8960. {
  8961. pet_catch_process2(sd,RFIFOL(fd,2));
  8962. }
  8963. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  8964. {
  8965. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  8966. {
  8967. //Forged packet, disconnect them [Kevin]
  8968. clif_authfail_fd(fd, 0);
  8969. return;
  8970. }
  8971. pet_select_egg(sd,RFIFOW(fd,2)-2);
  8972. sd->menuskill_val = sd->menuskill_id = 0;
  8973. }
  8974. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  8975. {
  8976. if(sd->pd)
  8977. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  8978. }
  8979. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  8980. {
  8981. pet_change_name(sd,(char*)RFIFOP(fd,2));
  8982. }
  8983. /*==========================================
  8984. * /kill <???>
  8985. * (or right click menu for GM "(name) force to quit")
  8986. * S 00cc <id>.L
  8987. *------------------------------------------*/
  8988. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  8989. {
  8990. struct block_list *target;
  8991. int tid,lv;
  8992. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8993. return;
  8994. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_kick)) )
  8995. return;
  8996. tid = RFIFOL(fd,2);
  8997. target = map_id2bl(tid);
  8998. if (!target) {
  8999. clif_GM_kickack(sd, 0);
  9000. return;
  9001. }
  9002. switch (target->type) {
  9003. case BL_PC:
  9004. {
  9005. struct map_session_data *tsd = (struct map_session_data *)target;
  9006. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9007. clif_GM_kickack(sd, 0);
  9008. return;
  9009. }
  9010. clif_GM_kick(sd, tsd);
  9011. if(log_config.gm && lv >= log_config.gm) {
  9012. char message[256];
  9013. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  9014. log_atcommand(sd, message);
  9015. }
  9016. }
  9017. break;
  9018. case BL_MOB:
  9019. status_percent_damage(&sd->bl, target, 100, 0, true);
  9020. if(log_config.gm && lv >= log_config.gm) {
  9021. char message[256];
  9022. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9023. log_atcommand(sd, message);
  9024. }
  9025. break;
  9026. case BL_NPC:
  9027. {
  9028. struct npc_data* nd = (struct npc_data *)target;
  9029. lv = get_atcommand_level(atcommand_unloadnpc);
  9030. if( pc_isGM(sd) < lv )
  9031. return;
  9032. npc_unload(nd);
  9033. if( log_config.gm && lv >= log_config.gm ) {
  9034. char message[256];
  9035. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9036. log_atcommand(sd, message);
  9037. }
  9038. }
  9039. break;
  9040. default:
  9041. clif_GM_kickack(sd, 0);
  9042. }
  9043. }
  9044. /*==========================================
  9045. * /killall
  9046. *------------------------------------------*/
  9047. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9048. {
  9049. is_atcommand(fd, sd, "@kickall");
  9050. }
  9051. /*==========================================
  9052. * /shift <name>
  9053. *------------------------------------------*/
  9054. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9055. {
  9056. char *player_name;
  9057. int lv;
  9058. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9059. return;
  9060. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9061. return;
  9062. player_name = (char*)RFIFOP(fd,2);
  9063. player_name[NAME_LENGTH-1] = '\0';
  9064. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9065. if( log_config.gm && lv >= log_config.gm ) {
  9066. char message[NAME_LENGTH+7];
  9067. sprintf(message, "/shift %s", player_name);
  9068. log_atcommand(sd, message);
  9069. }
  9070. }
  9071. /*==========================================
  9072. * /recall <name>
  9073. *------------------------------------------*/
  9074. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9075. {
  9076. char *player_name;
  9077. int lv;
  9078. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9079. return;
  9080. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9081. return;
  9082. player_name = (char*)RFIFOP(fd,2);
  9083. player_name[NAME_LENGTH-1] = '\0';
  9084. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9085. if( log_config.gm && lv >= log_config.gm ) {
  9086. char message[NAME_LENGTH+8];
  9087. sprintf(message, "/recall %s", player_name);
  9088. log_atcommand(sd, message);
  9089. }
  9090. }
  9091. /*==========================================
  9092. * /monster /item
  9093. *------------------------------------------*/
  9094. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9095. {
  9096. char *monster_item_name;
  9097. char message[NAME_LENGTH+10]; //For logging.
  9098. int level;
  9099. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9100. return;
  9101. monster_item_name = (char*)RFIFOP(fd,2);
  9102. monster_item_name[NAME_LENGTH-1] = '\0';
  9103. if( mobdb_searchname(monster_item_name) ) {
  9104. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  9105. return;
  9106. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  9107. if( log_config.gm && level >= log_config.gm )
  9108. { //Log action. [Skotlex]
  9109. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9110. log_atcommand(sd, message);
  9111. }
  9112. return;
  9113. }
  9114. if( itemdb_searchname(monster_item_name) == NULL )
  9115. return;
  9116. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  9117. return;
  9118. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9119. if( log_config.gm && level >= log_config.gm )
  9120. { //Log action. [Skotlex]
  9121. sprintf(message, "@item %s", monster_item_name);
  9122. log_atcommand(sd, message);
  9123. }
  9124. }
  9125. /*==========================================
  9126. * /hide
  9127. *------------------------------------------*/
  9128. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9129. {
  9130. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9131. return;
  9132. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  9133. return;
  9134. if( sd->sc.option & OPTION_INVISIBLE ) {
  9135. sd->sc.option &= ~OPTION_INVISIBLE;
  9136. if (sd->disguise)
  9137. status_set_viewdata(&sd->bl, sd->disguise);
  9138. else
  9139. status_set_viewdata(&sd->bl, sd->status.class_);
  9140. clif_displaymessage(fd, "Invisible: Off.");
  9141. } else {
  9142. sd->sc.option |= OPTION_INVISIBLE;
  9143. sd->vd.class_ = INVISIBLE_CLASS;
  9144. clif_displaymessage(fd, "Invisible: On.");
  9145. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  9146. log_atcommand(sd, "/hide");
  9147. }
  9148. clif_changeoption(&sd->bl);
  9149. }
  9150. /*==========================================
  9151. * GM adjustment of a player's manner value (right-click GM menu)
  9152. * S 0149 <id>.L <type>.B <value>.W
  9153. * type: 0 - positive points
  9154. * 1 - negative points
  9155. * 2 - self mute (+10 minutes)
  9156. *------------------------------------------*/
  9157. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9158. {
  9159. int id, type, value, level;
  9160. struct map_session_data *dstsd;
  9161. id = RFIFOL(fd,2);
  9162. type = RFIFOB(fd,6);
  9163. value = RFIFOW(fd,7);
  9164. if( type == 0 )
  9165. value = 0 - value;
  9166. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9167. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9168. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  9169. return;
  9170. dstsd = map_id2sd(id);
  9171. if( dstsd == NULL )
  9172. return;
  9173. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  9174. {
  9175. clif_manner_message(sd, 0);
  9176. clif_manner_message(dstsd, 5);
  9177. if( dstsd->status.manner < value ) {
  9178. dstsd->status.manner -= value;
  9179. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9180. } else {
  9181. dstsd->status.manner = 0;
  9182. status_change_end(&dstsd->bl,SC_NOCHAT,-1);
  9183. }
  9184. if( type != 2 )
  9185. clif_GM_silence(sd, dstsd, type);
  9186. }
  9187. }
  9188. /*==========================================
  9189. * GM adjustment of a player's manner value by -60 (using name)
  9190. * /rc <name>
  9191. * S 0212 <name>.24B
  9192. *------------------------------------------*/
  9193. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  9194. {
  9195. char* name = (char*)RFIFOP(fd,2);
  9196. struct map_session_data* dstsd;
  9197. name[23] = '\0';
  9198. dstsd = map_nick2sd(name);
  9199. if( dstsd == NULL )
  9200. return;
  9201. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  9202. {
  9203. clif_manner_message(sd, 0);
  9204. clif_manner_message(dstsd, 3);
  9205. dstsd->status.manner -= 60;
  9206. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9207. clif_GM_silence(sd, dstsd, 1);
  9208. }
  9209. }
  9210. /*==========================================
  9211. * GM requesting account name (for right-click gm menu)
  9212. * S 01df <id>.L
  9213. * R 01e0 <id>.L <name>.24B
  9214. *------------------------------------------*/
  9215. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  9216. {
  9217. int tid;
  9218. tid = RFIFOL(fd,2);
  9219. //TODO: find out if this works for any player or only for authorized GMs
  9220. WFIFOHEAD(fd,packet_len(0x1e0));
  9221. WFIFOW(fd,0) = 0x1e0;
  9222. WFIFOL(fd,2) = tid;
  9223. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  9224. WFIFOSET(fd, packet_len(0x1e0));
  9225. }
  9226. /*==========================================
  9227. * GM single cell type change request
  9228. * /changemaptype <x> <y> <type>
  9229. * S 0198 <x>.W <y>.W <gat>.W
  9230. *------------------------------------------*/
  9231. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  9232. {
  9233. int x,y,type;
  9234. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9235. return;
  9236. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  9237. return;
  9238. x = RFIFOW(fd,2);
  9239. y = RFIFOW(fd,4);
  9240. type = RFIFOW(fd,6);
  9241. map_setgatcell(sd->bl.m,x,y,type);
  9242. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  9243. //FIXME: once players leave the map, the client 'forgets' this information.
  9244. }
  9245. /// S 00cf <nick>.24B <type>.B
  9246. /// type: 0 (/ex nick) deny speech from nick
  9247. /// 1 (/in nick) allow speech from nick
  9248. ///
  9249. /// R 00d1 <type>.B <result>.B
  9250. /// type: 0: deny, 1: allow
  9251. /// result: 0: success, 1: fail 2: list full
  9252. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  9253. {
  9254. char output[512];
  9255. char* nick;
  9256. uint8 type;
  9257. int i;
  9258. nick = (char*)RFIFOP(fd,2); // speed up
  9259. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  9260. type = RFIFOB(fd,26);
  9261. WFIFOHEAD(fd,packet_len(0xd1));
  9262. WFIFOW(fd,0) = 0x0d1;
  9263. WFIFOB(fd,2) = type;
  9264. if( type == 0 )
  9265. { // Add name to ignore list (block)
  9266. // Bot-check...
  9267. if (strcmp(wisp_server_name, nick) == 0)
  9268. { // to find possible bot users who automaticaly ignore people
  9269. 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);
  9270. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9271. WFIFOB(fd,3) = 1; // fail
  9272. WFIFOSET(fd, packet_len(0x0d1));
  9273. return;
  9274. }
  9275. // try to find a free spot, while checking for duplicates at the same time
  9276. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9277. if( i == MAX_IGNORE_LIST )
  9278. {// no space for new entry
  9279. WFIFOB(fd,3) = 2; // fail
  9280. WFIFOSET(fd, packet_len(0x0d1));
  9281. return;
  9282. }
  9283. if( sd->ignore[i].name[0] != '\0' )
  9284. {// name already exists
  9285. WFIFOB(fd,3) = 0; // Aegis reports success.
  9286. WFIFOSET(fd, packet_len(0x0d1));
  9287. return;
  9288. }
  9289. //Insert in position i
  9290. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9291. WFIFOB(fd,3) = 0; // success
  9292. WFIFOSET(fd, packet_len(0x0d1));
  9293. }
  9294. else
  9295. { // Remove name from ignore list (unblock)
  9296. // find entry
  9297. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9298. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  9299. { //Not found
  9300. WFIFOB(fd,3) = 1; // fail
  9301. WFIFOSET(fd, packet_len(0x0d1));
  9302. return;
  9303. }
  9304. // move everything one place down to overwrite removed entry
  9305. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9306. // wipe last entry
  9307. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9308. WFIFOB(fd,3) = 0; // success
  9309. WFIFOSET(fd, packet_len(0x0d1));
  9310. }
  9311. return;
  9312. }
  9313. /// S 00d0 <type>.B
  9314. /// type: 0 (/exall) deny all speech
  9315. /// 1 (/inall) allow all speech
  9316. ///
  9317. /// R 00d2 <type>.B <fail>.B
  9318. /// type: 0: deny, 1: allow
  9319. /// fail: 0: success, 1: fail
  9320. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9321. {
  9322. WFIFOHEAD(fd,packet_len(0xd2));
  9323. WFIFOW(fd,0) = 0x0d2;
  9324. WFIFOB(fd,2) = RFIFOB(fd,2);
  9325. if( RFIFOB(fd,2) == 0 )
  9326. {// Deny all
  9327. if( sd->state.ignoreAll ) {
  9328. WFIFOB(fd,3) = 1; // fail
  9329. } else {
  9330. sd->state.ignoreAll = 1;
  9331. WFIFOB(fd,3) = 0; // success
  9332. }
  9333. }
  9334. else
  9335. {//Unblock everyone
  9336. if( sd->state.ignoreAll ) {
  9337. sd->state.ignoreAll = 0;
  9338. WFIFOB(fd,3) = 0; // success
  9339. } else {
  9340. if (sd->ignore[0].name[0] != '\0')
  9341. { //Wipe the ignore list.
  9342. memset(sd->ignore, 0, sizeof(sd->ignore));
  9343. WFIFOB(fd,3) = 0; // success
  9344. } else {
  9345. WFIFOB(fd,3) = 1; // fail
  9346. }
  9347. }
  9348. }
  9349. WFIFOSET(fd, packet_len(0x0d2));
  9350. return;
  9351. }
  9352. /*==========================================
  9353. * Wis拒否リスト
  9354. *------------------------------------------*/
  9355. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9356. {
  9357. int i;
  9358. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9359. WFIFOW(fd,0) = 0xd4;
  9360. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9361. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9362. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9363. WFIFOSET(fd, WFIFOW(fd,2));
  9364. return;
  9365. }
  9366. /*==========================================
  9367. * スパノビの/doridoriによるSPR2倍
  9368. *------------------------------------------*/
  9369. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9370. {
  9371. if (sd->state.doridori) return;
  9372. switch (sd->class_&MAPID_UPPERMASK)
  9373. {
  9374. case MAPID_SOUL_LINKER:
  9375. case MAPID_STAR_GLADIATOR:
  9376. case MAPID_TAEKWON:
  9377. if (!sd->state.rest)
  9378. break;
  9379. case MAPID_SUPER_NOVICE:
  9380. sd->state.doridori=1;
  9381. break;
  9382. }
  9383. return;
  9384. }
  9385. /*==========================================
  9386. * スパノビの爆裂波動
  9387. *------------------------------------------*/
  9388. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9389. {
  9390. if(sd){
  9391. int nextbaseexp=pc_nextbaseexp(sd);
  9392. if (battle_config.etc_log){
  9393. if(nextbaseexp != 0)
  9394. 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));
  9395. else
  9396. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9397. }
  9398. 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){
  9399. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9400. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  9401. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9402. }
  9403. }
  9404. return;
  9405. }
  9406. // random notes:
  9407. // 0x214: monster/player info ?
  9408. /*==========================================
  9409. * Friends List
  9410. *------------------------------------------*/
  9411. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9412. { //Toggles a single friend online/offline [Skotlex]
  9413. int i, fd = sd->fd;
  9414. //Seek friend.
  9415. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9416. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9417. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9418. return; //Not found
  9419. WFIFOHEAD(fd,packet_len(0x206));
  9420. WFIFOW(fd, 0) = 0x206;
  9421. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9422. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9423. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9424. WFIFOSET(fd, packet_len(0x206));
  9425. }
  9426. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9427. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9428. {
  9429. int account_id, char_id, online;
  9430. account_id = va_arg(ap, int);
  9431. char_id = va_arg(ap, int);
  9432. online = va_arg(ap, int);
  9433. clif_friendslist_toggle(sd, account_id, char_id, online);
  9434. return 0;
  9435. }
  9436. //For sending the whole friends list.
  9437. void clif_friendslist_send(struct map_session_data *sd)
  9438. {
  9439. int i = 0, n, fd = sd->fd;
  9440. // Send friends list
  9441. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9442. WFIFOW(fd, 0) = 0x201;
  9443. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9444. {
  9445. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9446. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9447. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9448. }
  9449. if (i) {
  9450. WFIFOW(fd,2) = 4 + 32 * i;
  9451. WFIFOSET(fd, WFIFOW(fd,2));
  9452. }
  9453. for (n = 0; n < i; n++)
  9454. { //Sending the online players
  9455. if (map_charid2sd(sd->status.friends[n].char_id))
  9456. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9457. }
  9458. }
  9459. /// Reply for add friend request: (success => type 0)
  9460. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9461. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9462. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9463. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9464. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9465. {
  9466. int fd;
  9467. nullpo_retv(sd);
  9468. fd = sd->fd;
  9469. WFIFOHEAD(fd,packet_len(0x209));
  9470. WFIFOW(fd,0) = 0x209;
  9471. WFIFOW(fd,2) = type;
  9472. if (f_sd)
  9473. {
  9474. WFIFOW(fd,4) = f_sd->status.account_id;
  9475. WFIFOW(fd,8) = f_sd->status.char_id;
  9476. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9477. }
  9478. WFIFOSET(fd, packet_len(0x209));
  9479. }
  9480. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9481. {
  9482. struct map_session_data *f_sd;
  9483. int i, f_fd;
  9484. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9485. // Friend doesn't exist (no player with this name)
  9486. if (f_sd == NULL) {
  9487. clif_displaymessage(fd, msg_txt(3));
  9488. return;
  9489. }
  9490. // @noask [LuzZza]
  9491. if(f_sd->state.noask) {
  9492. clif_noask_sub(sd, f_sd, 5);
  9493. return;
  9494. }
  9495. // Friend already exists
  9496. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9497. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9498. clif_displaymessage(fd, "Friend already exists.");
  9499. return;
  9500. }
  9501. }
  9502. if (i == MAX_FRIENDS) {
  9503. //No space, list full.
  9504. clif_friendslist_reqack(sd, f_sd, 2);
  9505. return;
  9506. }
  9507. f_fd = f_sd->fd;
  9508. WFIFOHEAD(f_fd,packet_len(0x207));
  9509. WFIFOW(f_fd,0) = 0x207;
  9510. WFIFOL(f_fd,2) = sd->status.account_id;
  9511. WFIFOL(f_fd,6) = sd->status.char_id;
  9512. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9513. WFIFOSET(f_fd, packet_len(0x207));
  9514. return;
  9515. }
  9516. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9517. {
  9518. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9519. struct map_session_data *f_sd;
  9520. int char_id, account_id;
  9521. char reply;
  9522. account_id = RFIFOL(fd,2);
  9523. char_id = RFIFOL(fd,6);
  9524. reply = RFIFOB(fd,10);
  9525. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9526. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9527. if (f_sd == NULL)
  9528. return;
  9529. if (reply == 0)
  9530. clif_friendslist_reqack(f_sd, sd, 1);
  9531. else {
  9532. int i;
  9533. // Find an empty slot
  9534. for (i = 0; i < MAX_FRIENDS; i++)
  9535. if (f_sd->status.friends[i].char_id == 0)
  9536. break;
  9537. if (i == MAX_FRIENDS) {
  9538. clif_friendslist_reqack(f_sd, sd, 2);
  9539. return;
  9540. }
  9541. f_sd->status.friends[i].account_id = sd->status.account_id;
  9542. f_sd->status.friends[i].char_id = sd->status.char_id;
  9543. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9544. clif_friendslist_reqack(f_sd, sd, 0);
  9545. if (battle_config.friend_auto_add) {
  9546. // Also add f_sd to sd's friendlist.
  9547. for (i = 0; i < MAX_FRIENDS; i++) {
  9548. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9549. return; //No need to add anything.
  9550. if (sd->status.friends[i].char_id == 0)
  9551. break;
  9552. }
  9553. if (i == MAX_FRIENDS) {
  9554. clif_friendslist_reqack(sd, f_sd, 2);
  9555. return;
  9556. }
  9557. sd->status.friends[i].account_id = f_sd->status.account_id;
  9558. sd->status.friends[i].char_id = f_sd->status.char_id;
  9559. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9560. clif_friendslist_reqack(sd, f_sd, 0);
  9561. }
  9562. }
  9563. return;
  9564. }
  9565. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9566. {
  9567. // 0x203 </o> <ID to be removed W 4B>
  9568. int account_id, char_id;
  9569. int i, j;
  9570. account_id = RFIFOL(fd,2);
  9571. char_id = RFIFOL(fd,6);
  9572. // Search friend
  9573. for (i = 0; i < MAX_FRIENDS &&
  9574. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9575. if (i == MAX_FRIENDS) {
  9576. clif_displaymessage(fd, "Name not found in list.");
  9577. return;
  9578. }
  9579. // move all chars down
  9580. for(j = i + 1; j < MAX_FRIENDS; j++)
  9581. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9582. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9583. clif_displaymessage(fd, "Friend removed");
  9584. WFIFOHEAD(fd,packet_len(0x20a));
  9585. WFIFOW(fd,0) = 0x20a;
  9586. WFIFOL(fd,2) = account_id;
  9587. WFIFOL(fd,6) = char_id;
  9588. WFIFOSET(fd, packet_len(0x20a));
  9589. // clif_friendslist_send(sd); //This is not needed anymore.
  9590. return;
  9591. }
  9592. /*==========================================
  9593. * /pvpinfo
  9594. *------------------------------------------*/
  9595. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9596. {
  9597. WFIFOHEAD(fd,packet_len(0x210));
  9598. WFIFOW(fd,0) = 0x210;
  9599. //WFIFOL(fd,2) = 0; // not sure what for yet
  9600. //WFIFOL(fd,6) = 0;
  9601. WFIFOL(fd,10) = sd->pvp_won; // times won
  9602. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9603. WFIFOL(fd,18) = sd->pvp_point;
  9604. WFIFOSET(fd, packet_len(0x210));
  9605. return;
  9606. }
  9607. /*==========================================
  9608. * /blacksmith
  9609. *------------------------------------------*/
  9610. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9611. {
  9612. int i;
  9613. const char* name;
  9614. WFIFOHEAD(fd,packet_len(0x219));
  9615. WFIFOW(fd,0) = 0x219;
  9616. //Packet size limits this list to 10 elements. [Skotlex]
  9617. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9618. if (smith_fame_list[i].id > 0) {
  9619. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9620. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9621. {
  9622. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9623. } else
  9624. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9625. } else
  9626. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9627. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9628. }
  9629. for(;i < 10; i++) { //In case the MAX is less than 10.
  9630. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9631. WFIFOL(fd, 242 + i * 4) = 0;
  9632. }
  9633. WFIFOSET(fd, packet_len(0x219));
  9634. }
  9635. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9636. {
  9637. int fd = sd->fd;
  9638. WFIFOHEAD(fd,packet_len(0x21b));
  9639. WFIFOW(fd,0) = 0x21b;
  9640. WFIFOL(fd,2) = points;
  9641. WFIFOL(fd,6) = sd->status.fame;
  9642. WFIFOSET(fd, packet_len(0x21b));
  9643. return 0;
  9644. }
  9645. /*==========================================
  9646. * /alchemist
  9647. *------------------------------------------*/
  9648. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9649. {
  9650. int i;
  9651. const char* name;
  9652. WFIFOHEAD(fd,packet_len(0x21a));
  9653. WFIFOW(fd,0) = 0x21a;
  9654. //Packet size limits this list to 10 elements. [Skotlex]
  9655. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9656. if (chemist_fame_list[i].id > 0) {
  9657. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9658. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9659. {
  9660. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9661. } else
  9662. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9663. } else
  9664. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9665. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9666. }
  9667. for(;i < 10; i++) { //In case the MAX is less than 10.
  9668. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9669. WFIFOL(fd, 242 + i * 4) = 0;
  9670. }
  9671. WFIFOSET(fd, packet_len(0x21a));
  9672. }
  9673. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9674. {
  9675. int fd = sd->fd;
  9676. WFIFOHEAD(fd,packet_len(0x21c));
  9677. WFIFOW(fd,0) = 0x21c;
  9678. WFIFOL(fd,2) = points;
  9679. WFIFOL(fd,6) = sd->status.fame;
  9680. WFIFOSET(fd, packet_len(0x21c));
  9681. return 0;
  9682. }
  9683. /*==========================================
  9684. * /taekwon
  9685. *------------------------------------------*/
  9686. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9687. {
  9688. int i;
  9689. const char* name;
  9690. WFIFOHEAD(fd,packet_len(0x226));
  9691. WFIFOW(fd,0) = 0x226;
  9692. //Packet size limits this list to 10 elements. [Skotlex]
  9693. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9694. if (taekwon_fame_list[i].id > 0) {
  9695. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9696. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9697. {
  9698. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9699. } else
  9700. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9701. } else
  9702. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9703. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9704. }
  9705. for(;i < 10; i++) { //In case the MAX is less than 10.
  9706. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9707. WFIFOL(fd, 242 + i * 4) = 0;
  9708. }
  9709. WFIFOSET(fd, packet_len(0x226));
  9710. }
  9711. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9712. {
  9713. int fd = sd->fd;
  9714. WFIFOHEAD(fd,packet_len(0x224));
  9715. WFIFOW(fd,0) = 0x224;
  9716. WFIFOL(fd,2) = points;
  9717. WFIFOL(fd,6) = sd->status.fame;
  9718. WFIFOSET(fd, packet_len(0x224));
  9719. return 0;
  9720. }
  9721. /*==========================================
  9722. * PK Ranking table?
  9723. *------------------------------------------*/
  9724. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9725. {
  9726. int i;
  9727. WFIFOHEAD(fd,packet_len(0x238));
  9728. WFIFOW(fd,0) = 0x238;
  9729. for(i=0;i<10;i++){
  9730. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9731. WFIFOL(fd,i*4+242) = 0;
  9732. }
  9733. WFIFOSET(fd, packet_len(0x238));
  9734. return;
  9735. }
  9736. /*==========================================
  9737. * SG Feel save OK [Komurka]
  9738. *------------------------------------------*/
  9739. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9740. {
  9741. int i;
  9742. if (sd->menuskill_id != SG_FEEL)
  9743. return;
  9744. i = sd->menuskill_val-1;
  9745. if (i<0 || i > 2) return; //Bug?
  9746. sd->feel_map[i].index = map_id2index(sd->bl.m);
  9747. sd->feel_map[i].m = sd->bl.m;
  9748. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  9749. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9750. // clif_misceffect2(&sd->bl, 0x1b0);
  9751. // clif_misceffect2(&sd->bl, 0x21f);
  9752. clif_feel_info(sd, i, 0);
  9753. sd->menuskill_val = sd->menuskill_id = 0;
  9754. }
  9755. /*==========================================
  9756. * Question about Star Glaldiator save map [Komurka]
  9757. *------------------------------------------*/
  9758. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9759. {
  9760. WFIFOHEAD(fd,packet_len(0x253));
  9761. WFIFOW(fd,0)=0x253;
  9762. WFIFOSET(fd, packet_len(0x253));
  9763. sd->menuskill_id = SG_FEEL;
  9764. sd->menuskill_val = skilllv;
  9765. }
  9766. /*==========================================
  9767. * Homunculus packets
  9768. *------------------------------------------*/
  9769. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9770. {
  9771. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9772. }
  9773. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9774. {
  9775. if(!merc_is_hom_active(sd->hd))
  9776. return;
  9777. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  9778. }
  9779. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd)
  9780. {
  9781. short x,y,cmd;
  9782. if(!merc_is_hom_active(sd->hd))
  9783. return;
  9784. cmd = RFIFOW(fd,0);
  9785. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  9786. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9787. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  9788. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9789. unit_walktoxy(&(sd->hd->bl),x,y,4);
  9790. }
  9791. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9792. { //[orn]
  9793. if(!merc_is_hom_active(sd->hd))
  9794. return;
  9795. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  9796. }
  9797. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9798. { //[orn]
  9799. int cmd;
  9800. cmd = RFIFOW(fd,0);
  9801. if(!merc_is_hom_active(sd->hd))
  9802. return;
  9803. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9804. }
  9805. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9806. {
  9807. int item_position = pc_search_inventory(sd, 7621);
  9808. if (item_position < 0)
  9809. return;
  9810. if (!status_revive(&sd->bl, 100, 100))
  9811. return;
  9812. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9813. pc_delitem(sd, item_position, 1, 0);
  9814. }
  9815. /// /check <string>
  9816. /// S 0213 <string>.24B
  9817. void clif_parse_Check(int fd, struct map_session_data *sd)
  9818. {
  9819. // no info
  9820. }
  9821. #ifndef TXT_ONLY
  9822. /*==========================================
  9823. * MAIL SYSTEM
  9824. * By Zephyrus
  9825. *==========================================*/
  9826. /*------------------------------------------
  9827. * Reply to Set Attachment operation
  9828. * 0 : Successfully attached item to mail
  9829. * 1 : Fail to set the attachment
  9830. *------------------------------------------*/
  9831. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  9832. {
  9833. WFIFOHEAD(fd,packet_len(0x255));
  9834. WFIFOW(fd,0) = 0x255;
  9835. WFIFOW(fd,2) = index;
  9836. WFIFOB(fd,4) = flag;
  9837. WFIFOSET(fd,packet_len(0x255));
  9838. }
  9839. /*------------------------------------------
  9840. * Reply to Get Attachment operation
  9841. * 0 : Successfully added attachment to Inventory
  9842. * 1 : Fail to set the item to inventory
  9843. * 2 : Weight problems
  9844. *------------------------------------------*/
  9845. void clif_Mail_getattachment(int fd, uint8 flag)
  9846. {
  9847. WFIFOHEAD(fd,packet_len(0x245));
  9848. WFIFOW(fd,0) = 0x245;
  9849. WFIFOB(fd,2) = flag;
  9850. WFIFOSET(fd,packet_len(0x245));
  9851. }
  9852. /*------------------------------------------
  9853. * Send Mail ack
  9854. * 0 : Message Send Ok
  9855. * 1 : Recipient does not exist
  9856. *------------------------------------------*/
  9857. void clif_Mail_send(int fd, bool fail)
  9858. {
  9859. WFIFOHEAD(fd,packet_len(0x249));
  9860. WFIFOW(fd,0) = 0x249;
  9861. WFIFOB(fd,2) = fail;
  9862. WFIFOSET(fd,packet_len(0x249));
  9863. }
  9864. /*------------------------------------------
  9865. * Delete Mail ack
  9866. * 0 : Delete ok
  9867. * 1 : Delete failed
  9868. *------------------------------------------*/
  9869. void clif_Mail_delete(int fd, int mail_id, short fail)
  9870. {
  9871. WFIFOHEAD(fd, packet_len(0x257));
  9872. WFIFOW(fd,0) = 0x257;
  9873. WFIFOL(fd,2) = mail_id;
  9874. WFIFOW(fd,6) = fail;
  9875. WFIFOSET(fd, packet_len(0x257));
  9876. }
  9877. /*------------------------------------------
  9878. * Return Mail ack
  9879. * 0 : Mail returned to the sender
  9880. * 1 : The mail does not exist
  9881. *------------------------------------------*/
  9882. void clif_Mail_return(int fd, int mail_id, short fail)
  9883. {
  9884. WFIFOHEAD(fd,packet_len(0x274));
  9885. WFIFOW(fd,0) = 0x274;
  9886. WFIFOL(fd,2) = mail_id;
  9887. WFIFOW(fd,6) = fail;
  9888. WFIFOSET(fd,packet_len(0x274));
  9889. }
  9890. /*------------------------------------------
  9891. * You have New Mail
  9892. *------------------------------------------*/
  9893. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  9894. {
  9895. WFIFOHEAD(fd,packet_len(0x24a));
  9896. WFIFOW(fd,0) = 0x24a;
  9897. WFIFOL(fd,2) = mail_id;
  9898. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  9899. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  9900. WFIFOSET(fd,packet_len(0x24a));
  9901. }
  9902. /*------------------------------------------
  9903. * Handles Mail Window on Client
  9904. * flag : 0 open | 1 close
  9905. *------------------------------------------*/
  9906. void clif_Mail_window(int fd, int flag)
  9907. {
  9908. WFIFOHEAD(fd,packet_len(0x260));
  9909. WFIFOW(fd,0) = 0x260;
  9910. WFIFOL(fd,2) = flag;
  9911. WFIFOSET(fd,packet_len(0x260));
  9912. }
  9913. /*------------------------------------------
  9914. * Send Inbox Data to Client
  9915. *------------------------------------------*/
  9916. void clif_Mail_refreshinbox(struct map_session_data *sd)
  9917. {
  9918. int fd = sd->fd;
  9919. struct mail_data *md = &sd->mail.inbox;
  9920. struct mail_message *msg;
  9921. int len, i, j;
  9922. len = 8 + (73 * md->amount);
  9923. WFIFOHEAD(fd,len);
  9924. WFIFOW(fd,0) = 0x240;
  9925. WFIFOW(fd,2) = len;
  9926. WFIFOL(fd,4) = md->amount;
  9927. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  9928. {
  9929. msg = &md->msg[i];
  9930. if (msg->id < 1)
  9931. continue;
  9932. WFIFOL(fd,8+73*j) = msg->id;
  9933. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  9934. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  9935. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  9936. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  9937. j++;
  9938. }
  9939. WFIFOSET(fd,len);
  9940. if( md->full )
  9941. {
  9942. char output[100];
  9943. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  9944. clif_disp_onlyself(sd, output, strlen(output));
  9945. }
  9946. }
  9947. /*------------------------------------------
  9948. * Client Request Inbox List
  9949. *------------------------------------------*/
  9950. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  9951. {
  9952. struct mail_data* md = &sd->mail.inbox;
  9953. if( md->amount < MAIL_MAX_INBOX && (md->full || md->changed) )
  9954. intif_Mail_requestinbox(sd->status.char_id, 1);
  9955. else
  9956. clif_Mail_refreshinbox(sd);
  9957. mail_removeitem(sd, 0);
  9958. mail_removezeny(sd, 0);
  9959. }
  9960. /*------------------------------------------
  9961. * Read Message
  9962. *------------------------------------------*/
  9963. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  9964. {
  9965. int i, fd = sd->fd;
  9966. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9967. if( i == MAIL_MAX_INBOX )
  9968. {
  9969. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  9970. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  9971. return;
  9972. }
  9973. else
  9974. {
  9975. struct mail_message *msg = &sd->mail.inbox.msg[i];
  9976. struct item *item = &msg->item;
  9977. struct item_data *data;
  9978. int msg_len = strlen(msg->body), len;
  9979. if( msg_len == 0 ) {
  9980. strcpy(msg->body, "(no message)");
  9981. msg_len = strlen(msg->body);
  9982. }
  9983. len = 101 + msg_len;
  9984. WFIFOHEAD(fd,len);
  9985. WFIFOW(fd,0) = 0x242;
  9986. WFIFOW(fd,2) = len;
  9987. WFIFOL(fd,4) = msg->id;
  9988. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  9989. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  9990. WFIFOL(fd,72) = 0;
  9991. WFIFOL(fd,76) = msg->zeny;
  9992. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  9993. {
  9994. WFIFOL(fd,80) = item->amount;
  9995. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  9996. WFIFOW(fd,86) = data->type;
  9997. WFIFOB(fd,88) = item->identify;
  9998. WFIFOB(fd,89) = item->attribute;
  9999. WFIFOB(fd,90) = item->refine;
  10000. WFIFOW(fd,91) = item->card[0];
  10001. WFIFOW(fd,93) = item->card[1];
  10002. WFIFOW(fd,95) = item->card[2];
  10003. WFIFOW(fd,97) = item->card[3];
  10004. }
  10005. else // no item, set all to zero
  10006. memset(WFIFOP(fd,80), 0x00, 19);
  10007. WFIFOB(fd,99) = (unsigned char)msg_len;
  10008. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  10009. WFIFOSET(fd,len);
  10010. if (msg->status == MAIL_UNREAD) {
  10011. msg->status = MAIL_READ;
  10012. intif_Mail_read(mail_id);
  10013. clif_parse_Mail_refreshinbox(fd, sd);
  10014. }
  10015. }
  10016. }
  10017. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  10018. {
  10019. if( mail_invalid_operation(sd) )
  10020. return;
  10021. clif_Mail_read(sd, RFIFOL(fd,2));
  10022. }
  10023. /*------------------------------------------
  10024. * Get Attachment from Message
  10025. *------------------------------------------*/
  10026. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  10027. {
  10028. int i, mail_id = RFIFOL(fd,2);
  10029. bool fail = false;
  10030. if( mail_invalid_operation(sd) )
  10031. return;
  10032. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10033. if( i == MAIL_MAX_INBOX )
  10034. return;
  10035. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  10036. return;
  10037. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  10038. {
  10039. struct item_data *data;
  10040. unsigned int weight;
  10041. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  10042. return;
  10043. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  10044. {
  10045. case ADDITEM_NEW:
  10046. fail = ( pc_inventoryblank(sd) == 0 );
  10047. break;
  10048. case ADDITEM_OVERAMOUNT:
  10049. fail = true;
  10050. }
  10051. if( fail )
  10052. {
  10053. clif_Mail_getattachment(fd, 1);
  10054. return;
  10055. }
  10056. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  10057. if( weight > sd->max_weight - sd->weight )
  10058. {
  10059. clif_Mail_getattachment(fd, 2);
  10060. return;
  10061. }
  10062. }
  10063. sd->mail.inbox.msg[i].zeny = 0;
  10064. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  10065. clif_Mail_read(sd, mail_id);
  10066. intif_Mail_getattach(sd->status.char_id, mail_id);
  10067. }
  10068. /*------------------------------------------
  10069. * Delete Message
  10070. *------------------------------------------*/
  10071. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  10072. {
  10073. int i, mail_id = RFIFOL(fd,2);
  10074. if( mail_invalid_operation(sd) )
  10075. return;
  10076. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10077. if (i < MAIL_MAX_INBOX)
  10078. {
  10079. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10080. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  10081. {// can't delete mail without removing attachment first
  10082. clif_Mail_delete(sd->fd, mail_id, 1);
  10083. return;
  10084. }
  10085. intif_Mail_delete(sd->status.char_id, mail_id);
  10086. }
  10087. }
  10088. /*------------------------------------------
  10089. * Return Mail Message
  10090. *------------------------------------------*/
  10091. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  10092. {
  10093. int i, mail_id = RFIFOL(fd,2);
  10094. if( mail_invalid_operation(sd) )
  10095. return;
  10096. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10097. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  10098. intif_Mail_return(sd->status.char_id, mail_id);
  10099. else
  10100. clif_Mail_return(sd->fd, mail_id, 1);
  10101. }
  10102. /*------------------------------------------
  10103. * Set Attachment
  10104. *------------------------------------------*/
  10105. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  10106. {
  10107. int idx = RFIFOW(fd,2);
  10108. int amount = RFIFOL(fd,4);
  10109. unsigned char flag;
  10110. if (idx < 0 || amount < 0)
  10111. return;
  10112. flag = mail_setitem(sd, idx, amount);
  10113. clif_Mail_setattachment(fd,idx,flag);
  10114. }
  10115. /*------------------------------------------
  10116. * Mail Window Operation
  10117. * 0 : Switch to 'new mail' window, or Close mailbox
  10118. * 1 : ???
  10119. * 2 : ???
  10120. *------------------------------------------*/
  10121. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  10122. {
  10123. int flag = RFIFOW(fd,2);
  10124. if (flag == 0 || flag == 1)
  10125. mail_removeitem(sd, 0);
  10126. if (flag == 0 || flag == 2)
  10127. mail_removezeny(sd, 0);
  10128. }
  10129. /*------------------------------------------
  10130. * Send Mail
  10131. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  10132. *------------------------------------------*/
  10133. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  10134. {
  10135. struct mail_message msg;
  10136. int body_len;
  10137. if( sd->state.trading )
  10138. return;
  10139. if( RFIFOW(fd,2) < 69 ) {
  10140. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  10141. return;
  10142. }
  10143. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  10144. {
  10145. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  10146. clif_Mail_send(fd, true); // fail
  10147. return;
  10148. }
  10149. body_len = RFIFOB(fd,68);
  10150. if (body_len > MAIL_BODY_LENGTH)
  10151. body_len = MAIL_BODY_LENGTH;
  10152. if( !mail_setattachment(sd, &msg) )
  10153. { // Invalid Append condition
  10154. clif_Mail_send(sd->fd, true); // fail
  10155. mail_removeitem(sd,0);
  10156. mail_removezeny(sd,0);
  10157. return;
  10158. }
  10159. msg.id = 0; // id will be assigned by charserver
  10160. msg.send_id = sd->status.char_id;
  10161. msg.dest_id = 0; // will attempt to resolve name
  10162. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  10163. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  10164. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  10165. if (body_len)
  10166. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  10167. else
  10168. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  10169. msg.timestamp = time(NULL);
  10170. if( !intif_Mail_send(sd->status.account_id, &msg) )
  10171. mail_deliveryfail(sd, &msg);
  10172. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  10173. }
  10174. /*==========================================
  10175. * AUCTION SYSTEM
  10176. * By Zephyrus
  10177. *==========================================*/
  10178. void clif_Auction_openwindow(struct map_session_data *sd)
  10179. {
  10180. int fd = sd->fd;
  10181. if( sd->state.storage_flag || sd->vender_id || sd->state.trading )
  10182. return;
  10183. WFIFOHEAD(fd,12);
  10184. WFIFOW(fd,0) = 0x25f;
  10185. WFIFOL(fd,2) = 0;
  10186. WFIFOB(fd,6) = 0xb6;
  10187. WFIFOB(fd,7) = 0x00;
  10188. WFIFOB(fd,8) = 0xa6;
  10189. WFIFOB(fd,9) = 0xde;
  10190. WFIFOW(fd,10) = 0;
  10191. WFIFOSET(fd,12);
  10192. }
  10193. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  10194. {
  10195. int i, fd = sd->fd, len = sizeof(struct auction_data);
  10196. struct auction_data auction;
  10197. struct item_data *item;
  10198. int k;
  10199. WFIFOHEAD(fd,20);
  10200. WFIFOW(fd,0) = 0x252;
  10201. WFIFOW(fd,2) = 12 + (count * 83);
  10202. WFIFOL(fd,4) = pages;
  10203. WFIFOL(fd,8) = count;
  10204. for( i = 0; i < count; i++ )
  10205. {
  10206. memcpy(&auction, RBUFP(buf,i * len), len);
  10207. k = 12 + (i * 83);
  10208. WFIFOL(fd,k) = auction.auction_id;
  10209. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  10210. if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
  10211. WFIFOW(fd,28+k) = item->view_id;
  10212. else
  10213. WFIFOW(fd,28+k) = auction.item.nameid;
  10214. WFIFOW(fd,30+k) = auction.type;
  10215. WFIFOW(fd,32+k) = 0; // ??
  10216. WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
  10217. WFIFOB(fd,36+k) = auction.item.identify;
  10218. WFIFOB(fd,37+k) = auction.item.attribute;
  10219. WFIFOB(fd,38+k) = auction.item.refine;
  10220. WFIFOW(fd,39+k) = auction.item.card[0];
  10221. WFIFOW(fd,41+k) = auction.item.card[1];
  10222. WFIFOW(fd,43+k) = auction.item.card[2];
  10223. WFIFOW(fd,45+k) = auction.item.card[3];
  10224. WFIFOL(fd,47+k) = auction.price;
  10225. WFIFOL(fd,51+k) = auction.buynow;
  10226. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  10227. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  10228. }
  10229. WFIFOSET(fd, 12 + (count * 83));
  10230. }
  10231. static void clif_Auction_setitem(int fd, int index, bool fail)
  10232. {
  10233. WFIFOHEAD(fd,packet_len(0x256));
  10234. WFIFOW(fd,0) = 0x256;
  10235. WFIFOW(fd,2) = index;
  10236. WFIFOB(fd,4) = fail;
  10237. WFIFOSET(fd,packet_len(0x256));
  10238. }
  10239. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  10240. {
  10241. if( sd->auction.amount > 0 )
  10242. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  10243. sd->auction.amount = 0;
  10244. }
  10245. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  10246. {
  10247. int idx = RFIFOW(fd,2) - 2;
  10248. int amount = RFIFOL(fd,4); // Allways 1
  10249. struct item_data *item;
  10250. if( sd->auction.amount > 0 )
  10251. sd->auction.amount = 0;
  10252. if( idx < 0 || idx >= MAX_INVENTORY )
  10253. {
  10254. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  10255. return;
  10256. }
  10257. if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
  10258. { // By client, amount is allways set to 1. Maybe this is a future implementation.
  10259. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  10260. return;
  10261. }
  10262. if( (item = itemdb_search(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) )
  10263. { // Consumible or pets are not allowed
  10264. clif_Auction_setitem(sd->fd, idx, true);
  10265. return;
  10266. }
  10267. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify )
  10268. { // Quest Item or something else
  10269. clif_Auction_setitem(sd->fd, idx, true);
  10270. return;
  10271. }
  10272. sd->auction.index = idx;
  10273. sd->auction.amount = amount;
  10274. clif_Auction_setitem(fd, idx + 2, false);
  10275. }
  10276. // 0 = You have failed to bid into the auction
  10277. // 1 = You have successfully bid in the auction
  10278. // 2 = The auction has been canceled
  10279. // 3 = An auction with at least one bidder cannot be canceled
  10280. // 4 = You cannot register more than 5 items in an auction at a time
  10281. // 5 = You do not have enough Zeny to pay the Auction Fee
  10282. // 6 = You have won the auction
  10283. // 7 = You have failed to win the auction
  10284. // 8 = You do not have enough Zeny
  10285. // 9 = You cannot place more than 5 bids at a time
  10286. void clif_Auction_message(int fd, unsigned char flag)
  10287. {
  10288. WFIFOHEAD(fd,3);
  10289. WFIFOW(fd,0) = 0x250;
  10290. WFIFOB(fd,2) = flag;
  10291. WFIFOSET(fd,3);
  10292. }
  10293. // 0 = You have ended the auction
  10294. // 1 = You cannot end the auction
  10295. // 2 = Bid number is incorrect
  10296. void clif_Auction_close(int fd, unsigned char flag)
  10297. {
  10298. WFIFOHEAD(fd,6);
  10299. WFIFOW(fd,0) = 0x25d;
  10300. WFIFOL(fd,2) = flag;
  10301. WFIFOSET(fd,6);
  10302. }
  10303. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  10304. {
  10305. struct auction_data auction;
  10306. struct item_data *item;
  10307. auction.price = RFIFOL(fd,2);
  10308. auction.buynow = RFIFOL(fd,6);
  10309. auction.hours = RFIFOW(fd,10);
  10310. // Invalid Situations...
  10311. if( sd->auction.amount < 1 )
  10312. {
  10313. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  10314. return;
  10315. }
  10316. if( auction.price >= auction.buynow )
  10317. {
  10318. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  10319. return;
  10320. }
  10321. if( auction.hours < 1 || auction.hours > 48 )
  10322. {
  10323. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  10324. return;
  10325. }
  10326. // Auction checks...
  10327. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  10328. {
  10329. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  10330. return;
  10331. }
  10332. if( auction.buynow > battle_config.auction_maximumprice )
  10333. { // Zeny Limits
  10334. auction.buynow = battle_config.auction_maximumprice;
  10335. if( auction.price >= auction.buynow )
  10336. auction.price = auction.buynow - 1;
  10337. }
  10338. auction.auction_id = 0;
  10339. auction.seller_id = sd->status.char_id;
  10340. safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
  10341. auction.buyer_id = 0;
  10342. memset(&auction.buyer_name, '\0', NAME_LENGTH);
  10343. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  10344. {
  10345. clif_Auction_message(fd, 2); // The auction has been canceled
  10346. return;
  10347. }
  10348. if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  10349. { // Just in case
  10350. clif_Auction_message(fd, 2); // The auction has been canceled
  10351. return;
  10352. }
  10353. safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
  10354. auction.type = item->type;
  10355. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  10356. auction.item.amount = 1;
  10357. auction.timestamp = 0;
  10358. if( !intif_Auction_register(&auction) )
  10359. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  10360. else
  10361. {
  10362. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1);
  10363. sd->auction.amount = 0;
  10364. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  10365. }
  10366. }
  10367. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  10368. {
  10369. unsigned int auction_id = RFIFOL(fd,2);
  10370. intif_Auction_cancel(sd->status.char_id, auction_id);
  10371. }
  10372. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  10373. {
  10374. unsigned int auction_id = RFIFOL(fd,2);
  10375. intif_Auction_close(sd->status.char_id, auction_id);
  10376. }
  10377. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  10378. {
  10379. unsigned int auction_id = RFIFOL(fd,2);
  10380. int bid = RFIFOL(fd,6);
  10381. if( bid <= 0 )
  10382. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  10383. else if( bid > sd->status.zeny )
  10384. clif_Auction_message(fd, 8); // You do not have enough zeny
  10385. else
  10386. {
  10387. pc_payzeny(sd, bid);
  10388. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  10389. }
  10390. }
  10391. /*------------------------------------------
  10392. * Auction Search
  10393. * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.w
  10394. * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
  10395. *------------------------------------------*/
  10396. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  10397. {
  10398. char search_text[NAME_LENGTH];
  10399. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  10400. int price = RFIFOL(fd,4);
  10401. clif_parse_Auction_cancelreg(fd, sd);
  10402. safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
  10403. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  10404. }
  10405. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  10406. {
  10407. short type = RFIFOW(fd,2) + 6;
  10408. clif_parse_Auction_cancelreg(fd, sd);
  10409. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  10410. }
  10411. #endif
  10412. /*==========================================
  10413. * CASH/POINT SHOP
  10414. *==========================================*/
  10415. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  10416. {
  10417. int fd,i;
  10418. nullpo_retv(sd);
  10419. nullpo_retv(nd);
  10420. fd = sd->fd;
  10421. sd->npc_shopid = nd->bl.id;
  10422. WFIFOHEAD(fd, 200 * 11 + 12);
  10423. WFIFOW(fd,0) = 0x287;
  10424. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  10425. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  10426. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  10427. for( i = 0; i < nd->u.shop.count; i++ )
  10428. {
  10429. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  10430. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  10431. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  10432. WFIFOB(fd,20+i*11) = itemtype(id->type);
  10433. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  10434. }
  10435. WFIFOSET(fd,WFIFOW(fd,2));
  10436. }
  10437. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  10438. {
  10439. int fail = 0, amount, points;
  10440. short nameid;
  10441. struct npc_data *nd;
  10442. nullpo_retv(sd);
  10443. nd = (struct npc_data *)map_id2bl(sd->npc_shopid);
  10444. nameid = RFIFOW(fd,2);
  10445. amount = RFIFOW(fd,4);
  10446. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  10447. fail = npc_cashshop_buy(sd, nameid, amount, points);
  10448. WFIFOHEAD(fd,12);
  10449. WFIFOW(fd,0) = 0x289;
  10450. WFIFOL(fd,2) = sd->cashPoints;
  10451. WFIFOL(fd,6) = sd->kafraPoints;
  10452. WFIFOW(fd,10) = fail;
  10453. WFIFOSET(fd,12);
  10454. }
  10455. /*==========================================
  10456. * Adoption System
  10457. *==========================================*/
  10458. // 0 : "You cannot adopt more than 1 child."
  10459. // 1 : "You must be at least character level 70 in order to adopt someone."
  10460. // 2 : "You cannot adopt a married person."
  10461. void clif_Adopt_reply(struct map_session_data *sd, int type)
  10462. {
  10463. int fd = sd->fd;
  10464. WFIFOHEAD(fd,6);
  10465. WFIFOW(fd,0) = 0x0216;
  10466. WFIFOL(fd,2) = type;
  10467. WFIFOSET(fd,6);
  10468. }
  10469. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  10470. {
  10471. int fd = sd->fd;
  10472. WFIFOHEAD(fd,34);
  10473. WFIFOW(fd,0) = 0x01f6;
  10474. WFIFOL(fd,2) = src->status.account_id;
  10475. WFIFOL(fd,6) = p_id;
  10476. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  10477. WFIFOSET(fd,34);
  10478. }
  10479. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  10480. {
  10481. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  10482. if( pc_can_Adopt(sd, p_sd, tsd) )
  10483. {
  10484. tsd->adopt_invite = sd->status.account_id;
  10485. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  10486. }
  10487. }
  10488. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  10489. {
  10490. int p1_id = RFIFOL(fd,2);
  10491. int p2_id = RFIFOL(fd,6);
  10492. int result = RFIFOL(fd,10);
  10493. struct map_session_data* p1_sd = map_id2sd(p1_id);
  10494. struct map_session_data* p2_sd = map_id2sd(p2_id);
  10495. int pid = sd->adopt_invite;
  10496. sd->adopt_invite = 0;
  10497. if( p1_sd == NULL || p2_sd == NULL )
  10498. return; // Both players need to be online
  10499. if( pid != p1_sd->status.account_id )
  10500. return; // Incorrect values
  10501. if( result == 0 )
  10502. return; // Rejected
  10503. pc_adoption(p1_sd, p2_sd, sd);
  10504. }
  10505. /*==========================================
  10506. * Convex Mirror
  10507. * S 0293 <flag>.b <x>.l <y>.l <Hours>.w <Minutes>.w <unknown>.l <monster name>.40B <unknown>.11B
  10508. *==========================================*/
  10509. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  10510. {
  10511. WFIFOHEAD(fd,70);
  10512. memset(WFIFOP(fd,0),0,70);
  10513. WFIFOW(fd,0) = 0x0293;
  10514. if( md != NULL )
  10515. {
  10516. if( md->bl.prev != NULL )
  10517. { // Boss on This Map
  10518. if( flag )
  10519. {
  10520. WFIFOB(fd,2) = 1;
  10521. WFIFOL(fd,3) = md->bl.x;
  10522. WFIFOL(fd,7) = md->bl.y;
  10523. }
  10524. else
  10525. WFIFOB(fd,2) = 2; // First Time
  10526. }
  10527. else
  10528. { // Boss is Dead
  10529. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  10530. unsigned int seconds;
  10531. int hours, minutes;
  10532. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000;
  10533. hours = seconds / (60 * 60);
  10534. seconds = seconds - (60 * 60 * hours);
  10535. minutes = seconds / 60;
  10536. WFIFOB(fd,2) = 3;
  10537. WFIFOW(fd,11) = hours; // Hours
  10538. WFIFOW(fd,13) = minutes; // Minutes
  10539. }
  10540. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  10541. }
  10542. WFIFOSET(fd,70);
  10543. }
  10544. /*==========================================
  10545. * Requesting equip of a player
  10546. *------------------------------------------*/
  10547. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  10548. {
  10549. int charid = RFIFOL(fd, 2);
  10550. struct map_session_data* tsd = map_id2sd(charid);
  10551. if (!tsd)
  10552. return;
  10553. if( tsd->status.show_equip || (battle_config.gm_viewequip_min_lv && pc_isGM(sd) >= battle_config.gm_viewequip_min_lv) )
  10554. clif_viewequip_ack(sd, tsd);
  10555. else
  10556. clif_viewequip_fail(sd);
  10557. }
  10558. /*==========================================
  10559. * Equip window (un)tick
  10560. * S 02d8 <zero?>.L <flag>.L
  10561. *------------------------------------------*/
  10562. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  10563. {
  10564. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  10565. sd->status.show_equip = flag;
  10566. clif_equiptickack(sd, flag);
  10567. }
  10568. /*==========================================
  10569. * Questlog System [Kevin]
  10570. * 02B5 <packet_len>.W <ignored>.L { }.10B* <-- UNKOWN PACKET
  10571. * 02B7 <quest_id>.L <state>.B
  10572. *------------------------------------------*/
  10573. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  10574. {
  10575. }
  10576. //Send simple list of quests upon login
  10577. //* 02B1 <packet_len>.W <ignored>.L { <quest_id>.L <state>.B }.5B*
  10578. void clif_send_questlog(struct map_session_data * sd)
  10579. {
  10580. int fd = sd->fd;
  10581. int i;
  10582. WFIFOHEAD(fd,sd->num_quests*5+8);
  10583. WFIFOW(fd, 0) = 0x02B1;
  10584. WFIFOW(fd, 2) = sd->num_quests*5+8;
  10585. for(i=0; i<MAX_QUEST; i++)
  10586. {
  10587. if(!sd->quest_log[i].quest_id)
  10588. continue;
  10589. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  10590. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  10591. }
  10592. WFIFOSET(fd, WFIFOW(fd, 2));
  10593. }
  10594. //Send objective info on login
  10595. //* 02B2 <packet_len>.W <ignored>.L { <quest_id>.L <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3] }.104B*
  10596. void clif_send_questlog_info(struct map_session_data * sd)
  10597. {
  10598. int fd = sd->fd;
  10599. int i, j;
  10600. WFIFOHEAD(fd,sd->num_quests*104+8);
  10601. WFIFOW(fd, 0) = 0x02B2;
  10602. WFIFOW(fd, 2) = sd->num_quests*104+8;
  10603. for(i=0; i<MAX_QUEST; i++)
  10604. {
  10605. if(!sd->quest_log[i].quest_id)
  10606. continue;
  10607. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  10608. // I have no idea what the time field does [Kevin]
  10609. WFIFOL(fd, i*104+16) = 0;
  10610. WFIFOW(fd, i*104+20) = sd->quest_log[i].num_objectives;
  10611. for(j=0; j<sd->quest_log[i].num_objectives; j++)
  10612. {
  10613. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].objectives[j].count;
  10614. memcpy(WFIFOP(fd, i*104+28+j*30), sd->quest_log[i].objectives[j].name, NAME_LENGTH);
  10615. }
  10616. }
  10617. WFIFOSET(fd, WFIFOW(fd, 2));
  10618. }
  10619. //Send info when objective info needs an update
  10620. //* 02B3 <quest_id>.L <state>.B <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3]
  10621. void clif_send_quest_info(struct map_session_data * sd, struct quest * qd)
  10622. {
  10623. int fd = sd->fd;
  10624. int i;
  10625. WFIFOHEAD(fd,qd->num_objectives*30+17);
  10626. WFIFOW(fd, 0) = 0x02B3;
  10627. WFIFOL(fd, 2) = qd->quest_id;
  10628. WFIFOB(fd, 6) = qd->state;
  10629. //Same time value thing
  10630. WFIFOW(fd, 11) = 0;
  10631. WFIFOW(fd, 15) = qd->num_objectives;
  10632. for(i=0; i<qd->num_objectives; i++)
  10633. {
  10634. WFIFOW(fd, i*30+21) = qd->objectives[i].count;
  10635. memcpy(WFIFOP(fd, i*30+23), qd->objectives[i].name, NAME_LENGTH);
  10636. }
  10637. WFIFOSET(fd, qd->num_objectives*30+17);
  10638. }
  10639. //Send delete msg
  10640. //* 02B4 <quest_id>.L
  10641. void clif_send_quest_delete(struct map_session_data * sd, int quest_id)
  10642. {
  10643. int fd = sd->fd;
  10644. WFIFOHEAD(fd, 6);
  10645. WFIFOW(fd, 0) = 0x02B4;
  10646. WFIFOL(fd, 2) = quest_id;
  10647. WFIFOSET(fd, 6);
  10648. }
  10649. //Change active state of the quest
  10650. //* 02B6 <quest_id>.L <state_to>.B
  10651. void clif_send_quest_status(struct map_session_data * sd, int quest_id, bool active)
  10652. {
  10653. int fd = sd->fd;
  10654. WFIFOHEAD(fd, 7);
  10655. WFIFOW(fd, 0) = 0x02B6;
  10656. WFIFOL(fd, 2) = quest_id;
  10657. WFIFOB(fd, 6) = active?1:0;
  10658. WFIFOSET(fd, 7);
  10659. }
  10660. /*==========================================
  10661. * パケットデバッグ
  10662. *------------------------------------------*/
  10663. void clif_parse_debug(int fd,struct map_session_data *sd)
  10664. {
  10665. int i, cmd, len;
  10666. cmd = RFIFOW(fd,0);
  10667. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10668. ShowDebug("packet debug 0x%4X\n",cmd);
  10669. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10670. for(i=0;i<len;i++){
  10671. if((i&15)==0)
  10672. ShowMessage("\n%04X ",i);
  10673. ShowMessage("%02X ",RFIFOB(fd,i));
  10674. }
  10675. ShowMessage("\n");
  10676. }
  10677. /*==========================================
  10678. * Main client packet processing function
  10679. *------------------------------------------*/
  10680. int clif_parse(int fd)
  10681. {
  10682. int cmd, packet_ver, packet_len, err;
  10683. TBL_PC* sd;
  10684. int pnum;
  10685. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  10686. // Note: "click masters" can do 80+ clicks in 10 seconds
  10687. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  10688. { // begin main client packet processing loop
  10689. sd = (TBL_PC *)session[fd]->session_data;
  10690. if (session[fd]->flag.eof) {
  10691. if (sd) {
  10692. if (sd->state.autotrade) {
  10693. //Disassociate character from the socket connection.
  10694. session[fd]->session_data = NULL;
  10695. sd->fd = 0;
  10696. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10697. } else
  10698. if (sd->state.active) {
  10699. // Player logout display [Valaris]
  10700. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10701. clif_quitsave(fd, sd);
  10702. } else {
  10703. //Unusual logout (during log on/off/map-changer procedure)
  10704. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  10705. map_quit(sd);
  10706. }
  10707. } else {
  10708. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  10709. }
  10710. do_close(fd);
  10711. return 0;
  10712. }
  10713. if (RFIFOREST(fd) < 2)
  10714. return 0;
  10715. cmd = RFIFOW(fd,0);
  10716. // identify client's packet version
  10717. if (sd) {
  10718. packet_ver = sd->packet_ver;
  10719. } else {
  10720. // check authentification packet to know packet version
  10721. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10722. if( err )
  10723. {// failed to identify packet version
  10724. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10725. err == 1 ? "" :
  10726. err == 2 ? ", possibly for having an invalid account_id" :
  10727. err == 3 ? ", possibly for having an invalid char_id." :
  10728. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10729. err == 4 ? ", possibly for having an invalid login_id1." :
  10730. err == 5 ? ", possibly for having an invalid client_tick." :
  10731. */
  10732. err == 6 ? ", possibly for having an invalid sex." :
  10733. ". ERROR invalid error code"));
  10734. WFIFOHEAD(fd,packet_len(0x6a));
  10735. WFIFOW(fd,0) = 0x6a;
  10736. WFIFOB(fd,2) = 3; // Rejected from Server
  10737. WFIFOSET(fd,packet_len(0x6a));
  10738. RFIFOSKIP(fd, RFIFOREST(fd));
  10739. set_eof(fd);
  10740. return 0;
  10741. }
  10742. }
  10743. // filter out invalid / unsupported packets
  10744. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  10745. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10746. set_eof(fd);
  10747. return 0;
  10748. }
  10749. // determine real packet length
  10750. packet_len = packet_db[packet_ver][cmd].len;
  10751. if (packet_len == -1) { // variable-length packet
  10752. if (RFIFOREST(fd) < 4)
  10753. return 0;
  10754. packet_len = RFIFOW(fd,2);
  10755. if (packet_len < 4 || packet_len > 32768) {
  10756. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10757. set_eof(fd);
  10758. return 0;
  10759. }
  10760. }
  10761. if ((int)RFIFOREST(fd) < packet_len)
  10762. return 0; // not enough data received to form the packet
  10763. if (packet_db[packet_ver][cmd].func) {
  10764. if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10765. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10766. else
  10767. if ((sd && sd->state.active)
  10768. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10769. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10770. ) //Only execute the function when there's an active sd (except for debug/wanttoconnect packets)
  10771. packet_db[packet_ver][cmd].func(fd, sd);
  10772. }
  10773. #if DUMP_UNKNOWN_PACKET
  10774. else if (battle_config.error_log)
  10775. {
  10776. int i;
  10777. FILE *fp;
  10778. char packet_txt[256] = "save/packet.txt";
  10779. time_t now;
  10780. dump = 1;
  10781. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10782. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10783. return 1;
  10784. } else {
  10785. time(&now);
  10786. if (sd && sd->state.active) {
  10787. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10788. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10789. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10790. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10791. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10792. for(i = 0; i < packet_len; i++) {
  10793. if ((i & 15) == 0)
  10794. fprintf(fp, "\n\t%04X ", i);
  10795. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10796. }
  10797. fprintf(fp, "\n\n");
  10798. fclose(fp);
  10799. }
  10800. }
  10801. #endif
  10802. /* TODO: use utils.c :: dump()
  10803. if (dump) {
  10804. int i;
  10805. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10806. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10807. for(i = 0; i < packet_len; i++) {
  10808. if ((i & 15) == 0)
  10809. ShowMessage("\n%04X ",i);
  10810. ShowMessage("%02X ", RFIFOB(fd,i));
  10811. }
  10812. ShowMessage("\n");
  10813. if (sd && sd->state.active) {
  10814. if (sd->status.name != NULL)
  10815. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  10816. sd->status.account_id, sd->status.char_id, sd->status.name);
  10817. else
  10818. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  10819. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10820. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  10821. }*/
  10822. RFIFOSKIP(fd, packet_len);
  10823. }; // main loop end
  10824. return 0;
  10825. }
  10826. /*==========================================
  10827. * パケットデータベース読み込み
  10828. *------------------------------------------*/
  10829. static int packetdb_readdb(void)
  10830. {
  10831. FILE *fp;
  10832. char line[1024];
  10833. int ln=0;
  10834. int cmd,i,j,packet_ver;
  10835. int max_cmd=-1;
  10836. int skip_ver = 0;
  10837. int warned = 0;
  10838. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10839. int packet_len_table[MAX_PACKET_DB] = {
  10840. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10844. //#0x0040
  10845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10847. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10848. #if PACKETVER < 2
  10849. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10850. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  10851. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10852. #else // change in 0x78 and 0x7c
  10853. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  10854. #endif
  10855. //#0x0080
  10856. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10857. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10858. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10859. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10860. //#0x00C0
  10861. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10862. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10863. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10864. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10865. //#0x0100
  10866. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10867. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10868. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10869. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10870. //#0x0140
  10871. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10872. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10873. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10874. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10875. //#0x0180
  10876. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10877. #if PACKETVER < 1
  10878. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10879. #else // 196 comodo以降 状態表示アイコン用
  10880. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10881. #endif
  10882. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10883. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10884. //#0x01C0, Set 0x1d5=-1
  10885. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10886. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10887. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10888. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10889. //#0x0200
  10890. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10891. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  10892. #if PACKETVER < 20071106
  10893. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10894. #else // 0x22c changed
  10895. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  10896. #endif
  10897. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  10898. //#0x0240
  10899. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  10900. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  10901. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10902. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10903. //#0x0280
  10904. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  10905. 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10907. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  10908. //#0x02C0
  10909. 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10910. 0, 0, 0, 0, 0, 0, 6, -1, 10, 10, 0, 0, 0, 0, 0, 0,
  10911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10913. };
  10914. struct {
  10915. void (*func)(int, struct map_session_data *);
  10916. char *name;
  10917. } clif_parse_func[]={
  10918. {clif_parse_WantToConnection,"wanttoconnection"},
  10919. {clif_parse_LoadEndAck,"loadendack"},
  10920. {clif_parse_TickSend,"ticksend"},
  10921. {clif_parse_WalkToXY,"walktoxy"},
  10922. {clif_parse_QuitGame,"quitgame"},
  10923. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10924. {clif_parse_GlobalMessage,"globalmessage"},
  10925. {clif_parse_MapMove,"mapmove"},
  10926. {clif_parse_ChangeDir,"changedir"},
  10927. {clif_parse_Emotion,"emotion"},
  10928. {clif_parse_HowManyConnections,"howmanyconnections"},
  10929. {clif_parse_ActionRequest,"actionrequest"},
  10930. {clif_parse_Restart,"restart"},
  10931. {clif_parse_WisMessage,"wis"},
  10932. {clif_parse_GMmessage,"gmmessage"},
  10933. {clif_parse_TakeItem,"takeitem"},
  10934. {clif_parse_DropItem,"dropitem"},
  10935. {clif_parse_UseItem,"useitem"},
  10936. {clif_parse_EquipItem,"equipitem"},
  10937. {clif_parse_UnequipItem,"unequipitem"},
  10938. {clif_parse_NpcClicked,"npcclicked"},
  10939. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10940. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10941. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10942. {clif_parse_CreateChatRoom,"createchatroom"},
  10943. {clif_parse_ChatAddMember,"chataddmember"},
  10944. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10945. {clif_parse_ChangeChatOwner,"changechatowner"},
  10946. {clif_parse_KickFromChat,"kickfromchat"},
  10947. {clif_parse_ChatLeave,"chatleave"},
  10948. {clif_parse_TradeRequest,"traderequest"},
  10949. {clif_parse_TradeAck,"tradeack"},
  10950. {clif_parse_TradeAddItem,"tradeadditem"},
  10951. {clif_parse_TradeOk,"tradeok"},
  10952. {clif_parse_TradeCancel,"tradecancel"},
  10953. {clif_parse_TradeCommit,"tradecommit"},
  10954. {clif_parse_StopAttack,"stopattack"},
  10955. {clif_parse_PutItemToCart,"putitemtocart"},
  10956. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10957. {clif_parse_RemoveOption,"removeoption"},
  10958. {clif_parse_ChangeCart,"changecart"},
  10959. {clif_parse_StatusUp,"statusup"},
  10960. {clif_parse_SkillUp,"skillup"},
  10961. {clif_parse_UseSkillToId,"useskilltoid"},
  10962. {clif_parse_UseSkillToPos,"useskilltopos"},
  10963. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10964. {clif_parse_UseSkillMap,"useskillmap"},
  10965. {clif_parse_RequestMemo,"requestmemo"},
  10966. {clif_parse_ProduceMix,"producemix"},
  10967. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10968. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10969. {clif_parse_NpcAmountInput,"npcamountinput"},
  10970. {clif_parse_NpcStringInput,"npcstringinput"},
  10971. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10972. {clif_parse_ItemIdentify,"itemidentify"},
  10973. {clif_parse_SelectArrow,"selectarrow"},
  10974. {clif_parse_AutoSpell,"autospell"},
  10975. {clif_parse_UseCard,"usecard"},
  10976. {clif_parse_InsertCard,"insertcard"},
  10977. {clif_parse_RepairItem,"repairitem"},
  10978. {clif_parse_WeaponRefine,"weaponrefine"},
  10979. {clif_parse_SolveCharName,"solvecharname"},
  10980. {clif_parse_ResetChar,"resetchar"},
  10981. {clif_parse_LGMmessage,"lgmmessage"},
  10982. {clif_parse_MoveToKafra,"movetokafra"},
  10983. {clif_parse_MoveFromKafra,"movefromkafra"},
  10984. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10985. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10986. {clif_parse_CloseKafra,"closekafra"},
  10987. {clif_parse_CreateParty,"createparty"},
  10988. {clif_parse_CreateParty2,"createparty2"},
  10989. {clif_parse_PartyInvite,"partyinvite"},
  10990. {clif_parse_PartyInvite2,"partyinvite2"},
  10991. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10992. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  10993. {clif_parse_LeaveParty,"leaveparty"},
  10994. {clif_parse_RemovePartyMember,"removepartymember"},
  10995. {clif_parse_PartyChangeOption,"partychangeoption"},
  10996. {clif_parse_PartyMessage,"partymessage"},
  10997. {clif_parse_CloseVending,"closevending"},
  10998. {clif_parse_VendingListReq,"vendinglistreq"},
  10999. {clif_parse_PurchaseReq,"purchasereq"},
  11000. {clif_parse_OpenVending,"openvending"},
  11001. {clif_parse_CreateGuild,"createguild"},
  11002. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  11003. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  11004. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  11005. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  11006. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  11007. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  11008. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  11009. {clif_parse_GuildInvite,"guildinvite"},
  11010. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  11011. {clif_parse_GuildLeave,"guildleave"},
  11012. {clif_parse_GuildExpulsion,"guildexpulsion"},
  11013. {clif_parse_GuildMessage,"guildmessage"},
  11014. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  11015. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  11016. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  11017. {clif_parse_GuildOpposition,"guildopposition"},
  11018. {clif_parse_GuildBreak,"guildbreak"},
  11019. {clif_parse_PetMenu,"petmenu"},
  11020. {clif_parse_CatchPet,"catchpet"},
  11021. {clif_parse_SelectEgg,"selectegg"},
  11022. {clif_parse_SendEmotion,"sendemotion"},
  11023. {clif_parse_ChangePetName,"changepetname"},
  11024. {clif_parse_GMKick,"gmkick"},
  11025. {clif_parse_GMHide,"gmhide"},
  11026. {clif_parse_GMReqNoChat,"gmreqnochat"},
  11027. {clif_parse_GMReqAccountName,"gmreqaccname"},
  11028. {clif_parse_GMKickAll,"killall"},
  11029. {clif_parse_GMRecall,"recall"},
  11030. {clif_parse_GMRecall,"summon"},
  11031. {clif_parse_GM_Monster_Item,"itemmonster"},
  11032. {clif_parse_GMShift,"remove"},
  11033. {clif_parse_GMShift,"shift"},
  11034. {clif_parse_GMChangeMapType,"changemaptype"},
  11035. {clif_parse_GMRc,"rc"},
  11036. {clif_parse_NoviceDoriDori,"sndoridori"},
  11037. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  11038. {clif_parse_PMIgnore,"wisexin"},
  11039. {clif_parse_PMIgnoreList,"wisexlist"},
  11040. {clif_parse_PMIgnoreAll,"wisall"},
  11041. {clif_parse_FriendsListAdd,"friendslistadd"},
  11042. {clif_parse_FriendsListRemove,"friendslistremove"},
  11043. {clif_parse_FriendsListReply,"friendslistreply"},
  11044. {clif_parse_Blacksmith,"blacksmith"},
  11045. {clif_parse_Alchemist,"alchemist"},
  11046. {clif_parse_Taekwon,"taekwon"},
  11047. {clif_parse_RankingPk,"rankingpk"},
  11048. {clif_parse_FeelSaveOk,"feelsaveok"},
  11049. {clif_parse_debug,"debug"},
  11050. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  11051. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  11052. {clif_parse_HomMoveTo,"hommoveto"},
  11053. {clif_parse_HomAttack,"homattack"},
  11054. {clif_parse_HomMenu,"hommenu"},
  11055. {clif_parse_StoragePassword,"storagepassword"},
  11056. {clif_parse_Hotkey,"hotkey"},
  11057. {clif_parse_AutoRevive,"autorevive"},
  11058. {clif_parse_Check,"check"},
  11059. {clif_parse_Adopt_request,"adoptrequest"},
  11060. {clif_parse_Adopt_reply,"adoptreply"},
  11061. #ifndef TXT_ONLY
  11062. // MAIL SYSTEM
  11063. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  11064. {clif_parse_Mail_read,"mailread"},
  11065. {clif_parse_Mail_getattach,"mailgetattach"},
  11066. {clif_parse_Mail_delete,"maildelete"},
  11067. {clif_parse_Mail_return,"mailreturn"},
  11068. {clif_parse_Mail_setattach,"mailsetattach"},
  11069. {clif_parse_Mail_winopen,"mailwinopen"},
  11070. {clif_parse_Mail_send,"mailsend"},
  11071. // AUCTION SYSTEM
  11072. {clif_parse_Auction_search,"auctionsearch"},
  11073. {clif_parse_Auction_buysell,"auctionbuysell"},
  11074. {clif_parse_Auction_setitem,"auctionsetitem"},
  11075. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  11076. {clif_parse_Auction_register,"auctionregister"},
  11077. {clif_parse_Auction_cancel,"auctioncancel"},
  11078. {clif_parse_Auction_close,"auctionclose"},
  11079. {clif_parse_Auction_bid,"auctionbid"},
  11080. #endif
  11081. {clif_parse_cashshop_buy,"cashshopbuy"},
  11082. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  11083. {clif_parse_EquipTick,"equiptickbox"},
  11084. {NULL,NULL}
  11085. };
  11086. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  11087. memset(packet_db,0,sizeof(packet_db));
  11088. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  11089. packet_len(i) = packet_len_table[i];
  11090. sprintf(line, "%s/packet_db.txt", db_path);
  11091. if( (fp=fopen(line,"r"))==NULL ){
  11092. ShowFatalError("can't read %s\n", line);
  11093. exit(EXIT_FAILURE);
  11094. }
  11095. clif_config.packet_db_ver = MAX_PACKET_VER;
  11096. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  11097. while( fgets(line, sizeof(line), fp) )
  11098. {
  11099. ln++;
  11100. if(line[0]=='/' && line[1]=='/')
  11101. continue;
  11102. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  11103. {
  11104. if(strcmpi(w1,"packet_ver")==0) {
  11105. int prev_ver = packet_ver;
  11106. skip_ver = 0;
  11107. packet_ver = atoi(w2);
  11108. if ( packet_ver > MAX_PACKET_VER )
  11109. { //Check to avoid overflowing. [Skotlex]
  11110. if( (warned&1) == 0 )
  11111. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  11112. warned &= 1;
  11113. skip_ver = 1;
  11114. }
  11115. else if( packet_ver < 0 )
  11116. {
  11117. if( (warned&2) == 0 )
  11118. ShowWarning("Negative packet versions are not supported.\n");
  11119. warned &= 2;
  11120. skip_ver = 1;
  11121. }
  11122. else if( packet_ver == SERVER )
  11123. {
  11124. if( (warned&4) == 0 )
  11125. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  11126. warned &= 4;
  11127. skip_ver = 1;
  11128. }
  11129. if( skip_ver )
  11130. {
  11131. ShowWarning("Skipping packet version %d.\n", packet_ver);
  11132. packet_ver = prev_ver;
  11133. continue;
  11134. }
  11135. // copy from previous version into new version and continue
  11136. // - indicating all following packets should be read into the newer version
  11137. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  11138. continue;
  11139. } else if(strcmpi(w1,"packet_db_ver")==0) {
  11140. if(strcmpi(w2,"default")==0) //This is the preferred version.
  11141. clif_config.packet_db_ver = MAX_PACKET_VER;
  11142. else // to manually set the packet DB version
  11143. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  11144. continue;
  11145. }
  11146. }
  11147. if( skip_ver != 0 )
  11148. continue; // Skipping current packet version
  11149. memset(str,0,sizeof(str));
  11150. for(j=0,p=line;j<4 && p; ++j)
  11151. {
  11152. str[j]=p;
  11153. p=strchr(p,',');
  11154. if(p) *p++=0;
  11155. }
  11156. if(str[0]==NULL)
  11157. continue;
  11158. cmd=strtol(str[0],(char **)NULL,0);
  11159. if(max_cmd < cmd)
  11160. max_cmd = cmd;
  11161. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  11162. continue;
  11163. if(str[1]==NULL){
  11164. ShowError("packet_db: packet len error\n");
  11165. continue;
  11166. }
  11167. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  11168. if(str[2]==NULL){
  11169. packet_db[packet_ver][cmd].func = NULL;
  11170. ln++;
  11171. continue;
  11172. }
  11173. // look up processing function by name
  11174. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  11175. if( j < ARRAYLENGTH(clif_parse_func) )
  11176. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  11177. // set the identifying cmd for the packet_db version
  11178. if (strcmp(str[2],"wanttoconnection")==0)
  11179. clif_config.connect_cmd[packet_ver] = cmd;
  11180. if(str[3]==NULL){
  11181. ShowError("packet_db: packet error\n");
  11182. exit(EXIT_FAILURE);
  11183. }
  11184. for(j=0,p2=str[3];p2;j++){
  11185. short k;
  11186. str2[j]=p2;
  11187. p2=strchr(p2,':');
  11188. if(p2) *p2++=0;
  11189. k = atoi(str2[j]);
  11190. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  11191. packet_db[packet_ver][cmd].pos[j] = k;
  11192. }
  11193. }
  11194. fclose(fp);
  11195. if(max_cmd > MAX_PACKET_DB)
  11196. {
  11197. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  11198. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  11199. }
  11200. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  11201. { //Locate the nearest version that we still support. [Skotlex]
  11202. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  11203. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  11204. }
  11205. 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);
  11206. return 0;
  11207. }
  11208. /*==========================================
  11209. *
  11210. *------------------------------------------*/
  11211. int do_init_clif(void)
  11212. {
  11213. clif_config.packet_db_ver = -1; // the main packet version of the DB
  11214. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  11215. memset(packet_db,0,sizeof(packet_db));
  11216. //Using the packet_db file is the only way to set up packets now [Skotlex]
  11217. packetdb_readdb();
  11218. set_defaultparse(clif_parse);
  11219. if( make_listen_bind(bind_ip,map_port) == -1 )
  11220. {
  11221. ShowFatalError("can't bind game port\n");
  11222. exit(EXIT_FAILURE);
  11223. }
  11224. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  11225. add_timer_func_list(clif_delayquit, "clif_delayquit");
  11226. return 0;
  11227. }