clif.c 334 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #define DUMP_UNKNOWN_PACKET 0
  4. #define DUMP_ALL_PACKETS 0
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdarg.h>
  10. #include <limits.h>
  11. #include <time.h>
  12. #include "../common/socket.h"
  13. #include "../common/timer.h"
  14. #include "../common/malloc.h"
  15. #include "../common/version.h"
  16. #include "../common/nullpo.h"
  17. #include "../common/showmsg.h"
  18. #include "map.h"
  19. #include "chrif.h"
  20. #include "clif.h"
  21. #include "pc.h"
  22. #include "status.h"
  23. #include "npc.h"
  24. #include "itemdb.h"
  25. #include "chat.h"
  26. #include "trade.h"
  27. #include "storage.h"
  28. #include "script.h"
  29. #include "skill.h"
  30. #include "atcommand.h"
  31. #include "charcommand.h"
  32. #include "intif.h"
  33. #include "battle.h"
  34. #include "mob.h"
  35. #include "party.h"
  36. #include "unit.h"
  37. #include "guild.h"
  38. #include "vending.h"
  39. #include "pet.h"
  40. #include "mercenary.h" //[orn]
  41. #include "log.h"
  42. #include "irc.h"
  43. struct Clif_Config {
  44. int packet_db_ver; //Preferred packet version.
  45. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  46. } clif_config;
  47. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
  48. static const int packet_len_table[MAX_PACKET_DB] = {
  49. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  50. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  51. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  52. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  53. //#0x0040
  54. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  55. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  56. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  57. #if PACKETVER < 2
  58. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  59. #else // 78-7b 亀島以降 lv99エフェクト用
  60. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  61. #endif
  62. //#0x0080
  63. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  64. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  65. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  66. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  67. //#0x00C0
  68. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  69. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  70. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  71. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  72. //#0x0100
  73. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  74. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  75. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  76. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  77. //#0x0140
  78. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  79. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  80. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  81. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  82. //#0x0180
  83. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  84. #if PACKETVER < 1
  85. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  86. #else // 196 comodo以降 状態表示アイコン用
  87. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  88. #endif
  89. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  90. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  91. //#0x01C0, Set 0x1d5=-1
  92. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  93. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  94. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  95. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  96. //#0x200
  97. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  98. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282,10, 10, -1, -1, 66,
  99. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  100. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  101. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  102. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4
  103. };
  104. //Converts item type in case of pet eggs.
  105. #define itemtype(a) (a == 7)?4:a
  106. #define WBUFPOS(p,pos,x,y,dir) { unsigned char *__p = (p); __p+=(pos); __p[0] = (x)>>2; __p[1] = ((x)<<6) | (((y)>>4)&0x3f); __p[2] = ((y)<<4)|((dir)&0xf); }
  107. #define WBUFPOS2(p,pos,x0,y0,x1,y1) { unsigned char *__p = (p); __p+=(pos); __p[0] = (unsigned char)((x0)>>2); __p[1] = (unsigned char)(((x0)<<6) | (((y0)>>4)&0x3f)); __p[2] = (unsigned char)(((y0)<<4) | (((x1)>>6)&0x0f)); __p[3]=(unsigned char)(((x1)<<2) | (((y1)>>8)&0x03)); __p[4]=(unsigned char)(y1); }
  108. #define WFIFOPOS(fd,pos,x,y,dir) { WBUFPOS (WFIFOP(fd,pos),0,x,y,dir); }
  109. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1) { WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1); }
  110. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  111. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  112. //Removed sd->npc_shopid because there is no packet sent from the client when you cancel a buy!
  113. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  114. #define clif_cant_act(sd) (sd->npc_id || sd->vender_id || sd->chatID || sd->sc.opt1 || sd->state.trading || sd->state.storage_flag)
  115. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  116. #define clif_trading(sd) (sd->npc_id || sd->vender_id || sd->state.trading )
  117. //To idenfity disguised characters.
  118. #define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
  119. static char map_ip_str[128];
  120. static in_addr_t map_ip;
  121. static in_addr_t bind_ip = INADDR_ANY;
  122. static int map_port = 5121;
  123. int map_fd;
  124. char talkie_mes[MESSAGE_SIZE];
  125. //These two will be used to verify the incoming player's validity.
  126. //It helps identify their client packet version correctly. [Skotlex]
  127. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  128. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  129. int clif_parse (int fd);
  130. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  131. /*==========================================
  132. * map鯖のip設定
  133. *------------------------------------------
  134. */
  135. int clif_setip(char *ip)
  136. {
  137. char ip_str[16];
  138. map_ip = resolve_hostbyname(ip,NULL,ip_str);
  139. if (!map_ip) {
  140. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  141. return 0;
  142. }
  143. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  144. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str);
  145. return 1;
  146. }
  147. void clif_setbindip(char *ip)
  148. {
  149. unsigned char ip_str[4];
  150. bind_ip = resolve_hostbyname(ip,ip_str,NULL);
  151. if (bind_ip) {
  152. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip, ip_str[0], ip_str[1], ip_str[2], ip_str[3]);
  153. } else {
  154. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  155. }
  156. }
  157. /*==========================================
  158. * map鯖のport設定
  159. *------------------------------------------
  160. */
  161. void clif_setport(int port)
  162. {
  163. map_port = port;
  164. }
  165. /*==========================================
  166. * map鯖のip読み出し
  167. *------------------------------------------
  168. */
  169. in_addr_t clif_getip(void)
  170. {
  171. return map_ip;
  172. }
  173. //Returns the ip casted as a basic type, to avoid needing to include the socket/net related libs by calling modules.
  174. unsigned long clif_getip_long(void)
  175. {
  176. return (unsigned long)map_ip;
  177. }
  178. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it
  179. //returns 0.
  180. unsigned long clif_refresh_ip(void) {
  181. in_addr_t new_ip;
  182. new_ip = resolve_hostbyname(map_ip_str, NULL, NULL);
  183. if (new_ip && new_ip != map_ip) {
  184. map_ip = new_ip;
  185. ShowInfo("Updating IP resolution of [%s].\n",map_ip_str);
  186. return (unsigned long)map_ip;
  187. }
  188. return 0;
  189. }
  190. /*==========================================
  191. * map鯖のport読み出し
  192. *------------------------------------------
  193. */
  194. int clif_getport(void)
  195. {
  196. return map_port;
  197. }
  198. /*==========================================
  199. * Counts connected players.
  200. *------------------------------------------
  201. */
  202. int clif_countusers(void)
  203. {
  204. int users = 0, i;
  205. struct map_session_data *sd;
  206. for(i = 0; i < fd_max; i++) {
  207. if (session[i] && session[i]->func_parse == clif_parse &&
  208. (sd = (struct map_session_data*)session[i]->session_data) &&
  209. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  210. users++;
  211. }
  212. return users;
  213. }
  214. /*==========================================
  215. * 全てのclientに対してfunc()実行
  216. *------------------------------------------
  217. */
  218. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  219. {
  220. int i;
  221. va_list ap;
  222. struct map_session_data *sd;
  223. va_start(ap,func);
  224. for(i = 0; i < fd_max; i++) {
  225. if ( session[i] && session[i]->func_parse == clif_parse) {
  226. sd = (struct map_session_data*)session[i]->session_data;
  227. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  228. func(sd, ap);
  229. }
  230. }
  231. va_end(ap);
  232. return 0;
  233. }
  234. /*==========================================
  235. * clif_sendでAREA*指定時用
  236. *------------------------------------------
  237. */
  238. int clif_send_sub(struct block_list *bl, va_list ap)
  239. {
  240. struct block_list *src_bl;
  241. struct map_session_data *sd;
  242. unsigned char *buf;
  243. int len, type, fd;
  244. nullpo_retr(0, bl);
  245. nullpo_retr(0, ap);
  246. nullpo_retr(0, sd = (struct map_session_data *)bl);
  247. fd = sd->fd;
  248. if (!fd) //Don't send to disconnected clients.
  249. return 0;
  250. buf = va_arg(ap,unsigned char*);
  251. len = va_arg(ap,int);
  252. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  253. type = va_arg(ap,int);
  254. switch(type) {
  255. case AREA_WOS:
  256. if (bl == src_bl)
  257. return 0;
  258. break;
  259. case AREA_WOC:
  260. if (sd->chatID || bl == src_bl)
  261. return 0;
  262. break;
  263. case AREA_WOSC:
  264. {
  265. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  266. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  267. return 0;
  268. }
  269. break;
  270. }
  271. if (session[fd] != NULL) {
  272. WFIFOHEAD(fd, len);
  273. if (WFIFOP(fd,0) == buf) {
  274. printf("WARNING: Invalid use of clif_send function\n");
  275. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  276. printf(" Please correct your code.\n");
  277. // don't send to not move the pointer of the packet for next sessions in the loop
  278. } else {
  279. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  280. memcpy(WFIFOP(fd,0), buf, len);
  281. //Check if hidden, better to modify the char's buffer than the
  282. //given buffer to prevent intravision affecting the packet as
  283. //it's being received by everyone. [Skotlex]
  284. /* New implementation... not quite correct yet as the client no longer
  285. * displays correctly the SI_INTRAVISION effect.
  286. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 )
  287. && bl != src_bl && WFIFOW(fd,0) == 0x0196)
  288. { //New intravision method, just modify the status change/start packet. [Skotlex]
  289. switch (WFIFOW(fd,2)) {
  290. case SI_HIDING:
  291. case SI_CLOAKING:
  292. case SI_CHASEWALK:
  293. WFIFOW(fd,2) = SI_INTRAVISION;
  294. }
  295. }
  296. */
  297. // Previous implementation.
  298. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 ) && bl != src_bl) {
  299. struct status_change *sc = status_get_sc(src_bl);
  300. if(sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK)))
  301. { //optionの修正
  302. switch(((unsigned short*)buf)[0])
  303. {
  304. #if PACKETVER > 6
  305. case 0x229:
  306. WFIFOL(fd,10) &= ~(OPTION_HIDE|OPTION_CLOAK);
  307. break;
  308. case 0x22a:
  309. case 0x22b:
  310. case 0x22c:
  311. WFIFOL(fd,12) &=~(OPTION_HIDE|OPTION_CLOAK);
  312. break;
  313. #endif
  314. #if PACKETVER > 3
  315. case 0x119:
  316. WFIFOW(fd,10) &= ~(OPTION_HIDE|OPTION_CLOAK);
  317. break;
  318. case 0x1d8:
  319. case 0x1d9:
  320. case 0x1da:
  321. #endif
  322. case 0x78:
  323. case 0x79:
  324. case 0x7a:
  325. case 0x7b:
  326. case 0x7c:
  327. WFIFOW(fd,12) &=~(OPTION_HIDE|OPTION_CLOAK);
  328. break;
  329. }
  330. }
  331. }
  332. WFIFOSET(fd,len);
  333. }
  334. }
  335. }
  336. return 0;
  337. }
  338. /*==========================================
  339. *
  340. *------------------------------------------
  341. */
  342. int clif_send (unsigned char *buf, int len, struct block_list *bl, int type) {
  343. int i;
  344. struct map_session_data *sd = NULL;
  345. struct party_data *p = NULL;
  346. struct guild *g = NULL;
  347. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  348. if (type != ALL_CLIENT &&
  349. type != CHAT_MAINCHAT) {
  350. nullpo_retr(0, bl);
  351. if (bl->type == BL_PC) {
  352. sd = (struct map_session_data *)bl;
  353. }
  354. }
  355. switch(type) {
  356. case ALL_CLIENT: //All player clients.
  357. for (i = 0; i < fd_max; i++) {
  358. if (session[i] && session[i]->func_parse == clif_parse &&
  359. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  360. sd->state.auth) {
  361. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  362. WFIFOHEAD(i, len);
  363. memcpy(WFIFOP(i,0), buf, len);
  364. WFIFOSET(i,len);
  365. }
  366. }
  367. }
  368. break;
  369. case ALL_SAMEMAP: //All players on the same map
  370. for(i = 0; i < fd_max; i++) {
  371. if (session[i] && session[i]->func_parse == clif_parse &&
  372. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  373. sd->state.auth && sd->bl.m == bl->m) {
  374. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  375. WFIFOHEAD(i,len);
  376. memcpy(WFIFOP(i,0), buf, len);
  377. WFIFOSET(i,len);
  378. }
  379. }
  380. }
  381. break;
  382. case AREA:
  383. case AREA_WOSC:
  384. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  385. clif_send (buf, len, bl, SELF);
  386. case AREA_WOC:
  387. case AREA_WOS:
  388. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  389. BL_PC, buf, len, bl, type);
  390. break;
  391. case AREA_CHAT_WOC:
  392. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  393. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  394. break;
  395. case CHAT:
  396. case CHAT_WOS:
  397. {
  398. struct chat_data *cd;
  399. if (sd) {
  400. cd = (struct chat_data*)map_id2bl(sd->chatID);
  401. } else if (bl->type == BL_CHAT) {
  402. cd = (struct chat_data*)bl;
  403. } else break;
  404. if (cd == NULL)
  405. break;
  406. for(i = 0; i < cd->users; i++) {
  407. if (type == CHAT_WOS && cd->usersd[i] == sd)
  408. continue;
  409. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  410. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  411. {
  412. WFIFOHEAD(fd,len);
  413. memcpy(WFIFOP(fd,0), buf, len);
  414. WFIFOSET(fd,len);
  415. }
  416. }
  417. }
  418. }
  419. break;
  420. case CHAT_MAINCHAT: //[LuzZza]
  421. for(i=1; i<fd_max; i++) {
  422. if (session[i] && session[i]->func_parse == clif_parse &&
  423. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  424. sd->state.mainchat && (fd=sd->fd))
  425. {
  426. WFIFOHEAD(fd, len);
  427. memcpy(WFIFOP(fd,0), buf, len);
  428. WFIFOSET(fd, len);
  429. }
  430. }
  431. break;
  432. case PARTY_AREA:
  433. case PARTY_AREA_WOS:
  434. x0 = bl->x - AREA_SIZE;
  435. y0 = bl->y - AREA_SIZE;
  436. x1 = bl->x + AREA_SIZE;
  437. y1 = bl->y + AREA_SIZE;
  438. case PARTY:
  439. case PARTY_WOS:
  440. case PARTY_SAMEMAP:
  441. case PARTY_SAMEMAP_WOS:
  442. if (sd && sd->status.party_id)
  443. p = party_search(sd->status.party_id);
  444. if (p) {
  445. for(i=0;i<MAX_PARTY;i++){
  446. if ((sd = p->data[i].sd) == NULL)
  447. continue;
  448. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  449. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  450. continue;
  451. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  452. continue;
  453. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  454. continue;
  455. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  456. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  457. continue;
  458. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  459. WFIFOHEAD(fd,len);
  460. memcpy(WFIFOP(fd,0), buf, len);
  461. WFIFOSET(fd,len);
  462. }
  463. }
  464. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  465. break;
  466. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  467. if (session[i] && session[i]->func_parse == clif_parse &&
  468. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  469. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  470. {
  471. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  472. WFIFOHEAD(fd,len);
  473. memcpy(WFIFOP(fd,0), buf, len);
  474. WFIFOSET(fd,len);
  475. }
  476. }
  477. }
  478. }
  479. break;
  480. case DUEL:
  481. case DUEL_WOS:
  482. if (!sd || !sd->duel_group) break; //Invalid usage.
  483. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  484. for (i = 0; i < fd_max; i++) {
  485. if (session[i] && session[i]->func_parse == clif_parse &&
  486. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  487. sd->state.auth && sd->duel_group == x0) {
  488. if (type == DUEL_WOS && bl->id == sd->bl.id)
  489. continue;
  490. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  491. WFIFOHEAD(i, len);
  492. memcpy(WFIFOP(i,0), buf, len);
  493. WFIFOSET(i,len);
  494. }
  495. }
  496. }
  497. break;
  498. case SELF:
  499. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  500. WFIFOHEAD(fd,len);
  501. memcpy(WFIFOP(fd,0), buf, len);
  502. WFIFOSET(fd,len);
  503. }
  504. break;
  505. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  506. case GUILD_AREA:
  507. case GUILD_AREA_WOS:
  508. x0 = bl->x - AREA_SIZE;
  509. y0 = bl->y - AREA_SIZE;
  510. x1 = bl->x + AREA_SIZE;
  511. y1 = bl->y + AREA_SIZE;
  512. case GUILD_SAMEMAP:
  513. case GUILD_SAMEMAP_WOS:
  514. case GUILD:
  515. case GUILD_WOS:
  516. if (sd && sd->status.guild_id)
  517. g = guild_search(sd->status.guild_id);
  518. if (g) {
  519. for(i = 0; i < g->max_member; i++) {
  520. if ((sd = g->member[i].sd) != NULL) {
  521. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  522. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  523. continue;
  524. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  525. continue;
  526. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  527. continue;
  528. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  529. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  530. continue;
  531. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  532. WFIFOHEAD(fd,len);
  533. memcpy(WFIFOP(fd,0), buf, len);
  534. WFIFOSET(fd,len);
  535. }
  536. }
  537. }
  538. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  539. break;
  540. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  541. if (session[i] && session[i]->func_parse == clif_parse &&
  542. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  543. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  544. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  545. WFIFOHEAD(fd,len);
  546. memcpy(WFIFOP(fd,0), buf, len);
  547. WFIFOSET(fd,len);
  548. }
  549. }
  550. }
  551. }
  552. break;
  553. /* End [Valaris] */
  554. default:
  555. if (battle_config.error_log)
  556. ShowError("clif_send: Unrecognized type %d\n",type);
  557. return -1;
  558. }
  559. return 0;
  560. }
  561. //For use in the @send command.
  562. int clif_send_debug(struct map_session_data *sd, int cmd, int* args, int args_num)
  563. {
  564. int fd = sd->fd;
  565. int len;
  566. if (cmd < 0 || cmd >= MAX_PACKET_DB)
  567. return 0;
  568. len = packet_db[sd->packet_ver][cmd].len;
  569. if (!fd || !len || len == -1) //len -1, variable width, not supported!
  570. return 0;
  571. switch (cmd)
  572. {
  573. case 0x209:
  574. {
  575. WFIFOHEAD(fd, len);
  576. WFIFOW(fd,0) = 0x209;
  577. WFIFOW(fd,2) = 2;
  578. memcpy(WFIFOP(fd, 12), sd->status.name, NAME_LENGTH);
  579. WFIFOSET(fd, len);
  580. break;
  581. }
  582. default:
  583. {
  584. int i;
  585. WFIFOHEAD(fd, len);
  586. memset(WFIFOP(fd,0), 0, len);
  587. WFIFOW(fd,0) = cmd;
  588. //Packet can only have len/2 arguments. Since each arg is a Word
  589. if (args_num > len/2 -2)
  590. args_num = len/2 -2;
  591. for(i=0; i<args_num; i++)
  592. WFIFOW(fd,i+1) = args[i];
  593. WFIFOSET(fd, len);
  594. break;
  595. }
  596. }
  597. return 1;
  598. }
  599. //
  600. // パケット作って送信
  601. //
  602. /*==========================================
  603. *
  604. *------------------------------------------
  605. */
  606. int clif_authok(struct map_session_data *sd) {
  607. int fd;
  608. if (!sd->fd)
  609. return 0;
  610. fd = sd->fd;
  611. WFIFOHEAD(fd, packet_len_table[0x73]);
  612. WFIFOW(fd, 0) = 0x73;
  613. WFIFOL(fd, 2) = gettick();
  614. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  615. WFIFOB(fd, 9) = 5;
  616. WFIFOB(fd,10) = 5;
  617. WFIFOSET(fd,packet_len_table[0x73]);
  618. return 0;
  619. }
  620. /*==========================================
  621. *
  622. *------------------------------------------
  623. */
  624. int clif_authfail_fd(int fd, int type) {
  625. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  626. return 0;
  627. WFIFOHEAD(fd, packet_len_table[0x81]);
  628. WFIFOW(fd,0) = 0x81;
  629. WFIFOB(fd,2) = type;
  630. WFIFOSET(fd,packet_len_table[0x81]);
  631. clif_setwaitclose(fd);
  632. return 0;
  633. }
  634. /*==========================================
  635. * Used to know which is the max valid account/char id [Skotlex]
  636. *------------------------------------------
  637. */
  638. void clif_updatemaxid(int account_id, int char_id)
  639. {
  640. max_account_id = account_id;
  641. max_char_id = char_id;
  642. }
  643. /*==========================================
  644. *
  645. *------------------------------------------
  646. */
  647. int clif_charselectok(int id) {
  648. struct map_session_data *sd;
  649. int fd;
  650. if ((sd = map_id2sd(id)) == NULL)
  651. return 1;
  652. if (!sd->fd)
  653. return 1;
  654. fd = sd->fd;
  655. WFIFOHEAD(fd, packet_len_table[0xb3]);
  656. WFIFOW(fd,0) = 0xb3;
  657. WFIFOB(fd,2) = 1;
  658. WFIFOSET(fd,packet_len_table[0xb3]);
  659. return 0;
  660. }
  661. /*==========================================
  662. *
  663. *------------------------------------------
  664. */
  665. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  666. int view;
  667. nullpo_retr(0, fitem);
  668. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  669. WBUFW(buf, 0) = 0x9e;
  670. WBUFL(buf, 2) = fitem->bl.id;
  671. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  672. WBUFW(buf, 6) = view;
  673. else
  674. WBUFW(buf, 6) = fitem->item_data.nameid;
  675. WBUFB(buf, 8) = fitem->item_data.identify;
  676. WBUFW(buf, 9) = fitem->bl.x;
  677. WBUFW(buf,11) = fitem->bl.y;
  678. WBUFB(buf,13) = fitem->subx;
  679. WBUFB(buf,14) = fitem->suby;
  680. WBUFW(buf,15) = fitem->item_data.amount;
  681. return packet_len_table[0x9e];
  682. }
  683. /*==========================================
  684. *
  685. *------------------------------------------
  686. */
  687. int clif_dropflooritem(struct flooritem_data *fitem) {
  688. unsigned char buf[64];
  689. nullpo_retr(0, fitem);
  690. if (fitem->item_data.nameid <= 0)
  691. return 0;
  692. clif_set009e(fitem, buf);
  693. clif_send(buf, packet_len_table[0x9e], &fitem->bl, AREA);
  694. return 0;
  695. }
  696. /*==========================================
  697. *
  698. *------------------------------------------
  699. */
  700. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  701. unsigned char buf[16];
  702. nullpo_retr(0, fitem);
  703. WBUFW(buf,0) = 0xa1;
  704. WBUFL(buf,2) = fitem->bl.id;
  705. if (fd == 0) {
  706. clif_send(buf, packet_len_table[0xa1], &fitem->bl, AREA);
  707. } else {
  708. WFIFOHEAD(fd,packet_len_table[0xa1]);
  709. memcpy(WFIFOP(fd,0), buf, 6);
  710. WFIFOSET(fd,packet_len_table[0xa1]);
  711. }
  712. return 0;
  713. }
  714. /*==========================================
  715. *
  716. *------------------------------------------
  717. */
  718. int clif_clearchar(struct block_list *bl, int type) {
  719. unsigned char buf[16];
  720. nullpo_retr(0, bl);
  721. WBUFW(buf,0) = 0x80;
  722. WBUFL(buf,2) = bl->id;
  723. WBUFB(buf,6) = type;
  724. clif_send(buf, packet_len_table[0x80], bl, type == 1 ? AREA : AREA_WOS);
  725. if(disguised(bl)) {
  726. WBUFL(buf,2) = -bl->id;
  727. clif_send(buf, packet_len_table[0x80], bl, SELF);
  728. }
  729. return 0;
  730. }
  731. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  732. struct block_list *bl = (struct block_list *)id;
  733. clif_clearchar(bl,data);
  734. aFree(bl);
  735. return 0;
  736. }
  737. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  738. struct block_list *tbl;
  739. tbl = aMalloc(sizeof (struct block_list));
  740. memcpy (tbl, bl, sizeof (struct block_list));
  741. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  742. return 0;
  743. }
  744. /*==========================================
  745. *
  746. *------------------------------------------
  747. */
  748. int clif_clearchar_id(int id, int type, int fd) {
  749. WFIFOHEAD(fd, packet_len_table[0x80]);
  750. WFIFOW(fd,0) = 0x80;
  751. WFIFOL(fd,2) = id;
  752. WFIFOB(fd,6) = (char)type; // Why use int for a char in the first place?
  753. WFIFOSET(fd, packet_len_table[0x80]);
  754. return 0;
  755. }
  756. void clif_get_weapon_view(TBL_PC* sd, unsigned short *rhand, unsigned short *lhand)
  757. {
  758. #if PACKETVER > 3
  759. struct item_data *id;
  760. #endif
  761. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  762. {
  763. *rhand = *lhand = 0;
  764. return;
  765. }
  766. #if PACKETVER < 4
  767. *rhand = sd->status.weapon;
  768. *lhand = sd->status.shield;
  769. #else
  770. if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]])
  771. {
  772. id = sd->inventory_data[sd->equip_index[9]];
  773. if (id->view_id > 0)
  774. *rhand = id->view_id;
  775. else
  776. *rhand = id->nameid;
  777. } else
  778. *rhand = 0;
  779. if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
  780. && sd->inventory_data[sd->equip_index[8]])
  781. {
  782. id = sd->inventory_data[sd->equip_index[8]];
  783. if (id->view_id > 0)
  784. *lhand = id->view_id;
  785. else
  786. *lhand = id->nameid;
  787. } else
  788. *lhand = 0;
  789. #endif
  790. }
  791. static void clif_get_guild_data(struct block_list *bl, long *guild_id, short *emblem_id)
  792. {
  793. //TODO: There has to be a way to clean this up.
  794. switch (bl->type) {
  795. case BL_PC:
  796. *guild_id = ((TBL_PC*)bl)->status.guild_id;
  797. *emblem_id = ((TBL_PC*)bl)->guild_emblem_id;
  798. break;
  799. case BL_MOB:
  800. if (((TBL_MOB*)bl)->guardian_data) {
  801. *guild_id =((TBL_MOB*)bl)->guardian_data->guild_id;
  802. *emblem_id =((TBL_MOB*)bl)->guardian_data->emblem_id;
  803. }
  804. break;
  805. case BL_NPC:
  806. if (bl->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) {
  807. struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id);
  808. if (g) {
  809. *guild_id =g->guild_id;
  810. *emblem_id =g->emblem_id;
  811. }
  812. }
  813. break;
  814. default:
  815. *guild_id = status_get_guild_id(bl);
  816. }
  817. return;
  818. }
  819. /*==========================================
  820. *
  821. *------------------------------------------
  822. */
  823. static int clif_set0078(struct block_list *bl, struct view_data *vd, unsigned char *buf) {
  824. struct status_change *sc;
  825. struct map_session_data *sd;
  826. long guild_id=0;
  827. unsigned short emblem_id=0, lv;
  828. unsigned short dir;
  829. nullpo_retr(0, bl);
  830. BL_CAST(BL_PC, bl, sd);
  831. sc = status_get_sc(bl);
  832. clif_get_guild_data(bl, &guild_id, &emblem_id);
  833. dir = unit_getdir(bl);
  834. lv = status_get_lv(bl);
  835. if(pcdb_checkid(vd->class_)) {
  836. #if PACKETVER > 6
  837. malloc_set(buf,0,packet_len_table[0x22a]);
  838. WBUFW(buf,0)=0x22a;
  839. WBUFL(buf,2)=bl->id;
  840. WBUFW(buf,6)=status_get_speed(bl);
  841. if (sc) {
  842. WBUFW(buf,8)=sc->opt1;
  843. WBUFW(buf,10)=sc->opt2;
  844. WBUFL(buf,12)=sc->option;
  845. WBUFL(buf,44)=sc->opt3;
  846. }
  847. WBUFW(buf,16)=vd->class_;
  848. WBUFW(buf,18)=vd->hair_style;
  849. WBUFW(buf,20)=vd->weapon;
  850. WBUFW(buf,22)=vd->shield;
  851. WBUFW(buf,24)=vd->head_bottom;
  852. WBUFW(buf,26)=vd->head_top;
  853. WBUFW(buf,28)=vd->head_mid;
  854. WBUFW(buf,30)=vd->hair_color;
  855. WBUFW(buf,32)=vd->cloth_color;
  856. WBUFW(buf,34)=sd?sd->head_dir:0;
  857. WBUFL(buf,36)=guild_id;
  858. WBUFW(buf,40)=emblem_id;
  859. if (sd) {
  860. WBUFW(buf,42)=sd->status.manner;
  861. WBUFB(buf,48)=sd->status.karma;
  862. }
  863. WBUFB(buf,49)=vd->sex;
  864. WBUFPOS(buf,50,bl->x,bl->y,dir);
  865. WBUFB(buf,53)=5;
  866. WBUFB(buf,54)=5;
  867. WBUFB(buf,55)=vd->dead_sit;
  868. WBUFW(buf,56)=clif_setlevel(lv);
  869. return packet_len_table[0x22a];
  870. #elif PACKETVER > 3
  871. malloc_set(buf,0,packet_len_table[0x1d8]);
  872. WBUFW(buf,0)=0x1d8;
  873. WBUFL(buf,2)=bl->id;
  874. WBUFW(buf,6)=status_get_speed(bl);
  875. if (sc) {
  876. WBUFW(buf,8)=sc->opt1;
  877. WBUFW(buf,10)=sc->opt2;
  878. WBUFW(buf,12)=sc->option;
  879. WBUFW(buf,42)=sc->opt3;
  880. }
  881. WBUFW(buf,14)=vd->class_;
  882. WBUFW(buf,16)=vd->hair_style;
  883. WBUFW(buf,18)=vd->weapon;
  884. WBUFW(buf,20)=vd->shield;
  885. WBUFW(buf,22)=vd->head_bottom;
  886. WBUFW(buf,24)=vd->head_top;
  887. WBUFW(buf,26)=vd->head_mid;
  888. WBUFW(buf,28)=vd->hair_color;
  889. WBUFW(buf,30)=vd->cloth_color;
  890. WBUFW(buf,32)=sd?sd->head_dir:0;
  891. WBUFL(buf,34)=guild_id;
  892. WBUFW(buf,38)=emblem_id;
  893. if (sd) {
  894. WBUFW(buf,40)=sd->status.manner;
  895. WBUFB(buf,44)=sd->status.karma;
  896. }
  897. WBUFB(buf,45)=vd->sex;
  898. WBUFPOS(buf,46,bl->x,bl->y,dir);
  899. WBUFB(buf,49)=5;
  900. WBUFB(buf,50)=5;
  901. WBUFB(buf,51)=vd->dead_sit;
  902. WBUFW(buf,52)=clif_setlevel(lv);
  903. return packet_len_table[0x1d8];
  904. #else
  905. malloc_set(buf,0,packet_len_table[0x78]);
  906. WBUFW(buf,0)=0x78;
  907. WBUFL(buf,2)=bl->id;
  908. WBUFW(buf,6)=status_get_speed(bl);
  909. if (sc) {
  910. WBUFW(buf,8)=sc->opt1;
  911. WBUFW(buf,10)=sc->opt2;
  912. WBUFW(buf,12)=sc->option;
  913. WBUFW(buf,42)=sc->opt3;
  914. }
  915. WBUFW(buf,14)=vd->class_;
  916. WBUFW(buf,16)=vd->hair_style;
  917. WBUFW(buf,18)=vd->weapon;
  918. WBUFW(buf,20)=vd->head_bottom;
  919. WBUFW(buf,22)=vd->shield;
  920. WBUFW(buf,24)=vd->head_top;
  921. WBUFW(buf,26)=vd->head_mid;
  922. WBUFW(buf,28)=vd->hair_color;
  923. WBUFW(buf,30)=vd->cloth_color;
  924. WBUFW(buf,32)=sd?sd->head_dir:0;
  925. WBUFL(buf,34)=guild_id;
  926. WBUFL(buf,38)=emblem_id;
  927. if (sd)
  928. WBUFB(buf,44)=sd->status.karma;
  929. WBUFB(buf,45)=vd->sex;
  930. WBUFPOS(buf,46,bl->x,bl->y,dir);
  931. WBUFB(buf,49)=5;
  932. WBUFB(buf,50)=5;
  933. WBUFB(buf,51)=vd->dead_sit;
  934. WBUFW(buf,52)=clif_setlevel(lv);
  935. return packet_len_table[0x78];
  936. #endif
  937. }
  938. //Non-player sprites need just a few fields filled.
  939. malloc_set(buf,0,packet_len_table[0x78]);
  940. WBUFW(buf,0)=0x78;
  941. WBUFL(buf,2)=bl->id;
  942. WBUFW(buf,6)=status_get_speed(bl);
  943. if (sc) {
  944. WBUFW(buf,8)=sc->opt1;
  945. WBUFW(buf,10)=sc->opt2;
  946. WBUFW(buf,12)=sc->option;
  947. WBUFW(buf,42)=sc->opt3;
  948. }
  949. WBUFW(buf,14)=vd->class_;
  950. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  951. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  952. if (bl->type == BL_NPC && vd->class_ == 722)
  953. { //The hell, why flags work like this?
  954. WBUFL(buf,22)=emblem_id;
  955. WBUFL(buf,26)=guild_id;
  956. }
  957. WBUFW(buf,32)=dir;
  958. WBUFL(buf,34)=guild_id;
  959. WBUFL(buf,38)=emblem_id;
  960. WBUFPOS(buf,46,bl->x,bl->y,dir);
  961. WBUFB(buf,49)=5;
  962. WBUFB(buf,50)=5;
  963. WBUFW(buf,52)=clif_setlevel(lv);
  964. return packet_len_table[0x78];
  965. }
  966. /*==========================================
  967. *
  968. *------------------------------------------
  969. */
  970. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf) {
  971. struct status_change *sc;
  972. struct map_session_data *sd;
  973. long guild_id=0;
  974. unsigned short emblem_id=0, lv;
  975. nullpo_retr(0, bl);
  976. BL_CAST(BL_PC, bl, sd);
  977. sc = status_get_sc(bl);
  978. clif_get_guild_data(bl, &guild_id, &emblem_id);
  979. lv = status_get_lv(bl);
  980. if(pcdb_checkid(vd->class_)) {
  981. #if PACKETVER > 6
  982. malloc_set(buf,0,packet_len_table[0x22c]);
  983. WBUFW(buf,0)=0x22c;
  984. WBUFL(buf,2)=bl->id;
  985. WBUFW(buf,6)=status_get_speed(bl);
  986. if (sc) {
  987. WBUFW(buf,8)= sc->opt1;
  988. WBUFW(buf,10)= sc->opt2;
  989. WBUFL(buf,12)= sc->option;
  990. WBUFL(buf,48)= sc->opt3;
  991. }
  992. WBUFW(buf,16)=vd->class_;
  993. WBUFW(buf,18)=vd->hair_style;
  994. WBUFW(buf,20)=vd->weapon;
  995. WBUFW(buf,22)=vd->shield;
  996. WBUFW(buf,24)=vd->head_bottom;
  997. WBUFL(buf,26)=gettick();
  998. WBUFW(buf,30)=vd->head_top;
  999. WBUFW(buf,32)=vd->head_mid;
  1000. WBUFW(buf,34)=vd->hair_color;
  1001. WBUFW(buf,36)=vd->cloth_color;
  1002. WBUFW(buf,38)=sd?sd->head_dir:0;
  1003. WBUFL(buf,40)=guild_id;
  1004. WBUFW(buf,44)=emblem_id;
  1005. if (sd) {
  1006. WBUFW(buf,46)=sd->status.manner;
  1007. WBUFB(buf,52)=sd->status.karma;
  1008. }
  1009. WBUFB(buf,53)=vd->sex;
  1010. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  1011. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  1012. WBUFB(buf,60)=0;
  1013. WBUFB(buf,61)=0;
  1014. WBUFW(buf,62)=clif_setlevel(lv);
  1015. return packet_len_table[0x22c];
  1016. #elif PACKETVER > 3
  1017. malloc_set(buf,0,packet_len_table[0x1da]);
  1018. WBUFW(buf,0)=0x1da;
  1019. WBUFL(buf,2)=bl->id;
  1020. WBUFW(buf,6)=status_get_speed(bl);
  1021. if (sc) {
  1022. WBUFW(buf,8)=sc->opt1;
  1023. WBUFW(buf,10)=sc->opt2;
  1024. WBUFW(buf,12)=sc->option;
  1025. WBUFW(buf,46)=sc->opt3;
  1026. }
  1027. WBUFW(buf,14)=vd->class_;
  1028. WBUFW(buf,16)=vd->hair_style;
  1029. WBUFW(buf,18)=vd->weapon;
  1030. WBUFW(buf,20)=vd->shield;
  1031. WBUFW(buf,22)=vd->head_bottom;
  1032. WBUFL(buf,24)=gettick();
  1033. WBUFW(buf,28)=vd->head_top;
  1034. WBUFW(buf,30)=vd->head_mid;
  1035. WBUFW(buf,32)=vd->hair_color;
  1036. WBUFW(buf,34)=vd->cloth_color;
  1037. WBUFW(buf,36)=sd?sd->head_dir:0;
  1038. WBUFL(buf,38)=guild_id;
  1039. WBUFW(buf,42)=emblem_id;
  1040. if (sd) {
  1041. WBUFW(buf,44)=sd->status.manner;
  1042. WBUFB(buf,48)=sd->status.karma;
  1043. }
  1044. WBUFB(buf,49)=vd->sex;
  1045. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1046. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1047. WBUFB(buf,56)=5;
  1048. WBUFB(buf,57)=5;
  1049. WBUFW(buf,58)=clif_setlevel(lv);
  1050. return packet_len_table[0x1da];
  1051. #else
  1052. malloc_set(buf,0,packet_len_table[0x7b]);
  1053. WBUFW(buf,0)=0x7b;
  1054. WBUFL(buf,2)=bl->id;
  1055. WBUFW(buf,6)=status_get_speed(bl);
  1056. if (sc) {
  1057. WBUFW(buf,8)=sc->opt1;
  1058. WBUFW(buf,10)=sc->opt2;
  1059. WBUFW(buf,12)=sc->option;
  1060. WBUFW(buf,46)=sc->opt3;
  1061. }
  1062. WBUFW(buf,14)=vd->class_;
  1063. WBUFW(buf,16)=vd->hair_style;
  1064. WBUFW(buf,18)=vd->weapon;
  1065. WBUFW(buf,20)=vd->head_bottom;
  1066. WBUFL(buf,22)=gettick();
  1067. WBUFW(buf,26)=vd->shield;
  1068. WBUFW(buf,28)=vd->head_top;
  1069. WBUFW(buf,30)=vd->head_mid;
  1070. WBUFW(buf,32)=vd->hair_color;
  1071. WBUFW(buf,34)=vd->cloth_color;
  1072. WBUFW(buf,36)=sd?sd->head_dir:0;
  1073. WBUFL(buf,38)=guild_id;
  1074. WBUFL(buf,42)=emblem_id;
  1075. if (sd)
  1076. WBUFB(buf,48)=sd->status.karma;
  1077. WBUFB(buf,49)=vd->sex;
  1078. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1079. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1080. WBUFB(buf,56)=5;
  1081. WBUFB(buf,57)=5;
  1082. WBUFW(buf,58)=clif_setlevel(lv);
  1083. return packet_len_table[0x7b];
  1084. #endif
  1085. }
  1086. //Non-player sprites only require a few fields.
  1087. #if PACKETVER > 6
  1088. malloc_set(buf,0,packet_len_table[0x22c]);
  1089. WBUFW(buf,0)=0x22c;
  1090. WBUFL(buf,2)=bl->id;
  1091. WBUFW(buf,6)=status_get_speed(bl);
  1092. if (sc) {
  1093. WBUFW(buf,8)=sc->opt1;
  1094. WBUFW(buf,10)=sc->opt2;
  1095. WBUFL(buf,12)=sc->option;
  1096. WBUFL(buf,48)=sc->opt3;
  1097. }
  1098. WBUFW(buf,16)=vd->class_;
  1099. WBUFW(buf,18)=vd->hair_style; //For pets
  1100. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  1101. WBUFL(buf,26)=gettick();
  1102. WBUFW(buf,38)=unit_getdir(bl);
  1103. WBUFL(buf,40)=guild_id;
  1104. WBUFL(buf,44)=emblem_id;
  1105. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  1106. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  1107. WBUFB(buf,60)=0;
  1108. WBUFB(buf,61)=0;
  1109. WBUFW(buf,62)=clif_setlevel(lv);
  1110. return packet_len_table[0x22c];
  1111. #else
  1112. malloc_set(buf,0,packet_len_table[0x7b]);
  1113. WBUFW(buf,0)=0x7b;
  1114. WBUFL(buf,2)=bl->id;
  1115. WBUFW(buf,6)=status_get_speed(bl);
  1116. if (sc) {
  1117. WBUFW(buf,8)=sc->opt1;
  1118. WBUFW(buf,10)=sc->opt2;
  1119. WBUFW(buf,12)=sc->option;
  1120. WBUFW(buf,46)=sc->opt3;
  1121. }
  1122. WBUFW(buf,14)=vd->class_;
  1123. WBUFW(buf,16)=vd->hair_style; //For pets
  1124. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  1125. WBUFL(buf,22)=gettick();
  1126. WBUFW(buf,36)=unit_getdir(bl);
  1127. WBUFL(buf,38)=guild_id;
  1128. WBUFL(buf,42)=emblem_id;
  1129. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1130. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1131. WBUFB(buf,56)=5;
  1132. WBUFB(buf,57)=5;
  1133. WBUFW(buf,58)=clif_setlevel(lv);
  1134. return packet_len_table[0x7b];
  1135. #endif
  1136. }
  1137. //Modifies the buffer for disguise characters and sends it to self.
  1138. //Flag = 0: change id to negative, buf will have disguise data.
  1139. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1140. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1141. //But no longer holds true for those packet of PACKETVER 7.
  1142. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag) {
  1143. if (flag) {
  1144. #if PACKETVER > 6
  1145. switch (WBUFW(buf,0)) {
  1146. case 0x22c:
  1147. case 0x22b:
  1148. case 0x22a:
  1149. WBUFL(buf,12)=OPTION_INVISIBLE;
  1150. WBUFW(buf,16)=sd->status.class_;
  1151. break;
  1152. default:
  1153. #endif
  1154. WBUFL(buf,2)=sd->bl.id;
  1155. WBUFW(buf,12)=OPTION_INVISIBLE;
  1156. WBUFW(buf,14)=sd->status.class_;
  1157. #if PACKETVER > 6
  1158. break;
  1159. }
  1160. #endif
  1161. } else {
  1162. WBUFL(buf,2)=-sd->bl.id;
  1163. }
  1164. clif_send(buf, len, &sd->bl, SELF);
  1165. }
  1166. /*==========================================
  1167. * クラスチェンジ typeはMobの場合は1で他は0?
  1168. *------------------------------------------
  1169. */
  1170. int clif_class_change(struct block_list *bl,int class_,int type)
  1171. {
  1172. unsigned char buf[16];
  1173. nullpo_retr(0, bl);
  1174. if(!pcdb_checkid(class_)) {
  1175. WBUFW(buf,0)=0x1b0;
  1176. WBUFL(buf,2)=bl->id;
  1177. WBUFB(buf,6)=type;
  1178. WBUFL(buf,7)=class_;
  1179. clif_send(buf,packet_len_table[0x1b0],bl,AREA);
  1180. }
  1181. return 0;
  1182. }
  1183. /*==========================================
  1184. *
  1185. *------------------------------------------
  1186. */
  1187. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1188. {
  1189. WFIFOHEAD(fd, packet_len_table[0x1e1]);
  1190. WFIFOW(fd,0)=0x1e1;
  1191. WFIFOL(fd,2)=sd->bl.id;
  1192. WFIFOW(fd,6)=sd->spiritball;
  1193. WFIFOSET(fd, packet_len_table[0x1e1]);
  1194. }
  1195. /*==========================================
  1196. *
  1197. *------------------------------------------
  1198. */
  1199. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1200. WFIFOHEAD(fd, packet_len_table[0x192]);
  1201. WFIFOW(fd,0) = 0x192;
  1202. WFIFOW(fd,2) = x;
  1203. WFIFOW(fd,4) = y;
  1204. WFIFOW(fd,6) = type;
  1205. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1206. WFIFOSET(fd,packet_len_table[0x192]);
  1207. return 0;
  1208. }
  1209. // new and improved weather display [Valaris]
  1210. static void clif_weather_sub(int fd, int id, int type) {
  1211. WFIFOHEAD(fd, packet_len_table[0x1f3]);
  1212. WFIFOW(fd,0) = 0x1f3;
  1213. WFIFOL(fd,2) = id;
  1214. WFIFOL(fd,6) = type;
  1215. WFIFOSET(fd,packet_len_table[0x1f3]);
  1216. }
  1217. /*==========================================
  1218. *
  1219. *------------------------------------------
  1220. */
  1221. static void clif_weather_check(struct map_session_data *sd) {
  1222. int m = sd->bl.m, fd = sd->fd;
  1223. if (map[m].flag.snow
  1224. || map[m].flag.clouds
  1225. || map[m].flag.fog
  1226. || map[m].flag.fireworks
  1227. || map[m].flag.sakura
  1228. || map[m].flag.leaves
  1229. || map[m].flag.rain
  1230. || map[m].flag.clouds2)
  1231. {
  1232. if (map[m].flag.snow)
  1233. clif_weather_sub(fd, sd->bl.id, 162);
  1234. if (map[m].flag.clouds)
  1235. clif_weather_sub(fd, sd->bl.id, 233);
  1236. if (map[m].flag.clouds2)
  1237. clif_weather_sub(fd, sd->bl.id, 516);
  1238. if (map[m].flag.fog)
  1239. clif_weather_sub(fd, sd->bl.id, 515);
  1240. if (map[m].flag.fireworks) {
  1241. clif_weather_sub(fd, sd->bl.id, 297);
  1242. clif_weather_sub(fd, sd->bl.id, 299);
  1243. clif_weather_sub(fd, sd->bl.id, 301);
  1244. }
  1245. if (map[m].flag.sakura)
  1246. clif_weather_sub(fd, sd->bl.id, 163);
  1247. if (map[m].flag.leaves)
  1248. clif_weather_sub(fd, sd->bl.id, 333);
  1249. if (map[m].flag.rain)
  1250. clif_weather_sub(fd, sd->bl.id, 161);
  1251. }
  1252. }
  1253. int clif_weather(int m) {
  1254. int i;
  1255. struct map_session_data *sd=NULL;
  1256. for(i = 0; i < fd_max; i++) {
  1257. if (session[i] && session[i]->func_parse == clif_parse &&
  1258. (sd = session[i]->session_data) != NULL &&
  1259. sd->state.auth && sd->bl.m == m) {
  1260. clif_weather_check(sd);
  1261. }
  1262. }
  1263. return 0;
  1264. }
  1265. int clif_spawn(struct block_list *bl)
  1266. {
  1267. unsigned char buf[128];
  1268. struct view_data *vd;
  1269. nullpo_retr(0, bl);
  1270. vd = status_get_viewdata(bl);
  1271. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1272. return 0;
  1273. if (pcdb_checkid(vd->class_))
  1274. { //Player spawn packet.
  1275. clif_set0078(bl, vd, buf);
  1276. switch(WBUFW(buf,0)) {
  1277. case 0x78: //Convert to 0x79
  1278. WBUFW(buf, 0) = 0x79;
  1279. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1280. clif_send(buf, packet_len_table[0x79], bl, AREA_WOS);
  1281. if (disguised(bl))
  1282. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x79], 0);
  1283. break;
  1284. #if PACKETVER > 3
  1285. case 0x1d8: //Convert to 0x1d9
  1286. WBUFW(buf, 0) = 0x1d9;
  1287. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1288. clif_send(buf, packet_len_table[0x1d9], bl, AREA_WOS);
  1289. if (disguised(bl))
  1290. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x1d9], 0);
  1291. break;
  1292. #endif
  1293. #if PACKETVER > 6
  1294. case 0x22a: //Convert to 0x22b
  1295. WBUFW(buf, 0) = 0x22b;
  1296. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1297. clif_send(buf, packet_len_table[0x22b], bl, AREA_WOS);
  1298. if (disguised(bl))
  1299. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x22b], 0);
  1300. break;
  1301. #endif
  1302. }
  1303. } else { //Mob spawn packet.
  1304. struct status_change *sc = status_get_sc(bl);
  1305. malloc_tsetdword(buf,0,sizeof(buf));
  1306. WBUFW(buf,0)=0x7c;
  1307. WBUFL(buf,2)=bl->id;
  1308. WBUFW(buf,6)=status_get_speed(bl);
  1309. if (sc) {
  1310. WBUFW(buf,8)=sc->opt1;
  1311. WBUFW(buf,10)=sc->opt2;
  1312. WBUFW(buf,12)=sc->option;
  1313. }
  1314. WBUFW(buf,20)=vd->class_;
  1315. WBUFW(buf,22)=vd->hair_style; //Required for pets.
  1316. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  1317. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1318. clif_send(buf,packet_len_table[0x7c],bl,AREA_WOS);
  1319. if (disguised(bl)) {
  1320. WBUFL(buf,2)=-bl->id;
  1321. clif_send(buf,packet_len_table[0x7c],bl,SELF);
  1322. }
  1323. }
  1324. if (vd->cloth_color)
  1325. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1326. switch (bl->type)
  1327. {
  1328. case BL_PC:
  1329. {
  1330. TBL_PC *sd = ((TBL_PC*)bl);
  1331. if (sd->spiritball > 0)
  1332. clif_spiritball(sd);
  1333. if(sd->state.size==2) // tiny/big players [Valaris]
  1334. clif_specialeffect(bl,423,AREA);
  1335. else if(sd->state.size==1)
  1336. clif_specialeffect(bl,421,AREA);
  1337. }
  1338. break;
  1339. case BL_MOB:
  1340. {
  1341. TBL_MOB *md = ((TBL_MOB*)bl);
  1342. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1343. clif_specialeffect(&md->bl,423,AREA);
  1344. else if(md->special_state.size==1)
  1345. clif_specialeffect(&md->bl,421,AREA);
  1346. }
  1347. break;
  1348. }
  1349. return 0;
  1350. }
  1351. //[orn]
  1352. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1353. {
  1354. struct status_data *status;
  1355. unsigned char buf[128];
  1356. nullpo_retr(0, hd);
  1357. status = &hd->battle_status;
  1358. malloc_set(buf,0,packet_len_table[0x22e]);
  1359. WBUFW(buf,0)=0x22e;
  1360. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1361. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1362. WBUFB(buf,26)=hd->homunculus.rename_flag | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1363. WBUFW(buf,27)=hd->homunculus.level;
  1364. WBUFW(buf,29)=hd->homunculus.hunger;
  1365. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1366. WBUFW(buf,33)=0; // equip id
  1367. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1368. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1369. WBUFW(buf,39)=status->hit;
  1370. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1371. WBUFW(buf,43)=status->def + status->vit ;
  1372. WBUFW(buf,45)=status->mdef;
  1373. WBUFW(buf,47)=status->flee;
  1374. WBUFW(buf,49)=(flag)?0:status->amotion;
  1375. if (status->max_hp > SHRT_MAX) {
  1376. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1377. WBUFW(buf,53) = 100;
  1378. } else {
  1379. WBUFW(buf,51)=status->hp;
  1380. WBUFW(buf,53)=status->max_hp;
  1381. }
  1382. if (status->max_sp > SHRT_MAX) {
  1383. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1384. WBUFW(buf,57) = 100;
  1385. } else {
  1386. WBUFW(buf,55)=status->sp;
  1387. WBUFW(buf,57)=status->max_sp;
  1388. }
  1389. WBUFL(buf,59)=hd->homunculus.exp;
  1390. WBUFL(buf,63)=hd->exp_next;
  1391. WBUFW(buf,67)=hd->homunculus.skillpts;
  1392. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1393. clif_send(buf,packet_len_table[0x22e],&sd->bl,SELF);
  1394. return 0;
  1395. }
  1396. void clif_send_homdata(struct map_session_data *sd, int type, int param) { //[orn]
  1397. int fd = sd->fd;
  1398. WFIFOHEAD(fd, packet_len_table[0x230]);
  1399. nullpo_retv(sd->hd);
  1400. WFIFOW(fd,0)=0x230;
  1401. WFIFOW(fd,2)=type;
  1402. WFIFOL(fd,4)=sd->hd->bl.id;
  1403. WFIFOL(fd,8)=param;
  1404. WFIFOSET(fd,packet_len_table[0x230]);
  1405. return;
  1406. }
  1407. int clif_homskillinfoblock(struct map_session_data *sd) { //[orn]
  1408. struct homun_data *hd;
  1409. int fd = sd->fd;
  1410. int i,j,len=4,id;
  1411. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1412. hd = sd->hd;
  1413. if ( !hd )
  1414. return 0 ;
  1415. WFIFOW(fd,0)=0x235;
  1416. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1417. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1418. j = id - HM_SKILLBASE - 1 ;
  1419. WFIFOW(fd,len ) = id ;
  1420. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1421. WFIFOW(fd,len+4) = 0 ;
  1422. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1423. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1424. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1425. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1426. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1427. len+=37;
  1428. }
  1429. }
  1430. WFIFOW(fd,2)=len;
  1431. WFIFOSET(fd,len);
  1432. return 0;
  1433. }
  1434. void clif_homskillup(struct map_session_data *sd, int skill_num) { //[orn]
  1435. struct homun_data *hd;
  1436. int fd=sd->fd, skillid;
  1437. WFIFOHEAD(fd, packet_len_table[0x239]);
  1438. nullpo_retv(sd);
  1439. skillid = skill_num - HM_SKILLBASE - 1;
  1440. hd=sd->hd;
  1441. WFIFOW(fd,0) = 0x239;
  1442. WFIFOW(fd,2) = skill_num;
  1443. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1444. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1445. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1446. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1447. WFIFOSET(fd,packet_len_table[0x239]);
  1448. return;
  1449. }
  1450. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd) { //[orn]
  1451. struct homun_data *hd;
  1452. RFIFOHEAD(fd);
  1453. nullpo_retv(sd);
  1454. if((hd=sd->hd) == NULL)
  1455. return;
  1456. memcpy(hd->homunculus.name,RFIFOP(fd,2),24);
  1457. hd->homunculus.rename_flag = 1;
  1458. clif_hominfo(sd,hd,0);
  1459. clif_charnameack(sd->fd,&hd->bl);
  1460. }
  1461. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd) { //[orn]
  1462. nullpo_retv(sd);
  1463. if(!merc_is_hom_active(sd->hd))
  1464. return;
  1465. if (!unit_can_move(&sd->hd->bl))
  1466. return;
  1467. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 0);
  1468. }
  1469. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd) { //[orn]
  1470. int x,y,cmd;
  1471. RFIFOHEAD(fd);
  1472. nullpo_retv(sd);
  1473. if(!merc_is_hom_active(sd->hd))
  1474. return;
  1475. cmd = RFIFOW(fd,0);
  1476. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  1477. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  1478. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  1479. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  1480. if (!unit_can_move(&sd->hd->bl))
  1481. return;
  1482. unit_walktoxy(&(sd->hd->bl),x,y,0);
  1483. }
  1484. void clif_parse_HomAttack(int fd,struct map_session_data *sd) { //[orn]
  1485. struct block_list *target;
  1486. RFIFOHEAD(fd);
  1487. nullpo_retv(sd);
  1488. if(!merc_is_hom_active(sd->hd))
  1489. return;
  1490. if ((target = map_id2bl(RFIFOL(fd,6))) == NULL || status_isdead(target))
  1491. return;
  1492. merc_stop_walking(sd->hd, 1);
  1493. merc_stop_attack(sd->hd);
  1494. unit_attack(&sd->hd->bl,RFIFOL(fd,6),1) ;
  1495. }
  1496. void clif_parse_HomMenu(int fd, struct map_session_data *sd) { //[orn]
  1497. int cmd;
  1498. RFIFOHEAD(fd);
  1499. cmd = RFIFOW(fd,0);
  1500. if(!merc_is_hom_active(sd->hd))
  1501. return;
  1502. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  1503. }
  1504. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1505. {
  1506. int fd=sd->fd;
  1507. WFIFOHEAD(fd,packet_len_table[0x22f]);
  1508. WFIFOW(fd,0)=0x22f;
  1509. WFIFOB(fd,2)=fail;
  1510. WFIFOW(fd,3)=foodid;
  1511. WFIFOSET(fd,packet_len_table[0x22f]);
  1512. return 0;
  1513. }
  1514. /*==========================================
  1515. *
  1516. *------------------------------------------
  1517. */
  1518. int clif_walkok(struct map_session_data *sd)
  1519. {
  1520. int fd=sd->fd;
  1521. WFIFOHEAD(fd, packet_len_table[0x87]);
  1522. WFIFOW(fd,0)=0x87;
  1523. WFIFOL(fd,2)=gettick();
  1524. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1525. WFIFOB(fd,11)=0x88;
  1526. WFIFOSET(fd,packet_len_table[0x87]);
  1527. return 0;
  1528. }
  1529. /*==========================================
  1530. *
  1531. *------------------------------------------
  1532. */
  1533. int clif_movepc(struct map_session_data *sd) {
  1534. unsigned char buf[256];
  1535. nullpo_retr(0, sd);
  1536. if (map[sd->bl.m].flag.snow
  1537. || map[sd->bl.m].flag.clouds
  1538. || map[sd->bl.m].flag.fog
  1539. || map[sd->bl.m].flag.fireworks
  1540. || map[sd->bl.m].flag.sakura
  1541. || map[sd->bl.m].flag.leaves
  1542. || map[sd->bl.m].flag.rain
  1543. || map[sd->bl.m].flag.clouds2
  1544. ) {
  1545. malloc_set(buf,0,packet_len_table[0x7b]);
  1546. WBUFW(buf,0)=0x7b;
  1547. WBUFL(buf,2)=-10;
  1548. WBUFW(buf,6)=sd->battle_status.speed;
  1549. WBUFW(buf,8)=0;
  1550. WBUFW(buf,10)=0;
  1551. WBUFW(buf,12)=OPTION_INVISIBLE;
  1552. WBUFW(buf,14)=100;
  1553. WBUFL(buf,22)=gettick();
  1554. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1555. WBUFB(buf,56)=5;
  1556. WBUFB(buf,57)=5;
  1557. clif_send(buf, packet_len_table[0x7b], &sd->bl, SELF);
  1558. }
  1559. return 0;
  1560. }
  1561. /*==========================================
  1562. *
  1563. *------------------------------------------
  1564. */
  1565. int clif_move(struct block_list *bl) {
  1566. struct view_data *vd;
  1567. struct unit_data *ud;
  1568. unsigned char buf[256];
  1569. int len;
  1570. nullpo_retr(0, bl);
  1571. vd = status_get_viewdata(bl);
  1572. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1573. return 0;
  1574. ud = unit_bl2ud(bl);
  1575. nullpo_retr(0, ud);
  1576. len = clif_set007b(bl,vd,ud,buf);
  1577. clif_send(buf,len,bl,AREA_WOS);
  1578. if (disguised(bl))
  1579. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1580. //Stupid client that needs this resent every time someone walks :X
  1581. if(vd->cloth_color)
  1582. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1583. switch(bl->type)
  1584. {
  1585. case BL_PC:
  1586. {
  1587. TBL_PC *sd = ((TBL_PC*)bl);
  1588. // clif_movepc(sd);
  1589. if(sd->state.size==2) // tiny/big players [Valaris]
  1590. clif_specialeffect(&sd->bl,423,AREA);
  1591. else if(sd->state.size==1)
  1592. clif_specialeffect(&sd->bl,421,AREA);
  1593. }
  1594. break;
  1595. case BL_MOB:
  1596. {
  1597. TBL_MOB *md = ((TBL_MOB*)bl);
  1598. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1599. clif_specialeffect(&md->bl,423,AREA);
  1600. else if(md->special_state.size==1)
  1601. clif_specialeffect(&md->bl,421,AREA);
  1602. }
  1603. break;
  1604. }
  1605. return 0;
  1606. }
  1607. /*==========================================
  1608. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1609. *------------------------------------------
  1610. */
  1611. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1612. struct map_session_data *sd = NULL;
  1613. //Remove player from map server
  1614. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1615. map_quit(sd);
  1616. return 0;
  1617. }
  1618. /*==========================================
  1619. *
  1620. *------------------------------------------
  1621. */
  1622. void clif_quitsave(int fd,struct map_session_data *sd)
  1623. {
  1624. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1625. !battle_config.prevent_logout ||
  1626. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1627. map_quit(sd);
  1628. else if (sd->fd)
  1629. { //Disassociate session from player (session is deleted after this function was called)
  1630. //And set a timer to make him quit later.
  1631. session[sd->fd]->session_data = NULL;
  1632. sd->fd = 0;
  1633. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1634. }
  1635. }
  1636. /*==========================================
  1637. *
  1638. *------------------------------------------
  1639. */
  1640. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1641. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1642. session[id]->eof = 1;
  1643. return 0;
  1644. }
  1645. /*==========================================
  1646. *
  1647. *------------------------------------------
  1648. */
  1649. void clif_setwaitclose(int fd) {
  1650. struct map_session_data *sd;
  1651. // if player is not already in the game (double connection probably)
  1652. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1653. // limited timer, just to send information.
  1654. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1655. } else
  1656. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1657. }
  1658. /*==========================================
  1659. *
  1660. *------------------------------------------
  1661. */
  1662. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1663. int fd;
  1664. nullpo_retr(0, sd);
  1665. fd = sd->fd;
  1666. WFIFOHEAD(fd, packet_len_table[0x91]);
  1667. WFIFOW(fd,0) = 0x91;
  1668. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1669. WFIFOW(fd,18) = x;
  1670. WFIFOW(fd,20) = y;
  1671. WFIFOSET(fd, packet_len_table[0x91]);
  1672. return 0;
  1673. }
  1674. /*==========================================
  1675. *
  1676. *------------------------------------------
  1677. */
  1678. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1679. int fd;
  1680. nullpo_retr(0, sd);
  1681. fd = sd->fd;
  1682. WFIFOHEAD(fd, packet_len_table[0x92]);
  1683. WFIFOW(fd,0) = 0x92;
  1684. //Better not trust the null-terminator is there. [Skotlex]
  1685. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1686. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1687. WFIFOW(fd,18) = x;
  1688. WFIFOW(fd,20) = y;
  1689. WFIFOL(fd,22) = ip;
  1690. WFIFOW(fd,26) = port;
  1691. WFIFOSET(fd, packet_len_table[0x92]);
  1692. return 0;
  1693. }
  1694. int clif_blown(struct block_list *bl) {
  1695. //Previous Aegis versions simply used clif_fixpos, but it seems clif_slide works better on current clients.
  1696. // return clif_fixpos(bl);
  1697. return clif_slide(bl, bl->x, bl->y);
  1698. }
  1699. /*==========================================
  1700. *
  1701. *------------------------------------------
  1702. */
  1703. int clif_fixpos(struct block_list *bl) {
  1704. unsigned char buf[16];
  1705. nullpo_retr(0, bl);
  1706. WBUFW(buf,0)=0x88;
  1707. WBUFL(buf,2)=bl->id;
  1708. WBUFW(buf,6)=bl->x;
  1709. WBUFW(buf,8)=bl->y;
  1710. clif_send(buf, packet_len_table[0x88], bl, AREA);
  1711. if (disguised(bl)) {
  1712. WBUFL(buf,2)=-bl->id;
  1713. clif_send(buf, packet_len_table[0x88], bl, SELF);
  1714. }
  1715. return 0;
  1716. }
  1717. /*==========================================
  1718. *
  1719. *------------------------------------------
  1720. */
  1721. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1722. int fd;
  1723. nullpo_retr(0, sd);
  1724. fd=sd->fd;
  1725. WFIFOHEAD(fd, packet_len_table[0xc4]);
  1726. WFIFOW(fd,0)=0xc4;
  1727. WFIFOL(fd,2)=id;
  1728. WFIFOSET(fd,packet_len_table[0xc4]);
  1729. return 0;
  1730. }
  1731. /*==========================================
  1732. *
  1733. *------------------------------------------
  1734. */
  1735. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1736. struct item_data *id;
  1737. int fd,i,val;
  1738. nullpo_retr(0, sd);
  1739. nullpo_retr(0, nd);
  1740. fd=sd->fd;
  1741. WFIFOHEAD(fd, 200 * 11 + 4);
  1742. WFIFOW(fd,0)=0xc6;
  1743. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1744. id = itemdb_search(nd->u.shop_item[i].nameid);
  1745. val=nd->u.shop_item[i].value;
  1746. WFIFOL(fd,4+i*11)=val;
  1747. if (!id->flag.value_notdc)
  1748. val=pc_modifybuyvalue(sd,val);
  1749. WFIFOL(fd,8+i*11)=val;
  1750. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1751. if (id->view_id > 0)
  1752. WFIFOW(fd,13+i*11)=id->view_id;
  1753. else
  1754. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1755. }
  1756. WFIFOW(fd,2)=i*11+4;
  1757. WFIFOSET(fd,WFIFOW(fd,2));
  1758. return 0;
  1759. }
  1760. /*==========================================
  1761. *
  1762. *------------------------------------------
  1763. */
  1764. int clif_selllist(struct map_session_data *sd) {
  1765. int fd,i,c=0,val;
  1766. nullpo_retr(0, sd);
  1767. fd=sd->fd;
  1768. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1769. WFIFOW(fd,0)=0xc7;
  1770. for(i=0;i<MAX_INVENTORY;i++) {
  1771. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1772. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1773. continue;
  1774. val=sd->inventory_data[i]->value_sell;
  1775. if (val < 0)
  1776. continue;
  1777. WFIFOW(fd,4+c*10)=i+2;
  1778. WFIFOL(fd,6+c*10)=val;
  1779. if (!sd->inventory_data[i]->flag.value_notoc)
  1780. val=pc_modifysellvalue(sd,val);
  1781. WFIFOL(fd,10+c*10)=val;
  1782. c++;
  1783. }
  1784. }
  1785. WFIFOW(fd,2)=c*10+4;
  1786. WFIFOSET(fd,WFIFOW(fd,2));
  1787. return 0;
  1788. }
  1789. /*==========================================
  1790. *
  1791. *------------------------------------------
  1792. */
  1793. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  1794. int fd = sd->fd;
  1795. int slen = strlen(mes) + 9;
  1796. WFIFOHEAD(fd, slen);
  1797. WFIFOW(fd,0)=0xb4;
  1798. WFIFOW(fd,2)=slen;
  1799. WFIFOL(fd,4)=npcid;
  1800. strcpy((char*)WFIFOP(fd,8),mes);
  1801. WFIFOSET(fd,WFIFOW(fd,2));
  1802. return 0;
  1803. }
  1804. /*==========================================
  1805. *
  1806. *------------------------------------------
  1807. */
  1808. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  1809. int fd;
  1810. nullpo_retr(0, sd);
  1811. fd=sd->fd;
  1812. WFIFOHEAD(fd, packet_len_table[0xb5]);
  1813. WFIFOW(fd,0)=0xb5;
  1814. WFIFOL(fd,2)=npcid;
  1815. WFIFOSET(fd,packet_len_table[0xb5]);
  1816. return 0;
  1817. }
  1818. /*==========================================
  1819. *
  1820. *------------------------------------------
  1821. */
  1822. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  1823. int fd;
  1824. nullpo_retr(0, sd);
  1825. fd=sd->fd;
  1826. WFIFOHEAD(fd, packet_len_table[0xb6]);
  1827. WFIFOW(fd,0)=0xb6;
  1828. WFIFOL(fd,2)=npcid;
  1829. WFIFOSET(fd,packet_len_table[0xb6]);
  1830. return 0;
  1831. }
  1832. /*==========================================
  1833. *
  1834. *------------------------------------------
  1835. */
  1836. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1837. int fd = sd->fd;
  1838. WFIFOHEAD(fd, packet_len_table[0x78]);
  1839. sd->state.using_fake_npc = 1;
  1840. malloc_set(WFIFOP(fd,0), 0, packet_len_table[0x78]);
  1841. WFIFOW(fd,0)=0x78;
  1842. WFIFOL(fd,2)=npcid;
  1843. WFIFOW(fd,14)=111;
  1844. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1845. WFIFOB(fd,49)=5;
  1846. WFIFOB(fd,50)=5;
  1847. WFIFOSET(fd, packet_len_table[0x78]);
  1848. return;
  1849. }
  1850. /*==========================================
  1851. *
  1852. *------------------------------------------
  1853. */
  1854. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  1855. int fd = sd->fd;
  1856. int slen = strlen(mes) + 8;
  1857. struct block_list *bl = NULL;
  1858. WFIFOHEAD(fd, slen);
  1859. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1860. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1861. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1862. clif_sendfakenpc(sd, npcid);
  1863. WFIFOW(fd,0)=0xb7;
  1864. WFIFOW(fd,2)=slen;
  1865. WFIFOL(fd,4)=npcid;
  1866. strcpy((char*)WFIFOP(fd,8),mes);
  1867. WFIFOSET(fd,WFIFOW(fd,2));
  1868. return 0;
  1869. }
  1870. /*==========================================
  1871. *
  1872. *------------------------------------------
  1873. */
  1874. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  1875. int fd;
  1876. struct block_list *bl = NULL;
  1877. nullpo_retr(0, sd);
  1878. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1879. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1880. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1881. clif_sendfakenpc(sd, npcid);
  1882. fd=sd->fd;
  1883. WFIFOHEAD(fd, packet_len_table[0x142]);
  1884. WFIFOW(fd,0)=0x142;
  1885. WFIFOL(fd,2)=npcid;
  1886. WFIFOSET(fd,packet_len_table[0x142]);
  1887. return 0;
  1888. }
  1889. /*==========================================
  1890. *
  1891. *------------------------------------------
  1892. */
  1893. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1894. int fd;
  1895. struct block_list *bl = NULL;
  1896. nullpo_retr(0, sd);
  1897. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1898. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1899. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1900. clif_sendfakenpc(sd, npcid);
  1901. fd=sd->fd;
  1902. WFIFOHEAD(fd, packet_len_table[0x1d4]);
  1903. WFIFOW(fd,0)=0x1d4;
  1904. WFIFOL(fd,2)=npcid;
  1905. WFIFOSET(fd,packet_len_table[0x1d4]);
  1906. return 0;
  1907. }
  1908. /*==========================================
  1909. *
  1910. *------------------------------------------
  1911. */
  1912. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  1913. int fd;
  1914. nullpo_retr(0, sd);
  1915. fd=sd->fd;
  1916. WFIFOHEAD(fd, packet_len_table[0x144]);
  1917. WFIFOW(fd,0)=0x144;
  1918. WFIFOL(fd,2)=npc_id;
  1919. WFIFOL(fd,6)=type;
  1920. WFIFOL(fd,10)=x;
  1921. WFIFOL(fd,14)=y;
  1922. WFIFOB(fd,18)=id;
  1923. WFIFOL(fd,19)=color;
  1924. WFIFOSET(fd,packet_len_table[0x144]);
  1925. return 0;
  1926. }
  1927. /*==========================================
  1928. *
  1929. *------------------------------------------
  1930. */
  1931. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  1932. int fd;
  1933. nullpo_retr(0, sd);
  1934. fd=sd->fd;
  1935. WFIFOHEAD(fd, packet_len_table[0x1b3]);
  1936. WFIFOW(fd,0)=0x1b3;
  1937. strncpy((char*)WFIFOP(fd,2),image,64);
  1938. WFIFOB(fd,66)=type;
  1939. WFIFOSET(fd,packet_len_table[0x1b3]);
  1940. return 0;
  1941. }
  1942. /*==========================================
  1943. * Fills in card data from the given item and into the buffer. [Skotlex]
  1944. *------------------------------------------
  1945. */
  1946. static void clif_addcards(unsigned char* buf, struct item* item)
  1947. {
  1948. int i=0,j;
  1949. if (item == NULL) { //Blank data
  1950. WBUFW(buf,0)=0;
  1951. WBUFW(buf,2)=0;
  1952. WBUFW(buf,4)=0;
  1953. WBUFW(buf,6)=0;
  1954. return;
  1955. }
  1956. if(item->card[0]==CARD0_PET) { //pet eggs
  1957. WBUFW(buf,0)=0;
  1958. WBUFW(buf,2)=0;
  1959. WBUFW(buf,4)=0;
  1960. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1961. return;
  1962. }
  1963. if(item->card[0]==CARD0_FORGE || item->card[0]==CARD0_CREATE) { //Forged/created items
  1964. WBUFW(buf,0)=item->card[0];
  1965. WBUFW(buf,2)=item->card[1];
  1966. WBUFW(buf,4)=item->card[2];
  1967. WBUFW(buf,6)=item->card[3];
  1968. return;
  1969. }
  1970. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1971. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1972. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1973. //Normal items.
  1974. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1975. WBUFW(buf,0)=j;
  1976. else
  1977. WBUFW(buf,0)= item->card[i];
  1978. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1979. WBUFW(buf,2)=j;
  1980. else
  1981. WBUFW(buf,2)=item->card[i];
  1982. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1983. WBUFW(buf,4)=j;
  1984. else
  1985. WBUFW(buf,4)=item->card[i];
  1986. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1987. WBUFW(buf,6)=j;
  1988. else
  1989. WBUFW(buf,6)=item->card[i];
  1990. }
  1991. /*==========================================
  1992. *
  1993. *------------------------------------------
  1994. */
  1995. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  1996. int fd;
  1997. unsigned char *buf;
  1998. nullpo_retr(0, sd);
  1999. fd = sd->fd;
  2000. if (!session_isActive(fd)) //Sasuke-
  2001. return 0;
  2002. WFIFOHEAD(fd,packet_len_table[0xa0]);
  2003. buf = WFIFOP(fd,0);
  2004. if(fail) {
  2005. WBUFW(buf,0)=0xa0;
  2006. WBUFW(buf,2)=n+2;
  2007. WBUFW(buf,4)=amount;
  2008. WBUFW(buf,6)=0;
  2009. WBUFB(buf,8)=0;
  2010. WBUFB(buf,9)=0;
  2011. WBUFB(buf,10)=0;
  2012. WBUFW(buf,11)=0;
  2013. WBUFW(buf,13)=0;
  2014. WBUFW(buf,15)=0;
  2015. WBUFW(buf,17)=0;
  2016. WBUFW(buf,19)=0;
  2017. WBUFB(buf,21)=0;
  2018. WBUFB(buf,22)=fail;
  2019. } else {
  2020. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  2021. return 1;
  2022. WBUFW(buf,0)=0xa0;
  2023. WBUFW(buf,2)=n+2;
  2024. WBUFW(buf,4)=amount;
  2025. if (sd->inventory_data[n]->view_id > 0)
  2026. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  2027. else
  2028. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  2029. WBUFB(buf,8)=sd->status.inventory[n].identify;
  2030. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  2031. WBUFB(buf,10)=sd->status.inventory[n].refine;
  2032. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  2033. WBUFW(buf,19)=pc_equippoint(sd,n);
  2034. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  2035. WBUFB(buf,22)=fail;
  2036. }
  2037. WFIFOSET(fd,packet_len_table[0xa0]);
  2038. return 0;
  2039. }
  2040. /*==========================================
  2041. *
  2042. *------------------------------------------
  2043. */
  2044. int clif_delitem(struct map_session_data *sd,int n,int amount)
  2045. {
  2046. int fd;
  2047. nullpo_retr(0, sd);
  2048. fd=sd->fd;
  2049. WFIFOHEAD(fd, packet_len_table[0xaf]);
  2050. WFIFOW(fd,0)=0xaf;
  2051. WFIFOW(fd,2)=n+2;
  2052. WFIFOW(fd,4)=amount;
  2053. WFIFOSET(fd,packet_len_table[0xaf]);
  2054. return 0;
  2055. }
  2056. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2057. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2058. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2059. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  2060. {
  2061. if (id->view_id > 0)
  2062. WBUFW(buf,n)=id->view_id;
  2063. else
  2064. WBUFW(buf,n)=i->nameid;
  2065. WBUFB(buf,n+2)=itemtype(id->type);
  2066. WBUFB(buf,n+3)=i->identify;
  2067. if (equip >= 0) { //Equippable item
  2068. WBUFW(buf,n+4)=equip;
  2069. WBUFW(buf,n+6)=i->equip;
  2070. WBUFB(buf,n+8)=i->attribute;
  2071. WBUFB(buf,n+9)=i->refine;
  2072. } else { //Stackable item.
  2073. WBUFW(buf,n+4)=i->amount;
  2074. if (equip == -2 && id->equip == EQP_AMMO)
  2075. WBUFW(buf,n+6)=EQP_AMMO;
  2076. else
  2077. WBUFW(buf,n+6)=0;
  2078. }
  2079. }
  2080. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2081. void clif_inventorylist(struct map_session_data *sd)
  2082. {
  2083. int i,n,ne,fd = sd->fd,arrow=-1;
  2084. unsigned char *buf;
  2085. unsigned char bufe[MAX_INVENTORY*20+4];
  2086. #if PACKETVER < 5
  2087. const int s = 10; //Entry size.
  2088. #else
  2089. const int s = 18;
  2090. #endif
  2091. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  2092. buf = WFIFOP(fd,0);
  2093. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  2094. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2095. continue;
  2096. if(!itemdb_isstackable2(sd->inventory_data[i]))
  2097. { //Non-stackable (Equippable)
  2098. WBUFW(bufe,ne*20+4)=i+2;
  2099. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2100. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  2101. ne++;
  2102. } else { //Stackable.
  2103. WBUFW(buf,n*s+4)=i+2;
  2104. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2105. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  2106. sd->status.inventory[i].equip)
  2107. arrow=i;
  2108. #if PACKETVER >= 5
  2109. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  2110. #endif
  2111. n++;
  2112. }
  2113. }
  2114. if (n) {
  2115. #if PACKETVER < 5
  2116. WBUFW(buf,0)=0xa3;
  2117. #else
  2118. WBUFW(buf,0)=0x1ee;
  2119. #endif
  2120. WBUFW(buf,2)=4+n*s;
  2121. WFIFOSET(fd,WFIFOW(fd,2));
  2122. }
  2123. if(arrow >= 0)
  2124. clif_arrowequip(sd,arrow);
  2125. if(ne){
  2126. WBUFW(bufe,0)=0xa4;
  2127. WBUFW(bufe,2)=4+ne*20;
  2128. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2129. }
  2130. }
  2131. //Required when items break/get-repaired. Only sends equippable item list.
  2132. void clif_equiplist(struct map_session_data *sd)
  2133. {
  2134. int i,n,fd = sd->fd;
  2135. unsigned char *buf;
  2136. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  2137. buf = WFIFOP(fd,0);
  2138. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2139. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2140. continue;
  2141. if(itemdb_isstackable2(sd->inventory_data[i]))
  2142. continue;
  2143. //Equippable
  2144. WBUFW(buf,n*20+4)=i+2;
  2145. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2146. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  2147. n++;
  2148. }
  2149. if (n) {
  2150. WBUFW(buf,0)=0xa4;
  2151. WBUFW(buf,2)=4+n*20;
  2152. WFIFOSET(fd,WFIFOW(fd,2));
  2153. }
  2154. }
  2155. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2156. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  2157. {
  2158. struct item_data *id;
  2159. int i,n,ne,fd=sd->fd;
  2160. unsigned char *buf;
  2161. unsigned char bufe[MAX_STORAGE*20+4];
  2162. #if PACKETVER < 5
  2163. const int s = 10; //Entry size.
  2164. #else
  2165. const int s = 18;
  2166. #endif
  2167. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  2168. buf = WFIFOP(fd,0);
  2169. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  2170. if(stor->storage_[i].nameid<=0)
  2171. continue;
  2172. id = itemdb_search(stor->storage_[i].nameid);
  2173. if(!itemdb_isstackable2(id))
  2174. { //Equippable
  2175. WBUFW(bufe,ne*20+4)=i+1;
  2176. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2177. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2178. ne++;
  2179. } else { //Stackable
  2180. WBUFW(buf,n*s+4)=i+1;
  2181. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2182. #if PACKETVER >= 5
  2183. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2184. #endif
  2185. n++;
  2186. }
  2187. }
  2188. if(n){
  2189. #if PACKETVER < 5
  2190. WBUFW(buf,0)=0xa5;
  2191. #else
  2192. WBUFW(buf,0)=0x1f0;
  2193. #endif
  2194. WBUFW(buf,2)=4+n*s;
  2195. WFIFOSET(fd,WFIFOW(fd,2));
  2196. }
  2197. if(ne){
  2198. WBUFW(bufe,0)=0xa6;
  2199. WBUFW(bufe,2)=4+ne*20;
  2200. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2201. }
  2202. }
  2203. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2204. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  2205. {
  2206. struct item_data *id;
  2207. int i,n,ne,fd=sd->fd;
  2208. unsigned char *buf;
  2209. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  2210. #if PACKETVER < 5
  2211. const int s = 10; //Entry size.
  2212. #else
  2213. const int s = 18;
  2214. #endif
  2215. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  2216. buf = WFIFOP(fd,0);
  2217. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  2218. if(stor->storage_[i].nameid<=0)
  2219. continue;
  2220. id = itemdb_search(stor->storage_[i].nameid);
  2221. if(!itemdb_isstackable2(id))
  2222. { //Equippable
  2223. WBUFW(bufe,ne*20+4)=i+1;
  2224. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2225. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2226. ne++;
  2227. } else { //Stackable
  2228. WBUFW(buf,n*s+4)=i+1;
  2229. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2230. #if PACKETVER >= 5
  2231. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2232. #endif
  2233. n++;
  2234. }
  2235. }
  2236. if(n){
  2237. #if PACKETVER < 5
  2238. WBUFW(buf,0)=0xa5;
  2239. #else
  2240. WBUFW(buf,0)=0x1f0;
  2241. #endif
  2242. WBUFW(buf,2)=4+n*s;
  2243. WFIFOSET(fd,WFIFOW(fd,2));
  2244. }
  2245. if(ne){
  2246. WBUFW(bufe,0)=0xa6;
  2247. WBUFW(bufe,2)=4+ne*20;
  2248. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2249. }
  2250. }
  2251. void clif_cartlist(struct map_session_data *sd)
  2252. {
  2253. struct item_data *id;
  2254. int i,n,ne,fd=sd->fd;
  2255. unsigned char *buf;
  2256. unsigned char bufe[MAX_CART*20+4];
  2257. #if PACKETVER < 5
  2258. const int s = 10; //Entry size.
  2259. #else
  2260. const int s = 18;
  2261. #endif
  2262. WFIFOHEAD(fd, MAX_CART * s + 4);
  2263. buf = WFIFOP(fd,0);
  2264. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2265. if(sd->status.cart[i].nameid<=0)
  2266. continue;
  2267. id = itemdb_search(sd->status.cart[i].nameid);
  2268. if(!itemdb_isstackable2(id))
  2269. { //Equippable
  2270. WBUFW(bufe,ne*20+4)=i+2;
  2271. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2272. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2273. ne++;
  2274. } else { //Stackable
  2275. WBUFW(buf,n*s+4)=i+2;
  2276. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2277. #if PACKETVER >= 5
  2278. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2279. #endif
  2280. n++;
  2281. }
  2282. }
  2283. if(n){
  2284. #if PACKETVER < 5
  2285. WBUFW(buf,0)=0x123;
  2286. #else
  2287. WBUFW(buf,0)=0x1ef;
  2288. #endif
  2289. WBUFW(buf,2)=4+n*s;
  2290. WFIFOSET(fd,WFIFOW(fd,2));
  2291. }
  2292. if(ne){
  2293. WBUFW(bufe,0)=0x122;
  2294. WBUFW(bufe,2)=4+ne*20;
  2295. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2296. }
  2297. return;
  2298. }
  2299. // Guild XY locators [Valaris]
  2300. int clif_guild_xy(struct map_session_data *sd)
  2301. {
  2302. unsigned char buf[10];
  2303. nullpo_retr(0, sd);
  2304. WBUFW(buf,0)=0x1eb;
  2305. WBUFL(buf,2)=sd->status.account_id;
  2306. WBUFW(buf,6)=sd->bl.x;
  2307. WBUFW(buf,8)=sd->bl.y;
  2308. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2309. return 0;
  2310. }
  2311. /*==========================================
  2312. * Sends x/y dot to a single fd. [Skotlex]
  2313. *------------------------------------------
  2314. */
  2315. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2316. {
  2317. WFIFOHEAD(fd,packet_len_table[0x1eb]);
  2318. WFIFOW(fd,0)=0x1eb;
  2319. WFIFOL(fd,2)=sd->status.account_id;
  2320. WFIFOW(fd,6)=sd->bl.x;
  2321. WFIFOW(fd,8)=sd->bl.y;
  2322. WFIFOSET(fd,packet_len_table[0x1eb]);
  2323. return 0;
  2324. }
  2325. // Guild XY locators [Valaris]
  2326. int clif_guild_xy_remove(struct map_session_data *sd)
  2327. {
  2328. unsigned char buf[10];
  2329. nullpo_retr(0, sd);
  2330. WBUFW(buf,0)=0x1eb;
  2331. WBUFL(buf,2)=sd->status.account_id;
  2332. WBUFW(buf,6)=-1;
  2333. WBUFW(buf,8)=-1;
  2334. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2335. return 0;
  2336. }
  2337. /*==========================================
  2338. * ステータスを送りつける
  2339. * 表示専用数字はこの中で計算して送る
  2340. *------------------------------------------
  2341. */
  2342. int clif_updatestatus(struct map_session_data *sd,int type)
  2343. {
  2344. int fd,len=8;
  2345. nullpo_retr(0, sd);
  2346. fd=sd->fd;
  2347. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2348. return 0;
  2349. WFIFOHEAD(fd, 14);
  2350. WFIFOW(fd,0)=0xb0;
  2351. WFIFOW(fd,2)=type;
  2352. switch(type){
  2353. // 00b0
  2354. case SP_WEIGHT:
  2355. pc_checkweighticon(sd);
  2356. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_checkweighticon can alter the buffer. [Skotlex]
  2357. WFIFOW(fd,2)=type;
  2358. WFIFOL(fd,4)=sd->weight;
  2359. break;
  2360. case SP_MAXWEIGHT:
  2361. WFIFOL(fd,4)=sd->max_weight;
  2362. break;
  2363. case SP_SPEED:
  2364. WFIFOL(fd,4)=sd->battle_status.speed;
  2365. break;
  2366. case SP_BASELEVEL:
  2367. WFIFOL(fd,4)=sd->status.base_level;
  2368. break;
  2369. case SP_JOBLEVEL:
  2370. WFIFOL(fd,4)=sd->status.job_level;
  2371. break;
  2372. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2373. WFIFOL(fd,4)=sd->status.karma;
  2374. break;
  2375. case SP_MANNER:
  2376. WFIFOL(fd,4)=sd->status.manner;
  2377. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2378. break;
  2379. case SP_STATUSPOINT:
  2380. WFIFOL(fd,4)=sd->status.status_point;
  2381. break;
  2382. case SP_SKILLPOINT:
  2383. WFIFOL(fd,4)=sd->status.skill_point;
  2384. break;
  2385. case SP_HIT:
  2386. WFIFOL(fd,4)=sd->battle_status.hit;
  2387. break;
  2388. case SP_FLEE1:
  2389. WFIFOL(fd,4)=sd->battle_status.flee;
  2390. break;
  2391. case SP_FLEE2:
  2392. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2393. break;
  2394. case SP_MAXHP:
  2395. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2396. break;
  2397. case SP_MAXSP:
  2398. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2399. break;
  2400. case SP_HP:
  2401. WFIFOL(fd,4)=sd->battle_status.hp;
  2402. if (battle_config.disp_hpmeter)
  2403. clif_hpmeter(sd);
  2404. if (!battle_config.party_hp_mode && sd->status.party_id)
  2405. clif_party_hp(sd);
  2406. break;
  2407. case SP_SP:
  2408. WFIFOL(fd,4)=sd->battle_status.sp;
  2409. break;
  2410. case SP_ASPD:
  2411. WFIFOL(fd,4)=sd->battle_status.amotion;
  2412. break;
  2413. case SP_ATK1:
  2414. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2415. break;
  2416. case SP_DEF1:
  2417. WFIFOL(fd,4)=sd->battle_status.def;
  2418. break;
  2419. case SP_MDEF1:
  2420. WFIFOL(fd,4)=sd->battle_status.mdef;
  2421. break;
  2422. case SP_ATK2:
  2423. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2424. break;
  2425. case SP_DEF2:
  2426. WFIFOL(fd,4)=sd->battle_status.def2;
  2427. break;
  2428. case SP_MDEF2:
  2429. //negative check (in case you have something like Berserk active)
  2430. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2431. if (len < 0) len = 0;
  2432. WFIFOL(fd,4)= len;
  2433. len = 8;
  2434. break;
  2435. case SP_CRITICAL:
  2436. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2437. break;
  2438. case SP_MATK1:
  2439. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2440. break;
  2441. case SP_MATK2:
  2442. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2443. break;
  2444. case SP_ZENY:
  2445. WFIFOW(fd,0)=0xb1;
  2446. WFIFOL(fd,4)=sd->status.zeny;
  2447. break;
  2448. case SP_BASEEXP:
  2449. WFIFOW(fd,0)=0xb1;
  2450. WFIFOL(fd,4)=sd->status.base_exp;
  2451. break;
  2452. case SP_JOBEXP:
  2453. WFIFOW(fd,0)=0xb1;
  2454. WFIFOL(fd,4)=sd->status.job_exp;
  2455. break;
  2456. case SP_NEXTBASEEXP:
  2457. WFIFOW(fd,0)=0xb1;
  2458. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2459. break;
  2460. case SP_NEXTJOBEXP:
  2461. WFIFOW(fd,0)=0xb1;
  2462. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2463. break;
  2464. // 00be 終了
  2465. case SP_USTR:
  2466. case SP_UAGI:
  2467. case SP_UVIT:
  2468. case SP_UINT:
  2469. case SP_UDEX:
  2470. case SP_ULUK:
  2471. WFIFOW(fd,0)=0xbe;
  2472. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2473. len=5;
  2474. break;
  2475. // 013a 終了
  2476. case SP_ATTACKRANGE:
  2477. WFIFOW(fd,0)=0x13a;
  2478. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2479. len=4;
  2480. break;
  2481. // 0141 終了
  2482. case SP_STR:
  2483. WFIFOW(fd,0)=0x141;
  2484. WFIFOL(fd,2)=type;
  2485. WFIFOL(fd,6)=sd->status.str;
  2486. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2487. len=14;
  2488. break;
  2489. case SP_AGI:
  2490. WFIFOW(fd,0)=0x141;
  2491. WFIFOL(fd,2)=type;
  2492. WFIFOL(fd,6)=sd->status.agi;
  2493. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2494. len=14;
  2495. break;
  2496. case SP_VIT:
  2497. WFIFOW(fd,0)=0x141;
  2498. WFIFOL(fd,2)=type;
  2499. WFIFOL(fd,6)=sd->status.vit;
  2500. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2501. len=14;
  2502. break;
  2503. case SP_INT:
  2504. WFIFOW(fd,0)=0x141;
  2505. WFIFOL(fd,2)=type;
  2506. WFIFOL(fd,6)=sd->status.int_;
  2507. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2508. len=14;
  2509. break;
  2510. case SP_DEX:
  2511. WFIFOW(fd,0)=0x141;
  2512. WFIFOL(fd,2)=type;
  2513. WFIFOL(fd,6)=sd->status.dex;
  2514. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2515. len=14;
  2516. break;
  2517. case SP_LUK:
  2518. WFIFOW(fd,0)=0x141;
  2519. WFIFOL(fd,2)=type;
  2520. WFIFOL(fd,6)=sd->status.luk;
  2521. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2522. len=14;
  2523. break;
  2524. case SP_CARTINFO:
  2525. WFIFOW(fd,0)=0x121;
  2526. WFIFOW(fd,2)=sd->cart_num;
  2527. WFIFOW(fd,4)=sd->cart_max_num;
  2528. WFIFOL(fd,6)=sd->cart_weight;
  2529. WFIFOL(fd,10)=sd->cart_max_weight;
  2530. len=14;
  2531. break;
  2532. default:
  2533. if(battle_config.error_log)
  2534. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2535. return 1;
  2536. }
  2537. WFIFOSET(fd,len);
  2538. return 0;
  2539. }
  2540. int clif_changestatus(struct block_list *bl,int type,int val)
  2541. {
  2542. unsigned char buf[12];
  2543. struct map_session_data *sd = NULL;
  2544. nullpo_retr(0, bl);
  2545. if(bl->type == BL_PC)
  2546. sd = (struct map_session_data *)bl;
  2547. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2548. if(sd){
  2549. WBUFW(buf,0)=0x1ab;
  2550. WBUFL(buf,2)=bl->id;
  2551. WBUFW(buf,6)=type;
  2552. switch(type){
  2553. case SP_MANNER:
  2554. WBUFL(buf,8)=val;
  2555. break;
  2556. default:
  2557. if(battle_config.error_log)
  2558. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2559. return 1;
  2560. }
  2561. clif_send(buf,packet_len_table[0x1ab],bl,AREA_WOS);
  2562. }
  2563. return 0;
  2564. }
  2565. /*==========================================
  2566. *
  2567. *------------------------------------------
  2568. */
  2569. int clif_changelook(struct block_list *bl,int type,int val)
  2570. {
  2571. unsigned char buf[32];
  2572. struct map_session_data *sd = NULL;
  2573. struct view_data *vd;
  2574. vd = status_get_viewdata(bl);
  2575. nullpo_retr(0, vd);
  2576. BL_CAST(BL_PC, bl, sd);
  2577. switch(type) {
  2578. case LOOK_WEAPON:
  2579. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2580. else vd->weapon = val;
  2581. break;
  2582. case LOOK_SHIELD:
  2583. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2584. else vd->shield = val;
  2585. break;
  2586. case LOOK_BASE:
  2587. vd->class_ = val;
  2588. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2589. vd->weapon = vd->shield = 0;
  2590. if (vd->cloth_color && (
  2591. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2592. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2593. ))
  2594. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2595. break;
  2596. case LOOK_HAIR:
  2597. vd->hair_style = val;
  2598. break;
  2599. case LOOK_HEAD_BOTTOM:
  2600. vd->head_bottom = val;
  2601. break;
  2602. case LOOK_HEAD_TOP:
  2603. vd->head_top = val;
  2604. break;
  2605. case LOOK_HEAD_MID:
  2606. vd->head_mid = val;
  2607. break;
  2608. case LOOK_HAIR_COLOR:
  2609. vd->hair_color = val;
  2610. break;
  2611. case LOOK_CLOTHES_COLOR:
  2612. if (val && (
  2613. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2614. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2615. ))
  2616. val = 0;
  2617. vd->cloth_color = val;
  2618. break;
  2619. case LOOK_SHOES:
  2620. #if PACKETVER > 3
  2621. if (sd) {
  2622. int n;
  2623. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2624. if(sd->inventory_data[n]->view_id > 0)
  2625. val = sd->inventory_data[n]->view_id;
  2626. else
  2627. val = sd->status.inventory[n].nameid;
  2628. }
  2629. val = 0;
  2630. }
  2631. #endif
  2632. //Shoes? No packet uses this....
  2633. break;
  2634. }
  2635. #if PACKETVER < 4
  2636. WBUFW(buf,0)=0xc3;
  2637. WBUFL(buf,2)=bl->id;
  2638. WBUFB(buf,6)=type;
  2639. WBUFB(buf,7)=val;
  2640. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2641. #else
  2642. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2643. WBUFW(buf,0)=0x1d7;
  2644. WBUFL(buf,2)=bl->id;
  2645. WBUFB(buf,6)=LOOK_WEAPON;
  2646. WBUFW(buf,7)=vd->weapon;
  2647. WBUFW(buf,9)=vd->shield;
  2648. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2649. }
  2650. else
  2651. {
  2652. WBUFW(buf,0)=0x1d7;
  2653. WBUFL(buf,2)=bl->id;
  2654. WBUFB(buf,6)=type;
  2655. WBUFW(buf,7)=val;
  2656. WBUFW(buf,9)=0;
  2657. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2658. }
  2659. #endif
  2660. return 0;
  2661. }
  2662. //Sends a change-base-look packet required for traps as they are triggered.
  2663. void clif_changetraplook(struct block_list *bl,int val)
  2664. {
  2665. unsigned char buf[32];
  2666. #if PACKETVER < 4
  2667. WBUFW(buf,0)=0xc3;
  2668. WBUFL(buf,2)=bl->id;
  2669. WBUFB(buf,6)=LOOK_BASE;
  2670. WBUFB(buf,7)=val;
  2671. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2672. #else
  2673. WBUFW(buf,0)=0x1d7;
  2674. WBUFL(buf,2)=bl->id;
  2675. WBUFB(buf,6)=LOOK_BASE;
  2676. WBUFW(buf,7)=val;
  2677. WBUFW(buf,9)=0;
  2678. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2679. #endif
  2680. }
  2681. //For the stupid cloth-dye bug. Resends the given view data
  2682. //to the area specified by bl.
  2683. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2684. {
  2685. unsigned char buf[32];
  2686. #if PACKETVER < 4
  2687. WBUFW(buf,0)=0xc3;
  2688. WBUFL(buf,2)=id;
  2689. WBUFB(buf,6)=type;
  2690. WBUFB(buf,7)=val;
  2691. clif_send(buf,packet_len_table[0xc3],bl,area);
  2692. #else
  2693. WBUFW(buf,0)=0x1d7;
  2694. WBUFL(buf,2)=id;
  2695. WBUFB(buf,6)=type;
  2696. WBUFW(buf,7)=val;
  2697. WBUFW(buf,9)=0;
  2698. clif_send(buf,packet_len_table[0x1d7],bl,area);
  2699. #endif
  2700. return;
  2701. }
  2702. /*==========================================
  2703. *
  2704. *------------------------------------------
  2705. */
  2706. int clif_initialstatus(struct map_session_data *sd)
  2707. {
  2708. int fd;
  2709. unsigned char *buf;
  2710. nullpo_retr(0, sd);
  2711. fd=sd->fd;
  2712. WFIFOHEAD(fd,packet_len_table[0xbd]);
  2713. buf=WFIFOP(fd,0);
  2714. WBUFW(buf,0)=0xbd;
  2715. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2716. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2717. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2718. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2719. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2720. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2721. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2722. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2723. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2724. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2725. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2726. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2727. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2728. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2729. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2730. WBUFW(buf,20) = sd->battle_status.matk_max;
  2731. WBUFW(buf,22) = sd->battle_status.matk_min;
  2732. WBUFW(buf,24) = sd->battle_status.def; // def
  2733. WBUFW(buf,26) = sd->battle_status.def2;
  2734. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2735. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2736. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2737. WBUFW(buf,30) = fd;
  2738. fd = sd->fd;
  2739. WBUFW(buf,32) = sd->battle_status.hit;
  2740. WBUFW(buf,34) = sd->battle_status.flee;
  2741. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2742. WBUFW(buf,38) = sd->battle_status.cri/10;
  2743. WBUFW(buf,40) = sd->status.karma;
  2744. WBUFW(buf,42) = sd->status.manner;
  2745. WFIFOSET(fd,packet_len_table[0xbd]);
  2746. clif_updatestatus(sd,SP_STR);
  2747. clif_updatestatus(sd,SP_AGI);
  2748. clif_updatestatus(sd,SP_VIT);
  2749. clif_updatestatus(sd,SP_INT);
  2750. clif_updatestatus(sd,SP_DEX);
  2751. clif_updatestatus(sd,SP_LUK);
  2752. clif_updatestatus(sd,SP_ATTACKRANGE);
  2753. clif_updatestatus(sd,SP_ASPD);
  2754. return 0;
  2755. }
  2756. /*==========================================
  2757. *矢装備
  2758. *------------------------------------------
  2759. */
  2760. int clif_arrowequip(struct map_session_data *sd,int val)
  2761. {
  2762. int fd;
  2763. nullpo_retr(0, sd);
  2764. pc_stop_attack(sd); // [Valaris]
  2765. fd=sd->fd;
  2766. WFIFOHEAD(fd, packet_len_table[0x013c]);
  2767. WFIFOW(fd,0)=0x013c;
  2768. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2769. WFIFOSET(fd,packet_len_table[0x013c]);
  2770. return 0;
  2771. }
  2772. /*==========================================
  2773. *
  2774. *------------------------------------------
  2775. */
  2776. int clif_arrow_fail(struct map_session_data *sd,int type)
  2777. {
  2778. int fd;
  2779. nullpo_retr(0, sd);
  2780. fd=sd->fd;
  2781. WFIFOHEAD(fd, packet_len_table[0x013b]);
  2782. WFIFOW(fd,0)=0x013b;
  2783. WFIFOW(fd,2)=type;
  2784. WFIFOSET(fd,packet_len_table[0x013b]);
  2785. return 0;
  2786. }
  2787. /*==========================================
  2788. * 作成可能 矢リスト送信
  2789. *------------------------------------------
  2790. */
  2791. int clif_arrow_create_list(struct map_session_data *sd)
  2792. {
  2793. int i, c, j;
  2794. int fd;
  2795. nullpo_retr(0, sd);
  2796. fd = sd->fd;
  2797. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2798. WFIFOW(fd,0) = 0x1ad;
  2799. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2800. if (skill_arrow_db[i].nameid > 0 &&
  2801. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2802. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2803. {
  2804. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2805. WFIFOW(fd,c*2+4) = j;
  2806. else
  2807. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2808. c++;
  2809. }
  2810. }
  2811. WFIFOW(fd,2) = c*2+4;
  2812. WFIFOSET(fd, WFIFOW(fd,2));
  2813. if (c > 0) {
  2814. sd->menuskill_id = AC_MAKINGARROW;
  2815. sd->menuskill_lv = c;
  2816. }
  2817. return 0;
  2818. }
  2819. /*==========================================
  2820. *
  2821. *------------------------------------------
  2822. */
  2823. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2824. {
  2825. int fd;
  2826. nullpo_retr(0, sd);
  2827. fd=sd->fd;
  2828. WFIFOHEAD(fd,packet_len_table[0xbc]);
  2829. WFIFOW(fd,0)=0xbc;
  2830. WFIFOW(fd,2)=type;
  2831. WFIFOB(fd,4)=ok;
  2832. WFIFOB(fd,5)=val;
  2833. WFIFOSET(fd,packet_len_table[0xbc]);
  2834. return 0;
  2835. }
  2836. /*==========================================
  2837. *
  2838. *------------------------------------------
  2839. */
  2840. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2841. {
  2842. int fd;
  2843. nullpo_retr(0, sd);
  2844. fd=sd->fd;
  2845. WFIFOHEAD(fd,packet_len_table[0xaa]);
  2846. WFIFOW(fd,0)=0xaa;
  2847. WFIFOW(fd,2)=n+2;
  2848. WFIFOW(fd,4)=pos;
  2849. WFIFOB(fd,6)=ok;
  2850. WFIFOSET(fd,packet_len_table[0xaa]);
  2851. return 0;
  2852. }
  2853. /*==========================================
  2854. *
  2855. *------------------------------------------
  2856. */
  2857. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2858. {
  2859. int fd;
  2860. nullpo_retr(0, sd);
  2861. fd=sd->fd;
  2862. WFIFOHEAD(fd,packet_len_table[0xac]);
  2863. WFIFOW(fd,0)=0xac;
  2864. WFIFOW(fd,2)=n+2;
  2865. WFIFOW(fd,4)=pos;
  2866. WFIFOB(fd,6)=ok;
  2867. WFIFOSET(fd,packet_len_table[0xac]);
  2868. return 0;
  2869. }
  2870. /*==========================================
  2871. *
  2872. *------------------------------------------
  2873. */
  2874. int clif_misceffect(struct block_list* bl,int type)
  2875. {
  2876. unsigned char buf[32];
  2877. nullpo_retr(0, bl);
  2878. WBUFW(buf,0) = 0x19b;
  2879. WBUFL(buf,2) = bl->id;
  2880. WBUFL(buf,6) = type;
  2881. clif_send(buf,packet_len_table[0x19b],bl,AREA);
  2882. return 0;
  2883. }
  2884. int clif_misceffect2(struct block_list *bl, int type) {
  2885. unsigned char buf[24];
  2886. nullpo_retr(0, bl);
  2887. malloc_set(buf, 0, packet_len_table[0x1f3]);
  2888. WBUFW(buf,0) = 0x1f3;
  2889. WBUFL(buf,2) = bl->id;
  2890. WBUFL(buf,6) = type;
  2891. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  2892. return 0;
  2893. }
  2894. /*==========================================
  2895. * 表示オプション変更
  2896. *------------------------------------------
  2897. */
  2898. int clif_changeoption(struct block_list* bl)
  2899. {
  2900. unsigned char buf[32];
  2901. struct status_change *sc;
  2902. nullpo_retr(0, bl);
  2903. sc = status_get_sc(bl);
  2904. if (!sc) return 0; //How can an option change if there's no sc?
  2905. #if PACKETVER > 6
  2906. WBUFW(buf,0) = 0x229;
  2907. WBUFL(buf,2) = bl->id;
  2908. WBUFW(buf,6) = sc->opt1;
  2909. WBUFW(buf,8) = sc->opt2;
  2910. WBUFL(buf,10) = sc->option;
  2911. WBUFB(buf,14) = 0; // ??
  2912. if(disguised(bl)) {
  2913. clif_send(buf,packet_len_table[0x229],bl,AREA_WOS);
  2914. WBUFL(buf,2) = -bl->id;
  2915. clif_send(buf,packet_len_table[0x229],bl,SELF);
  2916. WBUFL(buf,2) = bl->id;
  2917. WBUFL(buf,10) = OPTION_INVISIBLE;
  2918. clif_send(buf,packet_len_table[0x229],bl,SELF);
  2919. } else
  2920. clif_send(buf,packet_len_table[0x229],bl,AREA);
  2921. #else
  2922. WBUFW(buf,0) = 0x119;
  2923. WBUFL(buf,2) = bl->id;
  2924. WBUFW(buf,6) = sc->opt1;
  2925. WBUFW(buf,8) = sc->opt2;
  2926. WBUFW(buf,10) = sc->option;
  2927. WBUFB(buf,12) = 0; // ??
  2928. if(disguised(bl)) {
  2929. clif_send(buf,packet_len_table[0x119],bl,AREA_WOS);
  2930. WBUFL(buf,2) = -bl->id;
  2931. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2932. WBUFL(buf,2) = bl->id;
  2933. WBUFW(buf,10) = OPTION_INVISIBLE;
  2934. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2935. } else
  2936. clif_send(buf,packet_len_table[0x119],bl,AREA);
  2937. #endif
  2938. return 0;
  2939. }
  2940. /*==========================================
  2941. *
  2942. *------------------------------------------
  2943. */
  2944. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2945. {
  2946. nullpo_retr(0, sd);
  2947. if(!ok) {
  2948. int fd=sd->fd;
  2949. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2950. WFIFOW(fd,0)=0xa8;
  2951. WFIFOW(fd,2)=index+2;
  2952. WFIFOW(fd,4)=amount;
  2953. WFIFOB(fd,6)=ok;
  2954. WFIFOSET(fd,packet_len_table[0xa8]);
  2955. }
  2956. else {
  2957. #if PACKETVER < 3
  2958. int fd=sd->fd;
  2959. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2960. WFIFOW(fd,0)=0xa8;
  2961. WFIFOW(fd,2)=index+2;
  2962. WFIFOW(fd,4)=amount;
  2963. WFIFOB(fd,6)=ok;
  2964. WFIFOSET(fd,packet_len_table[0xa8]);
  2965. #else
  2966. unsigned char buf[32];
  2967. WBUFW(buf,0)=0x1c8;
  2968. WBUFW(buf,2)=index+2;
  2969. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2970. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2971. else
  2972. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2973. WBUFL(buf,6)=sd->bl.id;
  2974. WBUFW(buf,10)=amount;
  2975. WBUFB(buf,12)=ok;
  2976. clif_send(buf,packet_len_table[0x1c8],&sd->bl,AREA);
  2977. #endif
  2978. }
  2979. return 0;
  2980. }
  2981. /*==========================================
  2982. *
  2983. *------------------------------------------
  2984. */
  2985. int clif_createchat(struct map_session_data *sd,int fail)
  2986. {
  2987. int fd;
  2988. nullpo_retr(0, sd);
  2989. fd=sd->fd;
  2990. WFIFOHEAD(fd,packet_len_table[0xd6]);
  2991. WFIFOW(fd,0)=0xd6;
  2992. WFIFOB(fd,2)=fail;
  2993. WFIFOSET(fd,packet_len_table[0xd6]);
  2994. return 0;
  2995. }
  2996. /*==========================================
  2997. *
  2998. *------------------------------------------
  2999. */
  3000. int clif_dispchat(struct chat_data *cd,int fd)
  3001. {
  3002. unsigned char buf[128]; // 最大title(60バイト)+17
  3003. if(cd==NULL || *cd->owner==NULL)
  3004. return 1;
  3005. WBUFW(buf,0)=0xd7;
  3006. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  3007. WBUFL(buf,4)=(*cd->owner)->id;
  3008. WBUFL(buf,8)=cd->bl.id;
  3009. WBUFW(buf,12)=cd->limit;
  3010. WBUFW(buf,14)=cd->users;
  3011. WBUFB(buf,16)=cd->pub;
  3012. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  3013. if(fd){
  3014. WFIFOHEAD(fd, WBUFW(buf,2));
  3015. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3016. WFIFOSET(fd,WBUFW(buf,2));
  3017. } else {
  3018. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  3019. }
  3020. return 0;
  3021. }
  3022. /*==========================================
  3023. * chatの状態変更成功
  3024. * 外部の人用と命令コード(d7->df)が違うだけ
  3025. *------------------------------------------
  3026. */
  3027. int clif_changechatstatus(struct chat_data *cd)
  3028. {
  3029. unsigned char buf[128]; // 最大title(60バイト)+17
  3030. if(cd==NULL || cd->usersd[0]==NULL)
  3031. return 1;
  3032. WBUFW(buf,0)=0xdf;
  3033. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  3034. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  3035. WBUFL(buf,8)=cd->bl.id;
  3036. WBUFW(buf,12)=cd->limit;
  3037. WBUFW(buf,14)=cd->users;
  3038. WBUFB(buf,16)=cd->pub;
  3039. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  3040. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  3041. return 0;
  3042. }
  3043. /*==========================================
  3044. *
  3045. *------------------------------------------
  3046. */
  3047. int clif_clearchat(struct chat_data *cd,int fd)
  3048. {
  3049. unsigned char buf[32];
  3050. nullpo_retr(0, cd);
  3051. WBUFW(buf,0)=0xd8;
  3052. WBUFL(buf,2)=cd->bl.id;
  3053. if(fd){
  3054. WFIFOHEAD(fd,packet_len_table[0xd8]);
  3055. memcpy(WFIFOP(fd,0),buf,packet_len_table[0xd8]);
  3056. WFIFOSET(fd,packet_len_table[0xd8]);
  3057. } else {
  3058. clif_send(buf,packet_len_table[0xd8],*cd->owner,AREA_WOSC);
  3059. }
  3060. return 0;
  3061. }
  3062. /*==========================================
  3063. *
  3064. *------------------------------------------
  3065. */
  3066. int clif_joinchatfail(struct map_session_data *sd,int fail)
  3067. {
  3068. int fd;
  3069. nullpo_retr(0, sd);
  3070. fd=sd->fd;
  3071. WFIFOHEAD(fd,packet_len_table[0xda]);
  3072. WFIFOW(fd,0)=0xda;
  3073. WFIFOB(fd,2)=fail;
  3074. WFIFOSET(fd,packet_len_table[0xda]);
  3075. return 0;
  3076. }
  3077. /*==========================================
  3078. *
  3079. *------------------------------------------
  3080. */
  3081. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3082. {
  3083. int fd;
  3084. int i;
  3085. nullpo_retr(0, sd);
  3086. nullpo_retr(0, cd);
  3087. fd = sd->fd;
  3088. if (!session_isActive(fd))
  3089. return 0;
  3090. WFIFOHEAD(fd, 8 + (28*cd->users));
  3091. WFIFOW(fd, 0) = 0xdb;
  3092. WFIFOW(fd, 2) = 8 + (28*cd->users);
  3093. WFIFOL(fd, 4) = cd->bl.id;
  3094. for (i = 0; i < cd->users; i++) {
  3095. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  3096. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3097. }
  3098. WFIFOSET(fd, WFIFOW(fd, 2));
  3099. return 0;
  3100. }
  3101. /*==========================================
  3102. *
  3103. *------------------------------------------
  3104. */
  3105. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3106. {
  3107. unsigned char buf[32];
  3108. nullpo_retr(0, sd);
  3109. nullpo_retr(0, cd);
  3110. WBUFW(buf, 0) = 0x0dc;
  3111. WBUFW(buf, 2) = cd->users;
  3112. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3113. clif_send(buf,packet_len_table[0xdc],&sd->bl,CHAT_WOS);
  3114. return 0;
  3115. }
  3116. /*==========================================
  3117. *
  3118. *------------------------------------------
  3119. */
  3120. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  3121. {
  3122. unsigned char buf[64];
  3123. nullpo_retr(0, sd);
  3124. nullpo_retr(0, cd);
  3125. WBUFW(buf, 0) = 0xe1;
  3126. WBUFL(buf, 2) = 1;
  3127. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3128. WBUFW(buf,30) = 0xe1;
  3129. WBUFL(buf,32) = 0;
  3130. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3131. clif_send(buf,packet_len_table[0xe1]*2,&sd->bl,CHAT);
  3132. return 0;
  3133. }
  3134. /*==========================================
  3135. *
  3136. *------------------------------------------
  3137. */
  3138. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  3139. {
  3140. unsigned char buf[32];
  3141. nullpo_retr(0, sd);
  3142. nullpo_retr(0, cd);
  3143. WBUFW(buf, 0) = 0xdd;
  3144. WBUFW(buf, 2) = cd->users-1;
  3145. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3146. WBUFB(buf,28) = 0;
  3147. clif_send(buf,packet_len_table[0xdd],&sd->bl,CHAT);
  3148. return 0;
  3149. }
  3150. /*==========================================
  3151. * 取り引き要請受け
  3152. *------------------------------------------
  3153. */
  3154. int clif_traderequest(struct map_session_data *sd,char *name)
  3155. {
  3156. int fd;
  3157. nullpo_retr(0, sd);
  3158. fd=sd->fd;
  3159. WFIFOHEAD(fd,packet_len_table[0xe5]);
  3160. WFIFOW(fd,0)=0xe5;
  3161. strcpy((char*)WFIFOP(fd,2),name);
  3162. WFIFOSET(fd,packet_len_table[0xe5]);
  3163. return 0;
  3164. }
  3165. /*==========================================
  3166. * 取り引き要求応答
  3167. *------------------------------------------
  3168. */
  3169. int clif_tradestart(struct map_session_data *sd,int type)
  3170. {
  3171. int fd;
  3172. nullpo_retr(0, sd);
  3173. fd=sd->fd;
  3174. WFIFOHEAD(fd,packet_len_table[0xe7]);
  3175. WFIFOW(fd,0)=0xe7;
  3176. WFIFOB(fd,2)=type;
  3177. WFIFOSET(fd,packet_len_table[0xe7]);
  3178. return 0;
  3179. }
  3180. /*==========================================
  3181. * 相手方からのアイテム追加
  3182. *------------------------------------------
  3183. */
  3184. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  3185. {
  3186. int fd;
  3187. nullpo_retr(0, sd);
  3188. nullpo_retr(0, tsd);
  3189. fd=tsd->fd;
  3190. WFIFOHEAD(fd,packet_len_table[0xe9]);
  3191. WFIFOW(fd,0)=0xe9;
  3192. WFIFOL(fd,2)=amount;
  3193. if(index==0){
  3194. WFIFOW(fd,6) = 0; // type id
  3195. WFIFOB(fd,8) = 0; //identify flag
  3196. WFIFOB(fd,9) = 0; // attribute
  3197. WFIFOB(fd,10)= 0; //refine
  3198. WFIFOW(fd,11)= 0; //card (4w)
  3199. WFIFOW(fd,13)= 0; //card (4w)
  3200. WFIFOW(fd,15)= 0; //card (4w)
  3201. WFIFOW(fd,17)= 0; //card (4w)
  3202. }
  3203. else{
  3204. index-=2; //index fix
  3205. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3206. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3207. else
  3208. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3209. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3210. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3211. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3212. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3213. }
  3214. WFIFOSET(fd,packet_len_table[0xe9]);
  3215. return 0;
  3216. }
  3217. /*==========================================
  3218. * アイテム追加成功/失敗
  3219. *------------------------------------------
  3220. */
  3221. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3222. {
  3223. int fd;
  3224. nullpo_retr(0, sd);
  3225. fd=sd->fd;
  3226. WFIFOHEAD(fd,packet_len_table[0xea]);
  3227. WFIFOW(fd,0)=0xea;
  3228. WFIFOW(fd,2)=index;
  3229. WFIFOB(fd,4)=fail;
  3230. WFIFOSET(fd,packet_len_table[0xea]);
  3231. return 0;
  3232. }
  3233. /*==========================================
  3234. * 取り引きok押し
  3235. *------------------------------------------
  3236. */
  3237. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3238. {
  3239. int fd;
  3240. nullpo_retr(0, sd);
  3241. fd=sd->fd;
  3242. WFIFOHEAD(fd,packet_len_table[0xec]);
  3243. WFIFOW(fd,0)=0xec;
  3244. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3245. WFIFOSET(fd,packet_len_table[0xec]);
  3246. return 0;
  3247. }
  3248. /*==========================================
  3249. * 取り引きがキャンセルされました
  3250. *------------------------------------------
  3251. */
  3252. int clif_tradecancelled(struct map_session_data *sd)
  3253. {
  3254. int fd;
  3255. nullpo_retr(0, sd);
  3256. fd=sd->fd;
  3257. WFIFOHEAD(fd,packet_len_table[0xee]);
  3258. WFIFOW(fd,0)=0xee;
  3259. WFIFOSET(fd,packet_len_table[0xee]);
  3260. return 0;
  3261. }
  3262. /*==========================================
  3263. * 取り引き完了
  3264. *------------------------------------------
  3265. */
  3266. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3267. {
  3268. int fd;
  3269. nullpo_retr(0, sd);
  3270. fd=sd->fd;
  3271. WFIFOHEAD(fd,packet_len_table[0xf0]);
  3272. WFIFOW(fd,0)=0xf0;
  3273. WFIFOB(fd,2)=fail;
  3274. WFIFOSET(fd,packet_len_table[0xf0]);
  3275. return 0;
  3276. }
  3277. /*==========================================
  3278. * カプラ倉庫のアイテム数を更新
  3279. *------------------------------------------
  3280. */
  3281. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3282. {
  3283. int fd;
  3284. nullpo_retr(0, sd);
  3285. nullpo_retr(0, stor);
  3286. fd=sd->fd;
  3287. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3288. WFIFOW(fd,0) = 0xf2; // update storage amount
  3289. WFIFOW(fd,2) = stor->storage_amount; //items
  3290. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3291. WFIFOSET(fd,packet_len_table[0xf2]);
  3292. return 0;
  3293. }
  3294. /*==========================================
  3295. * カプラ倉庫にアイテムを追加する
  3296. *------------------------------------------
  3297. */
  3298. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3299. {
  3300. int view,fd;
  3301. nullpo_retr(0, sd);
  3302. nullpo_retr(0, stor);
  3303. fd=sd->fd;
  3304. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3305. WFIFOW(fd,0) =0xf4; // Storage item added
  3306. WFIFOW(fd,2) =index+1; // index
  3307. WFIFOL(fd,4) =amount; // amount
  3308. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3309. WFIFOW(fd,8) =view;
  3310. else
  3311. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3312. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3313. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3314. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3315. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3316. WFIFOSET(fd,packet_len_table[0xf4]);
  3317. return 0;
  3318. }
  3319. /*==========================================
  3320. *
  3321. *------------------------------------------
  3322. */
  3323. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3324. {
  3325. int fd;
  3326. nullpo_retr(0, sd);
  3327. nullpo_retr(0, stor);
  3328. fd=sd->fd;
  3329. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3330. WFIFOW(fd,0) = 0xf2; // update storage amount
  3331. WFIFOW(fd,2) = stor->storage_amount; //items
  3332. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3333. WFIFOSET(fd,packet_len_table[0xf2]);
  3334. return 0;
  3335. }
  3336. /*==========================================
  3337. *
  3338. *------------------------------------------
  3339. */
  3340. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3341. {
  3342. int view,fd;
  3343. nullpo_retr(0, sd);
  3344. nullpo_retr(0, stor);
  3345. fd=sd->fd;
  3346. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3347. WFIFOW(fd,0) =0xf4; // Storage item added
  3348. WFIFOW(fd,2) =index+1; // index
  3349. WFIFOL(fd,4) =amount; // amount
  3350. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3351. WFIFOW(fd,8) =view;
  3352. else
  3353. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3354. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3355. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3356. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3357. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3358. WFIFOSET(fd,packet_len_table[0xf4]);
  3359. return 0;
  3360. }
  3361. /*==========================================
  3362. * カプラ倉庫からアイテムを取り去る
  3363. *------------------------------------------
  3364. */
  3365. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3366. {
  3367. int fd;
  3368. nullpo_retr(0, sd);
  3369. fd=sd->fd;
  3370. WFIFOHEAD(fd,packet_len_table[0xf6]);
  3371. WFIFOW(fd,0)=0xf6; // Storage item removed
  3372. WFIFOW(fd,2)=index+1;
  3373. WFIFOL(fd,4)=amount;
  3374. WFIFOSET(fd,packet_len_table[0xf6]);
  3375. return 0;
  3376. }
  3377. /*==========================================
  3378. * カプラ倉庫を閉じる
  3379. *------------------------------------------
  3380. */
  3381. int clif_storageclose(struct map_session_data *sd)
  3382. {
  3383. int fd;
  3384. nullpo_retr(0, sd);
  3385. fd=sd->fd;
  3386. WFIFOHEAD(fd,packet_len_table[0xf8]);
  3387. WFIFOW(fd,0)=0xf8; // Storage Closed
  3388. WFIFOSET(fd,packet_len_table[0xf8]);
  3389. return 0;
  3390. }
  3391. //
  3392. // callback系 ?
  3393. //
  3394. /*==========================================
  3395. * PC表示
  3396. *------------------------------------------
  3397. */
  3398. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3399. {
  3400. int len;
  3401. if(dstsd->chatID){
  3402. struct chat_data *cd;
  3403. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3404. if(cd && cd->usersd[0]==dstsd)
  3405. clif_dispchat(cd,sd->fd);
  3406. }
  3407. if(dstsd->vender_id)
  3408. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3409. if(dstsd->spiritball > 0)
  3410. clif_spiritball_single(sd->fd, dstsd);
  3411. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3412. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3413. )
  3414. clif_hpmeter_single(sd->fd, dstsd);
  3415. if(dstsd->status.manner < 0)
  3416. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3417. // pvp circle for duel [LuzZza]
  3418. /*
  3419. if(dstsd->duel_group)
  3420. clif_specialeffect(&dstsd->bl, 159, 4);
  3421. */
  3422. }
  3423. void clif_getareachar_char(struct map_session_data* sd,struct block_list *bl)
  3424. {
  3425. struct unit_data *ud;
  3426. struct view_data *vd;
  3427. int len, fd = sd->fd;
  3428. vd = status_get_viewdata(bl);
  3429. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3430. return;
  3431. ud = unit_bl2ud(bl);
  3432. if (ud && ud->walktimer != -1)
  3433. {
  3434. #if PACKETVER > 6
  3435. WFIFOHEAD(fd, packet_len_table[0x22c]);
  3436. #elif PACKETVER > 3
  3437. WFIFOHEAD(fd, packet_len_table[0x1da]);
  3438. #else
  3439. WFIFOHEAD(fd, packet_len_table[0x7b]);
  3440. #endif
  3441. len = clif_set007b(bl,vd,ud,WFIFOP(fd,0));
  3442. WFIFOSET(fd,len);
  3443. } else {
  3444. #if PACKETVER > 6
  3445. WFIFOHEAD(fd,packet_len_table[0x22a]);
  3446. #elif PACKETVER > 3
  3447. WFIFOHEAD(fd,packet_len_table[0x1d8]);
  3448. #else
  3449. WFIFOHEAD(fd,packet_len_table[0x78]);
  3450. #endif
  3451. len = clif_set0078(bl,vd,WFIFOP(fd,0));
  3452. WFIFOSET(fd,len);
  3453. }
  3454. if (vd->cloth_color)
  3455. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3456. switch (bl->type)
  3457. {
  3458. case BL_PC:
  3459. {
  3460. TBL_PC* tsd = (TBL_PC*)bl;
  3461. clif_getareachar_pc(sd, tsd);
  3462. if(tsd->state.size==2) // tiny/big players [Valaris]
  3463. clif_specialeffect(bl,423,AREA);
  3464. else if(tsd->state.size==1)
  3465. clif_specialeffect(bl,421,AREA);
  3466. }
  3467. break;
  3468. case BL_NPC:
  3469. {
  3470. if(((TBL_NPC*)bl)->chat_id)
  3471. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3472. }
  3473. break;
  3474. case BL_MOB:
  3475. {
  3476. TBL_MOB* md = (TBL_MOB*)bl;
  3477. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3478. clif_specialeffect(bl,423,AREA);
  3479. else if(md->special_state.size==1)
  3480. clif_specialeffect(bl,421,AREA);
  3481. }
  3482. break;
  3483. }
  3484. }
  3485. /*==========================================
  3486. * Older fix pos packet.
  3487. *------------------------------------------
  3488. */
  3489. int clif_fixpos2(struct block_list* bl)
  3490. {
  3491. struct unit_data *ud;
  3492. struct view_data *vd;
  3493. unsigned char buf[256];
  3494. int len;
  3495. nullpo_retr(0, bl);
  3496. ud = unit_bl2ud(bl);
  3497. vd = status_get_viewdata(bl);
  3498. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3499. return 0;
  3500. if(ud && ud->walktimer != -1)
  3501. len = clif_set007b(bl,vd,ud,buf);
  3502. else
  3503. len = clif_set0078(bl,vd,buf);
  3504. if (disguised(bl)) {
  3505. clif_send(buf,len,bl,AREA_WOS);
  3506. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  3507. clif_setdisguise((TBL_PC*)bl, buf, len, 1);
  3508. } else
  3509. clif_send(buf,len,bl,AREA);
  3510. return 0;
  3511. }
  3512. //Modifies the type of damage according to status changes [Skotlex]
  3513. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3514. /*==========================================
  3515. * Estimates walk delay based on the damage criteria. [Skotlex]
  3516. *------------------------------------------
  3517. */
  3518. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3519. if (type == 4 || type == 9 || damage <=0)
  3520. return 0;
  3521. if (bl->type == BL_PC) {
  3522. if (battle_config.pc_walk_delay_rate != 100)
  3523. delay = delay*battle_config.pc_walk_delay_rate/100;
  3524. } else
  3525. if (battle_config.walk_delay_rate != 100)
  3526. delay = delay*battle_config.walk_delay_rate/100;
  3527. if (div_ > 1) //Multi-hit skills mean higher delays.
  3528. delay += battle_config.multihit_delay*(div_-1);
  3529. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3530. }
  3531. /*==========================================
  3532. * 通常攻撃エフェクト&ダメージ
  3533. *------------------------------------------
  3534. */
  3535. 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)
  3536. {
  3537. unsigned char buf[256];
  3538. struct status_change *sc;
  3539. nullpo_retr(0, src);
  3540. nullpo_retr(0, dst);
  3541. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3542. sc = status_get_sc(dst);
  3543. if(sc && sc->count) {
  3544. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3545. if(damage > 0)
  3546. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3547. if(damage2 > 0)
  3548. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3549. }
  3550. }
  3551. WBUFW(buf,0)=0x8a;
  3552. WBUFL(buf,2)=src->id;
  3553. WBUFL(buf,6)=dst->id;
  3554. WBUFL(buf,10)=tick;
  3555. WBUFL(buf,14)=sdelay;
  3556. WBUFL(buf,18)=ddelay;
  3557. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3558. WBUFW(buf,22)=damage?div:0;
  3559. WBUFW(buf,27)=damage2?div:0;
  3560. } else {
  3561. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3562. WBUFW(buf,27)=damage2;
  3563. }
  3564. WBUFW(buf,24)=div;
  3565. WBUFB(buf,26)=type;
  3566. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3567. if(disguised(src)) {
  3568. WBUFL(buf,2)=-src->id;
  3569. if(damage > 0)
  3570. WBUFW(buf,22)=-1;
  3571. if(damage2 > 0)
  3572. WBUFW(buf,27)=-1;
  3573. clif_send(buf,packet_len_table[0x8a],src,SELF);
  3574. }
  3575. if (disguised(dst)) {
  3576. WBUFL(buf,6)=-dst->id;
  3577. if (disguised(src))
  3578. WBUFL(buf,2)=src->id;
  3579. else {
  3580. if(damage > 0)
  3581. WBUFW(buf,22)=-1;
  3582. if(damage2 > 0)
  3583. WBUFW(buf,27)=-1;
  3584. }
  3585. clif_send(buf,packet_len_table[0x8a],dst,SELF);
  3586. }
  3587. //Return adjusted can't walk delay for further processing.
  3588. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3589. }
  3590. /*==========================================
  3591. *
  3592. *------------------------------------------
  3593. */
  3594. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3595. {
  3596. int view,fd;
  3597. fd=sd->fd;
  3598. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3599. WFIFOHEAD(fd,packet_len_table[0x9d]);
  3600. WFIFOW(fd,0)=0x9d;
  3601. WFIFOL(fd,2)=fitem->bl.id;
  3602. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3603. WFIFOW(fd,6)=view;
  3604. else
  3605. WFIFOW(fd,6)=fitem->item_data.nameid;
  3606. WFIFOB(fd,8)=fitem->item_data.identify;
  3607. WFIFOW(fd,9)=fitem->bl.x;
  3608. WFIFOW(fd,11)=fitem->bl.y;
  3609. WFIFOW(fd,13)=fitem->item_data.amount;
  3610. WFIFOB(fd,15)=fitem->subx;
  3611. WFIFOB(fd,16)=fitem->suby;
  3612. WFIFOSET(fd,packet_len_table[0x9d]);
  3613. }
  3614. /*==========================================
  3615. * 場所スキルエフェクトが視界に入る
  3616. *------------------------------------------
  3617. */
  3618. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3619. {
  3620. int fd;
  3621. struct block_list *bl;
  3622. fd=sd->fd;
  3623. bl=map_id2bl(unit->group->src_id);
  3624. #if PACKETVER >= 3
  3625. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3626. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3627. malloc_set(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3628. WFIFOW(fd, 0)=0x1c9;
  3629. WFIFOL(fd, 2)=unit->bl.id;
  3630. WFIFOL(fd, 6)=unit->group->src_id;
  3631. WFIFOW(fd,10)=unit->bl.x;
  3632. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3633. WFIFOB(fd,14)=unit->group->unit_id;
  3634. WFIFOB(fd,15)=1;
  3635. WFIFOB(fd,16)=1;
  3636. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3637. WFIFOSET(fd,packet_len_table[0x1c9]);
  3638. return 0;
  3639. }
  3640. #endif
  3641. WFIFOHEAD(fd,packet_len_table[0x11f]);
  3642. malloc_set(WFIFOP(fd,0),0,packet_len_table[0x11f]);
  3643. WFIFOW(fd, 0)=0x11f;
  3644. WFIFOL(fd, 2)=unit->bl.id;
  3645. WFIFOL(fd, 6)=unit->group->src_id;
  3646. WFIFOW(fd,10)=unit->bl.x;
  3647. WFIFOW(fd,12)=unit->bl.y;
  3648. //Use invisible unit id for traps.
  3649. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3650. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3651. else
  3652. WFIFOB(fd,14)=unit->group->unit_id;
  3653. WFIFOB(fd,15)=0;
  3654. WFIFOSET(fd,packet_len_table[0x11f]);
  3655. if(unit->group->skill_id == WZ_ICEWALL)
  3656. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3657. return 0;
  3658. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3659. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3660. malloc_set(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3661. WFIFOW(fd, 0)=0x1c9;
  3662. WFIFOL(fd, 2)=unit->bl.id;
  3663. WFIFOL(fd, 6)=unit->group->src_id;
  3664. WFIFOW(fd,10)=unit->bl.x;
  3665. WFIFOW(fd,12)=unit->bl.y;
  3666. WFIFOB(fd,14)=unit->group->unit_id;
  3667. WFIFOB(fd,15)=1;
  3668. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3669. WFIFOB(fd,16)=1;
  3670. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3671. } else {
  3672. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3673. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3674. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3675. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3676. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3677. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3678. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3679. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3680. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3681. //37-39
  3682. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3683. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3684. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3685. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3686. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3687. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3688. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3689. //65-68
  3690. //69-72
  3691. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3692. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3693. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3694. }
  3695. WFIFOSET(fd,packet_len_table[0x1c9]);
  3696. #endif
  3697. if(unit->group->skill_id == WZ_ICEWALL)
  3698. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3699. return 0;
  3700. */
  3701. }
  3702. /*==========================================
  3703. * 場所スキルエフェクトが視界から消える
  3704. *------------------------------------------
  3705. */
  3706. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3707. {
  3708. nullpo_retr(0, unit);
  3709. WFIFOHEAD(fd,packet_len_table[0x120]);
  3710. WFIFOW(fd, 0)=0x120;
  3711. WFIFOL(fd, 2)=unit->bl.id;
  3712. WFIFOSET(fd,packet_len_table[0x120]);
  3713. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3714. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3715. return 0;
  3716. }
  3717. /*==========================================
  3718. *
  3719. *------------------------------------------
  3720. */
  3721. int clif_01ac(struct block_list *bl)
  3722. {
  3723. unsigned char buf[32];
  3724. nullpo_retr(0, bl);
  3725. WBUFW(buf, 0) = 0x1ac;
  3726. WBUFL(buf, 2) = bl->id;
  3727. clif_send(buf,packet_len_table[0x1ac],bl,AREA);
  3728. return 0;
  3729. }
  3730. /*==========================================
  3731. *
  3732. *------------------------------------------
  3733. */
  3734. int clif_getareachar(struct block_list* bl,va_list ap)
  3735. {
  3736. struct map_session_data *sd;
  3737. nullpo_retr(0, bl);
  3738. nullpo_retr(0, ap);
  3739. sd=va_arg(ap,struct map_session_data*);
  3740. if (sd == NULL || !sd->fd || session[sd->fd] == NULL)
  3741. return 0;
  3742. switch(bl->type){
  3743. case BL_ITEM:
  3744. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3745. break;
  3746. case BL_SKILL:
  3747. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3748. break;
  3749. default:
  3750. if(&sd->bl == bl)
  3751. break;
  3752. clif_getareachar_char(sd,bl);
  3753. break;
  3754. }
  3755. return 0;
  3756. }
  3757. /*==========================================
  3758. * tbl has gone out of view-size of bl
  3759. *------------------------------------------
  3760. */
  3761. int clif_outsight(struct block_list *bl,va_list ap)
  3762. {
  3763. struct block_list *tbl;
  3764. struct view_data *vd;
  3765. TBL_PC *sd, *tsd;
  3766. tbl=va_arg(ap,struct block_list*);
  3767. if(bl == tbl) return 0;
  3768. BL_CAST(BL_PC, bl, sd);
  3769. BL_CAST(BL_PC, tbl, tsd);
  3770. if (tsd && tsd->fd)
  3771. { //tsd has lost sight of the bl object.
  3772. switch(bl->type){
  3773. case BL_PC:
  3774. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3775. clif_clearchar_id(bl->id,0,tsd->fd);
  3776. if(sd->chatID){
  3777. struct chat_data *cd;
  3778. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3779. if(cd->usersd[0]==sd)
  3780. clif_dispchat(cd,tsd->fd);
  3781. }
  3782. if(sd->vender_id)
  3783. clif_closevendingboard(bl,tsd->fd);
  3784. break;
  3785. case BL_ITEM:
  3786. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3787. break;
  3788. case BL_SKILL:
  3789. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3790. break;
  3791. default:
  3792. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3793. clif_clearchar_id(bl->id,0,tsd->fd);
  3794. break;
  3795. }
  3796. }
  3797. if (sd && sd->fd)
  3798. { //sd is watching tbl go out of view.
  3799. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3800. clif_clearchar_id(tbl->id,0,sd->fd);
  3801. }
  3802. return 0;
  3803. }
  3804. /*==========================================
  3805. * tbl has come into view of bl
  3806. *------------------------------------------
  3807. */
  3808. int clif_insight(struct block_list *bl,va_list ap)
  3809. {
  3810. struct block_list *tbl;
  3811. TBL_PC *sd, *tsd;
  3812. tbl=va_arg(ap,struct block_list*);
  3813. if (bl == tbl) return 0;
  3814. BL_CAST(BL_PC, bl, sd);
  3815. BL_CAST(BL_PC, tbl, tsd);
  3816. if (tsd && tsd->fd)
  3817. { //Tell tsd that bl entered into his view
  3818. switch(bl->type){
  3819. case BL_ITEM:
  3820. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3821. break;
  3822. case BL_SKILL:
  3823. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3824. break;
  3825. default:
  3826. clif_getareachar_char(tsd,bl);
  3827. break;
  3828. }
  3829. }
  3830. if (sd && sd->fd)
  3831. { //Tell sd that tbl walked into his view
  3832. clif_getareachar_char(sd,tbl);
  3833. }
  3834. return 0;
  3835. }
  3836. /*==========================================
  3837. *
  3838. *------------------------------------------
  3839. */
  3840. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3841. {
  3842. int fd,id, inf2;
  3843. nullpo_retr(0, sd);
  3844. fd=sd->fd;
  3845. if( (id=sd->status.skill[skillid].id) <= 0 )
  3846. return 0;
  3847. WFIFOHEAD(fd,packet_len_table[0x147]);
  3848. WFIFOW(fd,0)=0x147;
  3849. WFIFOW(fd,2) = id;
  3850. if(type < 0)
  3851. WFIFOW(fd,4) = skill_get_inf(id);
  3852. else
  3853. WFIFOW(fd,4) = type;
  3854. WFIFOW(fd,6) = 0;
  3855. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3856. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3857. if(range < 0)
  3858. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3859. WFIFOW(fd,12)= range;
  3860. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3861. inf2 = skill_get_inf2(id);
  3862. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3863. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3864. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill))
  3865. //WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_get_max(id) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3866. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3867. else
  3868. WFIFOB(fd,38) = 0;
  3869. WFIFOSET(fd,packet_len_table[0x147]);
  3870. return 0;
  3871. }
  3872. /*==========================================
  3873. * スキルリストを送信する
  3874. *------------------------------------------
  3875. */
  3876. int clif_skillinfoblock(struct map_session_data *sd)
  3877. {
  3878. int fd;
  3879. int i,c,len=4,id, inf2;
  3880. nullpo_retr(0, sd);
  3881. fd=sd->fd;
  3882. if (!fd) return 0;
  3883. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3884. WFIFOW(fd,0)=0x10f;
  3885. for ( i = c = 0; i < MAX_SKILL; i++){
  3886. if( (id=sd->status.skill[i].id)!=0 ){
  3887. WFIFOW(fd,len ) = id;
  3888. WFIFOW(fd,len+2) = skill_get_inf(id);
  3889. WFIFOW(fd,len+4) = 0;
  3890. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3891. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3892. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3893. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3894. inf2 = skill_get_inf2(id);
  3895. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3896. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3897. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill) )
  3898. WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[i].flag ==0 )? 1:0;
  3899. else
  3900. WFIFOB(fd,len+36) = 0;
  3901. len+=37;
  3902. c++;
  3903. }
  3904. }
  3905. WFIFOW(fd,2)=len;
  3906. WFIFOSET(fd,len);
  3907. return 1;
  3908. }
  3909. /*==========================================
  3910. * スキル割り振り通知
  3911. *------------------------------------------
  3912. */
  3913. int clif_skillup(struct map_session_data *sd,int skill_num)
  3914. {
  3915. int fd;
  3916. nullpo_retr(0, sd);
  3917. fd=sd->fd;
  3918. WFIFOHEAD(fd,packet_len_table[0x10e]);
  3919. WFIFOW(fd,0) = 0x10e;
  3920. WFIFOW(fd,2) = skill_num;
  3921. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3922. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3923. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3924. //WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_get_max(sd->status.skill[skill_num].id)) ? 1 : 0;
  3925. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3926. WFIFOSET(fd,packet_len_table[0x10e]);
  3927. return 0;
  3928. }
  3929. /*==========================================
  3930. * スキル詠唱エフェクトを送信する
  3931. *------------------------------------------
  3932. */
  3933. int clif_skillcasting(struct block_list* bl,
  3934. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  3935. {
  3936. int pl = skill_get_pl(skill_num);
  3937. unsigned char buf[32];
  3938. WBUFW(buf,0) = 0x13e;
  3939. WBUFL(buf,2) = src_id;
  3940. WBUFL(buf,6) = dst_id;
  3941. WBUFW(buf,10) = dst_x;
  3942. WBUFW(buf,12) = dst_y;
  3943. WBUFW(buf,14) = skill_num;
  3944. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3945. WBUFL(buf,20) = casttime;
  3946. clif_send(buf,packet_len_table[0x13e], bl, AREA);
  3947. if (disguised(bl)) {
  3948. WBUFL(buf,2) = -src_id;
  3949. WBUFL(buf,20) = 0;
  3950. clif_send(buf,packet_len_table[0x13e], bl, SELF);
  3951. }
  3952. return 0;
  3953. }
  3954. /*==========================================
  3955. *
  3956. *------------------------------------------
  3957. */
  3958. int clif_skillcastcancel(struct block_list* bl)
  3959. {
  3960. unsigned char buf[16];
  3961. nullpo_retr(0, bl);
  3962. WBUFW(buf,0) = 0x1b9;
  3963. WBUFL(buf,2) = bl->id;
  3964. clif_send(buf,packet_len_table[0x1b9], bl, AREA);
  3965. return 0;
  3966. }
  3967. /*==========================================
  3968. * スキル詠唱失敗
  3969. *------------------------------------------
  3970. */
  3971. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3972. {
  3973. int fd;
  3974. if (!sd) { //Since this is the most common nullpo....
  3975. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3976. return 0;
  3977. }
  3978. fd=sd->fd;
  3979. if(battle_config.display_skill_fail&1)
  3980. return 0; //Disable all skill failed messages
  3981. if(type==0x4 && !sd->state.showdelay)
  3982. return 0; //Disable delay failed messages
  3983. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3984. return 0;
  3985. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3986. return 0;
  3987. WFIFOHEAD(fd,packet_len_table[0x110]);
  3988. WFIFOW(fd,0) = 0x110;
  3989. WFIFOW(fd,2) = skill_id;
  3990. WFIFOW(fd,4) = btype;
  3991. WFIFOW(fd,6) = 0;
  3992. WFIFOB(fd,8) = 0;
  3993. WFIFOB(fd,9) = type;
  3994. WFIFOSET(fd,packet_len_table[0x110]);
  3995. return 1;
  3996. }
  3997. /*==========================================
  3998. * スキル攻撃エフェクト&ダメージ
  3999. *------------------------------------------
  4000. */
  4001. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  4002. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4003. {
  4004. unsigned char buf[64];
  4005. struct status_change *sc;
  4006. nullpo_retr(0, src);
  4007. nullpo_retr(0, dst);
  4008. type = (type>0)?type:skill_get_hit(skill_id);
  4009. type = clif_calc_delay(type, ddelay);
  4010. sc = status_get_sc(dst);
  4011. if(sc && sc->count) {
  4012. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  4013. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  4014. }
  4015. #if PACKETVER < 3
  4016. WBUFW(buf,0)=0x114;
  4017. WBUFW(buf,2)=skill_id;
  4018. WBUFL(buf,4)=src->id;
  4019. WBUFL(buf,8)=dst->id;
  4020. WBUFL(buf,12)=tick;
  4021. WBUFL(buf,16)=sdelay;
  4022. WBUFL(buf,20)=ddelay;
  4023. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4024. WBUFW(buf,24)=damage?div:0;
  4025. } else {
  4026. WBUFW(buf,24)=damage;
  4027. }
  4028. WBUFW(buf,26)=skill_lv;
  4029. WBUFW(buf,28)=div;
  4030. WBUFB(buf,30)=type;
  4031. clif_send(buf,packet_len_table[0x114],src,AREA);
  4032. if(disguised(src)) {
  4033. WBUFL(buf,4)=-src->id;
  4034. if(damage > 0)
  4035. WBUFW(buf,24)=-1;
  4036. clif_send(buf,packet_len_table[0x114],src,SELF);
  4037. }
  4038. if (disguised(dst)) {
  4039. WBUFL(buf,8)=-dst->id;
  4040. if (disguised(src))
  4041. WBUFL(buf,4)=src->id;
  4042. else if(damage > 0)
  4043. WBUFW(buf,24)=-1;
  4044. clif_send(buf,packet_len_table[0x114],dst,SELF);
  4045. }
  4046. #else
  4047. WBUFW(buf,0)=0x1de;
  4048. WBUFW(buf,2)=skill_id;
  4049. WBUFL(buf,4)=src->id;
  4050. WBUFL(buf,8)=dst->id;
  4051. WBUFL(buf,12)=tick;
  4052. WBUFL(buf,16)=sdelay;
  4053. WBUFL(buf,20)=ddelay;
  4054. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4055. WBUFL(buf,24)=damage?div:0;
  4056. } else {
  4057. WBUFL(buf,24)=damage;
  4058. }
  4059. WBUFW(buf,28)=skill_lv;
  4060. WBUFW(buf,30)=div;
  4061. WBUFB(buf,32)=type;
  4062. clif_send(buf,packet_len_table[0x1de],src,AREA);
  4063. if(disguised(src)) {
  4064. WBUFL(buf,4)=-src->id;
  4065. if(damage > 0)
  4066. WBUFW(buf,24)=-1;
  4067. clif_send(buf,packet_len_table[0x1de],src,SELF);
  4068. }
  4069. if (disguised(dst)) {
  4070. WBUFL(buf,8)=-dst->id;
  4071. if (disguised(src))
  4072. WBUFL(buf,4)=src->id;
  4073. else if(damage > 0)
  4074. WBUFW(buf,24)=-1;
  4075. clif_send(buf,packet_len_table[0x1de],dst,SELF);
  4076. }
  4077. #endif
  4078. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4079. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4080. }
  4081. /*==========================================
  4082. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  4083. *------------------------------------------
  4084. */
  4085. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  4086. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4087. {
  4088. unsigned char buf[64];
  4089. struct status_change *sc;
  4090. nullpo_retr(0, src);
  4091. nullpo_retr(0, dst);
  4092. type = (type>0)?type:skill_get_hit(skill_id);
  4093. type = clif_calc_delay(type, ddelay);
  4094. sc = status_get_sc(dst);
  4095. if(sc && sc->count) {
  4096. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  4097. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  4098. }
  4099. WBUFW(buf,0)=0x115;
  4100. WBUFW(buf,2)=skill_id;
  4101. WBUFL(buf,4)=src->id;
  4102. WBUFL(buf,8)=dst->id;
  4103. WBUFL(buf,12)=tick;
  4104. WBUFL(buf,16)=sdelay;
  4105. WBUFL(buf,20)=ddelay;
  4106. WBUFW(buf,24)=dst->x;
  4107. WBUFW(buf,26)=dst->y;
  4108. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4109. WBUFW(buf,28)=damage?div:0;
  4110. } else {
  4111. WBUFW(buf,28)=damage;
  4112. }
  4113. WBUFW(buf,30)=skill_lv;
  4114. WBUFW(buf,32)=div;
  4115. WBUFB(buf,34)=type;
  4116. clif_send(buf,packet_len_table[0x115],src,AREA);
  4117. if(disguised(src)) {
  4118. WBUFL(buf,4)=-src->id;
  4119. if(damage > 0)
  4120. WBUFW(buf,28)=-1;
  4121. clif_send(buf,packet_len_table[0x115],src,SELF);
  4122. }
  4123. if (disguised(dst)) {
  4124. WBUFL(buf,8)=-dst->id;
  4125. if (disguised(src))
  4126. WBUFL(buf,4)=src->id;
  4127. else if(damage > 0)
  4128. WBUFW(buf,28)=-1;
  4129. clif_send(buf,packet_len_table[0x115],dst,SELF);
  4130. }
  4131. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4132. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4133. }
  4134. /*==========================================
  4135. * 支援/回復スキルエフェクト
  4136. *------------------------------------------
  4137. */
  4138. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  4139. int skill_id,int heal,int fail)
  4140. {
  4141. unsigned char buf[32];
  4142. nullpo_retr(0, dst);
  4143. WBUFW(buf,0)=0x11a;
  4144. WBUFW(buf,2)=skill_id;
  4145. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  4146. WBUFL(buf,6)=dst->id;
  4147. WBUFL(buf,10)=src?src->id:0;
  4148. WBUFB(buf,14)=fail;
  4149. clif_send(buf,packet_len_table[0x11a],dst,AREA);
  4150. if (disguised(dst)) {
  4151. WBUFL(buf,6)=-dst->id;
  4152. clif_send(buf,packet_len_table[0x115],dst,SELF);
  4153. }
  4154. if(src && disguised(src)) {
  4155. WBUFL(buf,10)=-src->id;
  4156. if (disguised(dst))
  4157. WBUFL(buf,6)=dst->id;
  4158. clif_send(buf,packet_len_table[0x115],src,SELF);
  4159. }
  4160. return fail;
  4161. }
  4162. /*==========================================
  4163. * 場所スキルエフェクト
  4164. *------------------------------------------
  4165. */
  4166. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4167. {
  4168. unsigned char buf[32];
  4169. nullpo_retr(0, src);
  4170. WBUFW(buf,0)=0x117;
  4171. WBUFW(buf,2)=skill_id;
  4172. WBUFL(buf,4)=src->id;
  4173. WBUFW(buf,8)=val;
  4174. WBUFW(buf,10)=x;
  4175. WBUFW(buf,12)=y;
  4176. WBUFL(buf,14)=tick;
  4177. clif_send(buf,packet_len_table[0x117],src,AREA);
  4178. if(disguised(src)) {
  4179. WBUFL(buf,4)=-src->id;
  4180. clif_send(buf,packet_len_table[0x117],src,SELF);
  4181. }
  4182. return 0;
  4183. }
  4184. /*==========================================
  4185. * 場所スキルエフェクト表示
  4186. *------------------------------------------
  4187. */
  4188. int clif_skill_setunit(struct skill_unit *unit)
  4189. {
  4190. unsigned char buf[128];
  4191. struct block_list *bl;
  4192. nullpo_retr(0, unit);
  4193. bl=map_id2bl(unit->group->src_id);
  4194. // These are invisible client-side, but are necessary because
  4195. // otherwise the client will not know who caused the attack.
  4196. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  4197. // return 0;
  4198. #if PACKETVER >= 3
  4199. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4200. malloc_set(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4201. WBUFW(buf, 0)=0x1c9;
  4202. WBUFL(buf, 2)=unit->bl.id;
  4203. WBUFL(buf, 6)=unit->group->src_id;
  4204. WBUFW(buf,10)=unit->bl.x;
  4205. WBUFW(buf,12)=unit->bl.y;
  4206. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4207. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4208. } else {
  4209. WBUFB(buf,14)=unit->group->unit_id;
  4210. }
  4211. WBUFB(buf,15)=1;
  4212. WBUFB(buf,16)=1;
  4213. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4214. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4215. return 0;
  4216. }
  4217. #endif
  4218. malloc_set(WBUFP(buf, 0),0,packet_len_table[0x11f]);
  4219. WBUFW(buf, 0)=0x11f;
  4220. WBUFL(buf, 2)=unit->bl.id;
  4221. WBUFL(buf, 6)=unit->group->src_id;
  4222. WBUFW(buf,10)=unit->bl.x;
  4223. WBUFW(buf,12)=unit->bl.y;
  4224. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4225. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4226. } else {
  4227. WBUFB(buf,14)=unit->group->unit_id;
  4228. }
  4229. WBUFB(buf,15)=0;
  4230. clif_send(buf,packet_len_table[0x11f],&unit->bl,AREA);
  4231. return 0;
  4232. /* Previous mysterious implementation noone really understands. [Skotlex]
  4233. malloc_set(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4234. WBUFW(buf, 0)=0x1c9;
  4235. WBUFL(buf, 2)=unit->bl.id;
  4236. WBUFL(buf, 6)=unit->group->src_id;
  4237. WBUFW(buf,10)=unit->bl.x;
  4238. WBUFW(buf,12)=unit->bl.y;
  4239. WBUFB(buf,14)=unit->group->unit_id;
  4240. WBUFB(buf,15)=1;
  4241. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4242. WBUFB(buf,16)=1;
  4243. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4244. } else {
  4245. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4246. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4247. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4248. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4249. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4250. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4251. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4252. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4253. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4254. //37-39
  4255. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4256. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4257. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4258. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4259. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4260. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4261. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4262. //65-68
  4263. //69-72
  4264. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4265. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4266. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4267. }
  4268. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4269. #endif
  4270. return 0;
  4271. */
  4272. }
  4273. /*==========================================
  4274. * 場所スキルエフェクト削除
  4275. *------------------------------------------
  4276. */
  4277. int clif_skill_delunit(struct skill_unit *unit)
  4278. {
  4279. unsigned char buf[16];
  4280. nullpo_retr(0, unit);
  4281. WBUFW(buf, 0)=0x120;
  4282. WBUFL(buf, 2)=unit->bl.id;
  4283. clif_send(buf,packet_len_table[0x120],&unit->bl,AREA);
  4284. return 0;
  4285. }
  4286. /*==========================================
  4287. * ワープ場所選択
  4288. *------------------------------------------
  4289. */
  4290. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4291. const char *map1,const char *map2,const char *map3,const char *map4)
  4292. {
  4293. int fd;
  4294. nullpo_retr(0, sd);
  4295. fd=sd->fd;
  4296. WFIFOHEAD(fd,packet_len_table[0x11c]);
  4297. WFIFOW(fd,0)=0x11c;
  4298. WFIFOW(fd,2)=skill_num;
  4299. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4300. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4301. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4302. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4303. WFIFOSET(fd,packet_len_table[0x11c]);
  4304. sd->menuskill_id = skill_num;
  4305. if (skill_num == AL_WARP)
  4306. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4307. else
  4308. sd->menuskill_lv = skill_lv;
  4309. return 0;
  4310. }
  4311. /*==========================================
  4312. * メモ応答
  4313. *------------------------------------------
  4314. */
  4315. int clif_skill_memo(struct map_session_data *sd,int flag)
  4316. {
  4317. int fd;
  4318. nullpo_retr(0, sd);
  4319. fd=sd->fd;
  4320. WFIFOHEAD(fd,packet_len_table[0x11e]);
  4321. WFIFOW(fd,0)=0x11e;
  4322. WFIFOB(fd,2)=flag;
  4323. WFIFOSET(fd,packet_len_table[0x11e]);
  4324. return 0;
  4325. }
  4326. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4327. {
  4328. int fd;
  4329. nullpo_retr(0, sd);
  4330. fd=sd->fd;
  4331. WFIFOHEAD(fd,packet_len_table[0x189]);
  4332. WFIFOW(fd,0)=0x189;
  4333. WFIFOW(fd,2)=flag;
  4334. WFIFOSET(fd,packet_len_table[0x189]);
  4335. return 0;
  4336. }
  4337. /*==========================================
  4338. * モンスター情報
  4339. *------------------------------------------
  4340. */
  4341. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4342. {
  4343. struct status_data *status;
  4344. unsigned char buf[64];
  4345. int i;//, fix;
  4346. nullpo_retr(0, sd);
  4347. nullpo_retr(0, dst);
  4348. if(dst->type!=BL_MOB )
  4349. return 0;
  4350. status = status_get_status_data(dst);
  4351. WBUFW(buf, 0)=0x18c;
  4352. WBUFW(buf, 2)=status_get_class(dst);
  4353. WBUFW(buf, 4)=status_get_lv(dst);
  4354. WBUFW(buf, 6)=status->size;
  4355. WBUFL(buf, 8)=status->hp;
  4356. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4357. +(battle_config.estimation_type&2?status->def2:0);
  4358. WBUFW(buf,14)=status->race;
  4359. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4360. +(battle_config.estimation_type&2?status->mdef2:0);
  4361. WBUFW(buf,18)= status->def_ele;
  4362. for(i=0;i<9;i++)
  4363. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4364. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4365. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4366. clif_send(buf,packet_len_table[0x18c],&sd->bl,
  4367. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4368. return 0;
  4369. }
  4370. /*==========================================
  4371. * アイテム合成可能リスト
  4372. *------------------------------------------
  4373. */
  4374. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4375. {
  4376. int i,c,view,fd;
  4377. nullpo_retr(0, sd);
  4378. if(sd->menuskill_id == AM_PHARMACY)
  4379. return 0; //Avoid resending the menu twice or more times...
  4380. fd=sd->fd;
  4381. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4382. WFIFOW(fd, 0)=0x18d;
  4383. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4384. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4385. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4386. WFIFOW(fd,c*8+ 4)= view;
  4387. else
  4388. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4389. WFIFOW(fd,c*8+ 6)= 0x0012;
  4390. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4391. c++;
  4392. }
  4393. }
  4394. WFIFOW(fd, 2)=c*8+8;
  4395. WFIFOSET(fd,WFIFOW(fd,2));
  4396. if(c > 0) {
  4397. sd->menuskill_id = AM_PHARMACY;
  4398. sd->menuskill_lv = trigger;
  4399. return 1;
  4400. }
  4401. return 0;
  4402. }
  4403. /*==========================================
  4404. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4405. *------------------------------------------
  4406. */
  4407. int clif_status_load(struct block_list *bl,int type, int flag)
  4408. {
  4409. int fd;
  4410. if (type == SI_BLANK) //It shows nothing on the client...
  4411. return 0;
  4412. if (bl->type != BL_PC)
  4413. return 0;
  4414. fd = ((struct map_session_data*)bl)->fd;
  4415. WFIFOHEAD(fd,packet_len_table[0x196]);
  4416. WFIFOW(fd,0)=0x0196;
  4417. WFIFOW(fd,2)=type;
  4418. WFIFOL(fd,4)=bl->id;
  4419. WFIFOB(fd,8)=flag; //Status start
  4420. WFIFOSET(fd, packet_len_table[0x196]);
  4421. return 0;
  4422. }
  4423. /*==========================================
  4424. * 状態異常アイコン/メッセージ表示
  4425. *------------------------------------------
  4426. */
  4427. int clif_status_change(struct block_list *bl,int type,int flag)
  4428. {
  4429. unsigned char buf[16];
  4430. if (type == SI_BLANK) //It shows nothing on the client...
  4431. return 0;
  4432. nullpo_retr(0, bl);
  4433. WBUFW(buf,0)=0x0196;
  4434. WBUFW(buf,2)=type;
  4435. WBUFL(buf,4)=bl->id;
  4436. WBUFB(buf,8)=flag;
  4437. clif_send(buf,packet_len_table[0x196],bl,AREA);
  4438. return 0;
  4439. }
  4440. /*==========================================
  4441. * Send message (modified by [Yor])
  4442. *------------------------------------------
  4443. */
  4444. int clif_displaymessage(const int fd, char* mes)
  4445. {
  4446. // invalid pointer?
  4447. nullpo_retr(-1, mes);
  4448. //Console [Wizputer] //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4449. if (fd == 0)
  4450. return 0;
  4451. else {
  4452. int len_mes = strlen(mes);
  4453. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4454. WFIFOHEAD(fd, 5 + len_mes);
  4455. WFIFOW(fd,0) = 0x8e;
  4456. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4457. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4458. WFIFOSET(fd, 5 + len_mes);
  4459. }
  4460. }
  4461. return 0;
  4462. }
  4463. /*==========================================
  4464. * 天の声を送信する
  4465. *------------------------------------------
  4466. */
  4467. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4468. {
  4469. unsigned char *buf;
  4470. int lp;
  4471. lp = (flag & 0x10) ? 8 : 4;
  4472. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4473. WBUFW(buf,0) = 0x9a;
  4474. WBUFW(buf,2) = len + lp;
  4475. WBUFL(buf,4) = 0x65756c62; //"blue":
  4476. memcpy(WBUFP(buf,lp), mes, len);
  4477. flag &= 0x07;
  4478. clif_send(buf, WBUFW(buf,2), bl,
  4479. (flag == 1) ? ALL_SAMEMAP :
  4480. (flag == 2) ? AREA :
  4481. (flag == 3) ? SELF :
  4482. ALL_CLIENT);
  4483. if(buf) aFree(buf);
  4484. if(use_irc && irc_announce_flag && !flag)
  4485. irc_announce(mes);
  4486. return 0;
  4487. }
  4488. /*==========================================
  4489. * グローバルメッセージ
  4490. *------------------------------------------
  4491. */
  4492. void clif_GlobalMessage(struct block_list *bl,char *message)
  4493. {
  4494. char buf[100];
  4495. int len;
  4496. nullpo_retv(bl);
  4497. if(!message)
  4498. return;
  4499. len = strlen(message)+1;
  4500. WBUFW(buf,0)=0x8d;
  4501. WBUFW(buf,2)=len+8;
  4502. WBUFL(buf,4)=bl->id;
  4503. strncpy((char *) WBUFP(buf,8),message,len);
  4504. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4505. }
  4506. /*==========================================
  4507. * Send main chat message [LuzZza]
  4508. *------------------------------------------
  4509. */
  4510. void clif_MainChatMessage(char* message) {
  4511. char buf[200];
  4512. int len;
  4513. if(!message)
  4514. return;
  4515. len = strlen(message)+1;
  4516. if (len+8 > sizeof(buf)) {
  4517. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4518. len = sizeof(buf)-8;
  4519. }
  4520. WBUFW(buf,0)=0x8d;
  4521. WBUFW(buf,2)=len+8;
  4522. WBUFL(buf,4)=0;
  4523. strncpy((char *) WBUFP(buf,8),message,len);
  4524. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4525. }
  4526. /*==========================================
  4527. * Does an announce message in the given color.
  4528. *------------------------------------------
  4529. */
  4530. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4531. {
  4532. unsigned char *buf;
  4533. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4534. WBUFW(buf,0) = 0x1c3;
  4535. WBUFW(buf,2) = len + 16;
  4536. WBUFL(buf,4) = color;
  4537. WBUFW(buf,8) = 0x190; //Font style? Type?
  4538. WBUFW(buf,10) = 0x0c; //12? Font size?
  4539. WBUFL(buf,12) = 0; //Unknown!
  4540. memcpy(WBUFP(buf,16), mes, len);
  4541. flag &= 0x07;
  4542. clif_send(buf, WBUFW(buf,2), bl,
  4543. (flag == 1) ? ALL_SAMEMAP :
  4544. (flag == 2) ? AREA :
  4545. (flag == 3) ? SELF :
  4546. ALL_CLIENT);
  4547. if(buf) aFree(buf);
  4548. return 0;
  4549. }
  4550. /*==========================================
  4551. * HPSP回復エフェクトを送信する
  4552. *------------------------------------------
  4553. */
  4554. int clif_heal(int fd,int type,int val)
  4555. {
  4556. WFIFOHEAD(fd,packet_len_table[0x13d]);
  4557. WFIFOW(fd,0)=0x13d;
  4558. WFIFOW(fd,2)=type;
  4559. WFIFOW(fd,4)=val;
  4560. WFIFOSET(fd,packet_len_table[0x13d]);
  4561. return 0;
  4562. }
  4563. /*==========================================
  4564. * 復活する
  4565. *------------------------------------------
  4566. */
  4567. int clif_resurrection(struct block_list *bl,int type)
  4568. {
  4569. unsigned char buf[16];
  4570. nullpo_retr(0, bl);
  4571. WBUFW(buf,0)=0x148;
  4572. WBUFL(buf,2)=bl->id;
  4573. WBUFW(buf,6)=type;
  4574. clif_send(buf,packet_len_table[0x148],bl,type==1 ? AREA : AREA_WOS);
  4575. if (disguised(bl))
  4576. clif_spawn(bl);
  4577. return 0;
  4578. }
  4579. /*==========================================
  4580. * PVP実装?(仮)
  4581. *------------------------------------------
  4582. */
  4583. int clif_set0199(int fd,int type)
  4584. {
  4585. WFIFOHEAD(fd,packet_len_table[0x199]);
  4586. WFIFOW(fd,0)=0x199;
  4587. WFIFOW(fd,2)=type;
  4588. WFIFOSET(fd,packet_len_table[0x199]);
  4589. return 0;
  4590. }
  4591. /*==========================================
  4592. * PVP実装?(仮)
  4593. *------------------------------------------
  4594. */
  4595. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4596. {
  4597. nullpo_retr(0, sd);
  4598. if(type == 2) {
  4599. WFIFOHEAD(sd->fd,packet_len_table[0x19a]);
  4600. WFIFOW(sd->fd,0) = 0x19a;
  4601. WFIFOL(sd->fd,2) = sd->bl.id;
  4602. WFIFOL(sd->fd,6) = pvprank;
  4603. WFIFOL(sd->fd,10) = pvpnum;
  4604. WFIFOSET(sd->fd,packet_len_table[0x19a]);
  4605. } else {
  4606. unsigned char buf[32];
  4607. WBUFW(buf,0) = 0x19a;
  4608. WBUFL(buf,2) = sd->bl.id;
  4609. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4610. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4611. else
  4612. WBUFL(buf,6) = pvprank;
  4613. WBUFL(buf,10) = pvpnum;
  4614. if(sd->sc.option&OPTION_INVISIBLE)
  4615. clif_send(buf,packet_len_table[0x19a],&sd->bl,SELF);
  4616. else if(!type)
  4617. clif_send(buf,packet_len_table[0x19a],&sd->bl,AREA);
  4618. else
  4619. clif_send(buf,packet_len_table[0x19a],&sd->bl,ALL_SAMEMAP);
  4620. }
  4621. return 0;
  4622. }
  4623. /*==========================================
  4624. *
  4625. *------------------------------------------
  4626. */
  4627. int clif_send0199(int map,int type)
  4628. {
  4629. struct block_list bl;
  4630. unsigned char buf[16];
  4631. bl.id = 0;
  4632. bl.type = BL_NUL;
  4633. bl.m = map;
  4634. WBUFW(buf,0)=0x199;
  4635. WBUFW(buf,2)=type;
  4636. clif_send(buf,packet_len_table[0x199],&bl,ALL_SAMEMAP);
  4637. return 0;
  4638. }
  4639. /*==========================================
  4640. * 精錬エフェクトを送信する
  4641. *------------------------------------------
  4642. */
  4643. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  4644. {
  4645. WFIFOHEAD(fd,packet_len_table[0x188]);
  4646. WFIFOW(fd,0)=0x188;
  4647. WFIFOW(fd,2)=fail;
  4648. WFIFOW(fd,4)=index+2;
  4649. WFIFOW(fd,6)=val;
  4650. WFIFOSET(fd,packet_len_table[0x188]);
  4651. return 0;
  4652. }
  4653. /*==========================================
  4654. * Wisp/page is transmitted to the destination player
  4655. *------------------------------------------
  4656. */
  4657. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4658. {
  4659. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4660. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4661. WFIFOW(fd,0) = 0x97;
  4662. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4663. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4664. memcpy(WFIFOP(fd,28), mes, mes_len);
  4665. WFIFOSET(fd,WFIFOW(fd,2));
  4666. return 0;
  4667. }
  4668. /*==========================================
  4669. * The transmission result of Wisp/page is transmitted to the source player
  4670. *------------------------------------------
  4671. */
  4672. int clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper, 1: target character is not loged in, 2: ignored by target, 3: everyone ignored by target
  4673. {
  4674. WFIFOHEAD(fd,packet_len_table[0x98]);
  4675. WFIFOW(fd,0) = 0x98;
  4676. WFIFOW(fd,2) = flag;
  4677. WFIFOSET(fd,packet_len_table[0x98]);
  4678. return 0;
  4679. }
  4680. /*==========================================
  4681. * キャラID名前引き結果を送信する
  4682. *------------------------------------------
  4683. */
  4684. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4685. {
  4686. char *p= map_charid2nick(char_id);
  4687. int fd;
  4688. nullpo_retr(0, sd);
  4689. fd=sd->fd;
  4690. if(p!=NULL){
  4691. WFIFOHEAD(fd,packet_len_table[0x194]);
  4692. WFIFOW(fd,0)=0x194;
  4693. WFIFOL(fd,2)=char_id;
  4694. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4695. WFIFOSET(fd,packet_len_table[0x194]);
  4696. }else{
  4697. map_reqchariddb(sd,char_id);
  4698. chrif_searchcharid(char_id);
  4699. }
  4700. return 0;
  4701. }
  4702. /*==========================================
  4703. * カードの挿入可能リストを返す
  4704. *------------------------------------------
  4705. */
  4706. int clif_use_card(struct map_session_data *sd,int idx)
  4707. {
  4708. int i,c,ep;
  4709. int fd=sd->fd;
  4710. nullpo_retr(0, sd);
  4711. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4712. return 0;
  4713. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4714. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4715. ep=sd->inventory_data[idx]->equip;
  4716. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4717. WFIFOW(fd,0)=0x017b;
  4718. for(i=c=0;i<MAX_INVENTORY;i++){
  4719. int j;
  4720. if(sd->inventory_data[i] == NULL)
  4721. continue;
  4722. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4723. continue;
  4724. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4725. continue;
  4726. if(sd->status.inventory[i].identify==0 ) //Not identified
  4727. continue;
  4728. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4729. continue;
  4730. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4731. continue;
  4732. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4733. if( sd->status.inventory[i].card[j]==0 )
  4734. break;
  4735. }
  4736. if(j==sd->inventory_data[i]->slot) // No room
  4737. continue;
  4738. WFIFOW(fd,4+c*2)=i+2;
  4739. c++;
  4740. }
  4741. WFIFOW(fd,2)=4+c*2;
  4742. WFIFOSET(fd,WFIFOW(fd,2));
  4743. return 0;
  4744. }
  4745. /*==========================================
  4746. * カードの挿入終了
  4747. *------------------------------------------
  4748. */
  4749. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4750. {
  4751. int fd;
  4752. nullpo_retr(0, sd);
  4753. fd=sd->fd;
  4754. WFIFOHEAD(fd,packet_len_table[0x17d]);
  4755. WFIFOW(fd,0)=0x17d;
  4756. WFIFOW(fd,2)=idx_equip+2;
  4757. WFIFOW(fd,4)=idx_card+2;
  4758. WFIFOB(fd,6)=flag;
  4759. WFIFOSET(fd,packet_len_table[0x17d]);
  4760. return 0;
  4761. }
  4762. /*==========================================
  4763. * 鑑定可能アイテムリスト送信
  4764. *------------------------------------------
  4765. */
  4766. int clif_item_identify_list(struct map_session_data *sd)
  4767. {
  4768. int i,c;
  4769. int fd;
  4770. nullpo_retr(0, sd);
  4771. fd=sd->fd;
  4772. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4773. WFIFOW(fd,0)=0x177;
  4774. for(i=c=0;i<MAX_INVENTORY;i++){
  4775. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4776. WFIFOW(fd,c*2+4)=i+2;
  4777. c++;
  4778. }
  4779. }
  4780. if(c > 0) {
  4781. WFIFOW(fd,2)=c*2+4;
  4782. WFIFOSET(fd,WFIFOW(fd,2));
  4783. sd->menuskill_id = MC_IDENTIFY;
  4784. sd->menuskill_lv = c;
  4785. }
  4786. return 0;
  4787. }
  4788. /*==========================================
  4789. * 鑑定結果
  4790. *------------------------------------------
  4791. */
  4792. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4793. {
  4794. int fd;
  4795. nullpo_retr(0, sd);
  4796. fd=sd->fd;
  4797. WFIFOHEAD(fd,packet_len_table[0x179]);
  4798. WFIFOW(fd, 0)=0x179;
  4799. WFIFOW(fd, 2)=idx+2;
  4800. WFIFOB(fd, 4)=flag;
  4801. WFIFOSET(fd,packet_len_table[0x179]);
  4802. return 0;
  4803. }
  4804. /*==========================================
  4805. * 修理可能アイテムリスト送信
  4806. *------------------------------------------
  4807. */
  4808. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4809. {
  4810. int i,c;
  4811. int fd;
  4812. int nameid;
  4813. nullpo_retr(0, sd);
  4814. nullpo_retr(0, dstsd);
  4815. fd=sd->fd;
  4816. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4817. WFIFOW(fd,0)=0x1fc;
  4818. for(i=c=0;i<MAX_INVENTORY;i++){
  4819. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4820. WFIFOW(fd,c*13+4) = i;
  4821. WFIFOW(fd,c*13+6) = nameid;
  4822. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4823. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4824. WFIFOB(fd,c*13+16)= c;
  4825. c++;
  4826. }
  4827. }
  4828. if(c > 0) {
  4829. WFIFOW(fd,2)=c*13+4;
  4830. WFIFOSET(fd,WFIFOW(fd,2));
  4831. sd->menuskill_id = BS_REPAIRWEAPON;
  4832. sd->menuskill_lv = dstsd->bl.id;
  4833. }else
  4834. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4835. return 0;
  4836. }
  4837. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4838. {
  4839. int view,fd;
  4840. nullpo_retr(0, sd);
  4841. fd=sd->fd;
  4842. WFIFOHEAD(fd,packet_len_table[0x1fe]);
  4843. WFIFOW(fd, 0)=0x1fe;
  4844. if((view = itemdb_viewid(nameid)) > 0)
  4845. WFIFOW(fd, 2)=view;
  4846. else
  4847. WFIFOW(fd, 2)=nameid;
  4848. WFIFOB(fd, 4)=flag;
  4849. WFIFOSET(fd,packet_len_table[0x1fe]);
  4850. return 0;
  4851. }
  4852. /*==========================================
  4853. * Weapon Refining - Taken from jAthena
  4854. *------------------------------------------
  4855. */
  4856. int clif_item_refine_list(struct map_session_data *sd)
  4857. {
  4858. int i,c;
  4859. int fd;
  4860. int skilllv;
  4861. int wlv;
  4862. int refine_item[5];
  4863. nullpo_retr(0, sd);
  4864. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4865. fd=sd->fd;
  4866. refine_item[0] = -1;
  4867. refine_item[1] = pc_search_inventory(sd,1010);
  4868. refine_item[2] = pc_search_inventory(sd,1011);
  4869. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4870. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4871. WFIFOW(fd,0)=0x221;
  4872. for(i=c=0;i<MAX_INVENTORY;i++){
  4873. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4874. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4875. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4876. WFIFOW(fd,c*13+ 4)=i+2;
  4877. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4878. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4879. WFIFOW(fd,c*13+10)=0;
  4880. WFIFOB(fd,c*13+12)=c;
  4881. c++;
  4882. }
  4883. }
  4884. WFIFOW(fd,2)=c*13+4;
  4885. WFIFOSET(fd,WFIFOW(fd,2));
  4886. sd->menuskill_id = WS_WEAPONREFINE;
  4887. sd->menuskill_lv = skilllv;
  4888. return 0;
  4889. }
  4890. /*==========================================
  4891. * アイテムによる一時的なスキル効果
  4892. *------------------------------------------
  4893. */
  4894. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  4895. {
  4896. int fd;
  4897. nullpo_retr(0, sd);
  4898. fd=sd->fd;
  4899. WFIFOHEAD(fd,packet_len_table[0x147]);
  4900. WFIFOW(fd, 0)=0x147;
  4901. WFIFOW(fd, 2)=skillid;
  4902. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4903. WFIFOW(fd, 6)=0;
  4904. WFIFOW(fd, 8)=skilllv;
  4905. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4906. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4907. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  4908. WFIFOB(fd,38)=0;
  4909. WFIFOSET(fd,packet_len_table[0x147]);
  4910. return 0;
  4911. }
  4912. /*==========================================
  4913. * カートにアイテム追加
  4914. *------------------------------------------
  4915. */
  4916. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4917. {
  4918. int view,fd;
  4919. unsigned char *buf;
  4920. nullpo_retr(0, sd);
  4921. fd=sd->fd;
  4922. WFIFOHEAD(fd,packet_len_table[0x124]);
  4923. buf=WFIFOP(fd,0);
  4924. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4925. return 1;
  4926. WBUFW(buf,0)=0x124;
  4927. WBUFW(buf,2)=n+2;
  4928. WBUFL(buf,4)=amount;
  4929. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4930. WBUFW(buf,8)=view;
  4931. else
  4932. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4933. WBUFB(buf,10)=sd->status.cart[n].identify;
  4934. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4935. WBUFB(buf,12)=sd->status.cart[n].refine;
  4936. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4937. WFIFOSET(fd,packet_len_table[0x124]);
  4938. return 0;
  4939. }
  4940. /*==========================================
  4941. * カートからアイテム削除
  4942. *------------------------------------------
  4943. */
  4944. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4945. {
  4946. int fd;
  4947. nullpo_retr(0, sd);
  4948. fd=sd->fd;
  4949. WFIFOHEAD(fd,packet_len_table[0x125]);
  4950. WFIFOW(fd,0)=0x125;
  4951. WFIFOW(fd,2)=n+2;
  4952. WFIFOL(fd,4)=amount;
  4953. WFIFOSET(fd,packet_len_table[0x125]);
  4954. return 0;
  4955. }
  4956. /*==========================================
  4957. * 露店開設
  4958. *------------------------------------------
  4959. */
  4960. int clif_openvendingreq(struct map_session_data *sd,int num)
  4961. {
  4962. int fd;
  4963. nullpo_retr(0, sd);
  4964. fd=sd->fd;
  4965. WFIFOHEAD(fd,packet_len_table[0x12d]);
  4966. WFIFOW(fd,0)=0x12d;
  4967. WFIFOW(fd,2)=num;
  4968. WFIFOSET(fd,packet_len_table[0x12d]);
  4969. return 0;
  4970. }
  4971. /*==========================================
  4972. * 露店看板表示
  4973. *------------------------------------------
  4974. */
  4975. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  4976. {
  4977. unsigned char buf[128];
  4978. nullpo_retr(0, bl);
  4979. WBUFW(buf,0)=0x131;
  4980. WBUFL(buf,2)=bl->id;
  4981. strncpy((char*)WBUFP(buf,6),message,80);
  4982. if(fd){
  4983. WFIFOHEAD(fd,packet_len_table[0x131]);
  4984. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x131]);
  4985. WFIFOSET(fd,packet_len_table[0x131]);
  4986. }else{
  4987. clif_send(buf,packet_len_table[0x131],bl,AREA_WOS);
  4988. }
  4989. return 0;
  4990. }
  4991. /*==========================================
  4992. * 露店看板消去
  4993. *------------------------------------------
  4994. */
  4995. int clif_closevendingboard(struct block_list* bl,int fd)
  4996. {
  4997. unsigned char buf[16];
  4998. nullpo_retr(0, bl);
  4999. WBUFW(buf,0)=0x132;
  5000. WBUFL(buf,2)=bl->id;
  5001. if(fd){
  5002. WFIFOHEAD(fd,packet_len_table[0x132]);
  5003. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x132]);
  5004. WFIFOSET(fd,packet_len_table[0x132]);
  5005. }else{
  5006. clif_send(buf,packet_len_table[0x132],bl,AREA_WOS);
  5007. }
  5008. return 0;
  5009. }
  5010. /*==========================================
  5011. * 露店アイテムリスト
  5012. *------------------------------------------
  5013. */
  5014. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  5015. {
  5016. struct item_data *data;
  5017. int i,n,index,fd;
  5018. struct map_session_data *vsd;
  5019. unsigned char *buf;
  5020. nullpo_retr(0, sd);
  5021. nullpo_retr(0, vending);
  5022. nullpo_retr(0, vsd=map_id2sd(id));
  5023. fd=sd->fd;
  5024. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  5025. buf = WFIFOP(fd,0);
  5026. for(i=0,n=0;i<vsd->vend_num;i++){
  5027. if(vending[i].amount<=0)
  5028. continue;
  5029. WBUFL(buf,8+n*22)=vending[i].value;
  5030. WBUFW(buf,12+n*22)=vending[i].amount;
  5031. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  5032. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  5033. continue;
  5034. data = itemdb_search(vsd->status.cart[index].nameid);
  5035. WBUFB(buf,16+n*22)=itemtype(data->type);
  5036. if(data->view_id > 0)
  5037. WBUFW(buf,17+n*22)=data->view_id;
  5038. else
  5039. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  5040. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  5041. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  5042. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  5043. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  5044. n++;
  5045. }
  5046. if(n > 0){
  5047. WBUFW(buf,0)=0x133;
  5048. WBUFW(buf,2)=8+n*22;
  5049. WBUFL(buf,4)=id;
  5050. WFIFOSET(fd,WFIFOW(fd,2));
  5051. }
  5052. return 0;
  5053. }
  5054. /*==========================================
  5055. * 露店アイテム購入失敗
  5056. *------------------------------------------
  5057. */
  5058. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  5059. {
  5060. int fd;
  5061. nullpo_retr(0, sd);
  5062. fd=sd->fd;
  5063. WFIFOHEAD(fd,packet_len_table[0x135]);
  5064. WFIFOW(fd,0)=0x135;
  5065. WFIFOW(fd,2)=index+2;
  5066. WFIFOW(fd,4)=amount;
  5067. WFIFOB(fd,6)=fail;
  5068. WFIFOSET(fd,packet_len_table[0x135]);
  5069. return 0;
  5070. }
  5071. /*==========================================
  5072. * 露店開設成功
  5073. *------------------------------------------
  5074. */
  5075. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  5076. {
  5077. struct item_data *data;
  5078. int i,n,index,fd;
  5079. unsigned char *buf;
  5080. nullpo_retr(0, sd);
  5081. fd=sd->fd;
  5082. WFIFOHEAD(fd, 8+sd->vend_num*22);
  5083. buf = WFIFOP(fd,0);
  5084. for(i=0,n=0;i<sd->vend_num;i++){
  5085. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  5086. WBUFL(buf,8+n*22)=vending[i].value;
  5087. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  5088. WBUFW(buf,14+n*22)=vending[i].amount;
  5089. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || !sd->status.cart[index].identify ||
  5090. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  5091. continue;
  5092. data = itemdb_search(sd->status.cart[index].nameid);
  5093. WBUFB(buf,16+n*22)=itemtype(data->type);
  5094. if(data->view_id > 0)
  5095. WBUFW(buf,17+n*22)=data->view_id;
  5096. else
  5097. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  5098. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  5099. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  5100. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  5101. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  5102. n++;
  5103. }
  5104. if(n > 0){
  5105. WBUFW(buf,0)=0x136;
  5106. WBUFW(buf,2)=8+n*22;
  5107. WBUFL(buf,4)=id;
  5108. WFIFOSET(fd,WFIFOW(fd,2));
  5109. }
  5110. return n;
  5111. }
  5112. /*==========================================
  5113. * 露店アイテム販売報告
  5114. *------------------------------------------
  5115. */
  5116. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  5117. {
  5118. int fd;
  5119. nullpo_retr(0, sd);
  5120. fd=sd->fd;
  5121. WFIFOHEAD(fd,packet_len_table[0x137]);
  5122. WFIFOW(fd,0)=0x137;
  5123. WFIFOW(fd,2)=index+2;
  5124. WFIFOW(fd,4)=amount;
  5125. WFIFOSET(fd,packet_len_table[0x137]);
  5126. return 0;
  5127. }
  5128. /*==========================================
  5129. * パーティ作成完了
  5130. *------------------------------------------
  5131. */
  5132. int clif_party_created(struct map_session_data *sd,int flag)
  5133. {
  5134. int fd;
  5135. nullpo_retr(0, sd);
  5136. fd=sd->fd;
  5137. WFIFOHEAD(fd,packet_len_table[0xfa]);
  5138. WFIFOW(fd,0)=0xfa;
  5139. WFIFOB(fd,2)=flag;
  5140. WFIFOSET(fd,packet_len_table[0xfa]);
  5141. return 0;
  5142. }
  5143. int clif_party_main_info(struct party_data *p, int fd)
  5144. {
  5145. struct map_session_data *sd;
  5146. int i;
  5147. unsigned char buf[96];
  5148. for (i=0; i<MAX_PARTY && !p->party.member[i].leader; i++);
  5149. if (i >= MAX_PARTY) return 0; //Should never happen...
  5150. sd = p->data[i].sd;
  5151. WBUFW(buf,0)=0x1e9;
  5152. WBUFL(buf,2)= p->party.member[i].account_id;
  5153. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  5154. WBUFW(buf,10)=sd?sd->bl.x:0;
  5155. WBUFW(buf,12)=sd?sd->bl.y:0;
  5156. WBUFB(buf,14)=(p->party.member[i].online)?0:1; //This byte is also unconfirmed...
  5157. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5158. memcpy(WBUFP(buf,39), p->party.member[i].name, NAME_LENGTH);
  5159. memcpy(WBUFP(buf,63), mapindex_id2name(p->party.member[i].map), MAP_NAME_LENGTH);
  5160. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5161. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5162. if(fd>=0){
  5163. WFIFOHEAD(fd,packet_len_table[0x1e9]);
  5164. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x1e9]);
  5165. WFIFOSET(fd,packet_len_table[0x1e9]);
  5166. return 1;
  5167. }
  5168. if (!sd) {
  5169. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++)
  5170. if (i >= MAX_PARTY) return 0; //Should never happen...
  5171. sd=p->data[i].sd;
  5172. }
  5173. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY);
  5174. return 1;
  5175. }
  5176. int clif_party_join_info(struct party *p, struct map_session_data *sd)
  5177. {
  5178. unsigned char buf[96];
  5179. WBUFW(buf,0)=0x1e9;
  5180. WBUFL(buf,2)= sd->status.account_id;
  5181. WBUFL(buf,6)= 0; //Apparently setting this to 1 makes you adoptable.
  5182. WBUFW(buf,10)=sd->bl.x;
  5183. WBUFW(buf,12)=sd->bl.y;
  5184. WBUFB(buf,14)=0; //Unconfirmed byte.
  5185. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5186. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5187. memcpy(WBUFP(buf,63), mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  5188. WBUFB(buf,79) = (p->item&1)?1:0;
  5189. WBUFB(buf,80) = (p->item&2)?1:0;
  5190. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY_WOS);
  5191. return 1;
  5192. }
  5193. /*==========================================
  5194. * パーティ情報送信
  5195. *------------------------------------------
  5196. */
  5197. int clif_party_info(struct party_data *p,int fd)
  5198. {
  5199. unsigned char buf[1024];
  5200. int i,c;
  5201. struct map_session_data *sd=NULL;
  5202. nullpo_retr(0, p);
  5203. WBUFW(buf,0)=0xfb;
  5204. memcpy(WBUFP(buf,4),p->party.name,NAME_LENGTH);
  5205. for(i=c=0;i<MAX_PARTY;i++){
  5206. struct party_member *m=&p->party.member[i];
  5207. if(!m->account_id)
  5208. continue;
  5209. if(sd==NULL) sd=p->data[i].sd;
  5210. WBUFL(buf,28+c*46)=m->account_id;
  5211. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5212. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5213. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5214. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5215. c++;
  5216. }
  5217. WBUFW(buf,2)=28+c*46;
  5218. if(fd>=0){ // fdが設定されてるならそれに送る
  5219. WFIFOHEAD(fd, 28+c*46);
  5220. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5221. WFIFOSET(fd,WFIFOW(fd,2));
  5222. return 9;
  5223. }
  5224. if(sd!=NULL)
  5225. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5226. return 0;
  5227. }
  5228. /*==========================================
  5229. * パーティ勧誘
  5230. *------------------------------------------
  5231. */
  5232. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5233. {
  5234. int fd;
  5235. struct party_data *p;
  5236. nullpo_retr(0, sd);
  5237. nullpo_retr(0, tsd);
  5238. fd=tsd->fd;
  5239. if( (p=party_search(sd->status.party_id))==NULL )
  5240. return 0;
  5241. WFIFOHEAD(fd,packet_len_table[0xfe]);
  5242. WFIFOW(fd,0)=0xfe;
  5243. WFIFOL(fd,2)=sd->status.account_id;
  5244. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5245. WFIFOSET(fd,packet_len_table[0xfe]);
  5246. return 0;
  5247. }
  5248. /*==========================================
  5249. * Party invitation result. Flag values are:
  5250. * 0 -> char is already in a party
  5251. * 1 -> party invite was rejected
  5252. * 2 -> party invite was accepted
  5253. * 3 -> party is full
  5254. * 4 -> char of the same account already joined the party
  5255. *------------------------------------------
  5256. */
  5257. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5258. {
  5259. int fd;
  5260. nullpo_retr(0, sd);
  5261. fd=sd->fd;
  5262. WFIFOHEAD(fd,packet_len_table[0xfd]);
  5263. WFIFOW(fd,0)=0xfd;
  5264. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5265. WFIFOB(fd,26)=flag;
  5266. WFIFOSET(fd,packet_len_table[0xfd]);
  5267. return 0;
  5268. }
  5269. /*==========================================
  5270. * パーティ設定送信
  5271. * flag & 0x001=exp変更ミス
  5272. * 0x010=item変更ミス
  5273. * 0x100=一人にのみ送信
  5274. *------------------------------------------
  5275. */
  5276. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5277. {
  5278. unsigned char buf[16];
  5279. nullpo_retr(0, p);
  5280. // if(battle_config.etc_log)
  5281. // printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
  5282. if(sd==NULL && flag==0){
  5283. int i;
  5284. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5285. if (i < MAX_PARTY)
  5286. sd = p->data[i].sd;
  5287. }
  5288. if(sd==NULL)
  5289. return 0;
  5290. WBUFW(buf,0)=0x101;
  5291. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5292. WBUFW(buf,4)=0; //NOTE: We don't know yet what this is for, it is NOT for item share rules, though. [Skotlex]
  5293. if(flag==0)
  5294. clif_send(buf,packet_len_table[0x101],&sd->bl,PARTY);
  5295. else {
  5296. WFIFOHEAD(sd->fd,packet_len_table[0x101]);
  5297. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x101]);
  5298. WFIFOSET(sd->fd,packet_len_table[0x101]);
  5299. }
  5300. return 0;
  5301. }
  5302. /*==========================================
  5303. * パーティ脱退(脱退前に呼ぶこと)
  5304. *------------------------------------------
  5305. */
  5306. int clif_party_leaved(struct party_data *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5307. {
  5308. unsigned char buf[64];
  5309. int i;
  5310. nullpo_retr(0, p);
  5311. WBUFW(buf,0)=0x105;
  5312. WBUFL(buf,2)=account_id;
  5313. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5314. WBUFB(buf,30)=flag&0x0f;
  5315. if((flag&0xf0)==0){
  5316. if(sd==NULL) {
  5317. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5318. if (i < MAX_PARTY)
  5319. sd = p->data[i].sd;
  5320. }
  5321. if (sd)
  5322. clif_send(buf,packet_len_table[0x105],&sd->bl,PARTY);
  5323. } else if (sd!=NULL) {
  5324. WFIFOHEAD(sd->fd,packet_len_table[0x105]);
  5325. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x105]);
  5326. WFIFOSET(sd->fd,packet_len_table[0x105]);
  5327. }
  5328. return 0;
  5329. }
  5330. /*==========================================
  5331. * パーティメッセージ送信
  5332. *------------------------------------------
  5333. */
  5334. int clif_party_message(struct party_data *p,int account_id,char *mes,int len)
  5335. {
  5336. struct map_session_data *sd;
  5337. int i;
  5338. nullpo_retr(0, p);
  5339. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5340. if(i < MAX_PARTY){
  5341. unsigned char buf[1024];
  5342. sd = p->data[i].sd;
  5343. WBUFW(buf,0)=0x109;
  5344. WBUFW(buf,2)=len+8;
  5345. WBUFL(buf,4)=account_id;
  5346. memcpy(WBUFP(buf,8),mes,len);
  5347. clif_send(buf,len+8,&sd->bl,PARTY);
  5348. }
  5349. return 0;
  5350. }
  5351. /*==========================================
  5352. * パーティ座標通知
  5353. *------------------------------------------
  5354. */
  5355. int clif_party_xy(struct map_session_data *sd)
  5356. {
  5357. unsigned char buf[16];
  5358. nullpo_retr(0, sd);
  5359. WBUFW(buf,0)=0x107;
  5360. WBUFL(buf,2)=sd->status.account_id;
  5361. WBUFW(buf,6)=sd->bl.x;
  5362. WBUFW(buf,8)=sd->bl.y;
  5363. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  5364. return 0;
  5365. }
  5366. /*==========================================
  5367. * Sends x/y dot to a single fd. [Skotlex]
  5368. *------------------------------------------
  5369. */
  5370. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5371. {
  5372. WFIFOHEAD(fd,packet_len_table[0x107]);
  5373. WFIFOW(fd,0)=0x107;
  5374. WFIFOL(fd,2)=sd->status.account_id;
  5375. WFIFOW(fd,6)=sd->bl.x;
  5376. WFIFOW(fd,8)=sd->bl.y;
  5377. WFIFOSET(fd,packet_len_table[0x107]);
  5378. return 0;
  5379. }
  5380. /*==========================================
  5381. * パーティHP通知
  5382. *------------------------------------------
  5383. */
  5384. int clif_party_hp(struct map_session_data *sd)
  5385. {
  5386. unsigned char buf[16];
  5387. nullpo_retr(0, sd);
  5388. WBUFW(buf,0)=0x106;
  5389. WBUFL(buf,2)=sd->status.account_id;
  5390. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5391. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5392. WBUFW(buf,8) = 100;
  5393. } else {
  5394. WBUFW(buf,6) = sd->battle_status.hp;
  5395. WBUFW(buf,8) = sd->battle_status.max_hp;
  5396. }
  5397. clif_send(buf,packet_len_table[0x106],&sd->bl,PARTY_AREA_WOS);
  5398. return 0;
  5399. }
  5400. /*==========================================
  5401. * Sends HP bar to a single fd. [Skotlex]
  5402. *------------------------------------------
  5403. */
  5404. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5405. {
  5406. WFIFOHEAD(fd,packet_len_table[0x106]);
  5407. WFIFOW(fd,0) = 0x106;
  5408. WFIFOL(fd,2) = sd->status.account_id;
  5409. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5410. WFIFOW(fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5411. WFIFOW(fd,8) = 100;
  5412. } else {
  5413. WFIFOW(fd,6) = sd->battle_status.hp;
  5414. WFIFOW(fd,8) = sd->battle_status.max_hp;
  5415. }
  5416. WFIFOSET (fd, packet_len_table[0x106]);
  5417. }
  5418. /*==========================================
  5419. * GMへ場所とHP通知
  5420. *------------------------------------------
  5421. */
  5422. int clif_hpmeter(struct map_session_data *sd)
  5423. {
  5424. struct map_session_data *sd2;
  5425. unsigned char buf[16];
  5426. int i, x0, y0, x1, y1;
  5427. int level;
  5428. nullpo_retr(0, sd);
  5429. x0 = sd->bl.x - AREA_SIZE;
  5430. y0 = sd->bl.y - AREA_SIZE;
  5431. x1 = sd->bl.x + AREA_SIZE;
  5432. y1 = sd->bl.y + AREA_SIZE;
  5433. WBUFW(buf,0) = 0x106;
  5434. WBUFL(buf,2) = sd->status.account_id;
  5435. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5436. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5437. WBUFW(buf,8) = 100;
  5438. } else {
  5439. WBUFW(buf,6) = sd->battle_status.hp;
  5440. WBUFW(buf,8) = sd->battle_status.max_hp;
  5441. }
  5442. for (i = 0; i < fd_max; i++) {
  5443. if (session[i] && session[i]->func_parse == clif_parse &&
  5444. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5445. sd != sd2 && sd2->state.auth) {
  5446. if (sd2->bl.m != sd->bl.m ||
  5447. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5448. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5449. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5450. level < pc_isGM(sd))
  5451. continue;
  5452. WFIFOHEAD (i, packet_len_table[0x106]);
  5453. memcpy (WFIFOP(i,0), buf, packet_len_table[0x106]);
  5454. WFIFOSET (i, packet_len_table[0x106]);
  5455. }
  5456. }
  5457. return 0;
  5458. }
  5459. /*==========================================
  5460. * パーティ場所移動(未使用)
  5461. *------------------------------------------
  5462. */
  5463. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5464. {
  5465. unsigned char buf[128];
  5466. nullpo_retr(0, sd);
  5467. nullpo_retr(0, p);
  5468. WBUFW(buf, 0)=0x104;
  5469. WBUFL(buf, 2)=sd->status.account_id;
  5470. WBUFL(buf, 6)=0;
  5471. WBUFW(buf,10)=sd->bl.x;
  5472. WBUFW(buf,12)=sd->bl.y;
  5473. WBUFB(buf,14)=!online;
  5474. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5475. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5476. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5477. clif_send(buf,packet_len_table[0x104],&sd->bl,PARTY);
  5478. return 0;
  5479. }
  5480. /*==========================================
  5481. * 攻撃するために移動が必要
  5482. *------------------------------------------
  5483. */
  5484. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5485. {
  5486. int fd;
  5487. nullpo_retr(0, sd);
  5488. nullpo_retr(0, bl);
  5489. fd=sd->fd;
  5490. WFIFOHEAD(fd,packet_len_table[0x139]);
  5491. WFIFOW(fd, 0)=0x139;
  5492. WFIFOL(fd, 2)=bl->id;
  5493. WFIFOW(fd, 6)=bl->x;
  5494. WFIFOW(fd, 8)=bl->y;
  5495. WFIFOW(fd,10)=sd->bl.x;
  5496. WFIFOW(fd,12)=sd->bl.y;
  5497. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5498. WFIFOSET(fd,packet_len_table[0x139]);
  5499. return 0;
  5500. }
  5501. /*==========================================
  5502. * 製造エフェクト
  5503. *------------------------------------------
  5504. */
  5505. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5506. {
  5507. int view,fd;
  5508. nullpo_retr(0, sd);
  5509. fd=sd->fd;
  5510. // 名前の登録と送信を先にしておく
  5511. if( map_charid2nick(sd->status.char_id)==NULL )
  5512. map_addchariddb(sd->status.char_id,sd->status.name);
  5513. clif_solved_charname(sd,sd->status.char_id);
  5514. WFIFOHEAD(fd,packet_len_table[0x18f]);
  5515. WFIFOW(fd, 0)=0x18f;
  5516. WFIFOW(fd, 2)=flag;
  5517. if((view = itemdb_viewid(nameid)) > 0)
  5518. WFIFOW(fd, 4)=view;
  5519. else
  5520. WFIFOW(fd, 4)=nameid;
  5521. WFIFOSET(fd,packet_len_table[0x18f]);
  5522. return 0;
  5523. }
  5524. // pet
  5525. int clif_catch_process(struct map_session_data *sd)
  5526. {
  5527. int fd;
  5528. nullpo_retr(0, sd);
  5529. fd=sd->fd;
  5530. WFIFOHEAD(fd,packet_len_table[0x19e]);
  5531. WFIFOW(fd,0)=0x19e;
  5532. WFIFOSET(fd,packet_len_table[0x19e]);
  5533. sd->menuskill_id = SA_TAMINGMONSTER;
  5534. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5535. sd->menuskill_lv = 0; //Free catch
  5536. else
  5537. sd->menuskill_lv = sd->itemid; //Consume catch
  5538. return 0;
  5539. }
  5540. int clif_pet_rulet(struct map_session_data *sd,int data)
  5541. {
  5542. int fd;
  5543. nullpo_retr(0, sd);
  5544. fd=sd->fd;
  5545. WFIFOHEAD(fd,packet_len_table[0x1a0]);
  5546. WFIFOW(fd,0)=0x1a0;
  5547. WFIFOB(fd,2)=data;
  5548. WFIFOSET(fd,packet_len_table[0x1a0]);
  5549. return 0;
  5550. }
  5551. /*==========================================
  5552. * pet卵リスト作成
  5553. *------------------------------------------
  5554. */
  5555. int clif_sendegg(struct map_session_data *sd)
  5556. {
  5557. //R 01a6 <len>.w <index>.w*
  5558. int i,n=0,fd;
  5559. nullpo_retr(0, sd);
  5560. fd=sd->fd;
  5561. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5562. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5563. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5564. return 0;
  5565. }
  5566. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5567. WFIFOW(fd,0)=0x1a6;
  5568. if(sd->status.pet_id <= 0) {
  5569. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5570. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5571. sd->inventory_data[i]->type!=IT_PETEGG ||
  5572. sd->status.inventory[i].amount<=0)
  5573. continue;
  5574. WFIFOW(fd,n*2+4)=i+2;
  5575. n++;
  5576. }
  5577. }
  5578. WFIFOW(fd,2)=4+n*2;
  5579. WFIFOSET(fd,WFIFOW(fd,2));
  5580. sd->menuskill_id = SA_TAMINGMONSTER;
  5581. sd->menuskill_lv = -1;
  5582. return 0;
  5583. }
  5584. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5585. {
  5586. int fd;
  5587. nullpo_retr(0, sd);
  5588. nullpo_retr(0, sd->pd);
  5589. fd=sd->fd;
  5590. WFIFOHEAD(fd,packet_len_table[0x1a4]);
  5591. WFIFOW(fd,0)=0x1a4;
  5592. WFIFOB(fd,2)=type;
  5593. WFIFOL(fd,3)=sd->pd->bl.id;
  5594. WFIFOL(fd,7)=param;
  5595. WFIFOSET(fd,packet_len_table[0x1a4]);
  5596. return 0;
  5597. }
  5598. int clif_send_petstatus(struct map_session_data *sd)
  5599. {
  5600. int fd;
  5601. struct s_pet *pet;
  5602. nullpo_retr(0, sd);
  5603. nullpo_retr(0, sd->pd);
  5604. fd=sd->fd;
  5605. pet = &sd->pd->pet;
  5606. WFIFOHEAD(fd,packet_len_table[0x1a2]);
  5607. WFIFOW(fd,0)=0x1a2;
  5608. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5609. WFIFOB(fd,26)=(battle_config.pet_rename == 1)? 0:pet->rename_flag;
  5610. WFIFOW(fd,27)=pet->level;
  5611. WFIFOW(fd,29)=pet->hungry;
  5612. WFIFOW(fd,31)=pet->intimate;
  5613. WFIFOW(fd,33)=pet->equip;
  5614. WFIFOSET(fd,packet_len_table[0x1a2]);
  5615. return 0;
  5616. }
  5617. /*==========================================
  5618. *
  5619. *------------------------------------------
  5620. */
  5621. int clif_pet_emotion(struct pet_data *pd,int param)
  5622. {
  5623. unsigned char buf[16];
  5624. nullpo_retr(0, pd);
  5625. malloc_set(buf,0,packet_len_table[0x1aa]);
  5626. WBUFW(buf,0)=0x1aa;
  5627. WBUFL(buf,2)=pd->bl.id;
  5628. if(param >= 100 && pd->petDB->talk_convert_class) {
  5629. if(pd->petDB->talk_convert_class < 0)
  5630. return 0;
  5631. else if(pd->petDB->talk_convert_class > 0) {
  5632. param -= (pd->pet.class_ - 100)*100;
  5633. param += (pd->petDB->talk_convert_class - 100)*100;
  5634. }
  5635. }
  5636. WBUFL(buf,6)=param;
  5637. clif_send(buf,packet_len_table[0x1aa],&pd->bl,AREA);
  5638. return 0;
  5639. }
  5640. int clif_pet_performance(struct block_list *bl,int param)
  5641. {
  5642. unsigned char buf[16];
  5643. nullpo_retr(0, bl);
  5644. malloc_set(buf,0,packet_len_table[0x1a4]);
  5645. WBUFW(buf,0)=0x1a4;
  5646. WBUFB(buf,2)=4;
  5647. WBUFL(buf,3)=bl->id;
  5648. WBUFL(buf,7)=param;
  5649. clif_send(buf,packet_len_table[0x1a4],bl,AREA);
  5650. return 0;
  5651. }
  5652. int clif_pet_equip(struct pet_data *pd)
  5653. {
  5654. unsigned char buf[16];
  5655. nullpo_retr(0, pd);
  5656. malloc_set(buf,0,packet_len_table[0x1a4]);
  5657. WBUFW(buf,0)=0x1a4;
  5658. WBUFB(buf,2)=3;
  5659. WBUFL(buf,3)=pd->bl.id;
  5660. WBUFL(buf,7)=pd->vd.shield;
  5661. clif_send(buf,packet_len_table[0x1a4],&pd->bl,AREA);
  5662. return 0;
  5663. }
  5664. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5665. {
  5666. int fd;
  5667. nullpo_retr(0, sd);
  5668. fd=sd->fd;
  5669. WFIFOHEAD(fd,packet_len_table[0x1a3]);
  5670. WFIFOW(fd,0)=0x1a3;
  5671. WFIFOB(fd,2)=fail;
  5672. WFIFOW(fd,3)=foodid;
  5673. WFIFOSET(fd,packet_len_table[0x1a3]);
  5674. return 0;
  5675. }
  5676. /*==========================================
  5677. * オートスペル リスト送信
  5678. *------------------------------------------
  5679. */
  5680. int clif_autospell(struct map_session_data *sd,int skilllv)
  5681. {
  5682. int fd;
  5683. nullpo_retr(0, sd);
  5684. fd=sd->fd;
  5685. WFIFOHEAD(fd,packet_len_table[0x1cd]);
  5686. WFIFOW(fd, 0)=0x1cd;
  5687. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5688. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5689. else
  5690. WFIFOL(fd,2)= 0x00000000;
  5691. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5692. WFIFOL(fd,6)= MG_COLDBOLT;
  5693. else
  5694. WFIFOL(fd,6)= 0x00000000;
  5695. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5696. WFIFOL(fd,10)= MG_FIREBOLT;
  5697. else
  5698. WFIFOL(fd,10)= 0x00000000;
  5699. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5700. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5701. else
  5702. WFIFOL(fd,14)= 0x00000000;
  5703. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5704. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5705. else
  5706. WFIFOL(fd,18)= 0x00000000;
  5707. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5708. WFIFOL(fd,22)= MG_FIREBALL;
  5709. else
  5710. WFIFOL(fd,22)= 0x00000000;
  5711. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5712. WFIFOL(fd,26)= MG_FROSTDIVER;
  5713. else
  5714. WFIFOL(fd,26)= 0x00000000;
  5715. WFIFOSET(fd,packet_len_table[0x1cd]);
  5716. sd->menuskill_id = SA_AUTOSPELL;
  5717. sd->menuskill_lv = skilllv;
  5718. return 0;
  5719. }
  5720. /*==========================================
  5721. * ディボーションの青い糸
  5722. *------------------------------------------
  5723. */
  5724. int clif_devotion(struct map_session_data *sd)
  5725. {
  5726. unsigned char buf[56];
  5727. int i,n;
  5728. nullpo_retr(0, sd);
  5729. WBUFW(buf,0)=0x1cf;
  5730. WBUFL(buf,2)=sd->bl.id;
  5731. for(i=0,n=0;i<5;i++) {
  5732. if (!sd->devotion[i])
  5733. continue;
  5734. WBUFL(buf,6+4*n)=sd->devotion[i];
  5735. n++;
  5736. }
  5737. for(;n<5;n++)
  5738. WBUFL(buf,6+4*n)=0;
  5739. WBUFB(buf,26)=8;
  5740. WBUFB(buf,27)=0;
  5741. clif_send(buf,packet_len_table[0x1cf],&sd->bl,AREA);
  5742. return 0;
  5743. }
  5744. int clif_marionette(struct block_list *src, struct block_list *target)
  5745. {
  5746. unsigned char buf[56];
  5747. int n;
  5748. WBUFW(buf,0)=0x1cf;
  5749. WBUFL(buf,2)=src->id;
  5750. for(n=0;n<5;n++)
  5751. WBUFL(buf,6+4*n)=0;
  5752. if (target) //The target goes on the second slot.
  5753. WBUFL(buf,6+4) = target->id;
  5754. WBUFB(buf,26)=8;
  5755. WBUFB(buf,27)=0;
  5756. clif_send(buf,packet_len_table[0x1cf],src,AREA);
  5757. return 0;
  5758. }
  5759. /*==========================================
  5760. * 氣球
  5761. *------------------------------------------
  5762. */
  5763. int clif_spiritball(struct map_session_data *sd)
  5764. {
  5765. unsigned char buf[16];
  5766. nullpo_retr(0, sd);
  5767. WBUFW(buf,0)=0x1d0;
  5768. WBUFL(buf,2)=sd->bl.id;
  5769. WBUFW(buf,6)=sd->spiritball;
  5770. clif_send(buf,packet_len_table[0x1d0],&sd->bl,AREA);
  5771. return 0;
  5772. }
  5773. /*==========================================
  5774. *
  5775. *------------------------------------------
  5776. */
  5777. int clif_combo_delay(struct block_list *bl,int wait)
  5778. {
  5779. unsigned char buf[32];
  5780. nullpo_retr(0, bl);
  5781. WBUFW(buf,0)=0x1d2;
  5782. WBUFL(buf,2)=bl->id;
  5783. WBUFL(buf,6)=wait;
  5784. clif_send(buf,packet_len_table[0x1d2],bl,AREA);
  5785. return 0;
  5786. }
  5787. /*==========================================
  5788. *白刃取り
  5789. *------------------------------------------
  5790. */
  5791. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5792. int _bool)
  5793. {
  5794. unsigned char buf[32];
  5795. nullpo_retr(0, src);
  5796. nullpo_retr(0, dst);
  5797. WBUFW(buf,0)=0x1d1;
  5798. WBUFL(buf,2)=src->id;
  5799. WBUFL(buf,6)=dst->id;
  5800. WBUFL(buf,10)=_bool;
  5801. clif_send(buf,packet_len_table[0x1d1],src,AREA);
  5802. return 0;
  5803. }
  5804. /*==========================================
  5805. *
  5806. *------------------------------------------
  5807. */
  5808. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5809. {
  5810. struct block_list bl;
  5811. unsigned char buf[32];
  5812. bl.type = BL_NUL;
  5813. bl.m = m;
  5814. bl.x = x;
  5815. bl.y = y;
  5816. WBUFW(buf,0) = 0x192;
  5817. WBUFW(buf,2) = x;
  5818. WBUFW(buf,4) = y;
  5819. WBUFW(buf,6) = cell_type;
  5820. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  5821. if(!type)
  5822. clif_send(buf,packet_len_table[0x192],&bl,AREA);
  5823. else
  5824. clif_send(buf,packet_len_table[0x192],&bl,ALL_SAMEMAP);
  5825. return 0;
  5826. }
  5827. /*==========================================
  5828. * MVPエフェクト
  5829. *------------------------------------------
  5830. */
  5831. int clif_mvp_effect(struct map_session_data *sd)
  5832. {
  5833. unsigned char buf[16];
  5834. nullpo_retr(0, sd);
  5835. WBUFW(buf,0)=0x10c;
  5836. WBUFL(buf,2)=sd->bl.id;
  5837. clif_send(buf,packet_len_table[0x10c],&sd->bl,AREA);
  5838. return 0;
  5839. }
  5840. /*==========================================
  5841. * MVPアイテム所得
  5842. *------------------------------------------
  5843. */
  5844. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5845. {
  5846. int view,fd;
  5847. nullpo_retr(0, sd);
  5848. fd=sd->fd;
  5849. WFIFOHEAD(fd,packet_len_table[0x10a]);
  5850. WFIFOW(fd,0)=0x10a;
  5851. if((view = itemdb_viewid(nameid)) > 0)
  5852. WFIFOW(fd,2)=view;
  5853. else
  5854. WFIFOW(fd,2)=nameid;
  5855. WFIFOSET(fd,packet_len_table[0x10a]);
  5856. return 0;
  5857. }
  5858. /*==========================================
  5859. * MVP経験値所得
  5860. *------------------------------------------
  5861. */
  5862. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5863. {
  5864. int fd;
  5865. nullpo_retr(0, sd);
  5866. fd=sd->fd;
  5867. WFIFOHEAD(fd,packet_len_table[0x10b]);
  5868. WFIFOW(fd,0)=0x10b;
  5869. WFIFOL(fd,2)=exp;
  5870. WFIFOSET(fd,packet_len_table[0x10b]);
  5871. return 0;
  5872. }
  5873. /*==========================================
  5874. * ギルド作成可否通知
  5875. *------------------------------------------
  5876. */
  5877. int clif_guild_created(struct map_session_data *sd,int flag)
  5878. {
  5879. int fd;
  5880. nullpo_retr(0, sd);
  5881. fd=sd->fd;
  5882. WFIFOHEAD(fd,packet_len_table[0x167]);
  5883. WFIFOW(fd,0)=0x167;
  5884. WFIFOB(fd,2)=flag;
  5885. WFIFOSET(fd,packet_len_table[0x167]);
  5886. return 0;
  5887. }
  5888. /*==========================================
  5889. * ギルド所属通知
  5890. *------------------------------------------
  5891. */
  5892. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5893. {
  5894. int ps,fd;
  5895. nullpo_retr(0, sd);
  5896. nullpo_retr(0, g);
  5897. fd=sd->fd;
  5898. ps=guild_getposition(sd,g);
  5899. WFIFOHEAD(fd,packet_len_table[0x16c]);
  5900. malloc_set(WFIFOP(fd,0),0,packet_len_table[0x16c]);
  5901. WFIFOW(fd,0)=0x16c;
  5902. WFIFOL(fd,2)=g->guild_id;
  5903. WFIFOL(fd,6)=g->emblem_id;
  5904. WFIFOL(fd,10)=g->position[ps].mode;
  5905. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5906. WFIFOSET(fd,packet_len_table[0x16c]);
  5907. return 0;
  5908. }
  5909. /*==========================================
  5910. * ギルドメンバログイン通知
  5911. *------------------------------------------
  5912. */
  5913. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5914. {
  5915. unsigned char buf[64];
  5916. nullpo_retr(0, g);
  5917. WBUFW(buf, 0)=0x16d;
  5918. WBUFL(buf, 2)=g->member[idx].account_id;
  5919. WBUFL(buf, 6)=g->member[idx].char_id;
  5920. WBUFL(buf,10)=flag;
  5921. if(g->member[idx].sd==NULL){
  5922. struct map_session_data *sd=guild_getavailablesd(g);
  5923. if(sd!=NULL)
  5924. clif_send(buf,packet_len_table[0x16d],&sd->bl,GUILD);
  5925. }else
  5926. clif_send(buf,packet_len_table[0x16d],&g->member[idx].sd->bl,GUILD_WOS);
  5927. return 0;
  5928. }
  5929. // Function `clif_guild_memberlogin_notice` sends info about
  5930. // logins and logouts of a guild member to the rest members.
  5931. // But at the 1st time (after a player login or map changing)
  5932. // the client won't show the message.
  5933. // So I suggest use this function for sending "first-time-info"
  5934. // to some player on entering the game or changing location.
  5935. // At next time the client would always show the message.
  5936. // The function sends all the statuses in the single packet
  5937. // to economize traffic. [LuzZza]
  5938. int clif_guild_send_onlineinfo(struct map_session_data *sd) {
  5939. struct guild *g;
  5940. char buf[14*128];
  5941. int i, count=0, p_len;
  5942. nullpo_retr(0, sd);
  5943. p_len = packet_len_table[0x16d];
  5944. if(!(g = guild_search(sd->status.guild_id)))
  5945. return 0;
  5946. for(i=0; i<g->max_member; i++) {
  5947. if(g->member[i].account_id > 0 &&
  5948. g->member[i].account_id != sd->status.account_id) {
  5949. WBUFW(buf,count*p_len) = 0x16d;
  5950. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5951. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5952. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5953. count++;
  5954. }
  5955. }
  5956. clif_send(buf,p_len*count,&sd->bl,SELF);
  5957. return 0;
  5958. }
  5959. /*==========================================
  5960. * ギルドマスター通知(14dへの応答)
  5961. *------------------------------------------
  5962. */
  5963. int clif_guild_masterormember(struct map_session_data *sd)
  5964. {
  5965. int type=0x57,fd;
  5966. nullpo_retr(0, sd);
  5967. fd=sd->fd;
  5968. if(sd->state.gmaster_flag)
  5969. type=0xd7;
  5970. WFIFOHEAD(fd,packet_len_table[0x14e]);
  5971. WFIFOW(fd,0)=0x14e;
  5972. WFIFOL(fd,2)=type;
  5973. WFIFOSET(fd,packet_len_table[0x14e]);
  5974. return 0;
  5975. }
  5976. /*==========================================
  5977. * Basic Info (Territories [Valaris])
  5978. *------------------------------------------
  5979. */
  5980. int clif_guild_basicinfo(struct map_session_data *sd)
  5981. {
  5982. int fd,i,t=0;
  5983. struct guild *g;
  5984. struct guild_castle *gc=NULL;
  5985. nullpo_retr(0, sd);
  5986. fd=sd->fd;
  5987. g=guild_search(sd->status.guild_id);
  5988. if(g==NULL)
  5989. return 0;
  5990. WFIFOHEAD(fd,packet_len_table[0x1b6]);
  5991. WFIFOW(fd, 0)=0x1b6;//0x150;
  5992. WFIFOL(fd, 2)=g->guild_id;
  5993. WFIFOL(fd, 6)=g->guild_lv;
  5994. WFIFOL(fd,10)=g->connect_member;
  5995. WFIFOL(fd,14)=g->max_member;
  5996. WFIFOL(fd,18)=g->average_lv;
  5997. WFIFOL(fd,22)=g->exp;
  5998. WFIFOL(fd,26)=g->next_exp;
  5999. WFIFOL(fd,30)=0; // 上納
  6000. WFIFOL(fd,34)=0; // VW(性格の悪さ?:性向グラフ左右)
  6001. WFIFOL(fd,38)=0; // RF(正義の度合い?:性向グラフ上下)
  6002. WFIFOL(fd,42)=0; // 人数?
  6003. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6004. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6005. for(i=0;i<MAX_GUILDCASTLE;i++){
  6006. gc=guild_castle_search(i);
  6007. if(!gc) continue;
  6008. if(g->guild_id == gc->guild_id) t++;
  6009. }
  6010. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  6011. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  6012. else
  6013. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  6014. WFIFOSET(fd,packet_len_table[WFIFOW(fd,0)]);
  6015. clif_guild_emblem(sd,g); // Guild emblem vanish fix [Valaris]
  6016. return 0;
  6017. }
  6018. /*==========================================
  6019. * ギルド同盟/敵対情報
  6020. *------------------------------------------
  6021. */
  6022. int clif_guild_allianceinfo(struct map_session_data *sd)
  6023. {
  6024. int fd,i,c;
  6025. struct guild *g;
  6026. nullpo_retr(0, sd);
  6027. fd=sd->fd;
  6028. g=guild_search(sd->status.guild_id);
  6029. if(g==NULL)
  6030. return 0;
  6031. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6032. WFIFOW(fd, 0)=0x14c;
  6033. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6034. struct guild_alliance *a=&g->alliance[i];
  6035. if(a->guild_id>0){
  6036. WFIFOL(fd,c*32+4)=a->opposition;
  6037. WFIFOL(fd,c*32+8)=a->guild_id;
  6038. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6039. c++;
  6040. }
  6041. }
  6042. WFIFOW(fd, 2)=c*32+4;
  6043. WFIFOSET(fd,WFIFOW(fd,2));
  6044. return 0;
  6045. }
  6046. /*==========================================
  6047. * ギルドメンバーリスト
  6048. *------------------------------------------
  6049. */
  6050. int clif_guild_memberlist(struct map_session_data *sd)
  6051. {
  6052. int fd;
  6053. int i,c;
  6054. struct guild *g;
  6055. nullpo_retr(0, sd);
  6056. fd=sd->fd;
  6057. if (!fd)
  6058. return 0;
  6059. g=guild_search(sd->status.guild_id);
  6060. if(g==NULL)
  6061. return 0;
  6062. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6063. WFIFOW(fd, 0)=0x154;
  6064. for(i=0,c=0;i<g->max_member;i++){
  6065. struct guild_member *m=&g->member[i];
  6066. if(m->account_id==0)
  6067. continue;
  6068. WFIFOL(fd,c*104+ 4)=m->account_id;
  6069. WFIFOL(fd,c*104+ 8)=m->char_id;
  6070. WFIFOW(fd,c*104+12)=m->hair;
  6071. WFIFOW(fd,c*104+14)=m->hair_color;
  6072. WFIFOW(fd,c*104+16)=m->gender;
  6073. WFIFOW(fd,c*104+18)=m->class_;
  6074. WFIFOW(fd,c*104+20)=m->lv;
  6075. WFIFOL(fd,c*104+22)=m->exp;
  6076. WFIFOL(fd,c*104+26)=m->online;
  6077. WFIFOL(fd,c*104+30)=m->position;
  6078. malloc_tsetword(WFIFOP(fd,c*104+34),0,50); // メモ?
  6079. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6080. c++;
  6081. }
  6082. WFIFOW(fd, 2)=c*104+4;
  6083. WFIFOSET(fd,WFIFOW(fd,2));
  6084. return 0;
  6085. }
  6086. /*==========================================
  6087. * ギルド役職名リスト
  6088. *------------------------------------------
  6089. */
  6090. int clif_guild_positionnamelist(struct map_session_data *sd)
  6091. {
  6092. int i,fd;
  6093. struct guild *g;
  6094. nullpo_retr(0, sd);
  6095. fd=sd->fd;
  6096. g=guild_search(sd->status.guild_id);
  6097. if(g==NULL)
  6098. return 0;
  6099. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6100. WFIFOW(fd, 0)=0x166;
  6101. for(i=0;i<MAX_GUILDPOSITION;i++){
  6102. WFIFOL(fd,i*28+4)=i;
  6103. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6104. }
  6105. WFIFOW(fd,2)=i*28+4;
  6106. WFIFOSET(fd,WFIFOW(fd,2));
  6107. return 0;
  6108. }
  6109. /*==========================================
  6110. * ギルド役職情報リスト
  6111. *------------------------------------------
  6112. */
  6113. int clif_guild_positioninfolist(struct map_session_data *sd)
  6114. {
  6115. int i,fd;
  6116. struct guild *g;
  6117. nullpo_retr(0, sd);
  6118. fd=sd->fd;
  6119. g=guild_search(sd->status.guild_id);
  6120. if(g==NULL)
  6121. return 0;
  6122. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6123. WFIFOW(fd, 0)=0x160;
  6124. for(i=0;i<MAX_GUILDPOSITION;i++){
  6125. struct guild_position *p=&g->position[i];
  6126. WFIFOL(fd,i*16+ 4)=i;
  6127. WFIFOL(fd,i*16+ 8)=p->mode;
  6128. WFIFOL(fd,i*16+12)=i;
  6129. WFIFOL(fd,i*16+16)=p->exp_mode;
  6130. }
  6131. WFIFOW(fd, 2)=i*16+4;
  6132. WFIFOSET(fd,WFIFOW(fd,2));
  6133. return 0;
  6134. }
  6135. /*==========================================
  6136. * ギルド役職変更通知
  6137. *------------------------------------------
  6138. */
  6139. int clif_guild_positionchanged(struct guild *g,int idx)
  6140. {
  6141. struct map_session_data *sd;
  6142. unsigned char buf[128];
  6143. nullpo_retr(0, g);
  6144. WBUFW(buf, 0)=0x174;
  6145. WBUFW(buf, 2)=44;
  6146. WBUFL(buf, 4)=idx;
  6147. WBUFL(buf, 8)=g->position[idx].mode;
  6148. WBUFL(buf,12)=idx;
  6149. WBUFL(buf,16)=g->position[idx].exp_mode;
  6150. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6151. if( (sd=guild_getavailablesd(g))!=NULL )
  6152. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6153. return 0;
  6154. }
  6155. /*==========================================
  6156. * ギルドメンバ変更通知
  6157. *------------------------------------------
  6158. */
  6159. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6160. {
  6161. struct map_session_data *sd;
  6162. unsigned char buf[64];
  6163. nullpo_retr(0, g);
  6164. WBUFW(buf, 0)=0x156;
  6165. WBUFW(buf, 2)=16;
  6166. WBUFL(buf, 4)=g->member[idx].account_id;
  6167. WBUFL(buf, 8)=g->member[idx].char_id;
  6168. WBUFL(buf,12)=g->member[idx].position;
  6169. if( (sd=guild_getavailablesd(g))!=NULL )
  6170. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6171. return 0;
  6172. }
  6173. /*==========================================
  6174. * ギルドエンブレム送信
  6175. *------------------------------------------
  6176. */
  6177. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6178. {
  6179. int fd;
  6180. nullpo_retr(0, sd);
  6181. nullpo_retr(0, g);
  6182. fd=sd->fd;
  6183. if(g->emblem_len<=0)
  6184. return 0;
  6185. WFIFOHEAD(fd,g->emblem_len+12);
  6186. WFIFOW(fd,0)=0x152;
  6187. WFIFOW(fd,2)=g->emblem_len+12;
  6188. WFIFOL(fd,4)=g->guild_id;
  6189. WFIFOL(fd,8)=g->emblem_id;
  6190. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6191. WFIFOSET(fd,WFIFOW(fd,2));
  6192. return 0;
  6193. }
  6194. /*==========================================
  6195. * ギルドスキル送信
  6196. *------------------------------------------
  6197. */
  6198. int clif_guild_skillinfo(struct map_session_data *sd)
  6199. {
  6200. int fd;
  6201. int i,id,c,up=1;
  6202. struct guild *g;
  6203. nullpo_retr(0, sd);
  6204. fd=sd->fd;
  6205. g=guild_search(sd->status.guild_id);
  6206. if(g==NULL)
  6207. return 0;
  6208. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6209. WFIFOW(fd,0)=0x0162;
  6210. WFIFOW(fd,4)=g->skill_point;
  6211. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6212. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6213. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6214. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  6215. WFIFOW(fd,c*37+10) = 0;
  6216. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6217. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6218. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6219. strncpy(WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH);
  6220. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6221. up = 1;
  6222. else
  6223. up = 0;
  6224. WFIFOB(fd,c*37+42)= up;
  6225. c++;
  6226. }
  6227. }
  6228. WFIFOW(fd,2)=c*37+6;
  6229. WFIFOSET(fd,WFIFOW(fd,2));
  6230. return 0;
  6231. }
  6232. /*==========================================
  6233. * ギルド告知送信
  6234. *------------------------------------------
  6235. */
  6236. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6237. {
  6238. int fd;
  6239. nullpo_retr(0, sd);
  6240. nullpo_retr(0, g);
  6241. fd = sd->fd;
  6242. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6243. return 0;
  6244. if (fd <= 0)
  6245. return 0;
  6246. if(*g->mes1==0 && *g->mes2==0)
  6247. return 0;
  6248. WFIFOHEAD(fd,packet_len_table[0x16f]);
  6249. WFIFOW(fd,0)=0x16f;
  6250. memcpy(WFIFOP(fd,2),g->mes1,60);
  6251. memcpy(WFIFOP(fd,62),g->mes2,120);
  6252. WFIFOSET(fd,packet_len_table[0x16f]);
  6253. return 0;
  6254. }
  6255. /*==========================================
  6256. * ギルドメンバ勧誘
  6257. *------------------------------------------
  6258. */
  6259. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6260. {
  6261. int fd;
  6262. nullpo_retr(0, sd);
  6263. nullpo_retr(0, g);
  6264. fd=sd->fd;
  6265. WFIFOHEAD(fd,packet_len_table[0x16a]);
  6266. WFIFOW(fd,0)=0x16a;
  6267. WFIFOL(fd,2)=g->guild_id;
  6268. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6269. WFIFOSET(fd,packet_len_table[0x16a]);
  6270. return 0;
  6271. }
  6272. /*==========================================
  6273. * ギルドメンバ勧誘結果
  6274. *------------------------------------------
  6275. */
  6276. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6277. {
  6278. int fd;
  6279. nullpo_retr(0, sd);
  6280. fd=sd->fd;
  6281. WFIFOHEAD(fd,packet_len_table[0x169]);
  6282. WFIFOW(fd,0)=0x169;
  6283. WFIFOB(fd,2)=flag;
  6284. WFIFOSET(fd,packet_len_table[0x169]);
  6285. return 0;
  6286. }
  6287. /*==========================================
  6288. * ギルドメンバ脱退通知
  6289. *------------------------------------------
  6290. */
  6291. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6292. {
  6293. unsigned char buf[128];
  6294. nullpo_retr(0, sd);
  6295. WBUFW(buf, 0)=0x15a;
  6296. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6297. memcpy(WBUFP(buf,26),mes,40);
  6298. clif_send(buf,packet_len_table[0x15a],&sd->bl,GUILD);
  6299. return 0;
  6300. }
  6301. /*==========================================
  6302. * ギルドメンバ追放通知
  6303. *------------------------------------------
  6304. */
  6305. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  6306. int account_id)
  6307. {
  6308. unsigned char buf[128];
  6309. nullpo_retr(0, sd);
  6310. WBUFW(buf, 0)=0x15c;
  6311. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6312. memcpy(WBUFP(buf,26),mes,40);
  6313. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6314. clif_send(buf,packet_len_table[0x15c],&sd->bl,GUILD);
  6315. return 0;
  6316. }
  6317. /*==========================================
  6318. * ギルド追放メンバリスト
  6319. *------------------------------------------
  6320. */
  6321. int clif_guild_expulsionlist(struct map_session_data *sd)
  6322. {
  6323. int fd;
  6324. int i,c;
  6325. struct guild *g;
  6326. nullpo_retr(0, sd);
  6327. fd=sd->fd;
  6328. g=guild_search(sd->status.guild_id);
  6329. if(g==NULL)
  6330. return 0;
  6331. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  6332. WFIFOW(fd,0)=0x163;
  6333. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  6334. struct guild_expulsion *e=&g->expulsion[i];
  6335. if(e->account_id>0){
  6336. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6337. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6338. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6339. c++;
  6340. }
  6341. }
  6342. WFIFOW(fd,2)=c*88+4;
  6343. WFIFOSET(fd,WFIFOW(fd,2));
  6344. return 0;
  6345. }
  6346. /*==========================================
  6347. * ギルド会話
  6348. *------------------------------------------
  6349. */
  6350. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6351. {
  6352. struct map_session_data *sd;
  6353. unsigned char *buf;
  6354. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6355. WBUFW(buf, 0) = 0x17f;
  6356. WBUFW(buf, 2) = len + 4;
  6357. memcpy(WBUFP(buf,4), mes, len);
  6358. if ((sd = guild_getavailablesd(g)) != NULL)
  6359. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6360. if(buf) aFree(buf);
  6361. return 0;
  6362. }
  6363. /*==========================================
  6364. * ギルドスキル割り振り通知
  6365. *------------------------------------------
  6366. */
  6367. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6368. {
  6369. int fd;
  6370. nullpo_retr(0, sd);
  6371. fd=sd->fd;
  6372. WFIFOHEAD(fd,11);
  6373. WFIFOW(fd,0) = 0x10e;
  6374. WFIFOW(fd,2) = skill_num;
  6375. WFIFOW(fd,4) = lv;
  6376. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6377. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6378. WFIFOB(fd,10) = 1;
  6379. WFIFOSET(fd,11);
  6380. return 0;
  6381. }
  6382. /*==========================================
  6383. * ギルド同盟要請
  6384. *------------------------------------------
  6385. */
  6386. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6387. {
  6388. int fd;
  6389. nullpo_retr(0, sd);
  6390. fd=sd->fd;
  6391. WFIFOHEAD(fd,packet_len_table[0x171]);
  6392. WFIFOW(fd,0)=0x171;
  6393. WFIFOL(fd,2)=account_id;
  6394. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6395. WFIFOSET(fd,packet_len_table[0x171]);
  6396. return 0;
  6397. }
  6398. /*==========================================
  6399. * ギルド同盟結果
  6400. *------------------------------------------
  6401. */
  6402. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6403. {
  6404. int fd;
  6405. nullpo_retr(0, sd);
  6406. fd=sd->fd;
  6407. WFIFOHEAD(fd,packet_len_table[0x173]);
  6408. WFIFOW(fd,0)=0x173;
  6409. WFIFOL(fd,2)=flag;
  6410. WFIFOSET(fd,packet_len_table[0x173]);
  6411. return 0;
  6412. }
  6413. /*==========================================
  6414. * ギルド関係解消通知
  6415. *------------------------------------------
  6416. */
  6417. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6418. {
  6419. int fd;
  6420. nullpo_retr(0, sd);
  6421. fd = sd->fd;
  6422. if (fd <= 0)
  6423. return 0;
  6424. WFIFOHEAD(fd,packet_len_table[0x184]);
  6425. WFIFOW(fd,0)=0x184;
  6426. WFIFOL(fd,2)=guild_id;
  6427. WFIFOL(fd,6)=flag;
  6428. WFIFOSET(fd,packet_len_table[0x184]);
  6429. return 0;
  6430. }
  6431. /*==========================================
  6432. * ギルド敵対結果
  6433. *------------------------------------------
  6434. */
  6435. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6436. {
  6437. int fd;
  6438. nullpo_retr(0, sd);
  6439. fd=sd->fd;
  6440. WFIFOHEAD(fd,packet_len_table[0x181]);
  6441. WFIFOW(fd,0)=0x181;
  6442. WFIFOB(fd,2)=flag;
  6443. WFIFOSET(fd,packet_len_table[0x181]);
  6444. return 0;
  6445. }
  6446. /*==========================================
  6447. * ギルド関係追加
  6448. *------------------------------------------
  6449. */
  6450. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6451. {
  6452. unsigned char buf[64];
  6453. WBUFW(fd,0)=0x185;
  6454. WBUFL(fd,2)=g->alliance[idx].opposition;
  6455. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6456. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6457. clif_send(buf,packet_len_table[0x185],guild_getavailablesd(g),GUILD);
  6458. return 0;
  6459. }*/
  6460. /*==========================================
  6461. * ギルド解散通知
  6462. *------------------------------------------
  6463. */
  6464. int clif_guild_broken(struct map_session_data *sd,int flag)
  6465. {
  6466. int fd;
  6467. nullpo_retr(0, sd);
  6468. fd=sd->fd;
  6469. WFIFOHEAD(fd,packet_len_table[0x15e]);
  6470. WFIFOW(fd,0)=0x15e;
  6471. WFIFOL(fd,2)=flag;
  6472. WFIFOSET(fd,packet_len_table[0x15e]);
  6473. return 0;
  6474. }
  6475. /*==========================================
  6476. * エモーション
  6477. *------------------------------------------
  6478. */
  6479. void clif_emotion(struct block_list *bl,int type)
  6480. {
  6481. unsigned char buf[8];
  6482. nullpo_retv(bl);
  6483. WBUFW(buf,0)=0xc0;
  6484. WBUFL(buf,2)=bl->id;
  6485. WBUFB(buf,6)=type;
  6486. clif_send(buf,packet_len_table[0xc0],bl,AREA);
  6487. }
  6488. /*==========================================
  6489. * トーキーボックス
  6490. *------------------------------------------
  6491. */
  6492. void clif_talkiebox(struct block_list *bl,char* talkie)
  6493. {
  6494. unsigned char buf[86];
  6495. nullpo_retv(bl);
  6496. WBUFW(buf,0)=0x191;
  6497. WBUFL(buf,2)=bl->id;
  6498. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6499. clif_send(buf,packet_len_table[0x191],bl,AREA);
  6500. }
  6501. /*==========================================
  6502. * 結婚エフェクト
  6503. *------------------------------------------
  6504. */
  6505. void clif_wedding_effect(struct block_list *bl) {
  6506. unsigned char buf[6];
  6507. nullpo_retv(bl);
  6508. WBUFW(buf,0) = 0x1ea;
  6509. WBUFL(buf,2) = bl->id;
  6510. clif_send(buf, packet_len_table[0x1ea], bl, AREA);
  6511. }
  6512. /*==========================================
  6513. * あなたに逢いたい使用時名前叫び
  6514. *------------------------------------------
  6515. void clif_callpartner(struct map_session_data *sd)
  6516. {
  6517. unsigned char buf[26];
  6518. char *p;
  6519. nullpo_retv(sd);
  6520. if(sd->status.partner_id){
  6521. WBUFW(buf,0)=0x1e6;
  6522. p = map_charid2nick(sd->status.partner_id);
  6523. if(p){
  6524. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6525. }else{
  6526. map_reqchariddb(sd,sd->status.partner_id);
  6527. chrif_searchcharid(sd->status.partner_id);
  6528. WBUFB(buf,2) = 0;
  6529. }
  6530. clif_send(buf,packet_len_table[0x1e6],&sd->bl,AREA);
  6531. }
  6532. return;
  6533. }
  6534. */
  6535. /*==========================================
  6536. * Adopt baby [Celest]
  6537. *------------------------------------------
  6538. */
  6539. void clif_adopt_process(struct map_session_data *sd)
  6540. {
  6541. int fd;
  6542. nullpo_retv(sd);
  6543. fd=sd->fd;
  6544. WFIFOHEAD(fd,packet_len_table[0x1f8]);
  6545. WFIFOW(fd,0)=0x1f8;
  6546. WFIFOSET(fd,packet_len_table[0x1f8]);
  6547. }
  6548. /*==========================================
  6549. * Marry [DracoRPG]
  6550. *------------------------------------------
  6551. */
  6552. void clif_marriage_process(struct map_session_data *sd)
  6553. {
  6554. int fd;
  6555. nullpo_retv(sd);
  6556. fd=sd->fd;
  6557. WFIFOHEAD(fd,packet_len_table[0x1e4]);
  6558. WFIFOW(fd,0)=0x1e4;
  6559. WFIFOSET(fd,packet_len_table[0x1e4]);
  6560. }
  6561. /*==========================================
  6562. * Notice of divorce
  6563. *------------------------------------------
  6564. */
  6565. void clif_divorced(struct map_session_data *sd, char *name)
  6566. {
  6567. int fd;
  6568. nullpo_retv(sd);
  6569. fd=sd->fd;
  6570. WFIFOHEAD(fd,packet_len_table[0x205]);
  6571. WFIFOW(fd,0)=0x205;
  6572. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6573. WFIFOSET(fd, packet_len_table[0x205]);
  6574. }
  6575. /*==========================================
  6576. *
  6577. *------------------------------------------
  6578. */
  6579. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6580. nullpo_retv(sd);
  6581. WFIFOHEAD(fd,packet_len_table[0x1f6]);
  6582. WFIFOW(fd,0)=0x1f6;
  6583. WFIFOSET(fd, packet_len_table[0x1f6]);
  6584. }
  6585. /*==========================================
  6586. *
  6587. *------------------------------------------
  6588. */
  6589. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6590. nullpo_retv(sd);
  6591. WFIFOHEAD(fd,packet_len_table[0x1e2]);
  6592. WFIFOW(fd,0)=0x1e2;
  6593. WFIFOSET(fd, packet_len_table[0x1e2]);
  6594. }
  6595. /*==========================================
  6596. * 座る
  6597. *------------------------------------------
  6598. */
  6599. void clif_sitting(struct map_session_data *sd)
  6600. {
  6601. unsigned char buf[64];
  6602. nullpo_retv(sd);
  6603. WBUFW(buf, 0) = 0x8a;
  6604. WBUFL(buf, 2) = sd->bl.id;
  6605. WBUFB(buf,26) = 2;
  6606. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  6607. }
  6608. /*==========================================
  6609. *
  6610. *------------------------------------------
  6611. */
  6612. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  6613. {
  6614. int fd;
  6615. nullpo_retr(0, sd);
  6616. fd = sd->fd;
  6617. if (!fd || !len) return 0; //Disconnected player.
  6618. WFIFOHEAD(fd, len+5);
  6619. WFIFOW(fd, 0) = 0x17f;
  6620. WFIFOW(fd, 2) = len + 5;
  6621. memcpy(WFIFOP(fd,4), mes, len);
  6622. WFIFOSET(fd, WFIFOW(fd,2));
  6623. return 1;
  6624. }
  6625. /*==========================================
  6626. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6627. *------------------------------------------
  6628. */
  6629. void clif_disp_message(struct block_list *src, char *mes, int len, int type)
  6630. {
  6631. unsigned char buf[1024];
  6632. if (!len) return;
  6633. WBUFW(buf, 0) = 0x17f;
  6634. WBUFW(buf, 2) = len + 5;
  6635. memcpy(WBUFP(buf,4), mes, len);
  6636. clif_send(buf, WBUFW(buf,2), src, type);
  6637. return;
  6638. }
  6639. /*==========================================
  6640. *
  6641. *------------------------------------------
  6642. */
  6643. int clif_GM_kickack(struct map_session_data *sd, int id)
  6644. {
  6645. int fd;
  6646. nullpo_retr(0, sd);
  6647. fd = sd->fd;
  6648. WFIFOHEAD(fd,packet_len_table[0xcd]);
  6649. WFIFOW(fd,0) = 0xcd;
  6650. WFIFOL(fd,2) = id;
  6651. WFIFOSET(fd, packet_len_table[0xcd]);
  6652. return 0;
  6653. }
  6654. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6655. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6656. {
  6657. int fd = tsd->fd;
  6658. WFIFOHEAD(fd,packet_len_table[0x18b]);
  6659. if(type)
  6660. clif_GM_kickack(sd,tsd->status.account_id);
  6661. if (!fd) {
  6662. map_quit(tsd);
  6663. return 0;
  6664. }
  6665. WFIFOW(fd,0) = 0x18b;
  6666. WFIFOW(fd,2) = 0;
  6667. WFIFOSET(fd,packet_len_table[0x18b]);
  6668. clif_setwaitclose(fd);
  6669. return 0;
  6670. }
  6671. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6672. {
  6673. int fd;
  6674. nullpo_retr(0, sd);
  6675. nullpo_retr(0, tsd);
  6676. fd = tsd->fd;
  6677. if (fd <= 0)
  6678. return 0;
  6679. WFIFOHEAD(fd,packet_len_table[0x14b]);
  6680. WFIFOW(fd,0) = 0x14b;
  6681. WFIFOB(fd,2) = 0;
  6682. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6683. WFIFOSET(fd, packet_len_table[0x14b]);
  6684. return 0;
  6685. }
  6686. /*==========================================
  6687. *
  6688. *------------------------------------------
  6689. */
  6690. int clif_timedout(struct map_session_data *sd)
  6691. {
  6692. nullpo_retr(0, sd);
  6693. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6694. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6695. clif_setwaitclose(sd->fd); // Set session to EOF
  6696. return 0;
  6697. }
  6698. /*==========================================
  6699. * Wis拒否許可応答
  6700. *------------------------------------------
  6701. */
  6702. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6703. {
  6704. int fd;
  6705. nullpo_retr(0, sd);
  6706. fd=sd->fd;
  6707. WFIFOHEAD(fd,packet_len_table[0xd1]);
  6708. WFIFOW(fd,0)=0xd1;
  6709. WFIFOB(fd,2)=type;
  6710. WFIFOB(fd,3)=flag;
  6711. WFIFOSET(fd,packet_len_table[0xd1]);
  6712. return 0;
  6713. }
  6714. /*==========================================
  6715. * Wis全拒否許可応答
  6716. *------------------------------------------
  6717. */
  6718. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6719. {
  6720. int fd;
  6721. nullpo_retr(0, sd);
  6722. fd=sd->fd;
  6723. WFIFOHEAD(fd,packet_len_table[0xd2]);
  6724. WFIFOW(fd,0)=0xd2;
  6725. WFIFOB(fd,2)=type;
  6726. WFIFOB(fd,3)=flag;
  6727. WFIFOSET(fd,packet_len_table[0xd2]);
  6728. return 0;
  6729. }
  6730. /*==========================================
  6731. * サウンドエフェクト
  6732. *------------------------------------------
  6733. */
  6734. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  6735. {
  6736. int fd;
  6737. nullpo_retv(sd);
  6738. nullpo_retv(bl);
  6739. fd=sd->fd;
  6740. WFIFOHEAD(fd,packet_len_table[0x1d3]);
  6741. WFIFOW(fd,0)=0x1d3;
  6742. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6743. WFIFOB(fd,26)=type;
  6744. WFIFOL(fd,27)=0;
  6745. WFIFOL(fd,31)=bl->id;
  6746. WFIFOSET(fd,packet_len_table[0x1d3]);
  6747. return;
  6748. }
  6749. int clif_soundeffectall(struct block_list *bl, char *name, int type, int coverage)
  6750. {
  6751. unsigned char buf[40];
  6752. malloc_set(buf, 0, packet_len_table[0x1d3]);
  6753. if(coverage < 0 || coverage > 22){
  6754. ShowError("clif_soundeffectall: undefined coverage.\n");
  6755. return 0;
  6756. }
  6757. nullpo_retr(0, bl);
  6758. WBUFW(buf,0)=0x1d3;
  6759. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6760. WBUFB(buf,26)=type;
  6761. WBUFL(buf,27)=0;
  6762. WBUFL(buf,31)=bl->id;
  6763. clif_send(buf, packet_len_table[0x1d3], bl, coverage);
  6764. return 0;
  6765. }
  6766. // displaying special effects (npcs, weather, etc) [Valaris]
  6767. int clif_specialeffect(struct block_list *bl, int type, int flag)
  6768. {
  6769. unsigned char buf[24];
  6770. nullpo_retr(0, bl);
  6771. malloc_set(buf, 0, packet_len_table[0x1f3]);
  6772. WBUFW(buf,0) = 0x1f3;
  6773. WBUFL(buf,2) = bl->id;
  6774. WBUFL(buf,6) = type;
  6775. clif_send(buf, packet_len_table[0x1f3], bl, flag);
  6776. if (disguised(bl)) {
  6777. WBUFL(buf,2) = -bl->id;
  6778. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  6779. }
  6780. return 0;
  6781. }
  6782. // refresh the client's screen, getting rid of any effects
  6783. int clif_refresh(struct map_session_data *sd) {
  6784. nullpo_retr(-1, sd);
  6785. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6786. clif_inventorylist(sd);
  6787. if(pc_iscarton(sd)){
  6788. clif_cartlist(sd);
  6789. clif_updatestatus(sd,SP_CARTINFO);
  6790. }
  6791. clif_updatestatus(sd,SP_MAXWEIGHT);
  6792. clif_updatestatus(sd,SP_WEIGHT);
  6793. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6794. clif_weather_check(sd);
  6795. return 0;
  6796. }
  6797. // updates the object's (bl) name on client
  6798. int clif_charnameack (int fd, struct block_list *bl)
  6799. {
  6800. unsigned char buf[103];
  6801. int cmd = 0x95;
  6802. nullpo_retr(0, bl);
  6803. WBUFW(buf,0) = cmd;
  6804. WBUFL(buf,2) = bl->id;
  6805. switch(bl->type) {
  6806. case BL_PC:
  6807. {
  6808. struct map_session_data *ssd = (struct map_session_data *)bl;
  6809. struct party_data *p = NULL;
  6810. struct guild *g = NULL;
  6811. //Requesting your own "shadow" name. [Skotlex]
  6812. if (ssd->fd == fd && ssd->disguise)
  6813. WBUFL(buf,2) = -bl->id;
  6814. if (strlen(ssd->fakename)>1) {
  6815. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6816. break;
  6817. }
  6818. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6819. if (ssd->status.party_id > 0)
  6820. p = party_search(ssd->status.party_id);
  6821. if (ssd->status.guild_id > 0)
  6822. g = guild_search(ssd->status.guild_id);
  6823. if (p == NULL && g == NULL)
  6824. break;
  6825. WBUFW(buf, 0) = cmd = 0x195;
  6826. if (p)
  6827. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6828. else
  6829. WBUFB(buf,30) = 0;
  6830. if (g)
  6831. {
  6832. int i, ps = -1;
  6833. for(i = 0; i < g->max_member; i++) {
  6834. if (g->member[i].account_id == ssd->status.account_id &&
  6835. g->member[i].char_id == ssd->status.char_id )
  6836. {
  6837. ps = g->member[i].position;
  6838. break;
  6839. }
  6840. }
  6841. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6842. {
  6843. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6844. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6845. } else { //Assume no guild.
  6846. WBUFB(buf,54) = 0;
  6847. WBUFB(buf,78) = 0;
  6848. }
  6849. } else {
  6850. WBUFB(buf,54) = 0;
  6851. WBUFB(buf,78) = 0;
  6852. }
  6853. }
  6854. break;
  6855. //[blackhole89]
  6856. case BL_HOM:
  6857. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6858. break;
  6859. case BL_PET:
  6860. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6861. break;
  6862. case BL_NPC:
  6863. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6864. break;
  6865. case BL_MOB:
  6866. {
  6867. struct mob_data *md = (struct mob_data *)bl;
  6868. nullpo_retr(0, md);
  6869. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6870. if (md->guardian_data && md->guardian_data->guild_id) {
  6871. WBUFW(buf, 0) = cmd = 0x195;
  6872. WBUFB(buf,30) = 0;
  6873. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6874. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6875. } else if (battle_config.show_mob_info) {
  6876. char mobhp[50], *str_p = mobhp;
  6877. WBUFW(buf, 0) = cmd = 0x195;
  6878. if (battle_config.show_mob_info&4)
  6879. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6880. if (battle_config.show_mob_info&1)
  6881. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6882. if (battle_config.show_mob_info&2)
  6883. str_p += sprintf(str_p, "HP: %d%% | ",
  6884. md->status.max_hp > 10000?
  6885. md->status.hp/(md->status.max_hp/100):
  6886. 100*md->status.hp/md->status.max_hp);
  6887. //Even thought mobhp ain't a name, we send it as one so the client
  6888. //can parse it. [Skotlex]
  6889. if (str_p != mobhp) {
  6890. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6891. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6892. WBUFB(buf,54) = 0;
  6893. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6894. }
  6895. }
  6896. }
  6897. break;
  6898. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6899. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6900. // break;
  6901. return 0;
  6902. default:
  6903. if (battle_config.error_log)
  6904. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6905. return 0;
  6906. }
  6907. // if no receipient specified just update nearby clients
  6908. if (fd == 0)
  6909. clif_send(buf, packet_len_table[cmd], bl, AREA);
  6910. else {
  6911. WFIFOHEAD(fd, packet_len_table[cmd]);
  6912. memcpy(WFIFOP(fd, 0), buf, packet_len_table[cmd]);
  6913. WFIFOSET(fd, packet_len_table[cmd]);
  6914. }
  6915. return 0;
  6916. }
  6917. //Used to update when a char leaves a party/guild. [Skotlex]
  6918. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6919. int clif_charnameupdate (struct map_session_data *ssd)
  6920. {
  6921. unsigned char buf[103];
  6922. int cmd = 0x195;
  6923. struct party_data *p = NULL;
  6924. struct guild *g = NULL;
  6925. nullpo_retr(0, ssd);
  6926. if (strlen(ssd->fakename)>1)
  6927. return 0; //No need to update as the party/guild was not displayed anyway.
  6928. WBUFW(buf,0) = cmd;
  6929. WBUFL(buf,2) = ssd->bl.id;
  6930. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6931. if (ssd->status.party_id > 0)
  6932. p = party_search(ssd->status.party_id);
  6933. if (ssd->status.guild_id > 0)
  6934. g = guild_search(ssd->status.guild_id);
  6935. if (p)
  6936. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6937. else
  6938. WBUFB(buf,30) = 0;
  6939. if (g)
  6940. {
  6941. int i, ps = -1;
  6942. for(i = 0; i < g->max_member; i++) {
  6943. if (g->member[i].account_id == ssd->status.account_id &&
  6944. g->member[i].char_id == ssd->status.char_id )
  6945. {
  6946. ps = g->member[i].position;
  6947. break;
  6948. }
  6949. }
  6950. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6951. {
  6952. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6953. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6954. } else { //Assume no guild.
  6955. WBUFB(buf,54) = 0;
  6956. WBUFB(buf,78) = 0;
  6957. }
  6958. } else {
  6959. WBUFB(buf,54) = 0;
  6960. WBUFB(buf,78) = 0;
  6961. }
  6962. // Update nearby clients
  6963. clif_send(buf, packet_len_table[cmd], &ssd->bl, AREA);
  6964. return 0;
  6965. }
  6966. int clif_slide(struct block_list *bl, int x, int y){
  6967. unsigned char buf[10];
  6968. nullpo_retr(0, bl);
  6969. WBUFW(buf, 0) = 0x01ff;
  6970. WBUFL(buf, 2) = bl->id;
  6971. WBUFW(buf, 6) = x;
  6972. WBUFW(buf, 8) = y;
  6973. clif_send(buf, packet_len_table[0x1ff], bl, AREA);
  6974. return 0;
  6975. }
  6976. /*------------------------------------------
  6977. * @me command by lordalfa, rewritten implementation by Skotlex
  6978. *------------------------------------------
  6979. */
  6980. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  6981. {
  6982. unsigned char buf[256]; //This should be more than sufficient, the theorical max is MESSAGE_SIZE+NAME_LENGTH + 8 (pads and extra inserted crap)
  6983. int len_mes = strlen(mes)+1; //Account for \0
  6984. if (len_mes + 8 >= 256) {
  6985. if (battle_config.error_log)
  6986. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6987. len_mes = 247; //Trunk it to avoid problems.
  6988. }
  6989. // send message to others
  6990. WBUFW(buf,0) = 0x8d;
  6991. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6992. WBUFL(buf,4) = sd->bl.id;
  6993. memcpy(WBUFP(buf,8), mes, len_mes);
  6994. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6995. // send back message to the speaker
  6996. WBUFW(buf,0) = 0x8e;
  6997. WBUFW(buf, 2) = len_mes + 4;
  6998. memcpy(WBUFP(buf,4), mes, len_mes);
  6999. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7000. return 0;
  7001. }
  7002. /*==========================
  7003. * Minimap fix [Kevin]
  7004. * Remove dot from minimap
  7005. *--------------------------
  7006. */
  7007. int clif_party_xy_remove(struct map_session_data *sd)
  7008. {
  7009. unsigned char buf[16];
  7010. nullpo_retr(0, sd);
  7011. WBUFW(buf,0)=0x107;
  7012. WBUFL(buf,2)=sd->status.account_id;
  7013. WBUFW(buf,6)=-1;
  7014. WBUFW(buf,8)=-1;
  7015. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  7016. return 0;
  7017. }
  7018. //Displays gospel-buff information (thanks to Rayce):
  7019. //Type determines message based on this table:
  7020. /*
  7021. 0x15 End all negative status
  7022. 0x16 Immunity to all status
  7023. 0x17 MaxHP +100%
  7024. 0x18 MaxSP +100%
  7025. 0x19 All stats +20
  7026. 0x1c Enchant weapon with Holy element
  7027. 0x1d Enchant armor with Holy element
  7028. 0x1e DEF +25%
  7029. 0x1f ATK +100%
  7030. 0x20 HIT/Flee +50
  7031. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  7032. */
  7033. void clif_gospel_info(struct map_session_data *sd, int type)
  7034. {
  7035. int fd=sd->fd;
  7036. WFIFOHEAD(fd,packet_len_table[0x215]);
  7037. WFIFOW(fd,0)=0x215;
  7038. WFIFOL(fd,2)=type;
  7039. WFIFOSET(fd, packet_len_table[0x215]);
  7040. }
  7041. /*==========================================
  7042. * Info about Star Glaldiator save map [Komurka]
  7043. * type: 1: Information, 0: Map registered
  7044. *------------------------------------------
  7045. */
  7046. void clif_feel_info(struct map_session_data *sd, unsigned char feel_level, unsigned char type)
  7047. {
  7048. int fd=sd->fd;
  7049. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7050. WFIFOW(fd,0)=0x20e;
  7051. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  7052. WFIFOL(fd,26)=sd->bl.id;
  7053. WFIFOB(fd,30)=feel_level;
  7054. WFIFOB(fd,31)=type?1:0;
  7055. WFIFOSET(fd, packet_len_table[0x20e]);
  7056. }
  7057. /*==========================================
  7058. * Info about Star Glaldiator hate mob [Komurka]
  7059. * type: 1: Register mob, 0: Information.
  7060. *------------------------------------------
  7061. */
  7062. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7063. {
  7064. int fd=sd->fd;
  7065. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7066. WFIFOW(fd,0)=0x20e;
  7067. if (pcdb_checkid(class_))
  7068. strncpy(WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  7069. else if (mobdb_checkid(class_))
  7070. strncpy(WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  7071. else //Really shouldn't happen...
  7072. malloc_tsetdword(WFIFOP(fd,2), 0, NAME_LENGTH);
  7073. WFIFOL(fd,26)=sd->bl.id;
  7074. WFIFOB(fd,30)=hate_level;
  7075. WFIFOB(fd,31)=type?10:11; //Register/Info
  7076. WFIFOSET(fd, packet_len_table[0x20e]);
  7077. }
  7078. /*==========================================
  7079. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7080. *------------------------------------------
  7081. */
  7082. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7083. {
  7084. int fd=sd->fd;
  7085. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7086. WFIFOW(fd,0)=0x20e;
  7087. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  7088. WFIFOL(fd,26)=mob_id;
  7089. WFIFOB(fd,30)=progress; //Message to display
  7090. WFIFOB(fd,31)=20;
  7091. WFIFOSET(fd, packet_len_table[0x20e]);
  7092. }
  7093. /*==========================================
  7094. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7095. *------------------------------------------
  7096. */
  7097. void clif_feel_hate_reset(struct map_session_data *sd)
  7098. {
  7099. int fd=sd->fd;
  7100. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7101. WFIFOW(fd,0)=0x20e;
  7102. malloc_tsetdword(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  7103. WFIFOL(fd,26)=sd->bl.id;
  7104. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  7105. WFIFOB(fd,31)=30;
  7106. WFIFOSET(fd, packet_len_table[0x20e]);
  7107. }
  7108. // ---------------------
  7109. // clif_guess_PacketVer
  7110. // ---------------------
  7111. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7112. static int clif_guess_PacketVer(int fd, int get_previous)
  7113. {
  7114. static int packet_ver = -1;
  7115. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7116. RFIFOHEAD(fd);
  7117. if (get_previous) //For quick reruns, since the normal code flow is to fetch this once to identify the packet version, then again in the wanttoconnect function. [Skotlex]
  7118. return packet_ver;
  7119. //By default, start searching on the default one.
  7120. packet_ver = clif_config.packet_db_ver;
  7121. cmd = RFIFOW(fd,0);
  7122. packet_len = RFIFOREST(fd);
  7123. if (
  7124. cmd == clif_config.connect_cmd[packet_ver] &&
  7125. packet_len == packet_db[packet_ver][cmd].len &&
  7126. ((value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) == 0 || value == 1) &&
  7127. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) > 700000 && //Account ID is valid
  7128. value <= max_account_id &&
  7129. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) > 0 && //Char ID is valid
  7130. value <= max_char_id &&
  7131. (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) > 0 //Login 1 is a positive value (?)
  7132. )
  7133. return clif_config.packet_db_ver; //Default packet version found.
  7134. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7135. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7136. if (cmd != clif_config.connect_cmd[packet_ver] || //it is not a wanttoconnection for this version.
  7137. packet_len != packet_db[packet_ver][cmd].len) //The size of the wantoconnection packet does not matches.
  7138. continue;
  7139. if (
  7140. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < 700000 || value > max_account_id
  7141. || (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) < 1 || value > max_char_id
  7142. //What is login 1? In my tests it is a very very high value.
  7143. || (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) < 1
  7144. //This check seems redundant, all wanttoconnection packets have the gender on the very
  7145. //last byte of the packet.
  7146. || (value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) < 0 || value > 1
  7147. )
  7148. continue;
  7149. return packet_ver; //This is our best guess.
  7150. }
  7151. packet_ver = -1;
  7152. return -1;
  7153. }
  7154. // ------------
  7155. // clif_parse_*
  7156. // ------------
  7157. // パケット読み取って色々操作
  7158. /*==========================================
  7159. *
  7160. *------------------------------------------
  7161. */
  7162. void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
  7163. {
  7164. struct map_session_data *old_sd;
  7165. int cmd, account_id, char_id, login_id1, sex;
  7166. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7167. 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])
  7168. RFIFOHEAD(fd);
  7169. if (sd) {
  7170. if (battle_config.error_log)
  7171. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  7172. return;
  7173. }
  7174. packet_ver = clif_guess_PacketVer(fd, 1);
  7175. cmd = RFIFOW(fd,0);
  7176. if (packet_ver <= 0)
  7177. return;
  7178. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7179. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7180. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7181. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7182. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7183. if ((old_sd = map_id2sd(account_id)) != NULL)
  7184. { // if same account already connected, we disconnect the 2 sessions
  7185. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  7186. if (old_sd->state.finalsave || !old_sd->state.auth)
  7187. ; //Previous player is not done loading.
  7188. //Or he has quit, but is not done saving on the charserver.
  7189. else if (old_sd->fd)
  7190. clif_authfail_fd(old_sd->fd, 2); // same id
  7191. else
  7192. map_quit(old_sd);
  7193. clif_authfail_fd(fd, 8); // still recognizes last connection
  7194. return;
  7195. }
  7196. sd = (struct map_session_data*)aCalloc(1, sizeof(struct map_session_data));
  7197. sd->fd = fd;
  7198. sd->packet_ver = packet_ver;
  7199. session[fd]->session_data = sd;
  7200. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7201. WFIFOHEAD(fd,4);
  7202. WFIFOL(fd,0) = sd->bl.id;
  7203. WFIFOSET(fd,4);
  7204. chrif_authreq(sd);
  7205. return;
  7206. }
  7207. static int clif_nighttimer(int tid, unsigned int tick, int id, int data)
  7208. {
  7209. TBL_PC *sd;
  7210. sd=map_id2sd(id);
  7211. if (!sd) return 0;
  7212. //Check if character didn't instant-warped after logging in.
  7213. if (sd->bl.prev!=NULL) {
  7214. sd->state.night = 1;
  7215. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7216. }
  7217. return 0;
  7218. }
  7219. /*==========================================
  7220. * 007d クライアント側マップ読み込み完了
  7221. * map侵入時に必要なデータを全て送りつける
  7222. *------------------------------------------
  7223. */
  7224. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7225. {
  7226. if(sd->bl.prev != NULL)
  7227. return;
  7228. if (!sd->state.auth)
  7229. { //Character loading is not complete yet!
  7230. //Let pc_reg_received reinvoke this when ready.
  7231. sd->state.connect_new = 0;
  7232. return;
  7233. }
  7234. if (sd->state.rewarp)
  7235. { //Rewarp player.
  7236. sd->state.rewarp = 0;
  7237. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7238. return;
  7239. }
  7240. // look
  7241. #if PACKETVER < 4
  7242. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7243. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7244. #else
  7245. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7246. #endif
  7247. if(sd->vd.cloth_color)
  7248. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7249. // item
  7250. pc_checkitem(sd);
  7251. clif_inventorylist(sd);
  7252. // cart
  7253. if(pc_iscarton(sd)){
  7254. clif_cartlist(sd);
  7255. clif_updatestatus(sd,SP_CARTINFO);
  7256. }
  7257. // weight max , now
  7258. clif_updatestatus(sd,SP_MAXWEIGHT);
  7259. clif_updatestatus(sd,SP_WEIGHT);
  7260. if(battle_config.pc_invincible_time > 0) {
  7261. if(map_flag_gvg(sd->bl.m))
  7262. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7263. else
  7264. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7265. }
  7266. map_addblock(&sd->bl); // ブロック登録
  7267. clif_spawn(&sd->bl); // spawn
  7268. // Party
  7269. if(sd->status.party_id) {
  7270. party_send_movemap(sd);
  7271. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7272. }
  7273. // guild
  7274. if(sd->status.guild_id)
  7275. guild_send_memberinfoshort(sd,1);
  7276. // pvp
  7277. //if(sd->pvp_timer!=-1 && !battle_config.pk_mode) /PVP Client crash fix* Removed timer deletion
  7278. // delete_timer(sd->pvp_timer,pc_calc_pvprank_timer);
  7279. if(map[sd->bl.m].flag.pvp){
  7280. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7281. if (sd->pvp_timer == -1)
  7282. sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
  7283. sd->pvp_rank=0;
  7284. sd->pvp_lastusers=0;
  7285. sd->pvp_point=5;
  7286. sd->pvp_won=0;
  7287. sd->pvp_lost=0;
  7288. }
  7289. clif_set0199(fd,1);
  7290. } else
  7291. // set flag, if it's a duel [LuzZza]
  7292. if(sd->duel_group)
  7293. clif_set0199(fd, 1);
  7294. if(map_flag_gvg(sd->bl.m) || map[sd->bl.m].flag.gvg_dungeon)
  7295. clif_set0199(fd,3);
  7296. // pet
  7297. if(sd->pd) {
  7298. map_addblock(&sd->pd->bl);
  7299. clif_spawn(&sd->pd->bl);
  7300. clif_send_petdata(sd,0,0);
  7301. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7302. clif_send_petstatus(sd);
  7303. }
  7304. //homunculus [blackhole89]
  7305. if(merc_is_hom_active(sd->hd)) {
  7306. map_addblock(&sd->hd->bl);
  7307. clif_spawn(&sd->hd->bl);
  7308. clif_hominfo(sd,sd->hd,1);
  7309. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7310. clif_send_homdata(sd,0,0);
  7311. clif_homskillinfoblock(sd);
  7312. //Homunc mimic their master's speed on each map change. [Skotlex]
  7313. if (battle_config.slaves_inherit_speed&1)
  7314. status_calc_bl(&sd->hd->bl, SCB_SPEED);
  7315. }
  7316. if(sd->state.connect_new) {
  7317. int lv;
  7318. sd->state.connect_new = 0;
  7319. clif_skillinfoblock(sd);
  7320. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7321. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7322. clif_updatestatus(sd,SP_SKILLPOINT);
  7323. clif_initialstatus(sd);
  7324. if (sd->sc.option&OPTION_FALCON)
  7325. clif_status_load(&sd->bl, SI_FALCON, 1);
  7326. if (sd->sc.option&OPTION_RIDING)
  7327. clif_status_load(&sd->bl, SI_RIDING, 1);
  7328. if(sd->status.manner < 0)
  7329. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7330. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7331. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7332. if(sd->bl.m == sd->feel_map[0].m
  7333. || sd->bl.m == sd->feel_map[1].m
  7334. || sd->bl.m == sd->feel_map[2].m)
  7335. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7336. }
  7337. if(sd->pd && sd->pd->pet.intimate > 900)
  7338. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7339. //Delayed night effect on log-on fix for the glow-issue. Thanks to Larry.
  7340. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7341. add_timer(gettick()+1000,clif_nighttimer,sd->bl.id,0);
  7342. // Notify everyone that this char logged in [Skotlex].
  7343. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7344. //Login Event
  7345. npc_script_event(sd, NPCE_LOGIN);
  7346. } else {
  7347. //For some reason the client "loses" these on map-change.
  7348. clif_updatestatus(sd,SP_STR);
  7349. clif_updatestatus(sd,SP_AGI);
  7350. clif_updatestatus(sd,SP_VIT);
  7351. clif_updatestatus(sd,SP_INT);
  7352. clif_updatestatus(sd,SP_DEX);
  7353. clif_updatestatus(sd,SP_LUK);
  7354. sd->state.using_fake_npc = 0;
  7355. //New 'night' effect by dynamix [Skotlex]
  7356. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7357. { //Display night.
  7358. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  7359. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7360. else
  7361. sd->state.night = 1;
  7362. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7363. } else if (sd->state.night) { //Clear night display.
  7364. sd->state.night = 0;
  7365. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7366. }
  7367. if(sd->npc_id)
  7368. npc_event_dequeue(sd);
  7369. }
  7370. // Lance
  7371. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  7372. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  7373. npc_script_event(sd, NPCE_LOADMAP);
  7374. }
  7375. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7376. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7377. clif_weather_check(sd);
  7378. map_foreachinarea(clif_getareachar,sd->bl.m,
  7379. sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,
  7380. BL_ALL,sd);
  7381. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7382. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7383. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7384. else
  7385. sd->areanpc_id = 0;
  7386. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7387. if(pc_isdead(sd))
  7388. clif_clearchar_area(&sd->bl,1);
  7389. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7390. // else
  7391. // clif_changed_dir(&sd->bl, SELF);
  7392. }
  7393. /*==========================================
  7394. *
  7395. *------------------------------------------
  7396. */
  7397. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7398. RFIFOHEAD(fd);
  7399. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7400. WFIFOHEAD(fd, packet_len_table[0x7f]);
  7401. WFIFOW(fd,0)=0x7f;
  7402. WFIFOL(fd,2)=gettick();
  7403. WFIFOSET(fd,packet_len_table[0x7f]);
  7404. return;
  7405. }
  7406. static int clif_walktoxy_timer(int tid, unsigned int tick, int id, int data)
  7407. {
  7408. struct map_session_data *sd;
  7409. short x,y;
  7410. if (!session[id] || (sd = session[id]->session_data) == NULL)
  7411. return 0;
  7412. if (!unit_can_move(&sd->bl))
  7413. return 0;
  7414. x = data>>16;
  7415. y = data&0xffff;
  7416. unit_walktoxy(&sd->bl, x, y, 0);
  7417. return 1;
  7418. }
  7419. /*==========================================
  7420. *
  7421. *------------------------------------------
  7422. */
  7423. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7424. int x, y;
  7425. int cmd;
  7426. unsigned int tick;
  7427. RFIFOHEAD(fd);
  7428. if (pc_isdead(sd)) {
  7429. clif_clearchar_area(&sd->bl, 1);
  7430. return;
  7431. }
  7432. if (clif_cant_act(sd) && sd->sc.opt1 != OPT1_STONEWAIT)
  7433. return;
  7434. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7435. return;
  7436. pc_stop_attack(sd);
  7437. if (sd->invincible_timer != -1)
  7438. pc_delinvincibletimer(sd);
  7439. cmd = RFIFOW(fd,0);
  7440. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7441. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7442. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7443. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7444. //Set last idle time... [Skotlex]
  7445. sd->idletime = last_tick;
  7446. tick = gettick();
  7447. if (DIFF_TICK(sd->ud.canmove_tick, tick) > 0 &&
  7448. DIFF_TICK(sd->ud.canmove_tick, tick) < 2000)
  7449. { // Delay walking command. [Skotlex]
  7450. add_timer(sd->ud.canmove_tick+1, clif_walktoxy_timer, fd, (x<<16)|y);
  7451. return;
  7452. }
  7453. if (!unit_can_move(&sd->bl))
  7454. return;
  7455. unit_walktoxy(&sd->bl, x, y, 0);
  7456. }
  7457. /*==========================================
  7458. *
  7459. *------------------------------------------
  7460. */
  7461. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7462. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7463. WFIFOW(fd,0) = 0x18b;
  7464. /* Rovert's prevent logout option fixed [Valaris] */
  7465. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7466. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7467. ) {
  7468. clif_setwaitclose(fd);
  7469. WFIFOW(fd,2)=0;
  7470. } else {
  7471. WFIFOW(fd,2)=1;
  7472. }
  7473. WFIFOSET(fd,packet_len_table[0x18b]);
  7474. }
  7475. /*==========================================
  7476. *
  7477. *------------------------------------------
  7478. */
  7479. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7480. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7481. /* if (target_id == server_char_id) {
  7482. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7483. sprintf(message_to_gm, msg_txt(536), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake player).
  7484. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7485. // if we block people
  7486. if (battle_config.ban_bot < 0) {
  7487. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7488. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7489. // message about the ban
  7490. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7491. // if we ban people
  7492. } else if (battle_config.ban_bot > 0) {
  7493. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7494. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7495. // message about the ban
  7496. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7497. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7498. // message about the ban
  7499. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7500. }
  7501. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7502. // send this info cause the bot ask until get an answer, damn spam
  7503. malloc_tsetdword(WPACKETP(0), 0, packet_len_table[0x95]);
  7504. WPACKETW(0) = 0x95;
  7505. WPACKETL(2) = server_char_id;
  7506. strncpy(WPACKETP(6), sd->status.name, 24);
  7507. SENDPACKET(fd, packet_len_table[0x95]);
  7508. // take fake player out of screen
  7509. WPACKETW(0) = 0x80;
  7510. WPACKETL(2) = server_char_id;
  7511. WPACKETB(6) = 0;
  7512. SENDPACKET(fd, packet_len_table[0x80]);
  7513. // take fake mob out of screen
  7514. WPACKETW(0) = 0x80;
  7515. WPACKETL(2) = server_fake_mob_id;
  7516. WPACKETB(6) = 0;
  7517. SENDPACKET(fd, packet_len_table[0x80]);
  7518. }
  7519. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7520. if (target_id == server_fake_mob_id) {
  7521. int fake_mob;
  7522. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7523. sprintf(message_to_gm, msg_txt(537), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake mob).
  7524. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7525. // if we block people
  7526. if (battle_config.ban_bot < 0) {
  7527. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7528. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7529. // message about the ban
  7530. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7531. // if we ban people
  7532. } else if (battle_config.ban_bot > 0) {
  7533. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7534. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7535. // message about the ban
  7536. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7537. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7538. // message about the ban
  7539. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7540. }
  7541. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7542. // send this info cause the bot ask until get an answer, damn spam
  7543. malloc_tsetdword(WPACKETP(0), 0, packet_len_table[0x95]);
  7544. WPACKETW(0) = 0x95;
  7545. WPACKETL(2) = server_fake_mob_id;
  7546. fake_mob = fake_mob_list[(sd->bl.m + sd->fd + sd->status.char_id) % (sizeof(fake_mob_list) / sizeof(fake_mob_list[0]))]; // never same mob
  7547. if (!mobdb_checkid(fake_mob))
  7548. fake_mob = 1002; // poring (default)
  7549. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7550. SENDPACKET(fd, packet_len_table[0x95]);
  7551. // take fake mob out of screen
  7552. WPACKETW(0) = 0x80;
  7553. WPACKETL(2) = server_fake_mob_id;
  7554. WPACKETB(6) = 0;
  7555. SENDPACKET(fd, packet_len_table[0x80]);
  7556. // take fake player out of screen
  7557. WPACKETW(0) = 0x80;
  7558. WPACKETL(2) = server_char_id;
  7559. WPACKETB(6) = 0;
  7560. SENDPACKET(fd, packet_len_table[0x80]);
  7561. }
  7562. */
  7563. return;
  7564. }
  7565. /*==========================================
  7566. *
  7567. *------------------------------------------
  7568. */
  7569. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7570. int account_id;
  7571. struct block_list* bl;
  7572. struct status_change *sc;
  7573. RFIFOHEAD(fd);
  7574. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7575. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7576. account_id= sd->bl.id;
  7577. bl = map_id2bl(account_id);
  7578. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7579. if (!bl) return;
  7580. sc = status_get_sc(bl);
  7581. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) && pc_isGM(sd) < battle_config.hack_info_GM_level)
  7582. {
  7583. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7584. //Asked name of invisible player, this shouldn't be possible!
  7585. //Possible bot? Thanks to veider and qspirit
  7586. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7587. unsigned char gm_msg[256];
  7588. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requests name of invisible chars.", sd->status.name, sd->status.account_id);
  7589. ShowWarning(gm_msg);
  7590. // information is sended to all online GM
  7591. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7592. return;
  7593. }
  7594. clif_charnameack(fd, bl);
  7595. }
  7596. /*==========================================
  7597. *
  7598. *------------------------------------------
  7599. */
  7600. void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
  7601. char *message, *buf, buf2[128];
  7602. RFIFOHEAD(fd);
  7603. WFIFOHEAD(fd, RFIFOW(fd,2) + 4);
  7604. message = (unsigned char*)RFIFOP(fd,4);
  7605. if (strlen(message) < strlen(sd->status.name) || //If the incoming string is too short...
  7606. strncmp(message, sd->status.name, strlen(sd->status.name)) != 0) //Or the name does not matches...
  7607. {
  7608. //Hacked message, or infamous "client desynch" issue where they pick
  7609. //one char while loading another. Just kick them out to correct it.
  7610. clif_setwaitclose(fd);
  7611. return;
  7612. }
  7613. if ((is_atcommand(fd, sd, message) != AtCommand_None) ||
  7614. (is_charcommand(fd, sd, message) != CharCommand_None))
  7615. return;
  7616. if (sd->sc.count &&
  7617. (sd->sc.data[SC_BERSERK].timer != -1 ||
  7618. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)))
  7619. return;
  7620. if (battle_config.min_chat_delay)
  7621. { //[Skotlex]
  7622. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7623. return;
  7624. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7625. }
  7626. if (RFIFOW(fd,2)+4 < 128)
  7627. buf = buf2; //Use a static buffer.
  7628. else
  7629. buf = (unsigned char*)aMallocA((RFIFOW(fd,2) + 4)*sizeof(char));
  7630. // send message to others
  7631. WBUFW(buf,0) = 0x8d;
  7632. WBUFW(buf,2) = RFIFOW(fd,2) + 4; // len of message - 4 + 8
  7633. WBUFL(buf,4) = sd->bl.id;
  7634. memcpy(WBUFP(buf,8), message, RFIFOW(fd,2) - 4);
  7635. clif_send(buf, WBUFW(buf,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7636. if(buf != buf2) aFree(buf);
  7637. // send back message to the speaker
  7638. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7639. WFIFOW(fd,0) = 0x8e;
  7640. WFIFOSET(fd, WFIFOW(fd,2));
  7641. #ifdef PCRE_SUPPORT
  7642. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7643. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7644. #endif
  7645. // Celest
  7646. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7647. int next = pc_nextbaseexp(sd);
  7648. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7649. switch (sd->state.snovice_flag) {
  7650. case 0:
  7651. if (strstr(message, msg_txt(504)))
  7652. sd->state.snovice_flag++;
  7653. break;
  7654. case 1:
  7655. sprintf(buf2, msg_txt(505), sd->status.name);
  7656. if (strstr(message, buf2))
  7657. sd->state.snovice_flag++;
  7658. break;
  7659. case 2:
  7660. if (strstr(message, msg_txt(506)))
  7661. sd->state.snovice_flag++;
  7662. break;
  7663. case 3:
  7664. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7665. break; //Do not override the noskill mapflag. [Skotlex]
  7666. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7667. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7668. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7669. sd->state.snovice_flag = 0;
  7670. break;
  7671. }
  7672. }
  7673. }
  7674. return;
  7675. }
  7676. int clif_message(struct block_list *bl, char* msg)
  7677. {
  7678. unsigned short msg_len = strlen(msg) + 1;
  7679. unsigned char buf[256];
  7680. nullpo_retr(0, bl);
  7681. WBUFW(buf, 0) = 0x8d;
  7682. WBUFW(buf, 2) = msg_len + 8;
  7683. WBUFL(buf, 4) = bl->id;
  7684. memcpy(WBUFP(buf, 8), msg, msg_len);
  7685. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7686. return 0;
  7687. }
  7688. /*==========================================
  7689. *
  7690. *------------------------------------------
  7691. */
  7692. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7693. // /m /mapmove (as @rura GM command)
  7694. char output[30]; // 17+4+4=26, 30 max.
  7695. char map_name[MAP_NAME_LENGTH]; //Err... map names are 15+'\0' in size, not 16+'\0' [Skotlex]
  7696. RFIFOHEAD(fd);
  7697. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7698. (pc_isGM(sd) >= get_atcommand_level(AtCommand_MapMove))) {
  7699. memcpy(map_name, RFIFOP(fd,2), MAP_NAME_LENGTH-1);
  7700. map_name[MAP_NAME_LENGTH-1]='\0';
  7701. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7702. atcommand_rura(fd, sd, "@rura", output);
  7703. }
  7704. return;
  7705. }
  7706. /*==========================================
  7707. *
  7708. *------------------------------------------
  7709. */
  7710. void clif_changed_dir(struct block_list *bl, int type) {
  7711. unsigned char buf[64];
  7712. WBUFW(buf,0) = 0x9c;
  7713. WBUFL(buf,2) = bl->id;
  7714. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7715. WBUFB(buf,8) = unit_getdir(bl);
  7716. clif_send(buf, packet_len_table[0x9c], bl, type);
  7717. if (disguised(bl)) {
  7718. WBUFL(buf,2) = -bl->id;
  7719. WBUFW(buf,6) = 0;
  7720. clif_send(buf, packet_len_table[0x9c], bl, SELF);
  7721. }
  7722. return;
  7723. }
  7724. /*==========================================
  7725. *
  7726. *------------------------------------------
  7727. */
  7728. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7729. unsigned char headdir, dir;
  7730. RFIFOHEAD(fd);
  7731. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7732. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7733. pc_setdir(sd, dir, headdir);
  7734. clif_changed_dir(&sd->bl, AREA_WOS);
  7735. return;
  7736. }
  7737. /*==========================================
  7738. *
  7739. *------------------------------------------
  7740. */
  7741. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7742. unsigned char buf[64];
  7743. RFIFOHEAD(fd);
  7744. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7745. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7746. clif_skill_fail(sd, 1, 0, 1);
  7747. return;
  7748. }
  7749. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7750. if (sd->emotionlasttime >= time(NULL)) {
  7751. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7752. clif_skill_fail(sd, 1, 0, 1);
  7753. return;
  7754. }
  7755. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7756. WBUFW(buf,0) = 0xc0;
  7757. WBUFL(buf,2) = sd->bl.id;
  7758. WBUFB(buf,6) = RFIFOB(fd,2);
  7759. clif_send(buf, packet_len_table[0xc0], &sd->bl, AREA);
  7760. } else
  7761. clif_skill_fail(sd, 1, 0, 1);
  7762. }
  7763. /*==========================================
  7764. *
  7765. *------------------------------------------
  7766. */
  7767. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7768. WFIFOHEAD(fd,packet_len_table[0xc2]);
  7769. WFIFOW(fd,0) = 0xc2;
  7770. WFIFOL(fd,2) = map_getusers();
  7771. WFIFOSET(fd,packet_len_table[0xc2]);
  7772. }
  7773. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7774. {
  7775. unsigned char buf[64];
  7776. if (pc_isdead(sd)) {
  7777. clif_clearchar_area(&sd->bl, 1);
  7778. return;
  7779. }
  7780. if (sd->sc.count &&
  7781. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7782. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7783. sd->sc.data[SC_BLADESTOP].timer != -1))
  7784. return;
  7785. pc_stop_walking(sd, 1);
  7786. pc_stop_attack(sd);
  7787. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7788. target_id = sd->bl.id;
  7789. switch(action_type) {
  7790. case 0x00: // once attack
  7791. case 0x07: // continuous attack
  7792. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7793. return;
  7794. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  7795. return;
  7796. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7797. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7798. clif_skill_fail(sd, 1, 4, 0);
  7799. return;
  7800. }
  7801. }
  7802. if (sd->invincible_timer != -1)
  7803. pc_delinvincibletimer(sd);
  7804. sd->idletime = last_tick;
  7805. unit_attack(&sd->bl, target_id, action_type != 0);
  7806. break;
  7807. case 0x02: // sitdown
  7808. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7809. clif_skill_fail(sd, 1, 0, 2);
  7810. break;
  7811. }
  7812. if(pc_issit(sd)) {
  7813. //Bugged client? Just refresh them.
  7814. WBUFW(buf, 0) = 0x8a;
  7815. WBUFL(buf, 2) = sd->bl.id;
  7816. WBUFB(buf,26) = 2;
  7817. clif_send(buf, packet_len_table[0x8a], &sd->bl, SELF);
  7818. return;
  7819. }
  7820. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7821. break;
  7822. if (sd->sc.count && (
  7823. sd->sc.data[SC_DANCING].timer != -1 ||
  7824. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7825. )) //No sitting during these states neither.
  7826. break;
  7827. pc_setsit(sd);
  7828. skill_sit(sd, 1);
  7829. clif_sitting(sd);
  7830. break;
  7831. case 0x03: // standup
  7832. if (!pc_issit(sd)) {
  7833. //Bugged client? Just refresh them.
  7834. WBUFW(buf, 0) = 0x8a;
  7835. WBUFL(buf, 2) = sd->bl.id;
  7836. WBUFB(buf,26) = 3;
  7837. clif_send(buf, packet_len_table[0x8a], &sd->bl, SELF);
  7838. return;
  7839. }
  7840. pc_setstand(sd);
  7841. skill_sit(sd, 0);
  7842. WBUFW(buf, 0) = 0x8a;
  7843. WBUFL(buf, 2) = sd->bl.id;
  7844. WBUFB(buf,26) = 3;
  7845. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  7846. break;
  7847. }
  7848. }
  7849. /*==========================================
  7850. *
  7851. *------------------------------------------
  7852. */
  7853. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  7854. RFIFOHEAD(fd);
  7855. clif_parse_ActionRequest_sub(sd,
  7856. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7857. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7858. gettick()
  7859. );
  7860. }
  7861. /*==========================================
  7862. *
  7863. *------------------------------------------
  7864. */
  7865. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  7866. RFIFOHEAD(fd);
  7867. switch(RFIFOB(fd,2)) {
  7868. case 0x00:
  7869. if (pc_isdead(sd)) {
  7870. pc_setstand(sd);
  7871. pc_setrestartvalue(sd, 3);
  7872. if (sd->sc.count && battle_config.debuff_on_logout&2) {
  7873. //For some reason food buffs are removed when you respawn.
  7874. if(sd->sc.data[SC_STRFOOD].timer!=-1)
  7875. status_change_end(&sd->bl,SC_STRFOOD,-1);
  7876. if(sd->sc.data[SC_AGIFOOD].timer!=-1)
  7877. status_change_end(&sd->bl,SC_AGIFOOD,-1);
  7878. if(sd->sc.data[SC_VITFOOD].timer!=-1)
  7879. status_change_end(&sd->bl,SC_VITFOOD,-1);
  7880. if(sd->sc.data[SC_INTFOOD].timer!=-1)
  7881. status_change_end(&sd->bl,SC_INTFOOD,-1);
  7882. if(sd->sc.data[SC_DEXFOOD].timer!=-1)
  7883. status_change_end(&sd->bl,SC_DEXFOOD,-1);
  7884. if(sd->sc.data[SC_LUKFOOD].timer!=-1)
  7885. status_change_end(&sd->bl,SC_LUKFOOD,-1);
  7886. if(sd->sc.data[SC_HITFOOD].timer!=-1)
  7887. status_change_end(&sd->bl,SC_HITFOOD,-1);
  7888. if(sd->sc.data[SC_FLEEFOOD].timer!=-1)
  7889. status_change_end(&sd->bl,SC_FLEEFOOD,-1);
  7890. if(sd->sc.data[SC_BATKFOOD].timer!=-1)
  7891. status_change_end(&sd->bl,SC_BATKFOOD,-1);
  7892. if(sd->sc.data[SC_WATKFOOD].timer!=-1)
  7893. status_change_end(&sd->bl,SC_WATKFOOD,-1);
  7894. if(sd->sc.data[SC_MATKFOOD].timer!=-1)
  7895. status_change_end(&sd->bl,SC_MATKFOOD,-1);
  7896. }
  7897. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  7898. }
  7899. // in case the player's status somehow wasn't updated yet [Celest]
  7900. else if (sd->battle_status.hp <= 0)
  7901. pc_setdead(sd);
  7902. break;
  7903. case 0x01:
  7904. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7905. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7906. { //Send to char-server for character selection.
  7907. chrif_charselectreq(sd, session[fd]->client_addr.sin_addr.s_addr);
  7908. } else {
  7909. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7910. WFIFOW(fd,0)=0x18b;
  7911. WFIFOW(fd,2)=1;
  7912. WFIFOSET(fd,packet_len_table[0x018b]);
  7913. }
  7914. break;
  7915. }
  7916. }
  7917. /*==========================================
  7918. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7919. *------------------------------------------
  7920. */
  7921. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  7922. char *command, *msg;
  7923. struct map_session_data *dstsd;
  7924. int i=0;
  7925. struct npc_data *npc;
  7926. char split_data[10][50];
  7927. char target[NAME_LENGTH+1];
  7928. char output[256];
  7929. unsigned int len;
  7930. RFIFOHEAD(fd);
  7931. len = RFIFOW(fd,2); //Packet length
  7932. if (len < 28)
  7933. { //Invalid packet, specified size is less than minimum! [Skotlex]
  7934. ShowWarning("Hack on Whisper: %s (AID/CID: %d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  7935. clif_setwaitclose(fd);
  7936. return;
  7937. }
  7938. if (len == 28) return; //Not sure if client really lets you send a blank line.
  7939. len-=28; //Message length
  7940. // 24+3+(RFIFOW(fd,2)-28)+1 <- last 1 is '\0'
  7941. command = (char*)aMallocA((NAME_LENGTH+4+len) * sizeof(char));
  7942. //No need for out of memory checks, malloc.c aborts the map when that happens.
  7943. msg = command;
  7944. msg+= sprintf(command, "%s : ", sd->status.name);
  7945. memcpy(msg, RFIFOP(fd, 28), len);
  7946. msg[len]='\0'; //Force a terminator
  7947. if ((is_charcommand(fd, sd, command) != CharCommand_None) ||
  7948. (is_atcommand(fd, sd, command) != AtCommand_None)) {
  7949. aFree(command);
  7950. return;
  7951. }
  7952. if (sd->sc.count &&
  7953. (sd->sc.data[SC_BERSERK].timer!=-1 ||
  7954. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))) {
  7955. aFree(command);
  7956. return;
  7957. }
  7958. if (battle_config.min_chat_delay)
  7959. { //[Skotlex]
  7960. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7961. aFree(command);
  7962. return;
  7963. }
  7964. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7965. }
  7966. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7967. target[NAME_LENGTH]='\0';
  7968. //Chat Logging type 'W' / Whisper
  7969. if(log_config.chat&1 //we log everything then
  7970. || ( log_config.chat&2 //if Whisper bit is on
  7971. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  7972. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, msg);
  7973. //-------------------------------------------------------//
  7974. // Lordalfa - Paperboy - To whisper NPC commands //
  7975. //-------------------------------------------------------//
  7976. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7977. char *str= target+4; //Skip the NPC: string part.
  7978. if ((npc = npc_name2id(str)))
  7979. {
  7980. char *split;
  7981. str = msg;
  7982. for( i=0; i < 10; ++i )
  7983. {// Splits the message using '#' as separators
  7984. split = strchr(str,'#');
  7985. if( split == NULL )
  7986. { // use the remaining string
  7987. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7988. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7989. for( ++i; i < 10; ++i )
  7990. split_data[i][0] = '\0';
  7991. break;
  7992. }
  7993. *split = '\0';
  7994. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7995. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7996. str = split+1;
  7997. }
  7998. for (i=0;i<10;i++)
  7999. {
  8000. sprintf(output, "@whispervar%d$", i);
  8001. set_var(sd,output,(char *) split_data[i]);
  8002. }
  8003. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  8004. npc_event(sd,output,0); // Calls the NPC label
  8005. aFree(command);
  8006. return;
  8007. }
  8008. }
  8009. // Main chat [LuzZza]
  8010. if(strcmpi(target, main_chat_nick) == 0) {
  8011. if(!sd->state.mainchat)
  8012. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8013. else {
  8014. sprintf(output, msg_txt(386), sd->status.name, msg);
  8015. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  8016. }
  8017. aFree(command);
  8018. return;
  8019. }
  8020. // searching destination character
  8021. dstsd = map_nick2sd(target);
  8022. // player is not on this map-server
  8023. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8024. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8025. // and if we ask for 'Test', we must not contact 'test' player
  8026. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8027. if (dstsd == NULL ||
  8028. strcmp(dstsd->status.name, target) != 0)
  8029. { // send message to inter-server
  8030. intif_wis_message(sd, target, msg, len);
  8031. aFree(command);
  8032. return;
  8033. }
  8034. // player is on this map-server
  8035. if (dstsd->fd == fd) {
  8036. // if you send to your self, don't send anything to others
  8037. // but, normaly, it's impossible!
  8038. clif_wis_message(fd, wisp_server_name,
  8039. "You can not page yourself. Sorry.",
  8040. strlen("You can not page yourself. Sorry.") + 1);
  8041. aFree(command);
  8042. return;
  8043. }
  8044. // otherwise, send message and answer immediatly
  8045. if (dstsd->state.ignoreAll) {
  8046. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  8047. clif_wis_end(fd, 1); // 1: target character is not loged in
  8048. else
  8049. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8050. aFree(command);
  8051. return;
  8052. }
  8053. // if player ignore the source character
  8054. for(i = 0; i < MAX_IGNORE_LIST &&
  8055. dstsd->ignore[i].name[0] != '\0' &&
  8056. strcmp(dstsd->ignore[i].name, sd->status.name) != 0
  8057. ; i++);
  8058. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8059. { //Ignored
  8060. clif_wis_end(fd, 2); // 2: ignored by target
  8061. aFree(command);
  8062. return;
  8063. }
  8064. // if source player not found in ignore list
  8065. if(dstsd->away_message[0] != '\0') { // Send away automessage [LuzZza]
  8066. //(Automessage has been sent)
  8067. sprintf(output, "%s %s", msg, msg_txt(543));
  8068. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  8069. clif_wis_end(fd, 0); // 0: success to send wisper
  8070. if(dstsd->state.autotrade)
  8071. //"Away [AT] - \"%s\""
  8072. sprintf(output, msg_txt(544), dstsd->away_message);
  8073. else
  8074. //"Away - \"%s\""
  8075. sprintf(output, msg_txt(545), dstsd->away_message);
  8076. aFree(command);
  8077. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  8078. return;
  8079. }
  8080. // Normal message
  8081. clif_wis_message(dstsd->fd, sd->status.name, msg, len);
  8082. clif_wis_end(fd, 0); // 0: success to send wisper
  8083. aFree(command);
  8084. return;
  8085. }
  8086. /*==========================================
  8087. *
  8088. *------------------------------------------
  8089. */
  8090. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  8091. // /b
  8092. RFIFOHEAD(fd);
  8093. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8094. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast)))
  8095. intif_GMmessage((char*)RFIFOP(fd,4), RFIFOW(fd,2)-4, 0);
  8096. }
  8097. /*==========================================
  8098. *
  8099. *------------------------------------------
  8100. */
  8101. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  8102. struct flooritem_data *fitem;
  8103. int map_object_id;
  8104. RFIFOHEAD(fd);
  8105. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8106. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8107. do {
  8108. if (pc_isdead(sd)) {
  8109. clif_clearchar_area(&sd->bl, 1);
  8110. break;
  8111. }
  8112. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8113. break;
  8114. if (clif_cant_act(sd))
  8115. break;
  8116. //Disable cloaking/chasewalking characters from looting [Skotlex]
  8117. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  8118. break;
  8119. if(sd->sc.count && (
  8120. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  8121. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  8122. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  8123. )
  8124. break;
  8125. if (!pc_takeitem(sd, fitem))
  8126. break;
  8127. return;
  8128. } while (0);
  8129. // Client REQUIRES a fail packet or you can no longer pick items.
  8130. clif_additem(sd,0,0,6);
  8131. }
  8132. /*==========================================
  8133. *
  8134. *------------------------------------------
  8135. */
  8136. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  8137. int item_index, item_amount;
  8138. RFIFOHEAD(fd);
  8139. if (pc_isdead(sd)) {
  8140. clif_clearchar_area(&sd->bl, 1);
  8141. return;
  8142. }
  8143. if (clif_cant_act(sd))
  8144. return;
  8145. if (sd->sc.count && (
  8146. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  8147. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  8148. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  8149. ))
  8150. return;
  8151. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8152. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8153. if (!pc_dropitem(sd, item_index, item_amount))
  8154. //Because the client does not likes being ignored.
  8155. clif_delitem(sd, item_index,0);
  8156. }
  8157. /*==========================================
  8158. *
  8159. *------------------------------------------
  8160. */
  8161. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  8162. int n;
  8163. RFIFOHEAD(fd);
  8164. if (pc_isdead(sd)) {
  8165. clif_clearchar_area(&sd->bl, 1);
  8166. return;
  8167. }
  8168. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8169. return;
  8170. //This flag enables you to use items while in an NPC. [Skotlex]
  8171. if (sd->npc_id) {
  8172. if (sd->npc_id != sd->npc_item_flag)
  8173. return;
  8174. } else
  8175. if (clif_trading(sd))
  8176. return;
  8177. if (sd->invincible_timer != -1)
  8178. pc_delinvincibletimer(sd);
  8179. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8180. sd->idletime = last_tick;
  8181. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8182. if(n <0 || n >= MAX_INVENTORY)
  8183. return;
  8184. if (!pc_useitem(sd,n))
  8185. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8186. }
  8187. /*==========================================
  8188. *
  8189. *------------------------------------------
  8190. */
  8191. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8192. {
  8193. int index;
  8194. RFIFOHEAD(fd);
  8195. if(pc_isdead(sd)) {
  8196. clif_clearchar_area(&sd->bl,1);
  8197. return;
  8198. }
  8199. index = RFIFOW(fd,2)-2;
  8200. if (index < 0 || index >= MAX_INVENTORY)
  8201. return; //Out of bounds check.
  8202. if(sd->npc_id) {
  8203. if (sd->npc_id != sd->npc_item_flag)
  8204. return;
  8205. } else if (sd->state.storage_flag || sd->sc.opt1)
  8206. ; //You can equip/unequip stuff while storage is open/under status changes
  8207. else if (clif_cant_act(sd))
  8208. return;
  8209. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  8210. return;
  8211. if(!sd->status.inventory[index].identify) { // 未鑑定
  8212. clif_equipitemack(sd,index,0,0); // fail
  8213. return;
  8214. }
  8215. //ペット用装備であるかないか
  8216. if(sd->inventory_data[index]) {
  8217. if(sd->inventory_data[index]->type != IT_PETARMOR){
  8218. if(sd->inventory_data[index]->type == IT_AMMO)
  8219. pc_equipitem(sd,index,EQP_AMMO); //Client doesn't sends the position.
  8220. else
  8221. pc_equipitem(sd,index,RFIFOW(fd,4));
  8222. } else
  8223. pet_equipitem(sd,index);
  8224. }
  8225. }
  8226. /*==========================================
  8227. *
  8228. *------------------------------------------
  8229. */
  8230. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8231. {
  8232. int index;
  8233. RFIFOHEAD(fd);
  8234. if(pc_isdead(sd)) {
  8235. clif_clearchar_area(&sd->bl,1);
  8236. return;
  8237. }
  8238. if (sd->state.storage_flag)
  8239. ; //You can equip/unequip stuff while storage is open.
  8240. else if (clif_cant_act(sd))
  8241. return;
  8242. index = RFIFOW(fd,2)-2;
  8243. pc_unequipitem(sd,index,1);
  8244. }
  8245. /*==========================================
  8246. *
  8247. *------------------------------------------
  8248. */
  8249. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8250. {
  8251. struct block_list *bl;
  8252. RFIFOHEAD(fd);
  8253. if(pc_isdead(sd)) {
  8254. clif_clearchar_area(&sd->bl,1);
  8255. return;
  8256. }
  8257. if (clif_cant_act(sd))
  8258. return;
  8259. bl = map_id2bl(RFIFOL(fd,2));
  8260. if (!bl) return;
  8261. switch (bl->type) {
  8262. case BL_MOB:
  8263. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  8264. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8265. break;
  8266. case BL_PC:
  8267. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8268. break;
  8269. case BL_NPC:
  8270. npc_click(sd,(TBL_NPC*)bl);
  8271. break;
  8272. }
  8273. return;
  8274. }
  8275. /*==========================================
  8276. *
  8277. *------------------------------------------
  8278. */
  8279. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8280. {
  8281. RFIFOHEAD(fd);
  8282. if (sd->state.trading)
  8283. return;
  8284. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8285. }
  8286. /*==========================================
  8287. *
  8288. *------------------------------------------
  8289. */
  8290. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8291. {
  8292. int fail=0,n;
  8293. unsigned short *item_list;
  8294. RFIFOHEAD(fd);
  8295. n = (RFIFOW(fd,2)-4) /4;
  8296. item_list = (unsigned short*)RFIFOP(fd,4);
  8297. if (sd->state.trading|| !sd->npc_shopid)
  8298. fail = 1;
  8299. else
  8300. fail = npc_buylist(sd,n,item_list);
  8301. sd->npc_shopid = 0; //Clear shop data.
  8302. WFIFOHEAD(fd,packet_len_table[0xca]);
  8303. WFIFOW(fd,0)=0xca;
  8304. WFIFOB(fd,2)=fail;
  8305. WFIFOSET(fd,packet_len_table[0xca]);
  8306. }
  8307. /*==========================================
  8308. *
  8309. *------------------------------------------
  8310. */
  8311. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8312. {
  8313. int fail=0,n;
  8314. unsigned short *item_list;
  8315. RFIFOHEAD(fd);
  8316. n = (RFIFOW(fd,2)-4) /4;
  8317. item_list = (unsigned short*)RFIFOP(fd,4);
  8318. if (sd->state.trading || !sd->npc_shopid)
  8319. fail = 1;
  8320. else
  8321. fail = npc_selllist(sd,n,item_list);
  8322. sd->npc_shopid = 0; //Clear shop data.
  8323. WFIFOHEAD(fd,packet_len_table[0xcb]);
  8324. WFIFOW(fd,0)=0xcb;
  8325. WFIFOB(fd,2)=fail;
  8326. WFIFOSET(fd,packet_len_table[0xcb]);
  8327. }
  8328. /*==========================================
  8329. *
  8330. *------------------------------------------
  8331. */
  8332. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8333. {
  8334. RFIFOHEAD(fd);
  8335. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8336. return;
  8337. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8338. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8339. } else
  8340. clif_skill_fail(sd,1,0,3);
  8341. }
  8342. /*==========================================
  8343. *
  8344. *------------------------------------------
  8345. */
  8346. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8347. {
  8348. RFIFOHEAD(fd);
  8349. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8350. }
  8351. /*==========================================
  8352. *
  8353. *------------------------------------------
  8354. */
  8355. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8356. {
  8357. RFIFOHEAD(fd);
  8358. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8359. }
  8360. /*==========================================
  8361. *
  8362. *------------------------------------------
  8363. */
  8364. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8365. {
  8366. RFIFOHEAD(fd);
  8367. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8368. }
  8369. /*==========================================
  8370. *
  8371. *------------------------------------------
  8372. */
  8373. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8374. {
  8375. RFIFOHEAD(fd);
  8376. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8377. }
  8378. /*==========================================
  8379. *
  8380. *------------------------------------------
  8381. */
  8382. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8383. {
  8384. chat_leavechat(sd);
  8385. }
  8386. //Handles notifying asker and rejecter of what has just ocurred.
  8387. //Type is used to determine the correct msg_txt to use:
  8388. //0:
  8389. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8390. {
  8391. char *msg, output[256];
  8392. // Your request has been rejected by autoreject option.
  8393. msg = msg_txt(392);
  8394. clif_disp_onlyself(src, msg, strlen(msg));
  8395. //Notice that a request was rejected.
  8396. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8397. clif_disp_onlyself(target, output, strlen(output));
  8398. }
  8399. /*==========================================
  8400. * 取引要請を相手に送る
  8401. *------------------------------------------
  8402. */
  8403. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8404. {
  8405. struct map_session_data *t_sd;
  8406. RFIFOHEAD(fd);
  8407. t_sd = map_id2sd(RFIFOL(fd,2));
  8408. if(!sd->chatID && clif_cant_act(sd))
  8409. return; //You can trade while in a chatroom.
  8410. // @noask [LuzZza]
  8411. if(t_sd) {
  8412. if (t_sd->state.noask) {
  8413. clif_noask_sub(sd, t_sd, 0);
  8414. return;
  8415. }
  8416. if(!t_sd->chatID && clif_cant_act(t_sd))
  8417. return;
  8418. }
  8419. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8420. trade_traderequest(sd,t_sd);
  8421. } else
  8422. clif_skill_fail(sd,1,0,0);
  8423. }
  8424. /*==========================================
  8425. * 取引要請
  8426. *------------------------------------------
  8427. */
  8428. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8429. {
  8430. RFIFOHEAD(fd);
  8431. trade_tradeack(sd,RFIFOB(fd,2));
  8432. }
  8433. /*==========================================
  8434. * アイテム追加
  8435. *------------------------------------------
  8436. */
  8437. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8438. {
  8439. RFIFOHEAD(fd);
  8440. trade_tradeadditem(sd,RFIFOW(fd,2),RFIFOL(fd,4));
  8441. }
  8442. /*==========================================
  8443. * アイテム追加完了(ok押し)
  8444. *------------------------------------------
  8445. */
  8446. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8447. {
  8448. trade_tradeok(sd);
  8449. }
  8450. /*==========================================
  8451. * 取引キャンセル
  8452. *------------------------------------------
  8453. */
  8454. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8455. {
  8456. trade_tradecancel(sd);
  8457. }
  8458. /*==========================================
  8459. * 取引許諾(trade押し)
  8460. *------------------------------------------
  8461. */
  8462. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8463. {
  8464. trade_tradecommit(sd);
  8465. }
  8466. /*==========================================
  8467. *
  8468. *------------------------------------------
  8469. */
  8470. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8471. {
  8472. pc_stop_attack(sd);
  8473. }
  8474. /*==========================================
  8475. * カートへアイテムを移す
  8476. *------------------------------------------
  8477. */
  8478. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8479. {
  8480. RFIFOHEAD(fd);
  8481. if (clif_trading(sd))
  8482. return;
  8483. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8484. }
  8485. /*==========================================
  8486. * カートからアイテムを出す
  8487. *------------------------------------------
  8488. */
  8489. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8490. {
  8491. RFIFOHEAD(fd);
  8492. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8493. }
  8494. /*==========================================
  8495. * 付属品(鷹,ペコ,カート)をはずす
  8496. *------------------------------------------
  8497. */
  8498. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8499. {
  8500. //Can only remove Cart/Riding/Falcon.
  8501. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8502. }
  8503. /*==========================================
  8504. * チェンジカート
  8505. *------------------------------------------
  8506. */
  8507. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8508. {
  8509. RFIFOHEAD(fd);
  8510. pc_setcart(sd,RFIFOW(fd,2));
  8511. }
  8512. /*==========================================
  8513. * ステータスアップ
  8514. *------------------------------------------
  8515. */
  8516. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8517. {
  8518. RFIFOHEAD(fd);
  8519. pc_statusup(sd,RFIFOW(fd,2));
  8520. }
  8521. /*==========================================
  8522. * スキルレベルアップ
  8523. *------------------------------------------
  8524. */
  8525. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8526. {
  8527. RFIFOHEAD(fd);
  8528. pc_skillup(sd,RFIFOW(fd,2));
  8529. }
  8530. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, int skillnum, int skilllv, int target_id)
  8531. {
  8532. int lv;
  8533. if (!hd)
  8534. return;
  8535. if (skillnotok_hom(skillnum, hd)) //[orn]
  8536. return;
  8537. if (hd->bl.id != target_id &&
  8538. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8539. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8540. if (hd->ud.skilltimer != -1) {
  8541. if (skillnum != SA_CASTCANCEL)
  8542. return;
  8543. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8544. return;
  8545. lv = merc_hom_checkskill(hd, skillnum);
  8546. if (skilllv > lv)
  8547. skilllv = lv;
  8548. if (skilllv)
  8549. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8550. }
  8551. /*==========================================
  8552. * スキル使用(ID指定)
  8553. *------------------------------------------
  8554. */
  8555. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8556. int skillnum, skilllv, tmp, target_id;
  8557. unsigned int tick = gettick();
  8558. RFIFOHEAD(fd);
  8559. if (clif_cant_act(sd))
  8560. return;
  8561. if (pc_issit(sd))
  8562. return;
  8563. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8564. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8565. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8566. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8567. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8568. sd->idletime = last_tick;
  8569. tmp = skill_get_inf(skillnum);
  8570. if (tmp&INF_GROUND_SKILL)
  8571. return; //Using a ground skill on a target? WRONG.
  8572. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8573. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8574. return;
  8575. }
  8576. if (skillnotok(skillnum, sd))
  8577. return;
  8578. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8579. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8580. if (sd->ud.skilltimer != -1) {
  8581. if (skillnum != SA_CASTCANCEL)
  8582. return;
  8583. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8584. clif_skill_fail(sd, skillnum, 4, 0);
  8585. return;
  8586. }
  8587. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8588. return;
  8589. if (sd->invincible_timer != -1)
  8590. pc_delinvincibletimer(sd);
  8591. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8592. target_id = sd->bl.id;
  8593. if (sd->skillitem == skillnum) {
  8594. if (skilllv != sd->skillitemlv)
  8595. skilllv = sd->skillitemlv;
  8596. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8597. return;
  8598. }
  8599. sd->skillitem = sd->skillitemlv = 0;
  8600. if (skillnum == MO_EXTREMITYFIST) {
  8601. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8602. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8603. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8604. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8605. if (!sd->state.skill_flag ) {
  8606. sd->state.skill_flag = 1;
  8607. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8608. return;
  8609. } else if (sd->bl.id == target_id) {
  8610. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8611. return;
  8612. }
  8613. }
  8614. }
  8615. if (skillnum == TK_JUMPKICK) {
  8616. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8617. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8618. if (!sd->state.skill_flag ) {
  8619. sd->state.skill_flag = 1;
  8620. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8621. return;
  8622. } else if (sd->bl.id == target_id) {
  8623. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8624. return;
  8625. }
  8626. }
  8627. }
  8628. if (skillnum >= GD_SKILLBASE) {
  8629. if (sd->state.gmaster_flag)
  8630. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8631. else
  8632. skilllv = 0;
  8633. } else {
  8634. tmp = pc_checkskill(sd, skillnum);
  8635. if (skilllv > tmp)
  8636. skilllv = tmp;
  8637. }
  8638. if (skilllv)
  8639. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8640. if (sd->state.skill_flag)
  8641. sd->state.skill_flag = 0;
  8642. }
  8643. /*==========================================
  8644. * スキル使用(場所指定)
  8645. *------------------------------------------
  8646. */
  8647. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8648. {
  8649. int lv;
  8650. unsigned int tick = gettick();
  8651. RFIFOHEAD(fd);
  8652. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8653. sd->idletime = last_tick;
  8654. if (skillnotok(skillnum, sd))
  8655. return;
  8656. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8657. return; //Using a target skill on the ground? WRONG.
  8658. if (skillmoreinfo != -1) {
  8659. if (pc_issit(sd)) {
  8660. clif_skill_fail(sd, skillnum, 0, 0);
  8661. return;
  8662. }
  8663. memcpy(talkie_mes, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8664. talkie_mes[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8665. }
  8666. if (sd->ud.skilltimer != -1)
  8667. return;
  8668. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8669. {
  8670. clif_skill_fail(sd, skillnum, 4, 0);
  8671. return;
  8672. }
  8673. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8674. return;
  8675. if (sd->invincible_timer != -1)
  8676. pc_delinvincibletimer(sd);
  8677. if (sd->skillitem == skillnum) {
  8678. if (skilllv != sd->skillitemlv)
  8679. skilllv = sd->skillitemlv;
  8680. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8681. } else {
  8682. sd->skillitem = sd->skillitemlv = 0;
  8683. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8684. if (skilllv > lv)
  8685. skilllv = lv;
  8686. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8687. }
  8688. }
  8689. }
  8690. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8691. RFIFOHEAD(fd);
  8692. if (clif_cant_act(sd))
  8693. return;
  8694. if (pc_issit(sd))
  8695. return;
  8696. clif_parse_UseSkillToPosSub(fd, sd,
  8697. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8698. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8699. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8700. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8701. -1 //Skill more info.
  8702. );
  8703. }
  8704. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8705. RFIFOHEAD(fd);
  8706. if (clif_cant_act(sd))
  8707. return;
  8708. if (pc_issit(sd))
  8709. return;
  8710. clif_parse_UseSkillToPosSub(fd, sd,
  8711. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8712. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8713. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8714. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8715. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8716. );
  8717. }
  8718. /*==========================================
  8719. * スキル使用(map指定)
  8720. *------------------------------------------
  8721. */
  8722. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8723. {
  8724. RFIFOHEAD(fd);
  8725. if (clif_cant_act(sd))
  8726. return;
  8727. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8728. return;
  8729. if(sd->invincible_timer != -1)
  8730. pc_delinvincibletimer(sd);
  8731. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8732. }
  8733. /*==========================================
  8734. * メモ要求
  8735. *------------------------------------------
  8736. */
  8737. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8738. {
  8739. if (!pc_isdead(sd))
  8740. pc_memo(sd,-1);
  8741. }
  8742. /*==========================================
  8743. * アイテム合成
  8744. *------------------------------------------
  8745. */
  8746. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8747. {
  8748. RFIFOHEAD(fd);
  8749. if (sd->menuskill_id != AM_PHARMACY)
  8750. return;
  8751. if (clif_trading(sd)) {
  8752. //Make it fail to avoid shop exploits where you sell something different than you see.
  8753. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8754. sd->menuskill_lv = sd->menuskill_id = 0;
  8755. return;
  8756. }
  8757. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8758. sd->menuskill_lv = sd->menuskill_id = 0;
  8759. }
  8760. /*==========================================
  8761. * 武器修理
  8762. *------------------------------------------
  8763. */
  8764. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8765. {
  8766. RFIFOHEAD(fd);
  8767. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8768. return;
  8769. if (clif_trading(sd)) {
  8770. //Make it fail to avoid shop exploits where you sell something different than you see.
  8771. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8772. sd->menuskill_lv = sd->menuskill_id = 0;
  8773. return;
  8774. }
  8775. skill_repairweapon(sd,RFIFOW(fd,2));
  8776. sd->menuskill_lv = sd->menuskill_id = 0;
  8777. }
  8778. /*==========================================
  8779. *
  8780. *------------------------------------------
  8781. */
  8782. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8783. int idx;
  8784. RFIFOHEAD(fd);
  8785. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8786. return;
  8787. if (clif_trading(sd)) {
  8788. //Make it fail to avoid shop exploits where you sell something different than you see.
  8789. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8790. sd->menuskill_lv = sd->menuskill_id = 0;
  8791. return;
  8792. }
  8793. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8794. skill_weaponrefine(sd, idx-2);
  8795. sd->menuskill_lv = sd->menuskill_id = 0;
  8796. }
  8797. /*==========================================
  8798. *
  8799. *------------------------------------------
  8800. */
  8801. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8802. {
  8803. unsigned char select;
  8804. RFIFOHEAD(fd);
  8805. select = RFIFOB(fd,6);
  8806. if((select > sd->max_menu && select != 0xff) || !select){
  8807. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8808. clif_GM_kick(sd,sd,0);
  8809. } else {
  8810. sd->npc_menu=select;
  8811. npc_scriptcont(sd,RFIFOL(fd,2));
  8812. }
  8813. }
  8814. /*==========================================
  8815. *
  8816. *------------------------------------------
  8817. */
  8818. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8819. {
  8820. RFIFOHEAD(fd);
  8821. #ifdef __WIN32
  8822. //For some extraordinarily eerie reason that noone has figured out yet,
  8823. //windows native compiles NEED this nullpo_retv or the function is not found!
  8824. nullpo_retv(sd);
  8825. #endif
  8826. npc_scriptcont(sd,RFIFOL(fd,2));
  8827. }
  8828. /*==========================================
  8829. *
  8830. *------------------------------------------
  8831. */
  8832. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8833. {
  8834. RFIFOHEAD(fd);
  8835. #define RFIFOL_(fd,pos) (*(int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos)))
  8836. //Input Value overflow Exploit FIX
  8837. sd->npc_amount=RFIFOL_(fd,6); //fixed by Lupus. npc_amount is (int) but was RFIFOL changing it to (unsigned int)
  8838. #undef RFIFOL_
  8839. npc_scriptcont(sd,RFIFOL(fd,2));
  8840. }
  8841. /*==========================================
  8842. *
  8843. *------------------------------------------
  8844. */
  8845. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8846. {
  8847. short message_len;
  8848. RFIFOHEAD(fd);
  8849. message_len = RFIFOW(fd,2)-7;
  8850. if(message_len < 1)
  8851. return; //Blank message?
  8852. if(message_len >= sizeof(sd->npc_str)){
  8853. ShowWarning("clif: input string too long !\n");
  8854. message_len = sizeof(sd->npc_str);
  8855. }
  8856. // Exploit prevention if crafted packets (without null) is being sent. [Lance]
  8857. memcpy(sd->npc_str,RFIFOP(fd,8),message_len);
  8858. sd->npc_str[message_len-1]=0;
  8859. npc_scriptcont(sd,RFIFOL(fd,4));
  8860. }
  8861. /*==========================================
  8862. *
  8863. *------------------------------------------
  8864. */
  8865. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8866. {
  8867. RFIFOHEAD(fd);
  8868. if (sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8869. npc_scriptcont(sd,RFIFOL(fd,2));
  8870. }
  8871. /*==========================================
  8872. * アイテム鑑定
  8873. *------------------------------------------
  8874. */
  8875. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8876. {
  8877. RFIFOHEAD(fd);
  8878. if (sd->menuskill_id != MC_IDENTIFY)
  8879. return;
  8880. skill_identify(sd,RFIFOW(fd,2)-2);
  8881. sd->menuskill_lv = sd->menuskill_id = 0;
  8882. }
  8883. /*==========================================
  8884. * 矢作成
  8885. *------------------------------------------
  8886. */
  8887. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8888. {
  8889. RFIFOHEAD(fd);
  8890. if (sd->menuskill_id != AC_MAKINGARROW)
  8891. return;
  8892. if (clif_trading(sd)) {
  8893. //Make it fail to avoid shop exploits where you sell something different than you see.
  8894. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8895. sd->menuskill_lv = sd->menuskill_id = 0;
  8896. return;
  8897. }
  8898. skill_arrow_create(sd,RFIFOW(fd,2));
  8899. sd->menuskill_lv = sd->menuskill_id = 0;
  8900. }
  8901. /*==========================================
  8902. * オートスペル受信
  8903. *------------------------------------------
  8904. */
  8905. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8906. {
  8907. RFIFOHEAD(fd);
  8908. if (sd->menuskill_id != SA_AUTOSPELL)
  8909. return;
  8910. skill_autospell(sd,RFIFOW(fd,2));
  8911. sd->menuskill_lv = sd->menuskill_id = 0;
  8912. }
  8913. /*==========================================
  8914. * カード使用
  8915. *------------------------------------------
  8916. */
  8917. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8918. {
  8919. RFIFOHEAD(fd);
  8920. if (sd->state.trading!= 0)
  8921. return;
  8922. clif_use_card(sd,RFIFOW(fd,2)-2);
  8923. }
  8924. /*==========================================
  8925. * カード挿入装備選択
  8926. *------------------------------------------
  8927. */
  8928. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8929. {
  8930. RFIFOHEAD(fd);
  8931. if (sd->state.trading!= 0)
  8932. return;
  8933. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8934. }
  8935. /*==========================================
  8936. * 0193 キャラID名前引き
  8937. *------------------------------------------
  8938. */
  8939. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8940. int char_id;
  8941. RFIFOHEAD(fd);
  8942. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8943. clif_solved_charname(sd, char_id);
  8944. }
  8945. /*==========================================
  8946. * 0197 /resetskill /resetstate
  8947. *------------------------------------------
  8948. */
  8949. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8950. RFIFOHEAD(fd);
  8951. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8952. pc_isGM(sd) >= get_atcommand_level(AtCommand_ResetState)) {
  8953. switch(RFIFOW(fd,2)){
  8954. case 0:
  8955. pc_resetstate(sd);
  8956. break;
  8957. case 1:
  8958. pc_resetskill(sd,1);
  8959. break;
  8960. }
  8961. }
  8962. }
  8963. /*==========================================
  8964. * 019c /lb等
  8965. *------------------------------------------
  8966. */
  8967. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  8968. unsigned char buf[512];
  8969. RFIFOHEAD(fd);
  8970. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8971. (pc_isGM(sd) >= get_atcommand_level(AtCommand_LocalBroadcast))) {
  8972. WBUFW(buf,0) = 0x9a;
  8973. WBUFW(buf,2) = RFIFOW(fd,2);
  8974. memcpy(WBUFP(buf,4), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  8975. clif_send(buf, RFIFOW(fd,2), &sd->bl, ALL_SAMEMAP);
  8976. }
  8977. }
  8978. /*==========================================
  8979. * カプラ倉庫へ入れる
  8980. *------------------------------------------
  8981. */
  8982. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  8983. int item_index, item_amount;
  8984. RFIFOHEAD(fd);
  8985. if (clif_trading(sd))
  8986. return;
  8987. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8988. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8989. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8990. return;
  8991. if (sd->state.storage_flag == 1)
  8992. storage_storageadd(sd, item_index, item_amount);
  8993. else if (sd->state.storage_flag == 2)
  8994. storage_guild_storageadd(sd, item_index, item_amount);
  8995. }
  8996. /*==========================================
  8997. * カプラ倉庫から出す
  8998. *------------------------------------------
  8999. */
  9000. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  9001. int item_index, item_amount;
  9002. RFIFOHEAD(fd);
  9003. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9004. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9005. if (sd->state.storage_flag == 1)
  9006. storage_storageget(sd, item_index, item_amount);
  9007. else if(sd->state.storage_flag == 2)
  9008. storage_guild_storageget(sd, item_index, item_amount);
  9009. }
  9010. /*==========================================
  9011. * カプラ倉庫へカートから入れる
  9012. *------------------------------------------
  9013. */
  9014. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  9015. RFIFOHEAD(fd);
  9016. if(sd->vender_id)
  9017. return;
  9018. if (sd->state.storage_flag == 1)
  9019. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9020. else if (sd->state.storage_flag == 2)
  9021. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9022. }
  9023. /*==========================================
  9024. * カプラ倉庫から出す
  9025. *------------------------------------------
  9026. */
  9027. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  9028. RFIFOHEAD(fd);
  9029. if (sd->vender_id)
  9030. return;
  9031. if (sd->state.storage_flag == 1)
  9032. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9033. else if (sd->state.storage_flag == 2)
  9034. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9035. }
  9036. /*==========================================
  9037. * カプラ倉庫を閉じる
  9038. *------------------------------------------
  9039. */
  9040. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  9041. if (sd->state.storage_flag == 1)
  9042. storage_storageclose(sd);
  9043. else if (sd->state.storage_flag == 2)
  9044. storage_guild_storageclose(sd);
  9045. }
  9046. /*==========================================
  9047. * パーティを作る
  9048. *------------------------------------------
  9049. */
  9050. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  9051. RFIFOHEAD(fd);
  9052. if(map[sd->bl.m].flag.partylock)
  9053. { //Guild locked.
  9054. clif_displaymessage(fd, msg_txt(227));
  9055. return;
  9056. }
  9057. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  9058. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  9059. } else
  9060. clif_skill_fail(sd,1,0,4);
  9061. }
  9062. /*==========================================
  9063. * パーティを作る
  9064. *------------------------------------------
  9065. */
  9066. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  9067. if(map[sd->bl.m].flag.partylock)
  9068. { //Guild locked.
  9069. clif_displaymessage(fd, msg_txt(227));
  9070. return;
  9071. }
  9072. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  9073. RFIFOHEAD(fd);
  9074. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  9075. } else
  9076. clif_skill_fail(sd,1,0,4);
  9077. }
  9078. /*==========================================
  9079. * パーティに勧誘
  9080. *------------------------------------------
  9081. */
  9082. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  9083. struct map_session_data *t_sd;
  9084. RFIFOHEAD(fd);
  9085. if(map[sd->bl.m].flag.partylock)
  9086. { //Guild locked.
  9087. clif_displaymessage(fd, msg_txt(227));
  9088. return;
  9089. }
  9090. t_sd = map_id2sd(RFIFOL(fd,2));
  9091. // @noask [LuzZza]
  9092. if(t_sd && t_sd->state.noask) {
  9093. clif_noask_sub(sd, t_sd, 1);
  9094. return;
  9095. }
  9096. party_invite(sd, t_sd);
  9097. }
  9098. /*==========================================
  9099. * パーティ勧誘返答
  9100. *------------------------------------------
  9101. */
  9102. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  9103. RFIFOHEAD(fd);
  9104. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  9105. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9106. } else {
  9107. party_reply_invite(sd,RFIFOL(fd,2),-1);
  9108. clif_skill_fail(sd,1,0,4);
  9109. }
  9110. }
  9111. /*==========================================
  9112. * パーティ脱退要求
  9113. *------------------------------------------
  9114. */
  9115. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  9116. if(map[sd->bl.m].flag.partylock)
  9117. { //Guild locked.
  9118. clif_displaymessage(fd, msg_txt(227));
  9119. return;
  9120. }
  9121. party_leave(sd);
  9122. }
  9123. /*==========================================
  9124. * パーティ除名要求
  9125. *------------------------------------------
  9126. */
  9127. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  9128. RFIFOHEAD(fd);
  9129. if(map[sd->bl.m].flag.partylock)
  9130. { //Guild locked.
  9131. clif_displaymessage(fd, msg_txt(227));
  9132. return;
  9133. }
  9134. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9135. }
  9136. /*==========================================
  9137. * パーティ設定変更要求
  9138. *------------------------------------------
  9139. */
  9140. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  9141. struct party_data *p;
  9142. RFIFOHEAD(fd);
  9143. if(!sd->status.party_id)
  9144. return;
  9145. p = party_search(sd->status.party_id);
  9146. if (!p) return;
  9147. //The client no longer can change the item-field, therefore it always
  9148. //comes as zero. Here, resend the item data as it is.
  9149. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  9150. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  9151. }
  9152. /*==========================================
  9153. * パーティメッセージ送信要求
  9154. *------------------------------------------
  9155. */
  9156. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  9157. RFIFOHEAD(fd);
  9158. if (is_charcommand(fd, sd, (char*)RFIFOP(fd,4)) != CharCommand_None ||
  9159. is_atcommand(fd, sd, (char*)RFIFOP(fd,4)) != AtCommand_None)
  9160. return;
  9161. if (sd->sc.count && (
  9162. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9163. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9164. ))
  9165. return;
  9166. if (battle_config.min_chat_delay)
  9167. { //[Skotlex]
  9168. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9169. return;
  9170. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9171. }
  9172. party_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9173. }
  9174. /*==========================================
  9175. * 露店閉鎖
  9176. *------------------------------------------
  9177. */
  9178. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  9179. vending_closevending(sd);
  9180. }
  9181. /*==========================================
  9182. * 露店アイテムリスト要求
  9183. *------------------------------------------
  9184. */
  9185. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  9186. RFIFOHEAD(fd);
  9187. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9188. if(sd->npc_id)
  9189. npc_event_dequeue(sd);
  9190. }
  9191. /*==========================================
  9192. * 露店アイテム購入
  9193. *------------------------------------------
  9194. */
  9195. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  9196. RFIFOHEAD(fd);
  9197. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  9198. }
  9199. /*==========================================
  9200. * 露店開設
  9201. *------------------------------------------
  9202. */
  9203. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  9204. RFIFOHEAD(fd);
  9205. if (clif_trading(sd))
  9206. return;
  9207. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  9208. return;
  9209. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  9210. }
  9211. /*==========================================
  9212. * ギルドを作る
  9213. *------------------------------------------
  9214. */
  9215. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  9216. RFIFOHEAD(fd);
  9217. if(map[sd->bl.m].flag.guildlock)
  9218. { //Guild locked.
  9219. clif_displaymessage(fd, msg_txt(228));
  9220. return;
  9221. }
  9222. guild_create(sd, (char*)RFIFOP(fd,6));
  9223. }
  9224. /*==========================================
  9225. * ギルドマスターかどうか確認
  9226. *------------------------------------------
  9227. */
  9228. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  9229. clif_guild_masterormember(sd);
  9230. }
  9231. /*==========================================
  9232. * ギルド情報要求
  9233. *------------------------------------------
  9234. */
  9235. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  9236. RFIFOHEAD(fd);
  9237. switch(RFIFOL(fd,2)){
  9238. case 0: // ギルド基本情報、同盟敵対情報
  9239. clif_guild_basicinfo(sd);
  9240. clif_guild_allianceinfo(sd);
  9241. break;
  9242. case 1: // メンバーリスト、役職名リスト
  9243. clif_guild_positionnamelist(sd);
  9244. clif_guild_memberlist(sd);
  9245. break;
  9246. case 2: // 役職名リスト、役職情報リスト
  9247. clif_guild_positionnamelist(sd);
  9248. clif_guild_positioninfolist(sd);
  9249. break;
  9250. case 3: // スキルリスト
  9251. clif_guild_skillinfo(sd);
  9252. break;
  9253. case 4: // 追放リスト
  9254. clif_guild_expulsionlist(sd);
  9255. break;
  9256. default:
  9257. if (battle_config.error_log)
  9258. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9259. break;
  9260. }
  9261. }
  9262. /*==========================================
  9263. * ギルド役職変更
  9264. *------------------------------------------
  9265. */
  9266. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  9267. int i;
  9268. RFIFOHEAD(fd);
  9269. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9270. guild_change_position(sd, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9271. }
  9272. }
  9273. /*==========================================
  9274. * ギルドメンバ役職変更
  9275. *------------------------------------------
  9276. */
  9277. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  9278. int i;
  9279. RFIFOHEAD(fd);
  9280. for(i=4;i<RFIFOW(fd,2);i+=12){
  9281. guild_change_memberposition(sd->status.guild_id,
  9282. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9283. }
  9284. }
  9285. /*==========================================
  9286. * ギルドエンブレム要求
  9287. *------------------------------------------
  9288. */
  9289. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  9290. struct guild *g;
  9291. RFIFOHEAD(fd);
  9292. g=guild_search(RFIFOL(fd,2));
  9293. if(g!=NULL)
  9294. clif_guild_emblem(sd,g);
  9295. }
  9296. /*==========================================
  9297. * ギルドエンブレム変更
  9298. *------------------------------------------
  9299. */
  9300. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  9301. RFIFOHEAD(fd);
  9302. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9303. }
  9304. /*==========================================
  9305. * ギルド告知変更
  9306. *------------------------------------------
  9307. */
  9308. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  9309. RFIFOHEAD(fd);
  9310. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  9311. }
  9312. /*==========================================
  9313. * ギルド勧誘
  9314. *------------------------------------------
  9315. */
  9316. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  9317. struct map_session_data *t_sd;
  9318. RFIFOHEAD(fd);
  9319. if(map[sd->bl.m].flag.guildlock)
  9320. { //Guild locked.
  9321. clif_displaymessage(fd, msg_txt(228));
  9322. return;
  9323. }
  9324. t_sd = map_id2sd(RFIFOL(fd,2));
  9325. // @noask [LuzZza]
  9326. if(t_sd && t_sd->state.noask) {
  9327. clif_noask_sub(sd, t_sd, 2);
  9328. return;
  9329. }
  9330. guild_invite(sd,t_sd);
  9331. }
  9332. /*==========================================
  9333. * ギルド勧誘返信
  9334. *------------------------------------------
  9335. */
  9336. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9337. RFIFOHEAD(fd);
  9338. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9339. }
  9340. /*==========================================
  9341. * ギルド脱退
  9342. *------------------------------------------
  9343. */
  9344. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9345. RFIFOHEAD(fd);
  9346. if(map[sd->bl.m].flag.guildlock)
  9347. { //Guild locked.
  9348. clif_displaymessage(fd, msg_txt(228));
  9349. return;
  9350. }
  9351. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9352. }
  9353. /*==========================================
  9354. * ギルド追放
  9355. *------------------------------------------
  9356. */
  9357. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd) {
  9358. RFIFOHEAD(fd);
  9359. if(map[sd->bl.m].flag.guildlock)
  9360. { //Guild locked.
  9361. clif_displaymessage(fd, msg_txt(228));
  9362. return;
  9363. }
  9364. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9365. }
  9366. /*==========================================
  9367. * ギルド会話
  9368. *------------------------------------------
  9369. */
  9370. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9371. RFIFOHEAD(fd);
  9372. if (is_charcommand(fd, sd, (char*)RFIFOP(fd, 4)) != CharCommand_None ||
  9373. is_atcommand(fd, sd, (char*)RFIFOP(fd, 4)) != AtCommand_None)
  9374. return;
  9375. if (sd->sc.count && (
  9376. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9377. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9378. ))
  9379. return;
  9380. if (battle_config.min_chat_delay)
  9381. { //[Skotlex]
  9382. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9383. return;
  9384. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9385. }
  9386. guild_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9387. }
  9388. /*==========================================
  9389. * ギルド同盟要求
  9390. *------------------------------------------
  9391. */
  9392. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9393. struct map_session_data *t_sd;
  9394. RFIFOHEAD(fd);
  9395. if(map[sd->bl.m].flag.guildlock)
  9396. { //Guild locked.
  9397. clif_displaymessage(fd, msg_txt(228));
  9398. return;
  9399. }
  9400. t_sd = map_id2sd(RFIFOL(fd,2));
  9401. // @noask [LuzZza]
  9402. if(t_sd && t_sd->state.noask) {
  9403. clif_noask_sub(sd, t_sd, 3);
  9404. return;
  9405. }
  9406. guild_reqalliance(sd,t_sd);
  9407. }
  9408. /*==========================================
  9409. * ギルド同盟要求返信
  9410. *------------------------------------------
  9411. */
  9412. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9413. RFIFOHEAD(fd);
  9414. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9415. }
  9416. /*==========================================
  9417. * ギルド関係解消
  9418. *------------------------------------------
  9419. */
  9420. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9421. RFIFOHEAD(fd);
  9422. if(map[sd->bl.m].flag.guildlock)
  9423. { //Guild locked.
  9424. clif_displaymessage(fd, msg_txt(228));
  9425. return;
  9426. }
  9427. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9428. }
  9429. /*==========================================
  9430. * ギルド敵対
  9431. *------------------------------------------
  9432. */
  9433. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9434. struct map_session_data *t_sd;
  9435. RFIFOHEAD(fd);
  9436. if(map[sd->bl.m].flag.guildlock)
  9437. { //Guild locked.
  9438. clif_displaymessage(fd, msg_txt(228));
  9439. return;
  9440. }
  9441. t_sd = map_id2sd(RFIFOL(fd,2));
  9442. // @noask [LuzZza]
  9443. if(t_sd && t_sd->state.noask) {
  9444. clif_noask_sub(sd, t_sd, 4);
  9445. return;
  9446. }
  9447. guild_opposition(sd,t_sd);
  9448. }
  9449. /*==========================================
  9450. * ギルド解散
  9451. *------------------------------------------
  9452. */
  9453. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9454. RFIFOHEAD(fd);
  9455. if(map[sd->bl.m].flag.guildlock)
  9456. { //Guild locked.
  9457. clif_displaymessage(fd, msg_txt(228));
  9458. return;
  9459. }
  9460. guild_break(sd,(char*)RFIFOP(fd,2));
  9461. }
  9462. // pet
  9463. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9464. RFIFOHEAD(fd);
  9465. pet_menu(sd,RFIFOB(fd,2));
  9466. }
  9467. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9468. RFIFOHEAD(fd);
  9469. pet_catch_process2(sd,RFIFOL(fd,2));
  9470. }
  9471. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9472. RFIFOHEAD(fd);
  9473. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  9474. return;
  9475. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9476. sd->menuskill_lv = sd->menuskill_id = 0;
  9477. }
  9478. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9479. if(sd->pd) {
  9480. RFIFOHEAD(fd);
  9481. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9482. }
  9483. }
  9484. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9485. RFIFOHEAD(fd);
  9486. pet_change_name(sd,(char*)RFIFOP(fd,2), 0);
  9487. }
  9488. // Kick (right click menu for GM "(name) force to quit")
  9489. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9490. struct block_list *target;
  9491. int tid;
  9492. RFIFOHEAD(fd);
  9493. tid = RFIFOL(fd,2);
  9494. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9495. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Kick))) {
  9496. target = map_id2bl(tid);
  9497. if (target) {
  9498. if (target->type == BL_PC) {
  9499. struct map_session_data *tsd = (struct map_session_data *)target;
  9500. if (pc_isGM(sd) > pc_isGM(tsd))
  9501. clif_GM_kick(sd, tsd, 1);
  9502. else
  9503. clif_GM_kickack(sd, 0);
  9504. } else if (target->type == BL_MOB) {
  9505. status_percent_damage(&sd->bl, target, 100, 0);
  9506. } else
  9507. clif_GM_kickack(sd, 0);
  9508. } else
  9509. clif_GM_kickack(sd, 0);
  9510. }
  9511. }
  9512. /*==========================================
  9513. * /shift
  9514. *------------------------------------------
  9515. */
  9516. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9517. char player_name[NAME_LENGTH];
  9518. malloc_tsetdword(player_name, '\0', sizeof(player_name));
  9519. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9520. (pc_isGM(sd) >= get_atcommand_level(AtCommand_JumpTo))) {
  9521. RFIFOHEAD(fd);
  9522. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9523. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9524. }
  9525. return;
  9526. }
  9527. /*==========================================
  9528. * /recall
  9529. *------------------------------------------
  9530. */
  9531. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9532. char player_name[NAME_LENGTH];
  9533. malloc_tsetdword(player_name, '\0', sizeof(player_name));
  9534. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9535. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Recall))) {
  9536. RFIFOHEAD(fd);
  9537. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9538. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9539. }
  9540. return;
  9541. }
  9542. /*==========================================
  9543. * /monster /item rewriten by [Yor]
  9544. *------------------------------------------
  9545. */
  9546. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9547. char monster_item_name[NAME_LENGTH+10]; //Additional space is for logging, eg: "@monster Poring"
  9548. int level;
  9549. malloc_tsetdword(monster_item_name, '\0', sizeof(monster_item_name));
  9550. if (battle_config.atc_gmonly == 0 || pc_isGM(sd)) {
  9551. RFIFOHEAD(fd);
  9552. memcpy(monster_item_name, RFIFOP(fd,2), NAME_LENGTH);
  9553. if (mobdb_searchname(monster_item_name) != 0) {
  9554. if (pc_isGM(sd) >= (level =get_atcommand_level(AtCommand_Spawn))) // changed from AtCommand_Monster for Skots [Reddozen]
  9555. {
  9556. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9557. if(log_config.gm && level >= log_config.gm)
  9558. { //Log action. [Skotlex]
  9559. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@spawn %s", RFIFOP(fd,2));
  9560. log_atcommand(sd, monster_item_name);
  9561. }
  9562. }
  9563. } else if (itemdb_searchname(monster_item_name) != NULL) {
  9564. if (pc_isGM(sd) >= (level = get_atcommand_level(AtCommand_Item)))
  9565. {
  9566. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9567. if(log_config.gm && level >= log_config.gm)
  9568. { //Log action. [Skotlex]
  9569. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@item %s", RFIFOP(fd,2));
  9570. log_atcommand(sd, monster_item_name);
  9571. }
  9572. }
  9573. }
  9574. }
  9575. }
  9576. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9577. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9578. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) {
  9579. if (sd->sc.option & OPTION_INVISIBLE) {
  9580. sd->sc.option &= ~OPTION_INVISIBLE;
  9581. if (sd->disguise)
  9582. status_set_viewdata(&sd->bl, sd->disguise);
  9583. else
  9584. status_set_viewdata(&sd->bl, sd->status.class_);
  9585. clif_displaymessage(fd, "Invisible: Off.");
  9586. } else {
  9587. sd->sc.option |= OPTION_INVISIBLE;
  9588. //Experimental hidden mode, changes your view class to invisible [Skotlex]
  9589. sd->vd.class_ = INVISIBLE_CLASS;
  9590. clif_displaymessage(fd, "Invisible: On.");
  9591. }
  9592. clif_changeoption(&sd->bl);
  9593. }
  9594. }
  9595. /*==========================================
  9596. * GMによるチャット禁止時間付与
  9597. *------------------------------------------
  9598. */
  9599. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9600. {
  9601. int type, limit, level;
  9602. struct block_list *bl;
  9603. struct map_session_data *dstsd;
  9604. RFIFOHEAD(fd);
  9605. bl = map_id2bl(RFIFOL(fd,2));
  9606. if (!bl || bl->type != BL_PC)
  9607. return;
  9608. nullpo_retv(dstsd =(struct map_session_data *)bl);
  9609. type = RFIFOB(fd,6);
  9610. limit = RFIFOW(fd,7);
  9611. if (type == 0)
  9612. limit = 0 - limit;
  9613. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9614. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9615. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9616. return;
  9617. if (
  9618. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9619. || (type == 2 && !level)) {
  9620. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9621. dstsd->status.manner -= limit;
  9622. if(dstsd->status.manner < 0)
  9623. sc_start(bl,SC_NOCHAT,100,0,0);
  9624. else
  9625. {
  9626. dstsd->status.manner = 0;
  9627. status_change_end(bl,SC_NOCHAT,-1);
  9628. }
  9629. }
  9630. return;
  9631. }
  9632. /*==========================================
  9633. * GMによるチャット禁止時間参照(?)
  9634. *------------------------------------------
  9635. */
  9636. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9637. {
  9638. int tid;
  9639. RFIFOHEAD(fd);
  9640. tid = RFIFOL(fd,2);
  9641. WFIFOHEAD(fd,packet_len_table[0x1e0]);
  9642. WFIFOW(fd,0) = 0x1e0;
  9643. WFIFOL(fd,2) = tid;
  9644. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9645. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9646. WFIFOSET(fd, packet_len_table[0x1e0]);
  9647. return;
  9648. }
  9649. static int pstrcmp(const void *a, const void *b)
  9650. {
  9651. char *name1 = (char *)a;
  9652. char *name2 = (char *)b;
  9653. if (name1[0] && name2[0])
  9654. return strcmp(name1, name2);
  9655. //Since names are sorted in ascending order, send blank entries to the bottom.
  9656. if (name1[0])
  9657. return -1;
  9658. if (name2[0])
  9659. return 1;
  9660. return 0;
  9661. }
  9662. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9663. char output[512];
  9664. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9665. int i;
  9666. WFIFOHEAD(fd,packet_len_table[0xd1]);
  9667. RFIFOHEAD(fd);
  9668. malloc_tsetdword(output, '\0', sizeof(output));
  9669. nick = (char*)RFIFOP(fd,2); // speed up
  9670. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9671. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9672. WFIFOB(fd,2) = RFIFOB(fd,26);
  9673. // do nothing only if nick can not exist
  9674. if ((i = strlen(nick)) < 4) {
  9675. WFIFOB(fd,3) = 1; // fail
  9676. WFIFOSET(fd, packet_len_table[0x0d1]);
  9677. clif_wis_message(fd, wisp_server_name,
  9678. "This player name is not valid.",
  9679. strlen("This player name is not valid.")+1);
  9680. return;
  9681. }
  9682. // name can exist
  9683. // deny action (we add nick only if it's not already exist
  9684. if (RFIFOB(fd,26) == 0) { // Add block
  9685. for(i = 0; i < MAX_IGNORE_LIST &&
  9686. sd->ignore[i].name[0] != '\0' &&
  9687. strcmp(sd->ignore[i].name, nick) != 0
  9688. ; i++);
  9689. if (i == MAX_IGNORE_LIST) { //Full List
  9690. WFIFOB(fd,3) = 1; // fail
  9691. WFIFOSET(fd, packet_len_table[0x0d1]);
  9692. clif_wis_message(fd, wisp_server_name,
  9693. "You can not block more people.",
  9694. strlen("You can not block more people.") + 1);
  9695. if (strcmp(wisp_server_name, nick) == 0)
  9696. { // to found possible bot users who automaticaly ignore people.
  9697. 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);
  9698. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9699. }
  9700. return;
  9701. }
  9702. if(sd->ignore[i].name[0] != '\0')
  9703. { //Name already exists.
  9704. WFIFOB(fd,3) = 1; // fail
  9705. WFIFOSET(fd, packet_len_table[0x0d1]);
  9706. clif_wis_message(fd, wisp_server_name,
  9707. "This player is already blocked.",
  9708. strlen("This player is already blocked.") + 1);
  9709. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9710. sprintf(output, "Character '%s' (account: %d) has tried AGAIN to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  9711. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9712. }
  9713. return;
  9714. }
  9715. //Insert in position i
  9716. memcpy(sd->ignore[i].name, nick, NAME_LENGTH-1);
  9717. WFIFOB(fd,3) = 0; // success
  9718. WFIFOSET(fd, packet_len_table[0x0d1]);
  9719. if (strcmp(wisp_server_name, nick) == 0)
  9720. { // to found possible bot users who automaticaly ignore people.
  9721. 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);
  9722. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9723. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9724. clif_wis_message(fd, wisp_server_name,
  9725. "Adding me in your ignore list will not block my wisps.",
  9726. strlen("Adding me in your ignore list will not block my wisps.") + 1);
  9727. }
  9728. //Sort the ignore list.
  9729. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9730. return;
  9731. }
  9732. //Remove name
  9733. for(i = 0; i < MAX_IGNORE_LIST &&
  9734. sd->ignore[i].name[0] != '\0' &&
  9735. strcmp(sd->ignore[i].name, nick) != 0
  9736. ; i++);
  9737. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0')
  9738. { //Not found
  9739. WFIFOB(fd,3) = 1; // fail
  9740. WFIFOSET(fd, packet_len_table[0x0d1]);
  9741. clif_wis_message(fd, wisp_server_name,
  9742. "This player is not blocked by you.",
  9743. strlen("This player is not blocked by you.") + 1);
  9744. return;
  9745. }
  9746. //Move everything one place down to overwrite removed entry.
  9747. memmove(sd->ignore[i].name, sd->ignore[i+1].name,
  9748. (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9749. malloc_tsetdword(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9750. // success
  9751. WFIFOB(fd,3) = 0;
  9752. WFIFOSET(fd, packet_len_table[0x0d1]);
  9753. // for debug only
  9754. // for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++) /
  9755. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9756. return;
  9757. }
  9758. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9759. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9760. RFIFOHEAD(fd);
  9761. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9762. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9763. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9764. WFIFOW(fd,0) = 0x0d2;
  9765. WFIFOB(fd,2) = RFIFOB(fd,2);
  9766. if (RFIFOB(fd,2) == 0) { //Deny all
  9767. if (sd->state.ignoreAll) {
  9768. WFIFOB(fd,3) = 1; // fail
  9769. WFIFOSET(fd, packet_len_table[0x0d2]);
  9770. clif_wis_message(fd, wisp_server_name,
  9771. "You already block everyone.",
  9772. strlen("You already block everyone.") + 1);
  9773. return;
  9774. }
  9775. sd->state.ignoreAll = 1;
  9776. WFIFOB(fd,3) = 0; // success
  9777. WFIFOSET(fd, packet_len_table[0x0d2]);
  9778. return ;
  9779. }
  9780. //Unblock everyone
  9781. if (!sd->state.ignoreAll) {
  9782. WFIFOB(fd,3) = 1; // fail
  9783. WFIFOSET(fd, packet_len_table[0x0d2]);
  9784. clif_wis_message(fd, wisp_server_name,
  9785. "You already allow everyone.",
  9786. strlen("You already allow everyone.") + 1);
  9787. return;
  9788. }
  9789. sd->state.ignoreAll = 0;
  9790. WFIFOB(fd,3) = 0; // success
  9791. WFIFOSET(fd, packet_len_table[0x0d2]);
  9792. return;
  9793. }
  9794. /*==========================================
  9795. * Wis拒否リスト
  9796. *------------------------------------------
  9797. */
  9798. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9799. {
  9800. int i;
  9801. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9802. WFIFOW(fd,0) = 0xd4;
  9803. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9804. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9805. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9806. WFIFOSET(fd, WFIFOW(fd,2));
  9807. return;
  9808. }
  9809. /*==========================================
  9810. * スパノビの/doridoriによるSPR2倍
  9811. *------------------------------------------
  9812. */
  9813. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9814. if (sd->state.doridori) return;
  9815. switch (sd->class_&MAPID_UPPERMASK)
  9816. {
  9817. case MAPID_SOUL_LINKER:
  9818. case MAPID_STAR_GLADIATOR:
  9819. case MAPID_TAEKWON:
  9820. if (!sd->state.rest)
  9821. break;
  9822. case MAPID_SUPER_NOVICE:
  9823. sd->state.doridori=1;
  9824. break;
  9825. }
  9826. return;
  9827. }
  9828. /*==========================================
  9829. * スパノビの爆裂波動
  9830. *------------------------------------------
  9831. */
  9832. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9833. {
  9834. if(sd){
  9835. int nextbaseexp=pc_nextbaseexp(sd);
  9836. if (battle_config.etc_log){
  9837. if(nextbaseexp != 0)
  9838. 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));
  9839. else
  9840. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9841. }
  9842. 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){
  9843. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9844. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9845. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9846. }
  9847. }
  9848. return;
  9849. }
  9850. // random notes:
  9851. // 0x214: monster/player info ?
  9852. /*==========================================
  9853. * Friends List
  9854. *------------------------------------------
  9855. */
  9856. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9857. { //Toggles a single friend online/offline [Skotlex]
  9858. int i, fd = sd->fd;
  9859. //Seek friend.
  9860. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9861. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9862. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9863. return; //Not found
  9864. WFIFOHEAD(fd,packet_len_table[0x206]);
  9865. WFIFOW(fd, 0) = 0x206;
  9866. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9867. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9868. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9869. WFIFOSET(fd, packet_len_table[0x206]);
  9870. }
  9871. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9872. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9873. {
  9874. int account_id, char_id, online;
  9875. account_id = va_arg(ap, int);
  9876. char_id = va_arg(ap, int);
  9877. online = va_arg(ap, int);
  9878. clif_friendslist_toggle(sd, account_id, char_id, online);
  9879. return 0;
  9880. }
  9881. //For sending the whole friends list.
  9882. void clif_friendslist_send(struct map_session_data *sd) {
  9883. int i = 0, n, fd = sd->fd;
  9884. // Send friends list
  9885. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9886. WFIFOW(fd, 0) = 0x201;
  9887. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9888. {
  9889. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9890. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9891. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9892. }
  9893. if (i) {
  9894. WFIFOW(fd,2) = 4 + 32 * i;
  9895. WFIFOSET(fd, WFIFOW(fd,2));
  9896. }
  9897. for (n = 0; n < i; n++)
  9898. { //Sending the online players
  9899. if (map_charid2sd(sd->status.friends[n].char_id))
  9900. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9901. }
  9902. }
  9903. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9904. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9905. {
  9906. int fd;
  9907. nullpo_retv(sd);
  9908. fd = sd->fd;
  9909. WFIFOHEAD(fd,packet_len_table[0x209]);
  9910. WFIFOW(fd,0) = 0x209;
  9911. WFIFOW(fd,2) = type;
  9912. if (f_sd)
  9913. {
  9914. WFIFOW(fd,4) = f_sd->status.account_id;
  9915. WFIFOW(fd,8) = f_sd->status.char_id;
  9916. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9917. }
  9918. WFIFOSET(fd, packet_len_table[0x209]);
  9919. }
  9920. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9921. struct map_session_data *f_sd;
  9922. int i, f_fd;
  9923. RFIFOHEAD(fd);
  9924. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9925. // Friend doesn't exist (no player with this name)
  9926. if (f_sd == NULL) {
  9927. clif_displaymessage(fd, msg_txt(3));
  9928. return;
  9929. }
  9930. // @noask [LuzZza]
  9931. if(f_sd->state.noask) {
  9932. clif_noask_sub(sd, f_sd, 5);
  9933. return;
  9934. }
  9935. // Friend already exists
  9936. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9937. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9938. clif_displaymessage(fd, "Friend already exists.");
  9939. return;
  9940. }
  9941. }
  9942. if (i == MAX_FRIENDS) {
  9943. //No space, list full.
  9944. clif_friendslist_reqack(sd, f_sd, 2);
  9945. return;
  9946. }
  9947. f_fd = f_sd->fd;
  9948. WFIFOHEAD(f_fd,packet_len_table[0x207]);
  9949. WFIFOW(f_fd,0) = 0x207;
  9950. WFIFOL(f_fd,2) = sd->status.account_id;
  9951. WFIFOL(f_fd,6) = sd->status.char_id;
  9952. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9953. WFIFOSET(f_fd, packet_len_table[0x207]);
  9954. return;
  9955. }
  9956. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9957. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9958. struct map_session_data *f_sd;
  9959. int char_id, account_id;
  9960. char reply;
  9961. RFIFOHEAD(fd);
  9962. account_id = RFIFOL(fd,2);
  9963. char_id = RFIFOL(fd,6);
  9964. reply = RFIFOB(fd,10);
  9965. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9966. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9967. if (f_sd == NULL)
  9968. return;
  9969. if (reply == 0)
  9970. clif_friendslist_reqack(f_sd, sd, 1);
  9971. else {
  9972. int i;
  9973. // Find an empty slot
  9974. for (i = 0; i < MAX_FRIENDS; i++)
  9975. if (f_sd->status.friends[i].char_id == 0)
  9976. break;
  9977. if (i == MAX_FRIENDS) {
  9978. clif_friendslist_reqack(f_sd, sd, 2);
  9979. return;
  9980. }
  9981. f_sd->status.friends[i].account_id = sd->status.account_id;
  9982. f_sd->status.friends[i].char_id = sd->status.char_id;
  9983. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9984. clif_friendslist_reqack(f_sd, sd, 0);
  9985. if (battle_config.friend_auto_add) {
  9986. // Also add f_sd to sd's friendlist.
  9987. for (i = 0; i < MAX_FRIENDS; i++) {
  9988. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9989. return; //No need to add anything.
  9990. if (sd->status.friends[i].char_id == 0)
  9991. break;
  9992. }
  9993. if (i == MAX_FRIENDS) {
  9994. clif_friendslist_reqack(sd, f_sd, 2);
  9995. return;
  9996. }
  9997. sd->status.friends[i].account_id = f_sd->status.account_id;
  9998. sd->status.friends[i].char_id = f_sd->status.char_id;
  9999. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10000. clif_friendslist_reqack(sd, f_sd, 0);
  10001. }
  10002. }
  10003. return;
  10004. }
  10005. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  10006. // 0x203 </o> <ID to be removed W 4B>
  10007. int account_id, char_id;
  10008. int i, j;
  10009. RFIFOHEAD(fd);
  10010. account_id = RFIFOL(fd,2);
  10011. char_id = RFIFOL(fd,6);
  10012. // Search friend
  10013. for (i = 0; i < MAX_FRIENDS &&
  10014. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10015. if (i == MAX_FRIENDS) {
  10016. clif_displaymessage(fd, "Name not found in list.");
  10017. return;
  10018. }
  10019. // move all chars down
  10020. for(j = i + 1; j < MAX_FRIENDS; j++)
  10021. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  10022. malloc_set(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  10023. clif_displaymessage(fd, "Friend removed");
  10024. WFIFOHEAD(fd,packet_len_table[0x20a]);
  10025. WFIFOW(fd,0) = 0x20a;
  10026. WFIFOL(fd,2) = account_id;
  10027. WFIFOL(fd,6) = char_id;
  10028. WFIFOSET(fd, packet_len_table[0x20a]);
  10029. // clif_friendslist_send(sd); //This is not needed anymore.
  10030. return;
  10031. }
  10032. /*==========================================
  10033. * /killall
  10034. *------------------------------------------
  10035. */
  10036. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  10037. {
  10038. char message[50];
  10039. strncpy(message,sd->status.name, NAME_LENGTH);
  10040. is_atcommand(fd, sd, strcat(message," : @kickall"));
  10041. return;
  10042. }
  10043. /*==========================================
  10044. * /pvpinfo
  10045. *------------------------------------------
  10046. */
  10047. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10048. {
  10049. WFIFOHEAD(fd,packet_len_table[0x210]);
  10050. WFIFOW(fd,0) = 0x210;
  10051. //WFIFOL(fd,2) = 0; // not sure what for yet
  10052. //WFIFOL(fd,6) = 0;
  10053. WFIFOL(fd,10) = sd->pvp_won; // times won
  10054. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10055. WFIFOL(fd,18) = sd->pvp_point;
  10056. WFIFOSET(fd, packet_len_table[0x210]);
  10057. return;
  10058. }
  10059. /*==========================================
  10060. * /blacksmith
  10061. *------------------------------------------
  10062. */
  10063. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10064. {
  10065. int i;
  10066. char *name;
  10067. WFIFOHEAD(fd,packet_len_table[0x219]);
  10068. WFIFOW(fd,0) = 0x219;
  10069. //Packet size limits this list to 10 elements. [Skotlex]
  10070. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10071. if (smith_fame_list[i].id > 0) {
  10072. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10073. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10074. {
  10075. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10076. } else
  10077. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10078. } else
  10079. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10080. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10081. }
  10082. for(;i < 10; i++) { //In case the MAX is less than 10.
  10083. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10084. WFIFOL(fd, 242 + i * 4) = 0;
  10085. }
  10086. WFIFOSET(fd, packet_len_table[0x219]);
  10087. }
  10088. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  10089. {
  10090. int fd = sd->fd;
  10091. WFIFOHEAD(fd,packet_len_table[0x21b]);
  10092. WFIFOW(fd,0) = 0x21b;
  10093. WFIFOL(fd,2) = points;
  10094. WFIFOL(fd,6) = sd->status.fame;
  10095. WFIFOSET(fd, packet_len_table[0x21b]);
  10096. return 0;
  10097. }
  10098. /*==========================================
  10099. * /alchemist
  10100. *------------------------------------------
  10101. */
  10102. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10103. {
  10104. int i;
  10105. char *name;
  10106. WFIFOHEAD(fd,packet_len_table[0x21a]);
  10107. WFIFOW(fd,0) = 0x21a;
  10108. //Packet size limits this list to 10 elements. [Skotlex]
  10109. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10110. if (chemist_fame_list[i].id > 0) {
  10111. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10112. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10113. {
  10114. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10115. } else
  10116. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10117. } else
  10118. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10119. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10120. }
  10121. for(;i < 10; i++) { //In case the MAX is less than 10.
  10122. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10123. WFIFOL(fd, 242 + i * 4) = 0;
  10124. }
  10125. WFIFOSET(fd, packet_len_table[0x21a]);
  10126. }
  10127. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10128. {
  10129. int fd = sd->fd;
  10130. WFIFOHEAD(fd,packet_len_table[0x21c]);
  10131. WFIFOW(fd,0) = 0x21c;
  10132. WFIFOL(fd,2) = points;
  10133. WFIFOL(fd,6) = sd->status.fame;
  10134. WFIFOSET(fd, packet_len_table[0x21c]);
  10135. return 0;
  10136. }
  10137. /*==========================================
  10138. * /taekwon
  10139. *------------------------------------------
  10140. */
  10141. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10142. {
  10143. int i;
  10144. char *name;
  10145. WFIFOHEAD(fd,packet_len_table[0x226]);
  10146. WFIFOW(fd,0) = 0x226;
  10147. //Packet size limits this list to 10 elements. [Skotlex]
  10148. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10149. if (taekwon_fame_list[i].id > 0) {
  10150. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10151. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10152. {
  10153. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10154. } else
  10155. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10156. } else
  10157. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10158. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10159. }
  10160. for(;i < 10; i++) { //In case the MAX is less than 10.
  10161. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10162. WFIFOL(fd, 242 + i * 4) = 0;
  10163. }
  10164. WFIFOSET(fd, packet_len_table[0x226]);
  10165. }
  10166. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10167. {
  10168. int fd = sd->fd;
  10169. WFIFOHEAD(fd,packet_len_table[0x224]);
  10170. WFIFOW(fd,0) = 0x224;
  10171. WFIFOL(fd,2) = points;
  10172. WFIFOL(fd,6) = sd->status.fame;
  10173. WFIFOSET(fd, packet_len_table[0x224]);
  10174. return 0;
  10175. }
  10176. /*==========================================
  10177. * PK Ranking table?
  10178. *------------------------------------------
  10179. */
  10180. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10181. {
  10182. int i;
  10183. WFIFOHEAD(fd,packet_len_table[0x238]);
  10184. WFIFOW(fd,0) = 0x238;
  10185. for(i=0;i<10;i++){
  10186. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10187. WFIFOL(fd,i*4+242) = 0;
  10188. }
  10189. WFIFOSET(fd, packet_len_table[0x238]);
  10190. return;
  10191. }
  10192. /*==========================================
  10193. * SG Feel save OK [Komurka]
  10194. *------------------------------------------
  10195. */
  10196. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10197. {
  10198. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  10199. int i;
  10200. if (sd->menuskill_id != SG_FEEL)
  10201. return;
  10202. i = sd->menuskill_lv-1;
  10203. if (i<0 || i > 2) return; //Bug?
  10204. sd->feel_map[i].index = map[sd->bl.m].index;
  10205. sd->feel_map[i].m = sd->bl.m;
  10206. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  10207. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10208. // clif_misceffect2(&sd->bl, 0x1b0);
  10209. // clif_misceffect2(&sd->bl, 0x21f);
  10210. clif_feel_info(sd, i, 0);
  10211. sd->menuskill_lv = sd->menuskill_id = 0;
  10212. }
  10213. /*==========================================
  10214. * Question about Star Glaldiator save map [Komurka]
  10215. *------------------------------------------
  10216. */
  10217. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  10218. WFIFOHEAD(fd,packet_len_table[0x253]);
  10219. WFIFOW(fd,0)=0x253;
  10220. WFIFOSET(fd, packet_len_table[0x253]);
  10221. sd->menuskill_id=SG_FEEL;
  10222. sd->menuskill_lv=skilllv;
  10223. }
  10224. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd) {
  10225. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  10226. //Missing packets are the client's reply packets to the adopt request one.
  10227. //[Skotlex]
  10228. int account_id;
  10229. struct map_session_data *sd2;
  10230. RFIFOHEAD(fd);
  10231. account_id = RFIFOL(fd,2);
  10232. sd2 = map_id2sd(account_id);
  10233. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  10234. fd = sd2->fd;
  10235. WFIFOHEAD(fd,packet_len_table[0x1f9]);
  10236. WFIFOW(fd,0)=0x1f9;
  10237. WFIFOSET(fd, packet_len_table[0x1f9]);
  10238. }
  10239. }
  10240. /*==========================================
  10241. * パケットデバッグ
  10242. *------------------------------------------
  10243. */
  10244. void clif_parse_debug(int fd,struct map_session_data *sd)
  10245. {
  10246. int i, cmd, len;
  10247. RFIFOHEAD(fd);
  10248. cmd = RFIFOW(fd,0);
  10249. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10250. ShowDebug("packet debug 0x%4X\n",cmd);
  10251. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10252. for(i=0;i<len;i++){
  10253. if((i&15)==0)
  10254. printf("\n%04X ",i);
  10255. printf("%02X ",RFIFOB(fd,i));
  10256. }
  10257. printf("\n");
  10258. }
  10259. /*==========================================
  10260. * クライアントからのパケット解析
  10261. * socket.cのdo_parsepacketから呼び出される
  10262. *------------------------------------------
  10263. */
  10264. int clif_parse(int fd) {
  10265. int packet_len = 0, cmd, packet_ver, dump = 0;
  10266. struct map_session_data *sd;
  10267. RFIFOHEAD(fd);
  10268. if (fd <= 0)
  10269. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  10270. ShowError("clif_parse: Received invalid session %d\n", fd);
  10271. return 0;
  10272. }
  10273. sd = (struct map_session_data*)session[fd]->session_data;
  10274. if (sd && sd->fd != fd)
  10275. { //FIXME: Temporal debug until a certain mysterious crash is fixed.
  10276. ShowError("Player's connection value is incorrect! %d != %d\n", sd->fd, fd);
  10277. sd->fd = fd;
  10278. }
  10279. if (session[fd]->eof) {
  10280. if (sd) {
  10281. if (sd->state.autotrade) {
  10282. //Disassociate character from the socket connection.
  10283. session[fd]->session_data = NULL;
  10284. sd->fd = 0;
  10285. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n",
  10286. (pc_isGM(sd))?"GM ":"",sd->status.name);
  10287. } else
  10288. if (sd->state.auth) {
  10289. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  10290. // Player logout display [Valaris]
  10291. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n",
  10292. (pc_isGM(sd))?"GM ":"",sd->status.name);
  10293. } else {
  10294. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n",
  10295. sd->bl.id, sd->char_id);
  10296. }
  10297. } else {
  10298. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  10299. ShowInfo("Closed connection from '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip[0],ip[1],ip[2],ip[3]);
  10300. }
  10301. do_close(fd);
  10302. return 0;
  10303. }
  10304. if (RFIFOREST(fd) < 2)
  10305. return 0;
  10306. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  10307. cmd = RFIFOW(fd,0);
  10308. // 管理用パケット処理
  10309. if (cmd >= 30000) {
  10310. switch(cmd) {
  10311. case 0x7530: { //Why are we letting people know which version we are running?
  10312. WFIFOHEAD(fd, 10);
  10313. WFIFOW(fd,0) = 0x7531;
  10314. WFIFOB(fd,2) = ATHENA_MAJOR_VERSION;
  10315. WFIFOB(fd,3) = ATHENA_MINOR_VERSION;
  10316. WFIFOB(fd,4) = ATHENA_REVISION;
  10317. WFIFOB(fd,5) = ATHENA_RELEASE_FLAG;
  10318. WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG;
  10319. WFIFOB(fd,7) = ATHENA_SERVER_MAP;
  10320. WFIFOW(fd,8) = ATHENA_MOD_VERSION;
  10321. WFIFOSET(fd,10);
  10322. RFIFOSKIP(fd,2);
  10323. break;
  10324. }
  10325. case 0x7532: // 接続の切断
  10326. ShowWarning("clif_parse: session #%d disconnected for sending packet 0x04%x\n", fd, cmd);
  10327. session[fd]->eof=1;
  10328. break;
  10329. default:
  10330. ShowWarning("Unknown incoming packet (command: 0x%04x, session: %d), disconnecting.\n", cmd, fd);
  10331. session[fd]->eof=1;
  10332. break;
  10333. }
  10334. return 0;
  10335. }
  10336. // get packet version before to parse
  10337. packet_ver = 0;
  10338. if (sd) {
  10339. packet_ver = sd->packet_ver;
  10340. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  10341. session[fd]->eof = 1;
  10342. return 0;
  10343. }
  10344. } else {
  10345. // check authentification packet to know packet version
  10346. packet_ver = clif_guess_PacketVer(fd, 0);
  10347. // check if version is accepted
  10348. if (packet_ver < 5 || // reject really old client versions
  10349. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  10350. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
  10351. packet_ver > MAX_PACKET_VER) // no packet version support yet
  10352. {
  10353. ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
  10354. WFIFOHEAD(fd, 23);
  10355. WFIFOW(fd,0) = 0x6a;
  10356. WFIFOB(fd,2) = 5; // 05 = Game's EXE is not the latest version
  10357. WFIFOSET(fd,23);
  10358. packet_len = RFIFOREST(fd);
  10359. RFIFOSKIP(fd, packet_len);
  10360. clif_setwaitclose(fd);
  10361. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  10362. session[fd]->func_send(fd);
  10363. return 0;
  10364. }
  10365. }
  10366. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  10367. if (cmd >= MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) { // if packet is not inside these values: session is incorrect?? or auth packet is unknown
  10368. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10369. session[fd]->eof = 1;
  10370. return 0;
  10371. }
  10372. // パケット長を計算
  10373. packet_len = packet_db[packet_ver][cmd].len;
  10374. if (packet_len == -1) {
  10375. if (RFIFOREST(fd) < 4)
  10376. return 0; // 可変長パケットで長さの所までデータが来てない
  10377. packet_len = RFIFOW(fd,2);
  10378. if (packet_len < 4 || packet_len > 32768) {
  10379. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10380. session[fd]->eof =1;
  10381. return 0;
  10382. }
  10383. }
  10384. if ((int)RFIFOREST(fd) < packet_len)
  10385. return 0; // まだ1パケット分データが揃ってない
  10386. #if DUMP_ALL_PACKETS
  10387. {
  10388. int i;
  10389. FILE *fp;
  10390. char packet_txt[256] = "save/packet.txt";
  10391. time_t now;
  10392. dump = 1;
  10393. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10394. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10395. return 1;
  10396. } else {
  10397. time(&now);
  10398. if (sd && sd->state.auth) {
  10399. if (sd->status.name != NULL)
  10400. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent packet:\n",
  10401. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10402. else
  10403. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10404. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10405. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10406. fprintf(fp, "\tsession #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10407. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10408. for(i = 0; i < packet_len; i++) {
  10409. if ((i & 15) == 0)
  10410. fprintf(fp, "\n\t%04X ", i);
  10411. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10412. }
  10413. fprintf(fp, "\n\n");
  10414. fclose(fp);
  10415. }
  10416. }
  10417. #endif
  10418. if (sd && sd->state.waitingdisconnect == 1) {
  10419. // 切断待ちの場合パケットを処理しない
  10420. } else if (packet_db[packet_ver][cmd].func) {
  10421. if (sd && sd->bl.prev == NULL &&
  10422. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10423. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10424. else
  10425. if (sd
  10426. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10427. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10428. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10429. packet_db[packet_ver][cmd].func(fd, sd);
  10430. }
  10431. #ifdef DUMP_UNKNOWN_PACKET
  10432. else if (battle_config.error_log)
  10433. {
  10434. int i;
  10435. FILE *fp;
  10436. char packet_txt[256] = "save/packet.txt";
  10437. time_t now;
  10438. dump = 1;
  10439. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10440. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10441. return 1;
  10442. } else {
  10443. time(&now);
  10444. if (sd && sd->state.auth) {
  10445. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10446. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10447. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10448. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10449. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10450. for(i = 0; i < packet_len; i++) {
  10451. if ((i & 15) == 0)
  10452. fprintf(fp, "\n\t%04X ", i);
  10453. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10454. }
  10455. fprintf(fp, "\n\n");
  10456. fclose(fp);
  10457. }
  10458. }
  10459. #endif
  10460. if (dump) {
  10461. int i;
  10462. if (fd)
  10463. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10464. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10465. for(i = 0; i < packet_len; i++) {
  10466. if ((i & 15) == 0)
  10467. printf("\n%04X ",i);
  10468. printf("%02X ", RFIFOB(fd,i));
  10469. }
  10470. printf("\n");
  10471. if (sd && sd->state.auth) {
  10472. if (sd->status.name != NULL)
  10473. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10474. sd->status.account_id, sd->status.char_id, sd->status.name);
  10475. else
  10476. printf("\nAccount ID %d.\n", sd->bl.id);
  10477. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10478. printf("\nAccount ID %d.\n", sd->bl.id);
  10479. }
  10480. RFIFOSKIP(fd, packet_len);
  10481. return 0;
  10482. }
  10483. /*==========================================
  10484. * パケットデータベース読み込み
  10485. *------------------------------------------
  10486. */
  10487. static int packetdb_readdb(void)
  10488. {
  10489. FILE *fp;
  10490. char line[1024];
  10491. int ln=0;
  10492. int cmd,i,j,k,packet_ver;
  10493. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10494. struct {
  10495. void (*func)(int, struct map_session_data *);
  10496. char *name;
  10497. } clif_parse_func[]={
  10498. {clif_parse_WantToConnection,"wanttoconnection"},
  10499. {clif_parse_LoadEndAck,"loadendack"},
  10500. {clif_parse_TickSend,"ticksend"},
  10501. {clif_parse_WalkToXY,"walktoxy"},
  10502. {clif_parse_QuitGame,"quitgame"},
  10503. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10504. {clif_parse_GlobalMessage,"globalmessage"},
  10505. {clif_parse_MapMove,"mapmove"},
  10506. {clif_parse_ChangeDir,"changedir"},
  10507. {clif_parse_Emotion,"emotion"},
  10508. {clif_parse_HowManyConnections,"howmanyconnections"},
  10509. {clif_parse_ActionRequest,"actionrequest"},
  10510. {clif_parse_Restart,"restart"},
  10511. {clif_parse_Wis,"wis"},
  10512. {clif_parse_GMmessage,"gmmessage"},
  10513. {clif_parse_TakeItem,"takeitem"},
  10514. {clif_parse_DropItem,"dropitem"},
  10515. {clif_parse_UseItem,"useitem"},
  10516. {clif_parse_EquipItem,"equipitem"},
  10517. {clif_parse_UnequipItem,"unequipitem"},
  10518. {clif_parse_NpcClicked,"npcclicked"},
  10519. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10520. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10521. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10522. {clif_parse_CreateChatRoom,"createchatroom"},
  10523. {clif_parse_ChatAddMember,"chataddmember"},
  10524. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10525. {clif_parse_ChangeChatOwner,"changechatowner"},
  10526. {clif_parse_KickFromChat,"kickfromchat"},
  10527. {clif_parse_ChatLeave,"chatleave"},
  10528. {clif_parse_TradeRequest,"traderequest"},
  10529. {clif_parse_TradeAck,"tradeack"},
  10530. {clif_parse_TradeAddItem,"tradeadditem"},
  10531. {clif_parse_TradeOk,"tradeok"},
  10532. {clif_parse_TradeCancel,"tradecancel"},
  10533. {clif_parse_TradeCommit,"tradecommit"},
  10534. {clif_parse_StopAttack,"stopattack"},
  10535. {clif_parse_PutItemToCart,"putitemtocart"},
  10536. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10537. {clif_parse_RemoveOption,"removeoption"},
  10538. {clif_parse_ChangeCart,"changecart"},
  10539. {clif_parse_StatusUp,"statusup"},
  10540. {clif_parse_SkillUp,"skillup"},
  10541. {clif_parse_UseSkillToId,"useskilltoid"},
  10542. {clif_parse_UseSkillToPos,"useskilltopos"},
  10543. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10544. {clif_parse_UseSkillMap,"useskillmap"},
  10545. {clif_parse_RequestMemo,"requestmemo"},
  10546. {clif_parse_ProduceMix,"producemix"},
  10547. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10548. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10549. {clif_parse_NpcAmountInput,"npcamountinput"},
  10550. {clif_parse_NpcStringInput,"npcstringinput"},
  10551. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10552. {clif_parse_ItemIdentify,"itemidentify"},
  10553. {clif_parse_SelectArrow,"selectarrow"},
  10554. {clif_parse_AutoSpell,"autospell"},
  10555. {clif_parse_UseCard,"usecard"},
  10556. {clif_parse_InsertCard,"insertcard"},
  10557. {clif_parse_RepairItem,"repairitem"},
  10558. {clif_parse_WeaponRefine,"weaponrefine"},
  10559. {clif_parse_SolveCharName,"solvecharname"},
  10560. {clif_parse_ResetChar,"resetchar"},
  10561. {clif_parse_LGMmessage,"lgmmessage"},
  10562. {clif_parse_MoveToKafra,"movetokafra"},
  10563. {clif_parse_MoveFromKafra,"movefromkafra"},
  10564. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10565. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10566. {clif_parse_CloseKafra,"closekafra"},
  10567. {clif_parse_CreateParty,"createparty"},
  10568. {clif_parse_CreateParty2,"createparty2"},
  10569. {clif_parse_PartyInvite,"partyinvite"},
  10570. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10571. {clif_parse_LeaveParty,"leaveparty"},
  10572. {clif_parse_RemovePartyMember,"removepartymember"},
  10573. {clif_parse_PartyChangeOption,"partychangeoption"},
  10574. {clif_parse_PartyMessage,"partymessage"},
  10575. {clif_parse_CloseVending,"closevending"},
  10576. {clif_parse_VendingListReq,"vendinglistreq"},
  10577. {clif_parse_PurchaseReq,"purchasereq"},
  10578. {clif_parse_OpenVending,"openvending"},
  10579. {clif_parse_CreateGuild,"createguild"},
  10580. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10581. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10582. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10583. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10584. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10585. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10586. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10587. {clif_parse_GuildInvite,"guildinvite"},
  10588. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10589. {clif_parse_GuildLeave,"guildleave"},
  10590. {clif_parse_GuildExpulsion,"guildexplusion"},
  10591. {clif_parse_GuildMessage,"guildmessage"},
  10592. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10593. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10594. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10595. {clif_parse_GuildOpposition,"guildopposition"},
  10596. {clif_parse_GuildBreak,"guildbreak"},
  10597. {clif_parse_PetMenu,"petmenu"},
  10598. {clif_parse_CatchPet,"catchpet"},
  10599. {clif_parse_SelectEgg,"selectegg"},
  10600. {clif_parse_SendEmotion,"sendemotion"},
  10601. {clif_parse_ChangePetName,"changepetname"},
  10602. {clif_parse_GMKick,"gmkick"},
  10603. {clif_parse_GMHide,"gmhide"},
  10604. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10605. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10606. {clif_parse_NoviceDoriDori,"sndoridori"},
  10607. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10608. {clif_parse_PMIgnore,"wisexin"},
  10609. {clif_parse_PMIgnoreList,"wisexlist"},
  10610. {clif_parse_PMIgnoreAll,"wisall"},
  10611. {clif_parse_FriendsListAdd,"friendslistadd"},
  10612. {clif_parse_FriendsListRemove,"friendslistremove"},
  10613. {clif_parse_FriendsListReply,"friendslistreply"},
  10614. {clif_parse_GMKillAll,"killall"},
  10615. {clif_parse_Recall,"summon"},
  10616. {clif_parse_GM_Monster_Item,"itemmonster"},
  10617. {clif_parse_Shift,"shift"},
  10618. {clif_parse_Blacksmith,"blacksmith"},
  10619. {clif_parse_Alchemist,"alchemist"},
  10620. {clif_parse_Taekwon,"taekwon"},
  10621. {clif_parse_RankingPk,"rankingpk"},
  10622. {clif_parse_FeelSaveOk,"feelsaveok"},
  10623. {clif_parse_AdoptRequest,"adopt"},
  10624. {clif_parse_debug,"debug"},
  10625. //[blackhole89] //[orn]
  10626. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10627. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10628. {clif_parse_HomMoveTo,"hommoveto"},
  10629. {clif_parse_HomAttack,"homattack"},
  10630. {clif_parse_HomMenu,"hommenu"},
  10631. {NULL,NULL}
  10632. };
  10633. sprintf(line, "%s/packet_db.txt", db_path);
  10634. if( (fp=fopen(line,"r"))==NULL ){
  10635. ShowFatalError("can't read %s\n", line);
  10636. exit(1);
  10637. }
  10638. clif_config.packet_db_ver = MAX_PACKET_VER;
  10639. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10640. while(fgets(line,1020,fp)){
  10641. if(line[0]=='/' && line[1]=='/')
  10642. continue;
  10643. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10644. if(strcmpi(w1,"packet_ver")==0) {
  10645. int prev_ver = packet_ver;
  10646. packet_ver = atoi(w2);
  10647. if (packet_ver > MAX_PACKET_VER)
  10648. { //Check to avoid overflowing. [Skotlex]
  10649. ShowWarning("The packet_db table only has support up to version %d\n", MAX_PACKET_VER);
  10650. break;
  10651. }
  10652. // copy from previous version into new version and continue
  10653. // - indicating all following packets should be read into the newer version
  10654. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10655. continue;
  10656. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10657. //This is the preferred version.
  10658. if(strcmpi(w2,"default")==0)
  10659. clif_config.packet_db_ver = MAX_PACKET_VER;
  10660. else {
  10661. // to manually set the packet DB version
  10662. clif_config.packet_db_ver = atoi(w2);
  10663. // check for invalid version
  10664. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10665. clif_config.packet_db_ver < 0)
  10666. clif_config.packet_db_ver = MAX_PACKET_VER;
  10667. }
  10668. continue;
  10669. }
  10670. }
  10671. malloc_tsetdword(str,0,sizeof(str));
  10672. for(j=0,p=line;j<4 && p;j++){
  10673. str[j]=p;
  10674. p=strchr(p,',');
  10675. if(p) *p++=0;
  10676. }
  10677. if(str[0]==NULL)
  10678. continue;
  10679. cmd=strtol(str[0],(char **)NULL,0);
  10680. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10681. continue;
  10682. if(str[1]==NULL){
  10683. ShowError("packet_db: packet len error\n");
  10684. continue;
  10685. }
  10686. k = atoi(str[1]);
  10687. packet_db[packet_ver][cmd].len = k;
  10688. if(str[2]==NULL){
  10689. packet_db[packet_ver][cmd].func = NULL;
  10690. ln++;
  10691. continue;
  10692. }
  10693. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10694. if(clif_parse_func[j].name != NULL &&
  10695. strcmp(str[2],clif_parse_func[j].name)==0)
  10696. {
  10697. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10698. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10699. for(i=0;i<MAX_PACKET_DB;i++){
  10700. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10701. {
  10702. malloc_tsetword(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10703. break;
  10704. }
  10705. }
  10706. }
  10707. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10708. break;
  10709. }
  10710. }
  10711. // set the identifying cmd for the packet_db version
  10712. if (strcmp(str[2],"wanttoconnection")==0)
  10713. clif_config.connect_cmd[packet_ver] = cmd;
  10714. if(str[3]==NULL){
  10715. ShowError("packet_db: packet error\n");
  10716. exit(1);
  10717. }
  10718. for(j=0,p2=str[3];p2;j++){
  10719. str2[j]=p2;
  10720. p2=strchr(p2,':');
  10721. if(p2) *p2++=0;
  10722. k = atoi(str2[j]);
  10723. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10724. packet_db[packet_ver][cmd].pos[j] = k;
  10725. }
  10726. ln++;
  10727. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10728. // printf("packet_db ver %d: %d 0x%x %d %s %p\n",packet_ver,ln,cmd,packet_db[packet_ver][cmd].len,str[2],packet_db[packet_ver][cmd].func);
  10729. }
  10730. fclose(fp);
  10731. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10732. { //Locate the nearest version that we still support. [Skotlex]
  10733. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10734. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10735. }
  10736. 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);
  10737. return 0;
  10738. }
  10739. /*==========================================
  10740. *
  10741. *------------------------------------------
  10742. */
  10743. int do_init_clif(void) {
  10744. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10745. malloc_tsetdword(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10746. malloc_tsetword(packet_db,0,sizeof(packet_db));
  10747. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10748. packetdb_readdb();
  10749. set_defaultparse(clif_parse);
  10750. if (!make_listen_bind(bind_ip,map_port)) {
  10751. ShowFatalError("cant bind game port\n");
  10752. exit(1);
  10753. }
  10754. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10755. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10756. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10757. add_timer_func_list(clif_nighttimer, "clif_nighttimer");
  10758. add_timer_func_list(clif_walktoxy_timer, "clif_walktoxy_timer");
  10759. return 0;
  10760. }