clif.c 320 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #define DUMP_UNKNOWN_PACKET 0
  4. #define DUMP_ALL_PACKETS 0
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdarg.h>
  10. #include <limits.h>
  11. #ifdef __WIN32
  12. #define __USE_W32_SOCKETS
  13. #include <windows.h>
  14. #else
  15. #include <unistd.h>
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #include <netinet/in.h>
  19. #include <arpa/inet.h>
  20. #endif
  21. #include <time.h>
  22. #include "../common/socket.h"
  23. #include "../common/timer.h"
  24. #include "../common/malloc.h"
  25. #include "../common/version.h"
  26. #include "../common/nullpo.h"
  27. #include "../common/showmsg.h"
  28. #include "map.h"
  29. #include "chrif.h"
  30. #include "clif.h"
  31. #include "pc.h"
  32. #include "status.h"
  33. #include "npc.h"
  34. #include "itemdb.h"
  35. #include "chat.h"
  36. #include "trade.h"
  37. #include "storage.h"
  38. #include "script.h"
  39. #include "skill.h"
  40. #include "atcommand.h"
  41. #include "charcommand.h"
  42. #include "intif.h"
  43. #include "battle.h"
  44. #include "mob.h"
  45. #include "party.h"
  46. #include "unit.h"
  47. #include "guild.h"
  48. #include "vending.h"
  49. #include "pet.h"
  50. #include "log.h"
  51. #include "irc.h"
  52. struct Clif_Config {
  53. int packet_db_ver; //Preferred packet version.
  54. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  55. } clif_config;
  56. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
  57. static const int packet_len_table[MAX_PACKET_DB] = {
  58. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  59. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  60. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  61. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  62. //#0x0040
  63. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  64. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  65. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  66. #if PACKETVER < 2
  67. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  68. #else // 78-7b 亀島以降 lv99エフェクト用
  69. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  70. #endif
  71. //#0x0080
  72. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  73. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  74. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  75. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  76. //#0x00C0
  77. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  78. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  79. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  80. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  81. //#0x0100
  82. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  83. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  84. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  85. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  86. //#0x0140
  87. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  88. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  89. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  90. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  91. //#0x0180
  92. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  93. #if PACKETVER < 1
  94. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  95. #else // 196 comodo以降 状態表示アイコン用
  96. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  97. #endif
  98. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  99. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  100. //#0x01C0, Set 0x1d5=-1
  101. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  102. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  103. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  104. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  105. //#0x200
  106. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  107. 22, 0, 26, 26, 42, -1, -1, 2, 2,282,282,10, 10, -1, -1, 66,
  108. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 69, 5,
  109. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  110. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  111. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4
  112. };
  113. // local define
  114. enum {
  115. ALL_CLIENT,
  116. ALL_SAMEMAP,
  117. AREA,
  118. AREA_WOS,
  119. AREA_WOC,
  120. AREA_WOSC,
  121. AREA_CHAT_WOC,
  122. CHAT,
  123. CHAT_WOS,
  124. CHAT_MAINCHAT,
  125. PARTY,
  126. PARTY_WOS,
  127. PARTY_SAMEMAP,
  128. PARTY_SAMEMAP_WOS,
  129. PARTY_AREA,
  130. PARTY_AREA_WOS,
  131. GUILD,
  132. GUILD_WOS,
  133. GUILD_SAMEMAP, // [Valaris]
  134. GUILD_SAMEMAP_WOS,
  135. GUILD_AREA,
  136. GUILD_AREA_WOS, // end additions [Valaris]
  137. SELF
  138. };
  139. //Converts item type in case of pet eggs.
  140. #define itemtype(a) (a == 7)?4:a
  141. #define WBUFPOS(p,pos,x,y) { unsigned char *__p = (p); __p+=(pos); __p[0] = (x)>>2; __p[1] = ((x)<<6) | (((y)>>4)&0x3f); __p[2] = (y)<<4; }
  142. #define WBUFPOS2(p,pos,x0,y0,x1,y1) { unsigned char *__p = (p); __p+=(pos); __p[0] = (unsigned char)((x0)>>2); __p[1] = (unsigned char)(((x0)<<6) | (((y0)>>4)&0x3f)); __p[2] = (unsigned char)(((y0)<<4) | (((x1)>>6)&0x0f)); __p[3]=(unsigned char)(((x1)<<2) | (((y1)>>8)&0x03)); __p[4]=(unsigned char)(y1); }
  143. #define WFIFOPOS(fd,pos,x,y) { WBUFPOS (WFIFOP(fd,pos),0,x,y); }
  144. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1) { WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1); }
  145. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  146. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  147. //Removed sd->npc_shopid because there is no packet sent from the client when you cancel a buy!
  148. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  149. #define clif_cant_act(sd) (sd->npc_id || sd->vender_id || sd->chatID || sd->sc.opt1 || sd->state.trading || sd->state.storage_flag)
  150. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  151. #define clif_trading(sd) (sd->npc_id || sd->vender_id || sd->state.trading )
  152. //To idenfity disguised characters.
  153. #define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
  154. static char map_ip_str[16];
  155. static in_addr_t map_ip;
  156. static in_addr_t bind_ip = INADDR_ANY;
  157. static int map_port = 5121;
  158. int map_fd;
  159. char talkie_mes[MESSAGE_SIZE];
  160. //These two will be used to verify the incoming player's validity.
  161. //It helps identify their client packet version correctly. [Skotlex]
  162. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  163. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  164. int clif_parse (int fd);
  165. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  166. /*==========================================
  167. * map鯖のip設定
  168. *------------------------------------------
  169. */
  170. void clif_setip(char *ip)
  171. {
  172. memcpy(map_ip_str, ip, 16);
  173. map_ip = inet_addr(map_ip_str);
  174. }
  175. void clif_setbindip(char *ip)
  176. {
  177. bind_ip = inet_addr(ip);
  178. }
  179. /*==========================================
  180. * map鯖のport設定
  181. *------------------------------------------
  182. */
  183. void clif_setport(int port)
  184. {
  185. map_port = port;
  186. }
  187. /*==========================================
  188. * map鯖のip読み出し
  189. *------------------------------------------
  190. */
  191. in_addr_t clif_getip(void)
  192. {
  193. return map_ip;
  194. }
  195. /*==========================================
  196. * map鯖のport読み出し
  197. *------------------------------------------
  198. */
  199. int clif_getport(void)
  200. {
  201. return map_port;
  202. }
  203. /*==========================================
  204. * Counts connected players.
  205. *------------------------------------------
  206. */
  207. int clif_countusers(void)
  208. {
  209. int users = 0, i;
  210. struct map_session_data *sd;
  211. for(i = 0; i < fd_max; i++) {
  212. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) && sd->state.auth &&
  213. !(battle_config.hide_GM_session && pc_isGM(sd)))
  214. users++;
  215. }
  216. return users;
  217. }
  218. /*==========================================
  219. * 全てのclientに対してfunc()実行
  220. *------------------------------------------
  221. */
  222. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  223. {
  224. int i;
  225. va_list ap;
  226. struct map_session_data *sd;
  227. va_start(ap,func);
  228. for(i = 0; i < fd_max; i++) {
  229. if ( session[i] ) {
  230. sd = (struct map_session_data*)session[i]->session_data;
  231. if ( sd && session[i]->func_parse == clif_parse &&
  232. sd->state.auth && !sd->state.waitingdisconnect )
  233. func(sd, ap);
  234. }
  235. }
  236. va_end(ap);
  237. return 0;
  238. }
  239. /*==========================================
  240. * clif_sendでAREA*指定時用
  241. *------------------------------------------
  242. */
  243. int clif_send_sub(struct block_list *bl, va_list ap)
  244. {
  245. struct block_list *src_bl;
  246. struct map_session_data *sd;
  247. unsigned char *buf;
  248. int len, type;
  249. nullpo_retr(0, bl);
  250. nullpo_retr(0, ap);
  251. nullpo_retr(0, sd = (struct map_session_data *)bl);
  252. if (!sd->fd) //Avoid attempting to send to disconnected chars (may prevent buffer overrun errors?) [Skotlex]
  253. return 0;
  254. buf = va_arg(ap,unsigned char*);
  255. len = va_arg(ap,int);
  256. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  257. type = va_arg(ap,int);
  258. switch(type) {
  259. case AREA_WOS:
  260. if (bl == src_bl)
  261. return 0;
  262. break;
  263. case AREA_WOC:
  264. if (sd->chatID || bl == src_bl)
  265. return 0;
  266. break;
  267. case AREA_WOSC:
  268. {
  269. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  270. if ((ssd != 0) && (src_bl->type == BL_PC) && (sd->chatID != 0) && (sd->chatID == ssd->chatID))
  271. return 0;
  272. }
  273. break;
  274. }
  275. if (session[sd->fd] != NULL) {
  276. WFIFOHEAD(sd->fd, len);
  277. if (WFIFOP(sd->fd,0) == buf) {
  278. printf("WARNING: Invalid use of clif_send function\n");
  279. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  280. printf(" Please correct your code.\n");
  281. // don't send to not move the pointer of the packet for next sessions in the loop
  282. } else {
  283. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  284. memcpy(WFIFOP(sd->fd,0), buf, len);
  285. //Check if hidden, better to modify the char's buffer than the
  286. //given buffer to prevent intravision affecting the packet as
  287. //it's being received by everyone. [Skotlex]
  288. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 )
  289. && bl != src_bl && WFIFOW(sd->fd,0) == 0x0196)
  290. { //New intravision method, just modify the status change/start packet. [Skotlex]
  291. switch (WFIFOW(sd->fd,2)) {
  292. case SI_HIDING:
  293. case SI_CLOAKING:
  294. case SI_CHASEWALK:
  295. WFIFOW(sd->fd,2) = SI_INTRAVISION;
  296. }
  297. }
  298. /* Previous implementation.
  299. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 ) && bl != src_bl) {
  300. struct status_change *sc = status_get_sc(src_bl);
  301. if(sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK)))
  302. { //optionの修正
  303. switch(((unsigned short*)buf)[0])
  304. {
  305. case 0x119:
  306. WFIFOW(sd->fd,10) &= ~(OPTION_HIDE|OPTION_CLOAK);
  307. break;
  308. #if PACKETVER < 4
  309. case 0x78:
  310. #else
  311. case 0x1da:
  312. #endif
  313. case 0x7b:
  314. case 0x7c:
  315. case 0x1d8:
  316. WFIFOW(sd->fd,12) &=~(OPTION_HIDE|OPTION_CLOAK);
  317. break;
  318. }
  319. }
  320. }
  321. */
  322. WFIFOSET(sd->fd,len);
  323. }
  324. }
  325. }
  326. return 0;
  327. }
  328. /*==========================================
  329. *
  330. *------------------------------------------
  331. */
  332. int clif_send (unsigned char *buf, int len, struct block_list *bl, int type) {
  333. int i;
  334. struct map_session_data *sd = NULL;
  335. struct party *p = NULL;
  336. struct guild *g = NULL;
  337. int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
  338. if (type != ALL_CLIENT &&
  339. type != CHAT_MAINCHAT) {
  340. nullpo_retr(0, bl);
  341. if (bl->type == BL_PC) {
  342. sd = (struct map_session_data *)bl;
  343. }
  344. }
  345. switch(type) {
  346. case ALL_CLIENT: // 全クライアントに送信
  347. for (i = 0; i < fd_max; i++) {
  348. if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL && sd->state.auth) {
  349. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  350. WFIFOHEAD(i, len);
  351. memcpy(WFIFOP(i,0), buf, len);
  352. WFIFOSET(i,len);
  353. }
  354. }
  355. }
  356. break;
  357. case ALL_SAMEMAP: // 同じマップの全クライアントに送信
  358. for(i = 0; i < fd_max; i++) {
  359. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  360. sd->state.auth && sd->bl.m == bl->m) {
  361. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  362. WFIFOHEAD(i,len);
  363. memcpy(WFIFOP(i,0), buf, len);
  364. WFIFOSET(i,len);
  365. }
  366. }
  367. }
  368. break;
  369. case AREA:
  370. case AREA_WOS:
  371. case AREA_WOC:
  372. case AREA_WOSC:
  373. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  374. BL_PC, buf, len, bl, type);
  375. break;
  376. case AREA_CHAT_WOC:
  377. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  378. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  379. break;
  380. case CHAT:
  381. case CHAT_WOS:
  382. {
  383. struct chat_data *cd;
  384. if (sd) {
  385. cd = (struct chat_data*)map_id2bl(sd->chatID);
  386. } else if (bl->type == BL_CHAT) {
  387. cd = (struct chat_data*)bl;
  388. } else break;
  389. if (cd == NULL)
  390. break;
  391. for(i = 0; i < cd->users; i++) {
  392. if (type == CHAT_WOS && cd->usersd[i] == sd)
  393. continue;
  394. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  395. if (cd->usersd[i]->fd >0 && session[cd->usersd[i]->fd]) // Added check to see if session exists [PoW]
  396. {
  397. WFIFOHEAD(cd->usersd[i]->fd,len);
  398. memcpy(WFIFOP(cd->usersd[i]->fd,0), buf, len);
  399. WFIFOSET(cd->usersd[i]->fd,len);
  400. }
  401. }
  402. }
  403. }
  404. break;
  405. case CHAT_MAINCHAT: //[LuzZza]
  406. for(i=1; i<fd_max; i++) {
  407. if(session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  408. sd->state.mainchat && sd->fd) {
  409. WFIFOHEAD(sd->fd, len);
  410. memcpy(WFIFOP(sd->fd,0), buf, len);
  411. WFIFOSET(sd->fd, len);
  412. }
  413. }
  414. break;
  415. case PARTY_AREA: // 同じ画面内の全パーティーメンバに送信
  416. case PARTY_AREA_WOS: // 自分以外の同じ画面内の全パーティーメンバに送信
  417. x0 = bl->x - AREA_SIZE;
  418. y0 = bl->y - AREA_SIZE;
  419. x1 = bl->x + AREA_SIZE;
  420. y1 = bl->y + AREA_SIZE;
  421. case PARTY: // 全パーティーメンバに送信
  422. case PARTY_WOS: // 自分以外の全パーティーメンバに送信
  423. case PARTY_SAMEMAP: // 同じマップの全パーティーメンバに送信
  424. case PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信
  425. if (sd && sd->status.party_id)
  426. p = party_search(sd->status.party_id);
  427. if (p) {
  428. for(i=0;i<MAX_PARTY;i++){
  429. if ((sd = p->member[i].sd) != NULL) {
  430. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  431. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  432. continue;
  433. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  434. continue;
  435. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m) // マップチェック
  436. continue;
  437. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  438. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  439. continue;
  440. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  441. WFIFOHEAD(sd->fd,len);
  442. memcpy(WFIFOP(sd->fd,0), buf, len);
  443. WFIFOSET(sd->fd,len);
  444. }
  445. }
  446. }
  447. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  448. break;
  449. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  450. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL && sd->state.auth && sd->fd && sd->partyspy) {
  451. if (sd->partyspy == p->party_id) {
  452. if (sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  453. WFIFOHEAD(sd->fd,len);
  454. memcpy(WFIFOP(sd->fd,0), buf, len);
  455. WFIFOSET(sd->fd,len);
  456. }
  457. }
  458. }
  459. }
  460. }
  461. break;
  462. case SELF:
  463. if (sd && sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  464. WFIFOHEAD(sd->fd,len);
  465. memcpy(WFIFOP(sd->fd,0), buf, len);
  466. WFIFOSET(sd->fd,len);
  467. }
  468. break;
  469. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  470. case GUILD_AREA:
  471. case GUILD_AREA_WOS:
  472. x0 = bl->x - AREA_SIZE;
  473. y0 = bl->y - AREA_SIZE;
  474. x1 = bl->x + AREA_SIZE;
  475. y1 = bl->y + AREA_SIZE;
  476. case GUILD_SAMEMAP:
  477. case GUILD_SAMEMAP_WOS:
  478. case GUILD:
  479. case GUILD_WOS:
  480. if (sd && sd->status.guild_id)
  481. g = guild_search(sd->status.guild_id);
  482. if (g) {
  483. for(i = 0; i < g->max_member; i++) {
  484. if ((sd = g->member[i].sd) != NULL) {
  485. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  486. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  487. continue;
  488. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  489. continue;
  490. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  491. continue;
  492. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  493. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  494. continue;
  495. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  496. WFIFOHEAD(sd->fd,len);
  497. memcpy(WFIFOP(sd->fd,0), buf, len);
  498. WFIFOSET(sd->fd,len);
  499. }
  500. }
  501. }
  502. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  503. break;
  504. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  505. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL && sd->state.auth && sd->fd && sd->guildspy) {
  506. if (sd->guildspy == g->guild_id) {
  507. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  508. WFIFOHEAD(sd->fd,len);
  509. memcpy(WFIFOP(sd->fd,0), buf, len);
  510. WFIFOSET(sd->fd,len);
  511. }
  512. }
  513. }
  514. }
  515. }
  516. break;
  517. /* End [Valaris] */
  518. default:
  519. if (battle_config.error_log)
  520. ShowError("clif_send: Unrecognized type %d\n",type);
  521. return -1;
  522. }
  523. return 0;
  524. }
  525. //
  526. // パケット作って送信
  527. //
  528. /*==========================================
  529. *
  530. *------------------------------------------
  531. */
  532. int clif_authok(struct map_session_data *sd) {
  533. int fd;
  534. if (!sd->fd)
  535. return 0;
  536. fd = sd->fd;
  537. WFIFOHEAD(fd, packet_len_table[0x73]);
  538. WFIFOW(fd, 0) = 0x73;
  539. WFIFOL(fd, 2) = gettick();
  540. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y);
  541. WFIFOB(fd, 9) = 5;
  542. WFIFOB(fd,10) = 5;
  543. WFIFOSET(fd,packet_len_table[0x73]);
  544. return 0;
  545. }
  546. /*==========================================
  547. *
  548. *------------------------------------------
  549. */
  550. int clif_authfail_fd(int fd, int type) {
  551. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  552. return 0;
  553. WFIFOHEAD(fd, packet_len_table[0x81]);
  554. WFIFOW(fd,0) = 0x81;
  555. WFIFOB(fd,2) = type;
  556. WFIFOSET(fd,packet_len_table[0x81]);
  557. clif_setwaitclose(fd);
  558. return 0;
  559. }
  560. /*==========================================
  561. * Used to know which is the max valid account/char id [Skotlex]
  562. *------------------------------------------
  563. */
  564. void clif_updatemaxid(int account_id, int char_id)
  565. {
  566. max_account_id = account_id;
  567. max_char_id = char_id;
  568. }
  569. /*==========================================
  570. *
  571. *------------------------------------------
  572. */
  573. int clif_charselectok(int id) {
  574. struct map_session_data *sd;
  575. int fd;
  576. if ((sd = map_id2sd(id)) == NULL)
  577. return 1;
  578. if (!sd->fd)
  579. return 1;
  580. fd = sd->fd;
  581. WFIFOHEAD(fd, packet_len_table[0xb3]);
  582. WFIFOW(fd,0) = 0xb3;
  583. WFIFOB(fd,2) = 1;
  584. WFIFOSET(fd,packet_len_table[0xb3]);
  585. return 0;
  586. }
  587. /*==========================================
  588. *
  589. *------------------------------------------
  590. */
  591. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  592. int view;
  593. nullpo_retr(0, fitem);
  594. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  595. WBUFW(buf, 0) = 0x9e;
  596. WBUFL(buf, 2) = fitem->bl.id;
  597. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  598. WBUFW(buf, 6) = view;
  599. else
  600. WBUFW(buf, 6) = fitem->item_data.nameid;
  601. WBUFB(buf, 8) = fitem->item_data.identify;
  602. WBUFW(buf, 9) = fitem->bl.x;
  603. WBUFW(buf,11) = fitem->bl.y;
  604. WBUFB(buf,13) = fitem->subx;
  605. WBUFB(buf,14) = fitem->suby;
  606. WBUFW(buf,15) = fitem->item_data.amount;
  607. return packet_len_table[0x9e];
  608. }
  609. /*==========================================
  610. *
  611. *------------------------------------------
  612. */
  613. int clif_dropflooritem(struct flooritem_data *fitem) {
  614. unsigned char buf[64];
  615. nullpo_retr(0, fitem);
  616. if (fitem->item_data.nameid <= 0)
  617. return 0;
  618. clif_set009e(fitem, buf);
  619. clif_send(buf, packet_len_table[0x9e], &fitem->bl, AREA);
  620. return 0;
  621. }
  622. /*==========================================
  623. *
  624. *------------------------------------------
  625. */
  626. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  627. unsigned char buf[16];
  628. nullpo_retr(0, fitem);
  629. WBUFW(buf,0) = 0xa1;
  630. WBUFL(buf,2) = fitem->bl.id;
  631. if (fd == 0) {
  632. clif_send(buf, packet_len_table[0xa1], &fitem->bl, AREA);
  633. } else {
  634. WFIFOHEAD(fd,packet_len_table[0xa1]);
  635. memcpy(WFIFOP(fd,0), buf, 6);
  636. WFIFOSET(fd,packet_len_table[0xa1]);
  637. }
  638. return 0;
  639. }
  640. /*==========================================
  641. *
  642. *------------------------------------------
  643. */
  644. int clif_clearchar(struct block_list *bl, int type) {
  645. unsigned char buf[16];
  646. nullpo_retr(0, bl);
  647. WBUFW(buf,0) = 0x80;
  648. WBUFL(buf,2) = bl->id;
  649. WBUFB(buf,6) = type;
  650. clif_send(buf, packet_len_table[0x80], bl, type == 1 ? AREA : AREA_WOS);
  651. if(disguised(bl)) {
  652. WBUFL(buf,2) = -bl->id;
  653. clif_send(buf, packet_len_table[0x80], bl, SELF);
  654. }
  655. return 0;
  656. }
  657. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  658. struct block_list *bl = (struct block_list *)id;
  659. clif_clearchar(bl,data);
  660. aFree(bl);
  661. return 0;
  662. }
  663. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  664. struct block_list *tbl;
  665. tbl = aMalloc(sizeof (struct block_list));
  666. memcpy (tbl, bl, sizeof (struct block_list));
  667. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  668. return 0;
  669. }
  670. /*==========================================
  671. *
  672. *------------------------------------------
  673. */
  674. int clif_clearchar_id(int id, int type, int fd) {
  675. unsigned char buf[16];
  676. WBUFW(buf,0) = 0x80;
  677. WBUFL(buf,2) = id;
  678. WBUFB(buf,6) = type;
  679. WFIFOHEAD(fd, packet_len_table[0x80]);
  680. memcpy(WFIFOP(fd,0), buf, 7);
  681. WFIFOSET(fd, packet_len_table[0x80]);
  682. return 0;
  683. }
  684. void clif_get_weapon_view(TBL_PC* sd, short *rhand, short *lhand)
  685. {
  686. #if PACKETVER > 3
  687. struct item_data *id;
  688. #endif
  689. if (sd->sc.option&(OPTION_XMAS|OPTION_WEDDING))
  690. {
  691. *rhand = *lhand = 0;
  692. return;
  693. }
  694. #if PACKETVER < 4
  695. *rhand = sd->status.weapon;
  696. *lhand = sd->status.shield;
  697. #else
  698. if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]])
  699. {
  700. id = sd->inventory_data[sd->equip_index[9]];
  701. if (id->view_id > 0)
  702. *rhand = id->view_id;
  703. else
  704. *rhand = id->nameid;
  705. } else
  706. *rhand = 0;
  707. if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
  708. && sd->inventory_data[sd->equip_index[8]])
  709. {
  710. id = sd->inventory_data[sd->equip_index[8]];
  711. if (id->view_id > 0)
  712. *lhand = id->view_id;
  713. else
  714. *lhand = id->nameid;
  715. } else
  716. *lhand = 0;
  717. #endif
  718. }
  719. static void clif_get_guild_data(struct block_list *bl, long *guild_id, short *emblem_id)
  720. {
  721. //TODO: There has to be a way to clean this up.
  722. switch (bl->type) {
  723. case BL_PC:
  724. *guild_id = ((TBL_PC*)bl)->status.guild_id;
  725. *emblem_id = ((TBL_PC*)bl)->guild_emblem_id;
  726. break;
  727. case BL_MOB:
  728. if (((TBL_MOB*)bl)->guardian_data) {
  729. *guild_id =((TBL_MOB*)bl)->guardian_data->guild_id;
  730. *emblem_id =((TBL_MOB*)bl)->guardian_data->emblem_id;
  731. }
  732. break;
  733. case BL_NPC:
  734. if (bl->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) {
  735. struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id);
  736. if (g) {
  737. *guild_id =g->guild_id;
  738. *emblem_id =g->emblem_id;
  739. }
  740. }
  741. break;
  742. default:
  743. *guild_id = status_get_guild_id(bl);
  744. }
  745. return;
  746. }
  747. /*==========================================
  748. *
  749. *------------------------------------------
  750. */
  751. static int clif_set0078(struct block_list *bl, struct view_data *vd, unsigned char *buf) {
  752. struct status_change *sc;
  753. struct map_session_data *sd;
  754. long guild_id=0;
  755. unsigned short emblem_id=0, lv;
  756. unsigned short dir;
  757. nullpo_retr(0, bl);
  758. BL_CAST(BL_PC, bl, sd);
  759. sc = status_get_sc(bl);
  760. clif_get_guild_data(bl, &guild_id, &emblem_id);
  761. dir = unit_getdir(bl);
  762. lv = status_get_lv(bl);
  763. if(pcdb_checkid(vd->class_)) {
  764. #if PACKETVER > 3
  765. memset(buf,0,packet_len_table[0x1d8]);
  766. WBUFW(buf,0)=0x1d8;
  767. WBUFL(buf,2)=bl->id;
  768. WBUFW(buf,6)=status_get_speed(bl);
  769. if (sc) {
  770. WBUFW(buf,8)=sc->opt1;
  771. WBUFW(buf,10)=sc->opt2;
  772. WBUFW(buf,12)=sc->option;
  773. WBUFW(buf,42)=sc->opt3;
  774. }
  775. WBUFW(buf,14)=vd->class_;
  776. WBUFW(buf,16)=vd->hair_style;
  777. WBUFW(buf,18)=vd->weapon;
  778. WBUFW(buf,20)=vd->shield;
  779. WBUFW(buf,22)=vd->head_bottom;
  780. WBUFW(buf,24)=vd->head_top;
  781. WBUFW(buf,26)=vd->head_mid;
  782. WBUFW(buf,28)=vd->hair_color;
  783. WBUFW(buf,30)=vd->cloth_color;
  784. WBUFW(buf,32)=sd?sd->head_dir:dir;
  785. WBUFL(buf,34)=guild_id;
  786. WBUFL(buf,38)=emblem_id;
  787. if (sd) {
  788. WBUFW(buf,40)=sd->status.manner;
  789. WBUFB(buf,44)=sd->status.karma;
  790. }
  791. WBUFB(buf,45)=vd->sex;
  792. WBUFPOS(buf,46,bl->x,bl->y);
  793. WBUFB(buf,48)|=dir & 0x0f;
  794. WBUFB(buf,49)=5;
  795. WBUFB(buf,50)=5;
  796. WBUFB(buf,51)=vd->dead_sit;
  797. WBUFW(buf,52)=clif_setlevel(lv);
  798. return packet_len_table[0x1d8];
  799. #else
  800. memset(buf,0,packet_len_table[0x78]);
  801. WBUFW(buf,0)=0x78;
  802. WBUFL(buf,2)=bl->id;
  803. WBUFW(buf,6)=status_get_speed(bl);
  804. if (sc) {
  805. WBUFW(buf,8)=sc->opt1;
  806. WBUFW(buf,10)=sc->opt2;
  807. WBUFW(buf,12)=sc->option;
  808. }
  809. WBUFW(buf,14)=vd->class_;
  810. WBUFW(buf,16)=vd->hair_style;
  811. WBUFW(buf,18)=vd->weapon;
  812. WBUFW(buf,20)=vd->head_bottom;
  813. WBUFW(buf,22)=vd->shield;
  814. WBUFW(buf,24)=vd->head_top;
  815. WBUFW(buf,26)=vd->head_mid;
  816. WBUFW(buf,28)=vd->hair_color;
  817. WBUFW(buf,30)=vd->cloth_color;
  818. WBUFW(buf,32)=sd?sd->head_dir:dir;
  819. WBUFL(buf,34)=guild_id;
  820. WBUFL(buf,38)=emblem_id;
  821. if (sd) {
  822. WBUFW(buf,42)=sd->status.manner;
  823. WBUFB(buf,44)=sd->status.karma;
  824. }
  825. WBUFB(buf,45)=vd->sex;
  826. WBUFPOS(buf,46,bl->x,bl->y);
  827. WBUFB(buf,48)|=dir&0x0f;
  828. WBUFB(buf,49)=5;
  829. WBUFB(buf,50)=5;
  830. WBUFB(buf,51)=vd->dead_sit;
  831. WBUFW(buf,52)=clif_setlevel(lv);
  832. return packet_len_table[0x78];
  833. #endif
  834. }
  835. //Non-player sprites need just a few fields filled.
  836. memset(buf,0,packet_len_table[0x78]);
  837. WBUFW(buf,0)=0x78;
  838. WBUFL(buf,2)=bl->id;
  839. WBUFW(buf,6)=status_get_speed(bl);
  840. if (sc) {
  841. WBUFW(buf,8)=sc->opt1;
  842. WBUFW(buf,10)=sc->opt2;
  843. WBUFW(buf,12)=sc->option;
  844. }
  845. WBUFW(buf,14)=vd->class_;
  846. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  847. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  848. if (bl->type == BL_NPC && vd->class_ == 722)
  849. { //The hell, why flags work like this?
  850. WBUFL(buf,22)=emblem_id;
  851. WBUFL(buf,26)=guild_id;
  852. }
  853. WBUFW(buf,32)=dir;
  854. WBUFL(buf,34)=guild_id;
  855. WBUFL(buf,38)=emblem_id;
  856. WBUFPOS(buf,46,bl->x,bl->y);
  857. WBUFB(buf,48)|=dir&0x0f;
  858. WBUFB(buf,49)=5;
  859. WBUFB(buf,50)=5;
  860. WBUFW(buf,52)=clif_setlevel(lv);
  861. return packet_len_table[0x78];
  862. }
  863. /*==========================================
  864. *
  865. *------------------------------------------
  866. */
  867. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf) {
  868. struct status_change *sc;
  869. struct map_session_data *sd;
  870. long guild_id=0;
  871. unsigned short emblem_id=0, lv;
  872. nullpo_retr(0, bl);
  873. BL_CAST(BL_PC, bl, sd);
  874. sc = status_get_sc(bl);
  875. clif_get_guild_data(bl, &guild_id, &emblem_id);
  876. lv = status_get_lv(bl);
  877. if(pcdb_checkid(vd->class_)) {
  878. #if PACKETVER > 6
  879. memset(buf,0,packet_len_table[0x22c]);
  880. WBUFW(buf,0)=0x22c;
  881. WBUFL(buf,2)=bl->id;
  882. WBUFW(buf,6)=status_get_speed(bl);
  883. if (sc) {
  884. WBUFW(buf,8)= sc->opt1;
  885. WBUFW(buf,10)= sc->opt2;
  886. WBUFL(buf,12)= sc->option;
  887. WBUFL(buf,48)= sc->opt3;
  888. }
  889. WBUFW(buf,16)=vd->class_;
  890. WBUFW(buf,18)=vd->hair_style;
  891. WBUFW(buf,20)=vd->weapon;
  892. WBUFW(buf,22)=vd->shield;
  893. WBUFW(buf,24)=vd->head_bottom;
  894. WBUFL(buf,26)=gettick();
  895. WBUFW(buf,30)=vd->head_top;
  896. WBUFW(buf,32)=vd->head_mid;
  897. WBUFW(buf,34)=vd->hair_color;
  898. WBUFW(buf,36)=vd->cloth_color;
  899. WBUFW(buf,38)=sd?sd->head_dir:unit_getdir(bl);
  900. WBUFL(buf,40)=guild_id;
  901. WBUFW(buf,44)=emblem_id;
  902. if (sd) {
  903. WBUFW(buf,46)=sd->status.manner;
  904. WBUFB(buf,52)=sd->status.karma;
  905. }
  906. WBUFB(buf,53)=vd->sex;
  907. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  908. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  909. WBUFB(buf,60)=0;
  910. WBUFB(buf,61)=0;
  911. WBUFW(buf,62)=clif_setlevel(lv);
  912. return packet_len_table[0x22c];
  913. #elif PACKETVER > 3
  914. memset(buf,0,packet_len_table[0x1da]);
  915. WBUFW(buf,0)=0x1da;
  916. WBUFL(buf,2)=bl->id;
  917. WBUFW(buf,6)=status_get_speed(bl);
  918. if (sc) {
  919. WBUFW(buf,8)=sc->opt1;
  920. WBUFW(buf,10)=sc->opt2;
  921. WBUFW(buf,12)=sc->option;
  922. WBUFW(buf,46)=sc->opt3;
  923. }
  924. WBUFW(buf,14)=vd->class_;
  925. WBUFW(buf,16)=vd->hair_style;
  926. WBUFW(buf,18)=vd->weapon;
  927. WBUFW(buf,20)=vd->shield;
  928. WBUFW(buf,22)=vd->head_bottom;
  929. WBUFL(buf,24)=gettick();
  930. WBUFW(buf,28)=vd->head_top;
  931. WBUFW(buf,30)=vd->head_mid;
  932. WBUFW(buf,32)=vd->hair_color;
  933. WBUFW(buf,34)=vd->cloth_color;
  934. WBUFW(buf,36)=sd?sd->head_dir:unit_getdir(bl);
  935. WBUFL(buf,38)=guild_id;
  936. WBUFW(buf,42)=emblem_id;
  937. if (sd) {
  938. WBUFW(buf,44)=sd->status.manner;
  939. WBUFB(buf,48)=sd->status.karma;
  940. }
  941. WBUFB(buf,49)=vd->sex;
  942. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  943. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  944. WBUFB(buf,56)=5;
  945. WBUFB(buf,57)=5;
  946. WBUFW(buf,58)=clif_setlevel(lv);
  947. return packet_len_table[0x1da];
  948. #else
  949. memset(buf,0,packet_len_table[0x7b]);
  950. WBUFW(buf,0)=0x7b;
  951. WBUFL(buf,2)=bl->id;
  952. WBUFW(buf,6)=status_get_speed(bl);
  953. if (sc) {
  954. WBUFW(buf,8)=sc->opt1;
  955. WBUFW(buf,10)=sc->opt2;
  956. WBUFW(buf,12)=sc->option;
  957. WBUFW(buf,46)=sc->opt3;
  958. }
  959. WBUFW(buf,14)=vd->class_;
  960. WBUFW(buf,16)=vd->hair_style;
  961. WBUFW(buf,18)=vd->weapon;
  962. WBUFW(buf,20)=vd->head_bottom;
  963. WBUFL(buf,22)=gettick();
  964. WBUFW(buf,26)=vd->shield;
  965. WBUFW(buf,28)=vd->head_top;
  966. WBUFW(buf,30)=vd->head_mid;
  967. WBUFW(buf,32)=vd->hair_color;
  968. WBUFW(buf,34)=vd->cloth_color;
  969. WBUFW(buf,36)=sd?sd->head_dir:unit_getdir(bl);
  970. WBUFL(buf,38)=guild_id;
  971. WBUFL(buf,42)=emblem_id;
  972. if (sd)
  973. WBUFB(buf,48)=sd->status.karma;
  974. WBUFB(buf,49)=vd->sex;
  975. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  976. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  977. WBUFB(buf,56)=5;
  978. WBUFB(buf,57)=5;
  979. WBUFW(buf,58)=clif_setlevel(lv);
  980. return packet_len_table[0x7b];
  981. #endif
  982. }
  983. //Non-player sprites only require a few fields.
  984. #if PACKETVER > 6
  985. memset(buf,0,packet_len_table[0x22c]);
  986. WBUFW(buf,0)=0x22c;
  987. WBUFL(buf,2)=bl->id;
  988. WBUFW(buf,6)=status_get_speed(bl);
  989. if (sc) {
  990. WBUFW(buf,8)=sc->opt1;
  991. WBUFW(buf,10)=sc->opt2;
  992. WBUFL(buf,12)=sc->option;
  993. WBUFL(buf,48)=sc->opt3;
  994. }
  995. WBUFW(buf,16)=vd->class_;
  996. WBUFW(buf,18)=vd->hair_style; //For pets
  997. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  998. WBUFL(buf,26)=gettick();
  999. WBUFW(buf,38)=unit_getdir(bl);
  1000. WBUFL(buf,40)=guild_id;
  1001. WBUFL(buf,44)=emblem_id;
  1002. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y);
  1003. WBUFB(buf,59)=0x88; // Deals with acceleration in directions. [Valaris]
  1004. WBUFB(buf,60)=0;
  1005. WBUFB(buf,61)=0;
  1006. WBUFW(buf,62)=clif_setlevel(lv);
  1007. return packet_len_table[0x22c];
  1008. #else
  1009. memset(buf,0,packet_len_table[0x7b]);
  1010. WBUFW(buf,0)=0x7b;
  1011. WBUFL(buf,2)=bl->id;
  1012. WBUFW(buf,6)=status_get_speed(bl);
  1013. if (sc) {
  1014. WBUFW(buf,8)=sc->opt1;
  1015. WBUFW(buf,10)=sc->opt2;
  1016. WBUFW(buf,12)=sc->option;
  1017. WBUFW(buf,46)=sc->opt3;
  1018. }
  1019. WBUFW(buf,14)=vd->class_;
  1020. WBUFW(buf,16)=vd->hair_style; //For pets
  1021. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  1022. WBUFL(buf,22)=gettick();
  1023. WBUFW(buf,36)=unit_getdir(bl);
  1024. WBUFL(buf,38)=guild_id;
  1025. WBUFL(buf,42)=emblem_id;
  1026. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y);
  1027. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1028. WBUFB(buf,56)=5;
  1029. WBUFB(buf,57)=5;
  1030. WBUFW(buf,58)=clif_setlevel(lv);
  1031. return packet_len_table[0x7b];
  1032. #endif
  1033. }
  1034. //Modifies the buffer for disguise characters and sends it to self.
  1035. //Flag = 0: change id to negative, buf will have disguise data.
  1036. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1037. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1038. //But no longer holds true for packet 0x22c
  1039. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag) {
  1040. if (flag) {
  1041. #if PACKETVER > 6
  1042. if (WBUFW(buf,0)==0x22c) {
  1043. WBUFL(buf,12)=OPTION_INVISIBLE;
  1044. WBUFW(buf,16)=sd->status.class_;
  1045. } else {
  1046. #endif
  1047. WBUFL(buf,2)=sd->bl.id;
  1048. WBUFW(buf,12)=OPTION_INVISIBLE;
  1049. WBUFW(buf,14)=sd->status.class_;
  1050. #if PACKETVER > 6
  1051. }
  1052. #endif
  1053. } else {
  1054. WBUFL(buf,2)=-sd->bl.id;
  1055. }
  1056. clif_send(buf, len, &sd->bl, SELF);
  1057. }
  1058. /*==========================================
  1059. * クラスチェンジ typeはMobの場合は1で他は0?
  1060. *------------------------------------------
  1061. */
  1062. int clif_class_change(struct block_list *bl,int class_,int type)
  1063. {
  1064. unsigned char buf[16];
  1065. nullpo_retr(0, bl);
  1066. if(!pcdb_checkid(class_)) {
  1067. WBUFW(buf,0)=0x1b0;
  1068. WBUFL(buf,2)=bl->id;
  1069. WBUFB(buf,6)=type;
  1070. WBUFL(buf,7)=class_;
  1071. clif_send(buf,packet_len_table[0x1b0],bl,AREA);
  1072. }
  1073. return 0;
  1074. }
  1075. /*==========================================
  1076. *
  1077. *------------------------------------------
  1078. */
  1079. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1080. {
  1081. WFIFOHEAD(fd, packet_len_table[0x1e1]);
  1082. WFIFOW(fd,0)=0x1e1;
  1083. WFIFOL(fd,2)=sd->bl.id;
  1084. WFIFOW(fd,6)=sd->spiritball;
  1085. WFIFOSET(fd, packet_len_table[0x1e1]);
  1086. }
  1087. /*==========================================
  1088. *
  1089. *------------------------------------------
  1090. */
  1091. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1092. WFIFOHEAD(fd, packet_len_table[0x192]);
  1093. WFIFOW(fd,0) = 0x192;
  1094. WFIFOW(fd,2) = x;
  1095. WFIFOW(fd,4) = y;
  1096. WFIFOW(fd,6) = type;
  1097. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1098. WFIFOSET(fd,packet_len_table[0x192]);
  1099. return 0;
  1100. }
  1101. /*==========================================
  1102. *
  1103. *------------------------------------------
  1104. */
  1105. static void clif_weather_check(struct map_session_data *sd) {
  1106. int m = sd->bl.m, fd = sd->fd;
  1107. if (map[m].flag.snow
  1108. || map[m].flag.clouds
  1109. || map[m].flag.fog
  1110. || map[m].flag.fireworks
  1111. || map[m].flag.sakura
  1112. || map[m].flag.leaves
  1113. || map[m].flag.rain
  1114. || map[m].flag.clouds2)
  1115. {
  1116. WFIFOHEAD(fd, packet_len_table[0x7c]);
  1117. WFIFOW(fd,0)=0x7c;
  1118. WFIFOL(fd,2)=-10;
  1119. WFIFOW(fd,6)=0;
  1120. WFIFOW(fd,8)=0;
  1121. WFIFOW(fd,10)=0;
  1122. WFIFOW(fd,12)=OPTION_INVISIBLE;
  1123. WFIFOW(fd,20)=100;
  1124. WFIFOPOS(fd,36,sd->bl.x,sd->bl.y);
  1125. WFIFOSET(fd,packet_len_table[0x7c]);
  1126. if (map[m].flag.snow)
  1127. clif_weather_sub(fd, 162);
  1128. if (map[m].flag.clouds)
  1129. clif_weather_sub(fd, 233);
  1130. if (map[m].flag.clouds2)
  1131. clif_weather_sub(fd, 516);
  1132. if (map[m].flag.fog)
  1133. clif_weather_sub(fd, 515);
  1134. if (map[m].flag.fireworks) {
  1135. clif_weather_sub(fd, 297);
  1136. clif_weather_sub(fd, 299);
  1137. clif_weather_sub(fd, 301);
  1138. }
  1139. if (map[m].flag.sakura)
  1140. clif_weather_sub(fd, 163);
  1141. if (map[m].flag.leaves)
  1142. clif_weather_sub(fd, 333);
  1143. if (map[m].flag.rain)
  1144. clif_weather_sub(fd, 161);
  1145. }
  1146. }
  1147. // new and improved weather display [Valaris]
  1148. int clif_weather_sub(int fd, int type) {
  1149. WFIFOHEAD(fd, packet_len_table[0x1f3]);
  1150. WFIFOW(fd,0) = 0x1f3;
  1151. WFIFOL(fd,2) = -10;
  1152. WFIFOL(fd,6) = type;
  1153. WFIFOSET(fd,packet_len_table[0x1f3]);
  1154. return 0;
  1155. }
  1156. int clif_weather(int m) {
  1157. int i;
  1158. struct map_session_data *sd=NULL;
  1159. for(i = 0; i < fd_max; i++) {
  1160. if (session[i] && (sd = session[i]->session_data) != NULL && sd->state.auth && sd->bl.m == m) {
  1161. WFIFOHEAD(sd->fd, packet_len_table[0x80]);
  1162. WFIFOW(sd->fd,0) = 0x80;
  1163. WFIFOL(sd->fd,2) = -10;
  1164. WFIFOB(sd->fd,6) = 0;
  1165. WFIFOSET(sd->fd,packet_len_table[0x80]);
  1166. clif_weather_check(sd);
  1167. }
  1168. }
  1169. return 0;
  1170. }
  1171. int clif_spawn(struct block_list *bl)
  1172. {
  1173. unsigned char buf[128];
  1174. struct view_data *vd;
  1175. nullpo_retr(0, bl);
  1176. vd = status_get_viewdata(bl);
  1177. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1178. return 0;
  1179. if (pcdb_checkid(vd->class_))
  1180. { //Player spawn packet.
  1181. clif_set0078(bl, vd, buf);
  1182. #if PACKETVER > 3
  1183. if (WBUFW(buf,0)==0x78) {
  1184. WBUFW(buf, 0) = 0x79;
  1185. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1186. clif_send(buf, packet_len_table[0x79], bl, AREA_WOS);
  1187. if (disguised(bl))
  1188. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x79], 0);
  1189. } else {
  1190. #endif
  1191. WBUFW(buf, 0) = 0x1d9;
  1192. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1193. clif_send(buf, packet_len_table[0x1d9], bl, AREA_WOS);
  1194. if (disguised(bl))
  1195. clif_setdisguise((TBL_PC*)bl, buf, packet_len_table[0x1d9], 0);
  1196. #if PACKETVER > 3
  1197. }
  1198. #endif
  1199. } else { //Mob spawn packet.
  1200. struct status_change *sc = status_get_sc(bl);
  1201. WBUFW(buf,0)=0x7c;
  1202. WBUFL(buf,2)=bl->id;
  1203. WBUFW(buf,6)=status_get_speed(bl);
  1204. WBUFW(buf,8)=sc?sc->opt1:0;
  1205. WBUFW(buf,10)=sc?sc->opt2:0;
  1206. WBUFW(buf,12)=sc?sc->option:0;
  1207. WBUFW(buf,20)=vd->class_;
  1208. WBUFPOS(buf,36,bl->x,bl->y);
  1209. clif_send(buf,packet_len_table[0x7c],bl,AREA_WOS);
  1210. if (disguised(bl)) {
  1211. WBUFL(buf,2)=-bl->id;
  1212. clif_send(buf,packet_len_table[0x7c],bl,SELF);
  1213. }
  1214. }
  1215. if (vd->cloth_color)
  1216. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1217. switch (bl->type)
  1218. {
  1219. case BL_PC:
  1220. {
  1221. TBL_PC *sd = ((TBL_PC*)bl);
  1222. if (sd->spiritball > 0)
  1223. clif_spiritball(sd);
  1224. if(sd->state.size==2) // tiny/big players [Valaris]
  1225. clif_specialeffect(bl,423,0);
  1226. else if(sd->state.size==1)
  1227. clif_specialeffect(bl,421,0);
  1228. }
  1229. break;
  1230. case BL_MOB:
  1231. {
  1232. TBL_MOB *md = ((TBL_MOB*)bl);
  1233. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1234. clif_specialeffect(&md->bl,423,0);
  1235. else if(md->special_state.size==1)
  1236. clif_specialeffect(&md->bl,421,0);
  1237. }
  1238. break;
  1239. }
  1240. return 0;
  1241. }
  1242. /*==========================================
  1243. *
  1244. *------------------------------------------
  1245. */
  1246. int clif_servertick(struct map_session_data *sd)
  1247. {
  1248. int fd;
  1249. nullpo_retr(0, sd);
  1250. fd=sd->fd;
  1251. WFIFOHEAD(fd, packet_len_table[0x7f]);
  1252. WFIFOW(fd,0)=0x7f;
  1253. WFIFOL(fd,2)=sd->server_tick;
  1254. WFIFOSET(fd,packet_len_table[0x7f]);
  1255. return 0;
  1256. }
  1257. /*==========================================
  1258. *
  1259. *------------------------------------------
  1260. */
  1261. int clif_walkok(struct map_session_data *sd)
  1262. {
  1263. int fd;
  1264. nullpo_retr(0, sd);
  1265. fd=sd->fd;
  1266. WFIFOHEAD(fd, packet_len_table[0x87]);
  1267. WFIFOW(fd,0)=0x87;
  1268. WFIFOL(fd,2)=gettick();
  1269. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1270. WFIFOB(fd,11)=0x88;
  1271. WFIFOSET(fd,packet_len_table[0x87]);
  1272. return 0;
  1273. }
  1274. /*==========================================
  1275. *
  1276. *------------------------------------------
  1277. */
  1278. int clif_movepc(struct map_session_data *sd) {
  1279. unsigned char buf[256];
  1280. nullpo_retr(0, sd);
  1281. if (map[sd->bl.m].flag.snow
  1282. || map[sd->bl.m].flag.clouds
  1283. || map[sd->bl.m].flag.fog
  1284. || map[sd->bl.m].flag.fireworks
  1285. || map[sd->bl.m].flag.sakura
  1286. || map[sd->bl.m].flag.leaves
  1287. || map[sd->bl.m].flag.rain
  1288. || map[sd->bl.m].flag.clouds2
  1289. ) {
  1290. memset(buf,0,packet_len_table[0x7b]);
  1291. WBUFW(buf,0)=0x7b;
  1292. WBUFL(buf,2)=-10;
  1293. WBUFW(buf,6)=sd->speed;
  1294. WBUFW(buf,8)=0;
  1295. WBUFW(buf,10)=0;
  1296. WBUFW(buf,12)=OPTION_INVISIBLE;
  1297. WBUFW(buf,14)=100;
  1298. WBUFL(buf,22)=gettick();
  1299. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y);
  1300. WBUFB(buf,56)=5;
  1301. WBUFB(buf,57)=5;
  1302. clif_send(buf, packet_len_table[0x7b], &sd->bl, SELF);
  1303. }
  1304. return 0;
  1305. }
  1306. /*==========================================
  1307. *
  1308. *------------------------------------------
  1309. */
  1310. int clif_move(struct block_list *bl) {
  1311. struct view_data *vd;
  1312. struct unit_data *ud;
  1313. unsigned char buf[256];
  1314. int len;
  1315. nullpo_retr(0, bl);
  1316. vd = status_get_viewdata(bl);
  1317. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1318. return 0;
  1319. ud = unit_bl2ud(bl);
  1320. nullpo_retr(0, ud);
  1321. len = clif_set007b(bl,vd,ud,buf);
  1322. clif_send(buf,len,bl,AREA_WOS);
  1323. if (disguised(bl))
  1324. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1325. //Stupid client that needs this resent every time someone walks :X
  1326. if(vd->cloth_color)
  1327. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1328. switch(bl->type)
  1329. {
  1330. case BL_PC:
  1331. {
  1332. TBL_PC *sd = ((TBL_PC*)bl);
  1333. clif_movepc(sd);
  1334. if(sd->state.size==2) // tiny/big players [Valaris]
  1335. clif_specialeffect(&sd->bl,423,0);
  1336. else if(sd->state.size==1)
  1337. clif_specialeffect(&sd->bl,421,0);
  1338. }
  1339. break;
  1340. case BL_MOB:
  1341. {
  1342. TBL_MOB *md = ((TBL_MOB*)bl);
  1343. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1344. clif_specialeffect(&md->bl,423,0);
  1345. else if(md->special_state.size==1)
  1346. clif_specialeffect(&md->bl,421,0);
  1347. }
  1348. break;
  1349. }
  1350. return 0;
  1351. }
  1352. /*==========================================
  1353. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1354. *------------------------------------------
  1355. */
  1356. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1357. struct map_session_data *sd = NULL;
  1358. if (chrif_isconnect())
  1359. { //Remove player from map server
  1360. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1361. map_quit(sd);
  1362. } else //Save later.
  1363. add_timer(tick + 10000, clif_delayquit, id, 0);
  1364. return 0;
  1365. }
  1366. /*==========================================
  1367. *
  1368. *------------------------------------------
  1369. */
  1370. void clif_quitsave(int fd,struct map_session_data *sd)
  1371. {
  1372. if (chrif_isconnect() && (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1373. !battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout))
  1374. map_quit(sd);
  1375. else if (sd->fd)
  1376. { //Disassociate session from player (session is deleted after this function was called)
  1377. //And set a timer to delete this player later.
  1378. session[fd]->session_data = NULL;
  1379. sd->fd = 0;
  1380. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1381. }
  1382. }
  1383. /*==========================================
  1384. *
  1385. *------------------------------------------
  1386. */
  1387. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1388. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1389. session[id]->eof = 1;
  1390. return 0;
  1391. }
  1392. /*==========================================
  1393. *
  1394. *------------------------------------------
  1395. */
  1396. void clif_setwaitclose(int fd) {
  1397. struct map_session_data *sd;
  1398. // if player is not already in the game (double connection probably)
  1399. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1400. // limited timer, just to send information.
  1401. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1402. } else
  1403. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1404. }
  1405. /*==========================================
  1406. *
  1407. *------------------------------------------
  1408. */
  1409. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1410. int fd;
  1411. nullpo_retr(0, sd);
  1412. fd = sd->fd;
  1413. WFIFOHEAD(fd, packet_len_table[0x91]);
  1414. WFIFOW(fd,0) = 0x91;
  1415. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1416. WFIFOW(fd,18) = x;
  1417. WFIFOW(fd,20) = y;
  1418. WFIFOSET(fd, packet_len_table[0x91]);
  1419. if(pc_isdead(sd)) // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  1420. clif_clearchar_area(&sd->bl,1);
  1421. return 0;
  1422. }
  1423. /*==========================================
  1424. *
  1425. *------------------------------------------
  1426. */
  1427. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1428. int fd;
  1429. nullpo_retr(0, sd);
  1430. fd = sd->fd;
  1431. WFIFOHEAD(fd, packet_len_table[0x92]);
  1432. WFIFOW(fd,0) = 0x92;
  1433. //Better not trust the null-terminator is there. [Skotlex]
  1434. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1435. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1436. WFIFOW(fd,18) = x;
  1437. WFIFOW(fd,20) = y;
  1438. WFIFOL(fd,22) = ip;
  1439. WFIFOW(fd,26) = port;
  1440. WFIFOSET(fd, packet_len_table[0x92]);
  1441. return 0;
  1442. }
  1443. int clif_blown(struct block_list *bl) {
  1444. //Previous Aegis versions simply used clif_fixpos, but it seems clif_slide works better on current clients.
  1445. // return clif_fixpos(bl);
  1446. return clif_slide(bl, bl->x, bl->y);
  1447. }
  1448. /*==========================================
  1449. *
  1450. *------------------------------------------
  1451. */
  1452. int clif_fixpos(struct block_list *bl) {
  1453. unsigned char buf[16];
  1454. nullpo_retr(0, bl);
  1455. WBUFW(buf,0)=0x88;
  1456. WBUFL(buf,2)=bl->id;
  1457. WBUFW(buf,6)=bl->x;
  1458. WBUFW(buf,8)=bl->y;
  1459. clif_send(buf, packet_len_table[0x88], bl, AREA);
  1460. if (disguised(bl)) {
  1461. WBUFL(buf,2)=-bl->id;
  1462. clif_send(buf, packet_len_table[0x88], bl, SELF);
  1463. }
  1464. return 0;
  1465. }
  1466. /*==========================================
  1467. *
  1468. *------------------------------------------
  1469. */
  1470. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1471. int fd;
  1472. nullpo_retr(0, sd);
  1473. fd=sd->fd;
  1474. WFIFOHEAD(fd, packet_len_table[0xc4]);
  1475. WFIFOW(fd,0)=0xc4;
  1476. WFIFOL(fd,2)=id;
  1477. WFIFOSET(fd,packet_len_table[0xc4]);
  1478. return 0;
  1479. }
  1480. /*==========================================
  1481. *
  1482. *------------------------------------------
  1483. */
  1484. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1485. struct item_data *id;
  1486. int fd,i,val;
  1487. nullpo_retr(0, sd);
  1488. nullpo_retr(0, nd);
  1489. fd=sd->fd;
  1490. WFIFOHEAD(fd, 200 * 11 + 4);
  1491. WFIFOW(fd,0)=0xc6;
  1492. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1493. id = itemdb_search(nd->u.shop_item[i].nameid);
  1494. val=nd->u.shop_item[i].value;
  1495. WFIFOL(fd,4+i*11)=val;
  1496. if (!id->flag.value_notdc)
  1497. val=pc_modifybuyvalue(sd,val);
  1498. WFIFOL(fd,8+i*11)=val;
  1499. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1500. if (id->view_id > 0)
  1501. WFIFOW(fd,13+i*11)=id->view_id;
  1502. else
  1503. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1504. }
  1505. WFIFOW(fd,2)=i*11+4;
  1506. WFIFOSET(fd,WFIFOW(fd,2));
  1507. return 0;
  1508. }
  1509. /*==========================================
  1510. *
  1511. *------------------------------------------
  1512. */
  1513. int clif_selllist(struct map_session_data *sd) {
  1514. int fd,i,c=0,val;
  1515. nullpo_retr(0, sd);
  1516. fd=sd->fd;
  1517. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1518. WFIFOW(fd,0)=0xc7;
  1519. for(i=0;i<MAX_INVENTORY;i++) {
  1520. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1521. if (!itemdb_cansell(sd->status.inventory[i].nameid, pc_isGM(sd)))
  1522. continue;
  1523. val=sd->inventory_data[i]->value_sell;
  1524. if (val < 0)
  1525. continue;
  1526. WFIFOW(fd,4+c*10)=i+2;
  1527. WFIFOL(fd,6+c*10)=val;
  1528. if (!sd->inventory_data[i]->flag.value_notoc)
  1529. val=pc_modifysellvalue(sd,val);
  1530. WFIFOL(fd,10+c*10)=val;
  1531. c++;
  1532. }
  1533. }
  1534. WFIFOW(fd,2)=c*10+4;
  1535. WFIFOSET(fd,WFIFOW(fd,2));
  1536. return 0;
  1537. }
  1538. /*==========================================
  1539. *
  1540. *------------------------------------------
  1541. */
  1542. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  1543. int fd;
  1544. int slen = strlen(mes) + 9;
  1545. WFIFOHEAD(fd, slen);
  1546. nullpo_retr(0, sd);
  1547. fd=sd->fd;
  1548. WFIFOW(fd,0)=0xb4;
  1549. WFIFOW(fd,2)=slen;
  1550. WFIFOL(fd,4)=npcid;
  1551. strcpy((char*)WFIFOP(fd,8),mes);
  1552. WFIFOSET(fd,WFIFOW(fd,2));
  1553. return 0;
  1554. }
  1555. /*==========================================
  1556. *
  1557. *------------------------------------------
  1558. */
  1559. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  1560. int fd;
  1561. nullpo_retr(0, sd);
  1562. fd=sd->fd;
  1563. WFIFOHEAD(fd, packet_len_table[0xb5]);
  1564. WFIFOW(fd,0)=0xb5;
  1565. WFIFOL(fd,2)=npcid;
  1566. WFIFOSET(fd,packet_len_table[0xb5]);
  1567. return 0;
  1568. }
  1569. /*==========================================
  1570. *
  1571. *------------------------------------------
  1572. */
  1573. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  1574. int fd;
  1575. nullpo_retr(0, sd);
  1576. fd=sd->fd;
  1577. WFIFOHEAD(fd, packet_len_table[0xb6]);
  1578. WFIFOW(fd,0)=0xb6;
  1579. WFIFOL(fd,2)=npcid;
  1580. WFIFOSET(fd,packet_len_table[0xb6]);
  1581. return 0;
  1582. }
  1583. /*==========================================
  1584. *
  1585. *------------------------------------------
  1586. */
  1587. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1588. int fd = sd->fd;
  1589. sd->npc_id = npcid;
  1590. sd->state.using_fake_npc = 1;
  1591. memset(WFIFOP(fd,0), 0, packet_len_table[0x78]);
  1592. WFIFOW(fd,0)=0x78;
  1593. WFIFOL(fd,2)=npcid;
  1594. WFIFOW(fd,14)=111;
  1595. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y);
  1596. WFIFOB(fd,49)=5;
  1597. WFIFOB(fd,50)=5;
  1598. WFIFOSET(fd, packet_len_table[0x78]);
  1599. return;
  1600. }
  1601. /*==========================================
  1602. *
  1603. *------------------------------------------
  1604. */
  1605. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  1606. int fd;
  1607. int slen = strlen(mes) + 8;
  1608. struct block_list *bl = map_id2bl(npcid);
  1609. WFIFOHEAD(fd, slen);
  1610. nullpo_retr(0, sd);
  1611. if (bl->type == BL_PC || bl->m!=sd->bl.m ||
  1612. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1613. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1)
  1614. clif_sendfakenpc(sd, npcid);
  1615. fd=sd->fd;
  1616. WFIFOW(fd,0)=0xb7;
  1617. WFIFOW(fd,2)=slen;
  1618. WFIFOL(fd,4)=npcid;
  1619. strcpy((char*)WFIFOP(fd,8),mes);
  1620. WFIFOSET(fd,WFIFOW(fd,2));
  1621. return 0;
  1622. }
  1623. /*==========================================
  1624. *
  1625. *------------------------------------------
  1626. */
  1627. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  1628. int fd;
  1629. struct block_list *bl = map_id2bl(npcid);
  1630. nullpo_retr(0, sd);
  1631. if (bl->type == BL_PC || bl->m!=sd->bl.m ||
  1632. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1633. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1)
  1634. clif_sendfakenpc(sd, npcid);
  1635. fd=sd->fd;
  1636. WFIFOHEAD(fd, packet_len_table[0x142]);
  1637. WFIFOW(fd,0)=0x142;
  1638. WFIFOL(fd,2)=npcid;
  1639. WFIFOSET(fd,packet_len_table[0x142]);
  1640. return 0;
  1641. }
  1642. /*==========================================
  1643. *
  1644. *------------------------------------------
  1645. */
  1646. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1647. int fd;
  1648. struct block_list *bl = map_id2bl(npcid);
  1649. nullpo_retr(0, sd);
  1650. if (bl->type == BL_PC || bl->m!=sd->bl.m ||
  1651. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1652. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1)
  1653. clif_sendfakenpc(sd, npcid);
  1654. fd=sd->fd;
  1655. WFIFOHEAD(fd, packet_len_table[0x1d4]);
  1656. WFIFOW(fd,0)=0x1d4;
  1657. WFIFOL(fd,2)=npcid;
  1658. WFIFOSET(fd,packet_len_table[0x1d4]);
  1659. return 0;
  1660. }
  1661. /*==========================================
  1662. *
  1663. *------------------------------------------
  1664. */
  1665. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  1666. int fd;
  1667. nullpo_retr(0, sd);
  1668. fd=sd->fd;
  1669. WFIFOHEAD(fd, packet_len_table[0x144]);
  1670. WFIFOW(fd,0)=0x144;
  1671. WFIFOL(fd,2)=npc_id;
  1672. WFIFOL(fd,6)=type;
  1673. WFIFOL(fd,10)=x;
  1674. WFIFOL(fd,14)=y;
  1675. WFIFOB(fd,18)=id;
  1676. WFIFOL(fd,19)=color;
  1677. WFIFOSET(fd,packet_len_table[0x144]);
  1678. return 0;
  1679. }
  1680. /*==========================================
  1681. *
  1682. *------------------------------------------
  1683. */
  1684. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  1685. int fd;
  1686. nullpo_retr(0, sd);
  1687. fd=sd->fd;
  1688. WFIFOHEAD(fd, packet_len_table[0x1b3]);
  1689. WFIFOW(fd,0)=0x1b3;
  1690. strncpy((char*)WFIFOP(fd,2),image,64);
  1691. WFIFOB(fd,66)=type;
  1692. WFIFOSET(fd,packet_len_table[0x1b3]);
  1693. return 0;
  1694. }
  1695. /*==========================================
  1696. * Fills in card data from the given item and into the buffer. [Skotlex]
  1697. *------------------------------------------
  1698. */
  1699. static void clif_addcards(unsigned char* buf, struct item* item)
  1700. {
  1701. int i=0,j;
  1702. if (item == NULL) { //Blank data
  1703. WBUFW(buf,0)=0;
  1704. WBUFW(buf,2)=0;
  1705. WBUFW(buf,4)=0;
  1706. WBUFW(buf,6)=0;
  1707. return;
  1708. }
  1709. if(item->card[0]==(short)0xff00) { //pet eggs
  1710. WBUFW(buf,0)=0;
  1711. WBUFW(buf,2)=0;
  1712. WBUFW(buf,4)=0;
  1713. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1714. return;
  1715. }
  1716. if(item->card[0]==0x00ff || item->card[0]==0x00fe) { //Forged/created items
  1717. WBUFW(buf,0)=item->card[0];
  1718. WBUFW(buf,2)=item->card[1];
  1719. WBUFW(buf,4)=item->card[2];
  1720. WBUFW(buf,6)=item->card[3];
  1721. return;
  1722. }
  1723. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1724. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1725. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1726. //Normal items.
  1727. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1728. WBUFW(buf,0)=j;
  1729. else
  1730. WBUFW(buf,0)= item->card[i];
  1731. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1732. WBUFW(buf,2)=j;
  1733. else
  1734. WBUFW(buf,2)=item->card[i];
  1735. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1736. WBUFW(buf,4)=j;
  1737. else
  1738. WBUFW(buf,4)=item->card[i];
  1739. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1740. WBUFW(buf,6)=j;
  1741. else
  1742. WBUFW(buf,6)=item->card[i];
  1743. }
  1744. /*==========================================
  1745. *
  1746. *------------------------------------------
  1747. */
  1748. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  1749. int fd;
  1750. unsigned char *buf;
  1751. nullpo_retr(0, sd);
  1752. fd = sd->fd;
  1753. if (!session_isActive(fd)) //Sasuke-
  1754. return 0;
  1755. WFIFOHEAD(fd,packet_len_table[0xa0]);
  1756. buf = WFIFOP(fd,0);
  1757. if(fail) {
  1758. WBUFW(buf,0)=0xa0;
  1759. WBUFW(buf,2)=n+2;
  1760. WBUFW(buf,4)=amount;
  1761. WBUFW(buf,6)=0;
  1762. WBUFB(buf,8)=0;
  1763. WBUFB(buf,9)=0;
  1764. WBUFB(buf,10)=0;
  1765. WBUFW(buf,11)=0;
  1766. WBUFW(buf,13)=0;
  1767. WBUFW(buf,15)=0;
  1768. WBUFW(buf,17)=0;
  1769. WBUFW(buf,19)=0;
  1770. WBUFB(buf,21)=0;
  1771. WBUFB(buf,22)=fail;
  1772. } else {
  1773. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1774. return 1;
  1775. WBUFW(buf,0)=0xa0;
  1776. WBUFW(buf,2)=n+2;
  1777. WBUFW(buf,4)=amount;
  1778. if (sd->inventory_data[n]->view_id > 0)
  1779. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  1780. else
  1781. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  1782. WBUFB(buf,8)=sd->status.inventory[n].identify;
  1783. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  1784. WBUFB(buf,10)=sd->status.inventory[n].refine;
  1785. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  1786. WBUFW(buf,19)=pc_equippoint(sd,n);
  1787. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  1788. WBUFB(buf,22)=fail;
  1789. }
  1790. WFIFOSET(fd,packet_len_table[0xa0]);
  1791. return 0;
  1792. }
  1793. /*==========================================
  1794. *
  1795. *------------------------------------------
  1796. */
  1797. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1798. {
  1799. int fd;
  1800. nullpo_retr(0, sd);
  1801. fd=sd->fd;
  1802. WFIFOHEAD(fd, packet_len_table[0xaf]);
  1803. WFIFOW(fd,0)=0xaf;
  1804. WFIFOW(fd,2)=n+2;
  1805. WFIFOW(fd,4)=amount;
  1806. WFIFOSET(fd,packet_len_table[0xaf]);
  1807. return 0;
  1808. }
  1809. /*==========================================
  1810. *
  1811. *------------------------------------------
  1812. */
  1813. int clif_itemlist(struct map_session_data *sd)
  1814. {
  1815. int i,n,fd,arrow=-1;
  1816. unsigned char *buf;
  1817. nullpo_retr(0, sd);
  1818. fd=sd->fd;
  1819. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1820. buf = WFIFOP(fd,0);
  1821. #if PACKETVER < 5
  1822. WBUFW(buf,0)=0xa3;
  1823. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1824. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  1825. continue;
  1826. WBUFW(buf,n*10+4)=i+2;
  1827. if (sd->inventory_data[i]->view_id > 0)
  1828. WBUFW(buf,n*10+6)=sd->inventory_data[i]->view_id;
  1829. else
  1830. WBUFW(buf,n*10+6)=sd->status.inventory[i].nameid;
  1831. WBUFB(buf,n*10+8)=itemtype(sd->inventory_data[i]->type);
  1832. WBUFB(buf,n*10+9)=sd->status.inventory[i].identify;
  1833. WBUFW(buf,n*10+10)=sd->status.inventory[i].amount;
  1834. if (sd->inventory_data[i]->equip == 0x8000) {
  1835. WBUFW(buf,n*10+12)=0x8000;
  1836. if (sd->status.inventory[i].equip)
  1837. arrow=i; // ついでに矢装備チェック
  1838. } else
  1839. WBUFW(buf,n*10+12)=0;
  1840. n++;
  1841. }
  1842. if (n) {
  1843. WBUFW(buf,2)=4+n*10;
  1844. WFIFOSET(fd,WFIFOW(fd,2));
  1845. }
  1846. #else
  1847. WBUFW(buf,0)=0x1ee;
  1848. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1849. if(sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  1850. continue;
  1851. WBUFW(buf,n*18+4)=i+2;
  1852. if(sd->inventory_data[i]->view_id > 0)
  1853. WBUFW(buf,n*18+6)=sd->inventory_data[i]->view_id;
  1854. else
  1855. WBUFW(buf,n*18+6)=sd->status.inventory[i].nameid;
  1856. WBUFB(buf,n*18+8)=itemtype(sd->inventory_data[i]->type);
  1857. WBUFB(buf,n*18+9)=sd->status.inventory[i].identify;
  1858. WBUFW(buf,n*18+10)=sd->status.inventory[i].amount;
  1859. if (sd->inventory_data[i]->equip == 0x8000) {
  1860. WBUFW(buf,n*18+12)=0x8000;
  1861. if(sd->status.inventory[i].equip)
  1862. arrow=i; // ついでに矢装備チェック
  1863. } else
  1864. WBUFW(buf,n*18+12)=0;
  1865. clif_addcards(WBUFP(buf, n*18+14), &sd->status.inventory[i]);
  1866. n++;
  1867. }
  1868. if (n) {
  1869. WBUFW(buf,2)=4+n*18;
  1870. WFIFOSET(fd,WFIFOW(fd,2));
  1871. }
  1872. #endif
  1873. if(arrow >= 0)
  1874. clif_arrowequip(sd,arrow);
  1875. return 0;
  1876. }
  1877. /*==========================================
  1878. *
  1879. *------------------------------------------
  1880. */
  1881. int clif_equiplist(struct map_session_data *sd)
  1882. {
  1883. int i,n,fd;
  1884. nullpo_retr(0, sd);
  1885. fd=sd->fd;
  1886. if (!session_isActive(fd))
  1887. return 0;
  1888. WFIFOHEAD(fd, 4 + MAX_INVENTORY * 20);
  1889. WFIFOW(fd,0)=0xa4;
  1890. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1891. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL || !itemdb_isequip2(sd->inventory_data[i]))
  1892. continue;
  1893. WFIFOW(fd,n*20+4)=i+2;
  1894. if(sd->inventory_data[i]->view_id > 0)
  1895. WFIFOW(fd,n*20+6)=sd->inventory_data[i]->view_id;
  1896. else
  1897. WFIFOW(fd,n*20+6)=sd->status.inventory[i].nameid;
  1898. WFIFOB(fd,n*20+8)=itemtype(sd->inventory_data[i]->type);
  1899. WFIFOB(fd,n*20+9)=sd->status.inventory[i].identify;
  1900. WFIFOW(fd,n*20+10)=pc_equippoint(sd,i);
  1901. WFIFOW(fd,n*20+12)=sd->status.inventory[i].equip;
  1902. WFIFOB(fd,n*20+14)=sd->status.inventory[i].attribute;
  1903. WFIFOB(fd,n*20+15)=sd->status.inventory[i].refine;
  1904. clif_addcards(WFIFOP(fd, n*20+16), &sd->status.inventory[i]);
  1905. n++;
  1906. }
  1907. if(n){
  1908. WFIFOW(fd,2)=4+n*20;
  1909. WFIFOSET(fd,WFIFOW(fd,2));
  1910. }
  1911. return 0;
  1912. }
  1913. /*==========================================
  1914. * カプラさんに預けてある消耗品&収集品リスト
  1915. *------------------------------------------
  1916. */
  1917. int clif_storageitemlist(struct map_session_data *sd,struct storage *stor)
  1918. {
  1919. struct item_data *id;
  1920. int i,n,fd;
  1921. unsigned char *buf;
  1922. nullpo_retr(0, sd);
  1923. nullpo_retr(0, stor);
  1924. fd=sd->fd;
  1925. WFIFOHEAD(fd,MAX_STORAGE * 18 + 4);
  1926. buf = WFIFOP(fd,0);
  1927. #if PACKETVER < 5
  1928. WBUFW(buf,0)=0xa5;
  1929. for(i=0,n=0;i<MAX_STORAGE;i++){
  1930. if(stor->storage_[i].nameid<=0)
  1931. continue;
  1932. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1933. if(itemdb_isequip2(id))
  1934. continue;
  1935. WBUFW(buf,n*10+4)=i+1;
  1936. if(id->view_id > 0)
  1937. WBUFW(buf,n*10+6)=id->view_id;
  1938. else
  1939. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  1940. WBUFB(buf,n*10+8)=itemtype(id->type);
  1941. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  1942. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  1943. WBUFW(buf,n*10+12)=0;
  1944. n++;
  1945. }
  1946. if(n){
  1947. WBUFW(buf,2)=4+n*10;
  1948. WFIFOSET(fd,WFIFOW(fd,2));
  1949. }
  1950. #else
  1951. WBUFW(buf,0)=0x1f0;
  1952. for(i=0,n=0;i<MAX_STORAGE;i++){
  1953. if(stor->storage_[i].nameid<=0)
  1954. continue;
  1955. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1956. if(itemdb_isequip2(id))
  1957. continue;
  1958. WBUFW(buf,n*18+4)=i+1;
  1959. if(id->view_id > 0)
  1960. WBUFW(buf,n*18+6)=id->view_id;
  1961. else
  1962. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  1963. WBUFB(buf,n*18+8)=itemtype(id->type);
  1964. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  1965. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  1966. WBUFW(buf,n*18+12)=0;
  1967. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  1968. n++;
  1969. }
  1970. if(n){
  1971. WBUFW(buf,2)=4+n*18;
  1972. WFIFOSET(fd,WFIFOW(fd,2));
  1973. }
  1974. #endif
  1975. return 0;
  1976. }
  1977. /*==========================================
  1978. * カプラさんに預けてある装備リスト
  1979. *------------------------------------------
  1980. */
  1981. int clif_storageequiplist(struct map_session_data *sd,struct storage *stor)
  1982. {
  1983. struct item_data *id;
  1984. int i,n,fd;
  1985. unsigned char *buf;
  1986. nullpo_retr(0, sd);
  1987. nullpo_retr(0, stor);
  1988. fd=sd->fd;
  1989. WFIFOHEAD(fd,MAX_STORAGE * 20 + 4);
  1990. buf = WFIFOP(fd,0);
  1991. WBUFW(buf,0)=0xa6;
  1992. for(i=0,n=0;i<MAX_STORAGE;i++){
  1993. if(stor->storage_[i].nameid<=0)
  1994. continue;
  1995. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  1996. if(!itemdb_isequip2(id))
  1997. continue;
  1998. WBUFW(buf,n*20+4)=i+1;
  1999. if(id->view_id > 0)
  2000. WBUFW(buf,n*20+6)=id->view_id;
  2001. else
  2002. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2003. WBUFB(buf,n*20+8)=itemtype(id->type);
  2004. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2005. WBUFW(buf,n*20+10)=id->equip;
  2006. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2007. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2008. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2009. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2010. n++;
  2011. }
  2012. if(n){
  2013. WBUFW(buf,2)=4+n*20;
  2014. WFIFOSET(fd,WFIFOW(fd,2));
  2015. }
  2016. return 0;
  2017. }
  2018. /*==========================================
  2019. *
  2020. *------------------------------------------
  2021. */
  2022. int clif_guildstorageitemlist(struct map_session_data *sd,struct guild_storage *stor)
  2023. {
  2024. struct item_data *id;
  2025. int i,n,fd;
  2026. unsigned char *buf;
  2027. nullpo_retr(0, sd);
  2028. nullpo_retr(0, stor);
  2029. fd=sd->fd;
  2030. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 18 + 4);
  2031. buf=WFIFOP(fd,0);
  2032. #if PACKETVER < 5
  2033. WBUFW(buf,0)=0xa5;
  2034. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2035. if(stor->storage_[i].nameid<=0)
  2036. continue;
  2037. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2038. if(itemdb_isequip2(id))
  2039. continue;
  2040. WBUFW(buf,n*10+4)=i+1;
  2041. if(id->view_id > 0)
  2042. WBUFW(buf,n*10+6)=id->view_id;
  2043. else
  2044. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  2045. WBUFB(buf,n*10+8)=itemtype(id->type);
  2046. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  2047. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  2048. WBUFW(buf,n*10+12)=0;
  2049. n++;
  2050. }
  2051. if(n){
  2052. WBUFW(buf,2)=4+n*10;
  2053. WFIFOSET(fd,WFIFOW(fd,2));
  2054. }
  2055. #else
  2056. WBUFW(buf,0)=0x1f0;
  2057. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2058. if(stor->storage_[i].nameid<=0)
  2059. continue;
  2060. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2061. if(itemdb_isequip2(id))
  2062. continue;
  2063. WBUFW(buf,n*18+4)=i+1;
  2064. if(id->view_id > 0)
  2065. WBUFW(buf,n*18+6)=id->view_id;
  2066. else
  2067. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  2068. WBUFB(buf,n*18+8)=itemtype(id->type);
  2069. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  2070. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  2071. WBUFW(buf,n*18+12)=0;
  2072. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  2073. n++;
  2074. }
  2075. if(n){
  2076. WBUFW(buf,2)=4+n*18;
  2077. WFIFOSET(fd,WFIFOW(fd,2));
  2078. }
  2079. #endif
  2080. return 0;
  2081. }
  2082. /*==========================================
  2083. *
  2084. *------------------------------------------
  2085. */
  2086. int clif_guildstorageequiplist(struct map_session_data *sd,struct guild_storage *stor)
  2087. {
  2088. struct item_data *id;
  2089. int i,n,fd;
  2090. unsigned char *buf;
  2091. nullpo_retr(0, sd);
  2092. fd=sd->fd;
  2093. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 20 + 4);
  2094. buf=WFIFOP(fd,0);
  2095. WBUFW(buf,0)=0xa6;
  2096. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2097. if(stor->storage_[i].nameid<=0)
  2098. continue;
  2099. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2100. if(!itemdb_isequip2(id))
  2101. continue;
  2102. WBUFW(buf,n*20+4)=i+1;
  2103. if(id->view_id > 0)
  2104. WBUFW(buf,n*20+6)=id->view_id;
  2105. else
  2106. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2107. WBUFB(buf,n*20+8)=itemtype(id->type);
  2108. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2109. WBUFW(buf,n*20+10)=id->equip;
  2110. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2111. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2112. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2113. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2114. n++;
  2115. }
  2116. if(n){
  2117. WBUFW(buf,2)=4+n*20;
  2118. WFIFOSET(fd,WFIFOW(fd,2));
  2119. }
  2120. return 0;
  2121. }
  2122. // Guild XY locators [Valaris]
  2123. int clif_guild_xy(struct map_session_data *sd)
  2124. {
  2125. unsigned char buf[10];
  2126. nullpo_retr(0, sd);
  2127. WBUFW(buf,0)=0x1eb;
  2128. WBUFL(buf,2)=sd->status.account_id;
  2129. WBUFW(buf,6)=sd->bl.x;
  2130. WBUFW(buf,8)=sd->bl.y;
  2131. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2132. return 0;
  2133. }
  2134. /*==========================================
  2135. * Sends x/y dot to a single fd. [Skotlex]
  2136. *------------------------------------------
  2137. */
  2138. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2139. {
  2140. WFIFOHEAD(fd,packet_len_table[0x1eb]);
  2141. WFIFOW(fd,0)=0x1eb;
  2142. WFIFOL(fd,2)=sd->status.account_id;
  2143. WFIFOW(fd,6)=sd->bl.x;
  2144. WFIFOW(fd,8)=sd->bl.y;
  2145. WFIFOSET(fd,packet_len_table[0x1eb]);
  2146. return 0;
  2147. }
  2148. // Guild XY locators [Valaris]
  2149. int clif_guild_xy_remove(struct map_session_data *sd)
  2150. {
  2151. unsigned char buf[10];
  2152. nullpo_retr(0, sd);
  2153. WBUFW(buf,0)=0x1eb;
  2154. WBUFL(buf,2)=sd->status.account_id;
  2155. WBUFW(buf,6)=-1;
  2156. WBUFW(buf,8)=-1;
  2157. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2158. return 0;
  2159. }
  2160. /*==========================================
  2161. * ステータスを送りつける
  2162. * 表示専用数字はこの中で計算して送る
  2163. *------------------------------------------
  2164. */
  2165. int clif_updatestatus(struct map_session_data *sd,int type)
  2166. {
  2167. int fd,len=8;
  2168. nullpo_retr(0, sd);
  2169. fd=sd->fd;
  2170. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2171. return 0;
  2172. WFIFOHEAD(fd, 14);
  2173. WFIFOW(fd,0)=0xb0;
  2174. WFIFOW(fd,2)=type;
  2175. switch(type){
  2176. // 00b0
  2177. case SP_WEIGHT:
  2178. pc_checkweighticon(sd);
  2179. WFIFOW(fd,0)=0xb0;
  2180. WFIFOW(fd,2)=type; //Added this packet back, Temp fix to the slow motion [Lupus]
  2181. WFIFOL(fd,4)=sd->weight;
  2182. break;
  2183. case SP_MAXWEIGHT:
  2184. WFIFOL(fd,4)=sd->max_weight;
  2185. break;
  2186. case SP_SPEED:
  2187. WFIFOL(fd,4)=sd->speed;
  2188. break;
  2189. case SP_BASELEVEL:
  2190. WFIFOL(fd,4)=sd->status.base_level;
  2191. break;
  2192. case SP_JOBLEVEL:
  2193. WFIFOL(fd,4)=sd->status.job_level;
  2194. break;
  2195. case SP_MANNER:
  2196. WFIFOL(fd,4)=sd->status.manner;
  2197. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2198. break;
  2199. case SP_STATUSPOINT:
  2200. WFIFOL(fd,4)=sd->status.status_point;
  2201. break;
  2202. case SP_SKILLPOINT:
  2203. WFIFOL(fd,4)=sd->status.skill_point;
  2204. break;
  2205. case SP_HIT:
  2206. WFIFOL(fd,4)=sd->hit;
  2207. break;
  2208. case SP_FLEE1:
  2209. WFIFOL(fd,4)=sd->flee;
  2210. break;
  2211. case SP_FLEE2:
  2212. WFIFOL(fd,4)=sd->flee2/10;
  2213. break;
  2214. case SP_MAXHP:
  2215. WFIFOL(fd,4)=sd->status.max_hp;
  2216. break;
  2217. case SP_MAXSP:
  2218. WFIFOL(fd,4)=sd->status.max_sp;
  2219. break;
  2220. case SP_HP:
  2221. WFIFOL(fd,4)=sd->status.hp;
  2222. if (sd->status.party_id)
  2223. clif_party_hp(sd);
  2224. if (battle_config.disp_hpmeter)
  2225. clif_hpmeter(sd);
  2226. break;
  2227. case SP_SP:
  2228. WFIFOL(fd,4)=sd->status.sp;
  2229. break;
  2230. case SP_ASPD:
  2231. WFIFOL(fd,4)=sd->aspd;
  2232. break;
  2233. case SP_ATK1:
  2234. WFIFOL(fd,4)=sd->base_atk+sd->right_weapon.watk+sd->left_weapon.watk;
  2235. break;
  2236. case SP_DEF1:
  2237. WFIFOL(fd,4)=sd->def;
  2238. break;
  2239. case SP_MDEF1:
  2240. WFIFOL(fd,4)=sd->mdef;
  2241. break;
  2242. case SP_ATK2:
  2243. WFIFOL(fd,4)=sd->right_weapon.watk2 + sd->left_weapon.watk2;
  2244. break;
  2245. case SP_DEF2:
  2246. WFIFOL(fd,4)=sd->def2;
  2247. break;
  2248. case SP_MDEF2:
  2249. WFIFOL(fd,4)=sd->mdef2;
  2250. break;
  2251. case SP_CRITICAL:
  2252. WFIFOL(fd,4)=sd->critical/10;
  2253. break;
  2254. case SP_MATK1:
  2255. WFIFOL(fd,4)=sd->matk1;
  2256. break;
  2257. case SP_MATK2:
  2258. WFIFOL(fd,4)=sd->matk2;
  2259. break;
  2260. case SP_ZENY:
  2261. WFIFOW(fd,0)=0xb1;
  2262. if(sd->status.zeny < 0)
  2263. sd->status.zeny = 0;
  2264. WFIFOL(fd,4)=sd->status.zeny;
  2265. break;
  2266. case SP_BASEEXP:
  2267. WFIFOW(fd,0)=0xb1;
  2268. WFIFOL(fd,4)=sd->status.base_exp;
  2269. break;
  2270. case SP_JOBEXP:
  2271. WFIFOW(fd,0)=0xb1;
  2272. WFIFOL(fd,4)=sd->status.job_exp;
  2273. break;
  2274. case SP_NEXTBASEEXP:
  2275. WFIFOW(fd,0)=0xb1;
  2276. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2277. break;
  2278. case SP_NEXTJOBEXP:
  2279. WFIFOW(fd,0)=0xb1;
  2280. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2281. break;
  2282. // 00be 終了
  2283. case SP_USTR:
  2284. case SP_UAGI:
  2285. case SP_UVIT:
  2286. case SP_UINT:
  2287. case SP_UDEX:
  2288. case SP_ULUK:
  2289. WFIFOW(fd,0)=0xbe;
  2290. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2291. len=5;
  2292. break;
  2293. // 013a 終了
  2294. case SP_ATTACKRANGE:
  2295. WFIFOW(fd,0)=0x13a;
  2296. WFIFOW(fd,2)=sd->attackrange;
  2297. len=4;
  2298. break;
  2299. // 0141 終了
  2300. case SP_STR:
  2301. WFIFOW(fd,0)=0x141;
  2302. WFIFOL(fd,2)=type;
  2303. WFIFOL(fd,6)=sd->status.str;
  2304. WFIFOL(fd,10)=sd->paramb[0] + sd->parame[0];
  2305. len=14;
  2306. break;
  2307. case SP_AGI:
  2308. WFIFOW(fd,0)=0x141;
  2309. WFIFOL(fd,2)=type;
  2310. WFIFOL(fd,6)=sd->status.agi;
  2311. WFIFOL(fd,10)=sd->paramb[1] + sd->parame[1];
  2312. len=14;
  2313. break;
  2314. case SP_VIT:
  2315. WFIFOW(fd,0)=0x141;
  2316. WFIFOL(fd,2)=type;
  2317. WFIFOL(fd,6)=sd->status.vit;
  2318. WFIFOL(fd,10)=sd->paramb[2] + sd->parame[2];
  2319. len=14;
  2320. break;
  2321. case SP_INT:
  2322. WFIFOW(fd,0)=0x141;
  2323. WFIFOL(fd,2)=type;
  2324. WFIFOL(fd,6)=sd->status.int_;
  2325. WFIFOL(fd,10)=sd->paramb[3] + sd->parame[3];
  2326. len=14;
  2327. break;
  2328. case SP_DEX:
  2329. WFIFOW(fd,0)=0x141;
  2330. WFIFOL(fd,2)=type;
  2331. WFIFOL(fd,6)=sd->status.dex;
  2332. WFIFOL(fd,10)=sd->paramb[4] + sd->parame[4];
  2333. len=14;
  2334. break;
  2335. case SP_LUK:
  2336. WFIFOW(fd,0)=0x141;
  2337. WFIFOL(fd,2)=type;
  2338. WFIFOL(fd,6)=sd->status.luk;
  2339. WFIFOL(fd,10)=sd->paramb[5] + sd->parame[5];
  2340. len=14;
  2341. break;
  2342. case SP_CARTINFO:
  2343. WFIFOW(fd,0)=0x121;
  2344. WFIFOW(fd,2)=sd->cart_num;
  2345. WFIFOW(fd,4)=sd->cart_max_num;
  2346. WFIFOL(fd,6)=sd->cart_weight;
  2347. WFIFOL(fd,10)=sd->cart_max_weight;
  2348. len=14;
  2349. break;
  2350. default:
  2351. if(battle_config.error_log)
  2352. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2353. return 1;
  2354. }
  2355. WFIFOSET(fd,len);
  2356. return 0;
  2357. }
  2358. int clif_changestatus(struct block_list *bl,int type,int val)
  2359. {
  2360. unsigned char buf[12];
  2361. struct map_session_data *sd = NULL;
  2362. nullpo_retr(0, bl);
  2363. if(bl->type == BL_PC)
  2364. sd = (struct map_session_data *)bl;
  2365. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2366. if(sd){
  2367. WBUFW(buf,0)=0x1ab;
  2368. WBUFL(buf,2)=bl->id;
  2369. WBUFW(buf,6)=type;
  2370. switch(type){
  2371. case SP_MANNER:
  2372. WBUFL(buf,8)=val;
  2373. break;
  2374. default:
  2375. if(battle_config.error_log)
  2376. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2377. return 1;
  2378. }
  2379. clif_send(buf,packet_len_table[0x1ab],bl,AREA_WOS);
  2380. }
  2381. return 0;
  2382. }
  2383. /*==========================================
  2384. *
  2385. *------------------------------------------
  2386. */
  2387. int clif_changelook(struct block_list *bl,int type,int val)
  2388. {
  2389. unsigned char buf[32];
  2390. struct map_session_data *sd = NULL;
  2391. struct view_data *vd;
  2392. vd = status_get_viewdata(bl);
  2393. nullpo_retr(0, vd);
  2394. if(bl->type == BL_PC)
  2395. sd = (struct map_session_data *)bl;
  2396. switch(type) {
  2397. case LOOK_WEAPON:
  2398. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2399. else vd->weapon = val;
  2400. break;
  2401. case LOOK_SHIELD:
  2402. if (sd) clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2403. else vd->shield = val;
  2404. break;
  2405. case LOOK_BASE:
  2406. vd->class_ = val;
  2407. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2408. vd->weapon = vd->shield = 0;
  2409. if (
  2410. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2411. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2412. )
  2413. vd->cloth_color = 0;
  2414. break;
  2415. case LOOK_HAIR:
  2416. vd->hair_style = val;
  2417. break;
  2418. case LOOK_HEAD_BOTTOM:
  2419. vd->head_bottom = val;
  2420. break;
  2421. case LOOK_HEAD_TOP:
  2422. vd->head_top = val;
  2423. break;
  2424. case LOOK_HEAD_MID:
  2425. vd->head_mid = val;
  2426. break;
  2427. case LOOK_HAIR_COLOR:
  2428. vd->hair_color = val;
  2429. break;
  2430. case LOOK_CLOTHES_COLOR:
  2431. if (
  2432. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2433. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2434. )
  2435. val = 0;
  2436. vd->cloth_color = val;
  2437. break;
  2438. case LOOK_SHOES:
  2439. #if PACKETVER > 3
  2440. if (sd) {
  2441. int n;
  2442. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2443. if(sd->inventory_data[n]->view_id > 0)
  2444. val = sd->inventory_data[n]->view_id;
  2445. else
  2446. val = sd->status.inventory[n].nameid;
  2447. }
  2448. val = 0;
  2449. }
  2450. #endif
  2451. //Shoes? No packet uses this....
  2452. break;
  2453. }
  2454. #if PACKETVER < 4
  2455. WBUFW(buf,0)=0xc3;
  2456. WBUFL(buf,2)=bl->id;
  2457. WBUFB(buf,6)=type;
  2458. WBUFB(buf,7)=val;
  2459. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2460. #else
  2461. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2462. WBUFW(buf,0)=0x1d7;
  2463. WBUFL(buf,2)=bl->id;
  2464. WBUFB(buf,6)=LOOK_WEAPON;
  2465. WBUFW(buf,7)=vd->weapon;
  2466. WBUFW(buf,9)=vd->shield;
  2467. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2468. }
  2469. else if(type == LOOK_BASE && val > 255)
  2470. {
  2471. WBUFW(buf,0)=0x1d7;
  2472. WBUFL(buf,2)=bl->id;
  2473. WBUFB(buf,6)=type;
  2474. WBUFW(buf,7)=val;
  2475. WBUFW(buf,9)=0;
  2476. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2477. } else {
  2478. WBUFW(buf,0)=0xc3;
  2479. WBUFL(buf,2)=bl->id;
  2480. WBUFB(buf,6)=type;
  2481. WBUFB(buf,7)=val;
  2482. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2483. }
  2484. #endif
  2485. return 0;
  2486. }
  2487. //Sends a change-base-look packet required for traps as they are triggered.
  2488. void clif_changetraplook(struct block_list *bl,int val)
  2489. {
  2490. unsigned char buf[32];
  2491. #if PACKETVER < 4
  2492. WBUFW(buf,0)=0xc3;
  2493. WBUFL(buf,2)=bl->id;
  2494. WBUFB(buf,6)=LOOK_BASE;
  2495. WBUFB(buf,7)=val;
  2496. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2497. #else
  2498. if (val > 255)
  2499. {
  2500. WBUFW(buf,0)=0x1d7;
  2501. WBUFL(buf,2)=bl->id;
  2502. WBUFB(buf,6)=LOOK_BASE;
  2503. WBUFW(buf,7)=val;
  2504. WBUFW(buf,9)=0;
  2505. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2506. } else {
  2507. WBUFW(buf,0)=0xc3;
  2508. WBUFL(buf,2)=bl->id;
  2509. WBUFB(buf,6)=LOOK_BASE;
  2510. WBUFB(buf,7)=val;
  2511. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2512. }
  2513. #endif
  2514. }
  2515. //For the stupid cloth-dye bug. Resends the given view data
  2516. //to the area specified by bl.
  2517. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2518. {
  2519. unsigned char buf[32];
  2520. #if PACKETVER < 4
  2521. WBUFW(buf,0)=0xc3;
  2522. WBUFL(buf,2)=id;
  2523. WBUFB(buf,6)=type;
  2524. WBUFB(buf,7)=val;
  2525. clif_send(buf,packet_len_table[0xc3],bl,area);
  2526. #else
  2527. if(type == LOOK_BASE && val > 255)
  2528. {
  2529. WBUFW(buf,0)=0x1d7;
  2530. WBUFL(buf,2)=id;
  2531. WBUFB(buf,6)=type;
  2532. WBUFW(buf,7)=val;
  2533. WBUFW(buf,9)=0;
  2534. clif_send(buf,packet_len_table[0x1d7],bl,area);
  2535. } else {
  2536. WBUFW(buf,0)=0xc3;
  2537. WBUFL(buf,2)=id;
  2538. WBUFB(buf,6)=type;
  2539. WBUFB(buf,7)=val;
  2540. clif_send(buf,packet_len_table[0xc3],bl,area);
  2541. }
  2542. #endif
  2543. return;
  2544. }
  2545. /*==========================================
  2546. *
  2547. *------------------------------------------
  2548. */
  2549. int clif_initialstatus(struct map_session_data *sd)
  2550. {
  2551. int fd;
  2552. unsigned char *buf;
  2553. nullpo_retr(0, sd);
  2554. fd=sd->fd;
  2555. WFIFOHEAD(fd,packet_len_table[0xbd]);
  2556. buf=WFIFOP(fd,0);
  2557. WBUFW(buf,0)=0xbd;
  2558. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2559. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2560. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2561. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2562. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2563. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2564. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2565. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2566. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2567. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2568. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2569. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2570. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2571. WBUFW(buf,16) = sd->base_atk + sd->right_weapon.watk + sd->left_weapon.watk;
  2572. WBUFW(buf,18) = sd->right_weapon.watk2 + sd->left_weapon.watk2; //atk bonus
  2573. WBUFW(buf,20) = sd->matk1;
  2574. WBUFW(buf,22) = sd->matk2;
  2575. WBUFW(buf,24) = sd->def; // def
  2576. WBUFW(buf,26) = sd->def2;
  2577. WBUFW(buf,28) = sd->mdef; // mdef
  2578. WBUFW(buf,30) = sd->mdef2;
  2579. WBUFW(buf,32) = sd->hit;
  2580. WBUFW(buf,34) = sd->flee;
  2581. WBUFW(buf,36) = sd->flee2/10;
  2582. WBUFW(buf,38) = sd->critical/10;
  2583. WBUFW(buf,40) = sd->status.karma;
  2584. WBUFW(buf,42) = sd->status.manner;
  2585. WFIFOSET(fd,packet_len_table[0xbd]);
  2586. clif_updatestatus(sd,SP_STR);
  2587. clif_updatestatus(sd,SP_AGI);
  2588. clif_updatestatus(sd,SP_VIT);
  2589. clif_updatestatus(sd,SP_INT);
  2590. clif_updatestatus(sd,SP_DEX);
  2591. clif_updatestatus(sd,SP_LUK);
  2592. clif_updatestatus(sd,SP_ATTACKRANGE);
  2593. clif_updatestatus(sd,SP_ASPD);
  2594. return 0;
  2595. }
  2596. /*==========================================
  2597. *矢装備
  2598. *------------------------------------------
  2599. */
  2600. int clif_arrowequip(struct map_session_data *sd,int val)
  2601. {
  2602. int fd;
  2603. nullpo_retr(0, sd);
  2604. pc_stop_attack(sd); // [Valaris]
  2605. fd=sd->fd;
  2606. WFIFOHEAD(fd, packet_len_table[0x013c]);
  2607. WFIFOW(fd,0)=0x013c;
  2608. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2609. WFIFOSET(fd,packet_len_table[0x013c]);
  2610. return 0;
  2611. }
  2612. /*==========================================
  2613. *
  2614. *------------------------------------------
  2615. */
  2616. int clif_arrow_fail(struct map_session_data *sd,int type)
  2617. {
  2618. int fd;
  2619. nullpo_retr(0, sd);
  2620. fd=sd->fd;
  2621. WFIFOHEAD(fd, packet_len_table[0x013b]);
  2622. WFIFOW(fd,0)=0x013b;
  2623. WFIFOW(fd,2)=type;
  2624. WFIFOSET(fd,packet_len_table[0x013b]);
  2625. return 0;
  2626. }
  2627. /*==========================================
  2628. * 作成可能 矢リスト送信
  2629. *------------------------------------------
  2630. */
  2631. int clif_arrow_create_list(struct map_session_data *sd)
  2632. {
  2633. int i, c, j;
  2634. int fd;
  2635. nullpo_retr(0, sd);
  2636. fd = sd->fd;
  2637. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2638. WFIFOW(fd,0) = 0x1ad;
  2639. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2640. if (skill_arrow_db[i].nameid > 0 &&
  2641. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2642. !sd->status.inventory[j].equip)
  2643. {
  2644. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2645. WFIFOW(fd,c*2+4) = j;
  2646. else
  2647. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2648. c++;
  2649. }
  2650. }
  2651. WFIFOW(fd,2) = c*2+4;
  2652. WFIFOSET(fd, WFIFOW(fd,2));
  2653. if (c > 0) {
  2654. sd->menuskill_id = AC_MAKINGARROW;
  2655. sd->menuskill_lv = c;
  2656. }
  2657. return 0;
  2658. }
  2659. /*==========================================
  2660. *
  2661. *------------------------------------------
  2662. */
  2663. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2664. {
  2665. int fd;
  2666. nullpo_retr(0, sd);
  2667. fd=sd->fd;
  2668. WFIFOHEAD(fd,packet_len_table[0xbc]);
  2669. WFIFOW(fd,0)=0xbc;
  2670. WFIFOW(fd,2)=type;
  2671. WFIFOB(fd,4)=ok;
  2672. WFIFOB(fd,5)=val;
  2673. WFIFOSET(fd,packet_len_table[0xbc]);
  2674. return 0;
  2675. }
  2676. /*==========================================
  2677. *
  2678. *------------------------------------------
  2679. */
  2680. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2681. {
  2682. int fd;
  2683. nullpo_retr(0, sd);
  2684. fd=sd->fd;
  2685. WFIFOHEAD(fd,packet_len_table[0xaa]);
  2686. WFIFOW(fd,0)=0xaa;
  2687. WFIFOW(fd,2)=n+2;
  2688. WFIFOW(fd,4)=pos;
  2689. WFIFOB(fd,6)=ok;
  2690. WFIFOSET(fd,packet_len_table[0xaa]);
  2691. return 0;
  2692. }
  2693. /*==========================================
  2694. *
  2695. *------------------------------------------
  2696. */
  2697. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2698. {
  2699. int fd;
  2700. nullpo_retr(0, sd);
  2701. fd=sd->fd;
  2702. WFIFOHEAD(fd,packet_len_table[0xac]);
  2703. WFIFOW(fd,0)=0xac;
  2704. WFIFOW(fd,2)=n+2;
  2705. WFIFOW(fd,4)=pos;
  2706. WFIFOB(fd,6)=ok;
  2707. WFIFOSET(fd,packet_len_table[0xac]);
  2708. return 0;
  2709. }
  2710. /*==========================================
  2711. *
  2712. *------------------------------------------
  2713. */
  2714. int clif_misceffect(struct block_list* bl,int type)
  2715. {
  2716. unsigned char buf[32];
  2717. nullpo_retr(0, bl);
  2718. WBUFW(buf,0) = 0x19b;
  2719. WBUFL(buf,2) = bl->id;
  2720. WBUFL(buf,6) = type;
  2721. clif_send(buf,packet_len_table[0x19b],bl,AREA);
  2722. return 0;
  2723. }
  2724. int clif_misceffect2(struct block_list *bl, int type) {
  2725. unsigned char buf[24];
  2726. nullpo_retr(0, bl);
  2727. memset(buf, 0, packet_len_table[0x1f3]);
  2728. WBUFW(buf,0) = 0x1f3;
  2729. WBUFL(buf,2) = bl->id;
  2730. WBUFL(buf,6) = type;
  2731. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  2732. return 0;
  2733. }
  2734. /*==========================================
  2735. * 表示オプション変更
  2736. *------------------------------------------
  2737. */
  2738. int clif_changeoption(struct block_list* bl)
  2739. {
  2740. unsigned char buf[32];
  2741. struct status_change *sc;
  2742. nullpo_retr(0, bl);
  2743. sc = status_get_sc(bl);
  2744. if (!sc) return 0; //How can an option change if there's no sc?
  2745. #if PACKETVER > 6
  2746. WBUFW(buf,0) = 0x229;
  2747. WBUFL(buf,2) = bl->id;
  2748. WBUFW(buf,6) = sc->opt1;
  2749. WBUFW(buf,8) = sc->opt2;
  2750. WBUFL(buf,10) = sc->option;
  2751. WBUFB(buf,14) = 0; // ??
  2752. if(disguised(bl)) {
  2753. clif_send(buf,packet_len_table[0x229],bl,AREA_WOS);
  2754. WBUFL(buf,2) = -bl->id;
  2755. clif_send(buf,packet_len_table[0x229],bl,SELF);
  2756. WBUFL(buf,2) = bl->id;
  2757. WBUFL(buf,10) = OPTION_INVISIBLE;
  2758. clif_send(buf,packet_len_table[0x229],bl,SELF);
  2759. } else
  2760. clif_send(buf,packet_len_table[0x229],bl,AREA);
  2761. #else
  2762. WBUFW(buf,0) = 0x119;
  2763. WBUFL(buf,2) = bl->id;
  2764. WBUFW(buf,6) = sc->opt1;
  2765. WBUFW(buf,8) = sc->opt2;
  2766. WBUFW(buf,10) = sc->option;
  2767. WBUFB(buf,12) = 0; // ??
  2768. if(disguised(bl)) {
  2769. clif_send(buf,packet_len_table[0x119],bl,AREA_WOS);
  2770. WBUFL(buf,2) = -bl->id;
  2771. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2772. WBUFL(buf,2) = bl->id;
  2773. WBUFW(buf,10) = OPTION_INVISIBLE;
  2774. clif_send(buf,packet_len_table[0x119],bl,SELF);
  2775. } else
  2776. clif_send(buf,packet_len_table[0x119],bl,AREA);
  2777. #endif
  2778. return 0;
  2779. }
  2780. /*==========================================
  2781. *
  2782. *------------------------------------------
  2783. */
  2784. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2785. {
  2786. nullpo_retr(0, sd);
  2787. if(!ok) {
  2788. int fd=sd->fd;
  2789. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2790. WFIFOW(fd,0)=0xa8;
  2791. WFIFOW(fd,2)=index+2;
  2792. WFIFOW(fd,4)=amount;
  2793. WFIFOB(fd,6)=ok;
  2794. WFIFOSET(fd,packet_len_table[0xa8]);
  2795. }
  2796. else {
  2797. #if PACKETVER < 3
  2798. int fd=sd->fd;
  2799. WFIFOHEAD(fd,packet_len_table[0xa8]);
  2800. WFIFOW(fd,0)=0xa8;
  2801. WFIFOW(fd,2)=index+2;
  2802. WFIFOW(fd,4)=amount;
  2803. WFIFOB(fd,6)=ok;
  2804. WFIFOSET(fd,packet_len_table[0xa8]);
  2805. #else
  2806. unsigned char buf[32];
  2807. WBUFW(buf,0)=0x1c8;
  2808. WBUFW(buf,2)=index+2;
  2809. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2810. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2811. else
  2812. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2813. WBUFL(buf,6)=sd->bl.id;
  2814. WBUFW(buf,10)=amount;
  2815. WBUFB(buf,12)=ok;
  2816. clif_send(buf,packet_len_table[0x1c8],&sd->bl,AREA);
  2817. #endif
  2818. }
  2819. return 0;
  2820. }
  2821. /*==========================================
  2822. *
  2823. *------------------------------------------
  2824. */
  2825. int clif_createchat(struct map_session_data *sd,int fail)
  2826. {
  2827. int fd;
  2828. nullpo_retr(0, sd);
  2829. fd=sd->fd;
  2830. WFIFOHEAD(fd,packet_len_table[0xd6]);
  2831. WFIFOW(fd,0)=0xd6;
  2832. WFIFOB(fd,2)=fail;
  2833. WFIFOSET(fd,packet_len_table[0xd6]);
  2834. return 0;
  2835. }
  2836. /*==========================================
  2837. *
  2838. *------------------------------------------
  2839. */
  2840. int clif_dispchat(struct chat_data *cd,int fd)
  2841. {
  2842. unsigned char buf[128]; // 最大title(60バイト)+17
  2843. if(cd==NULL || *cd->owner==NULL)
  2844. return 1;
  2845. WBUFW(buf,0)=0xd7;
  2846. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  2847. WBUFL(buf,4)=(*cd->owner)->id;
  2848. WBUFL(buf,8)=cd->bl.id;
  2849. WBUFW(buf,12)=cd->limit;
  2850. WBUFW(buf,14)=cd->users;
  2851. WBUFB(buf,16)=cd->pub;
  2852. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2853. if(fd){
  2854. WFIFOHEAD(fd, WBUFW(buf,2));
  2855. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2856. WFIFOSET(fd,WBUFW(buf,2));
  2857. } else {
  2858. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  2859. }
  2860. return 0;
  2861. }
  2862. /*==========================================
  2863. * chatの状態変更成功
  2864. * 外部の人用と命令コード(d7->df)が違うだけ
  2865. *------------------------------------------
  2866. */
  2867. int clif_changechatstatus(struct chat_data *cd)
  2868. {
  2869. unsigned char buf[128]; // 最大title(60バイト)+17
  2870. if(cd==NULL || cd->usersd[0]==NULL)
  2871. return 1;
  2872. WBUFW(buf,0)=0xdf;
  2873. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  2874. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  2875. WBUFL(buf,8)=cd->bl.id;
  2876. WBUFW(buf,12)=cd->limit;
  2877. WBUFW(buf,14)=cd->users;
  2878. WBUFB(buf,16)=cd->pub;
  2879. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2880. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2881. return 0;
  2882. }
  2883. /*==========================================
  2884. *
  2885. *------------------------------------------
  2886. */
  2887. int clif_clearchat(struct chat_data *cd,int fd)
  2888. {
  2889. unsigned char buf[32];
  2890. nullpo_retr(0, cd);
  2891. WBUFW(buf,0)=0xd8;
  2892. WBUFL(buf,2)=cd->bl.id;
  2893. if(fd){
  2894. WFIFOHEAD(fd,packet_len_table[0xd8]);
  2895. memcpy(WFIFOP(fd,0),buf,packet_len_table[0xd8]);
  2896. WFIFOSET(fd,packet_len_table[0xd8]);
  2897. } else {
  2898. clif_send(buf,packet_len_table[0xd8],*cd->owner,AREA_WOSC);
  2899. }
  2900. return 0;
  2901. }
  2902. /*==========================================
  2903. *
  2904. *------------------------------------------
  2905. */
  2906. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2907. {
  2908. int fd;
  2909. nullpo_retr(0, sd);
  2910. fd=sd->fd;
  2911. WFIFOHEAD(fd,packet_len_table[0xda]);
  2912. WFIFOW(fd,0)=0xda;
  2913. WFIFOB(fd,2)=fail;
  2914. WFIFOSET(fd,packet_len_table[0xda]);
  2915. return 0;
  2916. }
  2917. /*==========================================
  2918. *
  2919. *------------------------------------------
  2920. */
  2921. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2922. {
  2923. int fd;
  2924. int i;
  2925. nullpo_retr(0, sd);
  2926. nullpo_retr(0, cd);
  2927. fd = sd->fd;
  2928. if (!session_isActive(fd))
  2929. return 0;
  2930. WFIFOHEAD(fd, 8 + (28*cd->users));
  2931. WFIFOW(fd, 0) = 0xdb;
  2932. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2933. WFIFOL(fd, 4) = cd->bl.id;
  2934. for (i = 0; i < cd->users; i++) {
  2935. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  2936. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2937. }
  2938. WFIFOSET(fd, WFIFOW(fd, 2));
  2939. return 0;
  2940. }
  2941. /*==========================================
  2942. *
  2943. *------------------------------------------
  2944. */
  2945. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2946. {
  2947. unsigned char buf[32];
  2948. nullpo_retr(0, sd);
  2949. nullpo_retr(0, cd);
  2950. WBUFW(buf, 0) = 0x0dc;
  2951. WBUFW(buf, 2) = cd->users;
  2952. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2953. clif_send(buf,packet_len_table[0xdc],&sd->bl,CHAT_WOS);
  2954. return 0;
  2955. }
  2956. /*==========================================
  2957. *
  2958. *------------------------------------------
  2959. */
  2960. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  2961. {
  2962. unsigned char buf[64];
  2963. nullpo_retr(0, sd);
  2964. nullpo_retr(0, cd);
  2965. WBUFW(buf, 0) = 0xe1;
  2966. WBUFL(buf, 2) = 1;
  2967. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2968. WBUFW(buf,30) = 0xe1;
  2969. WBUFL(buf,32) = 0;
  2970. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2971. clif_send(buf,packet_len_table[0xe1]*2,&sd->bl,CHAT);
  2972. return 0;
  2973. }
  2974. /*==========================================
  2975. *
  2976. *------------------------------------------
  2977. */
  2978. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  2979. {
  2980. unsigned char buf[32];
  2981. nullpo_retr(0, sd);
  2982. nullpo_retr(0, cd);
  2983. WBUFW(buf, 0) = 0xdd;
  2984. WBUFW(buf, 2) = cd->users-1;
  2985. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2986. WBUFB(buf,28) = 0;
  2987. clif_send(buf,packet_len_table[0xdd],&sd->bl,CHAT);
  2988. return 0;
  2989. }
  2990. /*==========================================
  2991. * 取り引き要請受け
  2992. *------------------------------------------
  2993. */
  2994. int clif_traderequest(struct map_session_data *sd,char *name)
  2995. {
  2996. int fd;
  2997. nullpo_retr(0, sd);
  2998. fd=sd->fd;
  2999. WFIFOHEAD(fd,packet_len_table[0xe5]);
  3000. WFIFOW(fd,0)=0xe5;
  3001. strcpy((char*)WFIFOP(fd,2),name);
  3002. WFIFOSET(fd,packet_len_table[0xe5]);
  3003. return 0;
  3004. }
  3005. /*==========================================
  3006. * 取り引き要求応答
  3007. *------------------------------------------
  3008. */
  3009. int clif_tradestart(struct map_session_data *sd,int type)
  3010. {
  3011. int fd;
  3012. nullpo_retr(0, sd);
  3013. fd=sd->fd;
  3014. WFIFOHEAD(fd,packet_len_table[0xe7]);
  3015. WFIFOW(fd,0)=0xe7;
  3016. WFIFOB(fd,2)=type;
  3017. WFIFOSET(fd,packet_len_table[0xe7]);
  3018. return 0;
  3019. }
  3020. /*==========================================
  3021. * 相手方からのアイテム追加
  3022. *------------------------------------------
  3023. */
  3024. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  3025. {
  3026. int fd;
  3027. nullpo_retr(0, sd);
  3028. nullpo_retr(0, tsd);
  3029. fd=tsd->fd;
  3030. WFIFOHEAD(fd,packet_len_table[0xe9]);
  3031. WFIFOW(fd,0)=0xe9;
  3032. WFIFOL(fd,2)=amount;
  3033. if(index==0){
  3034. WFIFOW(fd,6) = 0; // type id
  3035. WFIFOB(fd,8) = 0; //identify flag
  3036. WFIFOB(fd,9) = 0; // attribute
  3037. WFIFOB(fd,10)= 0; //refine
  3038. WFIFOW(fd,11)= 0; //card (4w)
  3039. WFIFOW(fd,13)= 0; //card (4w)
  3040. WFIFOW(fd,15)= 0; //card (4w)
  3041. WFIFOW(fd,17)= 0; //card (4w)
  3042. }
  3043. else{
  3044. index-=2; //index fix
  3045. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3046. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3047. else
  3048. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3049. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3050. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3051. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3052. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3053. }
  3054. WFIFOSET(fd,packet_len_table[0xe9]);
  3055. return 0;
  3056. }
  3057. /*==========================================
  3058. * アイテム追加成功/失敗
  3059. *------------------------------------------
  3060. */
  3061. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3062. {
  3063. int fd;
  3064. nullpo_retr(0, sd);
  3065. fd=sd->fd;
  3066. WFIFOHEAD(fd,packet_len_table[0xea]);
  3067. WFIFOW(fd,0)=0xea;
  3068. WFIFOW(fd,2)=index;
  3069. WFIFOB(fd,4)=fail;
  3070. WFIFOSET(fd,packet_len_table[0xea]);
  3071. return 0;
  3072. }
  3073. /*==========================================
  3074. * 取り引きok押し
  3075. *------------------------------------------
  3076. */
  3077. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3078. {
  3079. int fd;
  3080. nullpo_retr(0, sd);
  3081. fd=sd->fd;
  3082. WFIFOHEAD(fd,packet_len_table[0xec]);
  3083. WFIFOW(fd,0)=0xec;
  3084. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3085. WFIFOSET(fd,packet_len_table[0xec]);
  3086. return 0;
  3087. }
  3088. /*==========================================
  3089. * 取り引きがキャンセルされました
  3090. *------------------------------------------
  3091. */
  3092. int clif_tradecancelled(struct map_session_data *sd)
  3093. {
  3094. int fd;
  3095. nullpo_retr(0, sd);
  3096. fd=sd->fd;
  3097. WFIFOHEAD(fd,packet_len_table[0xee]);
  3098. WFIFOW(fd,0)=0xee;
  3099. WFIFOSET(fd,packet_len_table[0xee]);
  3100. return 0;
  3101. }
  3102. /*==========================================
  3103. * 取り引き完了
  3104. *------------------------------------------
  3105. */
  3106. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3107. {
  3108. int fd;
  3109. nullpo_retr(0, sd);
  3110. fd=sd->fd;
  3111. WFIFOHEAD(fd,packet_len_table[0xf0]);
  3112. WFIFOW(fd,0)=0xf0;
  3113. WFIFOB(fd,2)=fail;
  3114. WFIFOSET(fd,packet_len_table[0xf0]);
  3115. return 0;
  3116. }
  3117. /*==========================================
  3118. * カプラ倉庫のアイテム数を更新
  3119. *------------------------------------------
  3120. */
  3121. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3122. {
  3123. int fd;
  3124. nullpo_retr(0, sd);
  3125. nullpo_retr(0, stor);
  3126. fd=sd->fd;
  3127. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3128. WFIFOW(fd,0) = 0xf2; // update storage amount
  3129. WFIFOW(fd,2) = stor->storage_amount; //items
  3130. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3131. WFIFOSET(fd,packet_len_table[0xf2]);
  3132. return 0;
  3133. }
  3134. /*==========================================
  3135. * カプラ倉庫にアイテムを追加する
  3136. *------------------------------------------
  3137. */
  3138. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3139. {
  3140. int view,fd;
  3141. nullpo_retr(0, sd);
  3142. nullpo_retr(0, stor);
  3143. fd=sd->fd;
  3144. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3145. WFIFOW(fd,0) =0xf4; // Storage item added
  3146. WFIFOW(fd,2) =index+1; // index
  3147. WFIFOL(fd,4) =amount; // amount
  3148. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3149. WFIFOW(fd,8) =view;
  3150. else
  3151. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3152. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3153. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3154. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3155. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3156. WFIFOSET(fd,packet_len_table[0xf4]);
  3157. return 0;
  3158. }
  3159. /*==========================================
  3160. *
  3161. *------------------------------------------
  3162. */
  3163. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3164. {
  3165. int fd;
  3166. nullpo_retr(0, sd);
  3167. nullpo_retr(0, stor);
  3168. fd=sd->fd;
  3169. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3170. WFIFOW(fd,0) = 0xf2; // update storage amount
  3171. WFIFOW(fd,2) = stor->storage_amount; //items
  3172. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3173. WFIFOSET(fd,packet_len_table[0xf2]);
  3174. return 0;
  3175. }
  3176. /*==========================================
  3177. *
  3178. *------------------------------------------
  3179. */
  3180. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3181. {
  3182. int view,fd;
  3183. nullpo_retr(0, sd);
  3184. nullpo_retr(0, stor);
  3185. fd=sd->fd;
  3186. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3187. WFIFOW(fd,0) =0xf4; // Storage item added
  3188. WFIFOW(fd,2) =index+1; // index
  3189. WFIFOL(fd,4) =amount; // amount
  3190. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3191. WFIFOW(fd,8) =view;
  3192. else
  3193. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3194. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3195. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3196. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3197. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3198. WFIFOSET(fd,packet_len_table[0xf4]);
  3199. return 0;
  3200. }
  3201. /*==========================================
  3202. * カプラ倉庫からアイテムを取り去る
  3203. *------------------------------------------
  3204. */
  3205. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3206. {
  3207. int fd;
  3208. nullpo_retr(0, sd);
  3209. fd=sd->fd;
  3210. WFIFOHEAD(fd,packet_len_table[0xf6]);
  3211. WFIFOW(fd,0)=0xf6; // Storage item removed
  3212. WFIFOW(fd,2)=index+1;
  3213. WFIFOL(fd,4)=amount;
  3214. WFIFOSET(fd,packet_len_table[0xf6]);
  3215. return 0;
  3216. }
  3217. /*==========================================
  3218. * カプラ倉庫を閉じる
  3219. *------------------------------------------
  3220. */
  3221. int clif_storageclose(struct map_session_data *sd)
  3222. {
  3223. int fd;
  3224. nullpo_retr(0, sd);
  3225. fd=sd->fd;
  3226. WFIFOHEAD(fd,packet_len_table[0xf8]);
  3227. WFIFOW(fd,0)=0xf8; // Storage Closed
  3228. WFIFOSET(fd,packet_len_table[0xf8]);
  3229. return 0;
  3230. }
  3231. //
  3232. // callback系 ?
  3233. //
  3234. /*==========================================
  3235. * PC表示
  3236. *------------------------------------------
  3237. */
  3238. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3239. {
  3240. int len;
  3241. if(dstsd->chatID){
  3242. struct chat_data *cd;
  3243. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3244. if(cd && cd->usersd[0]==dstsd)
  3245. clif_dispchat(cd,sd->fd);
  3246. }
  3247. if(dstsd->vender_id)
  3248. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3249. if(dstsd->spiritball > 0)
  3250. clif_spiritball_single(sd->fd, dstsd);
  3251. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3252. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3253. )
  3254. clif_hpmeter_single(sd->fd, dstsd);
  3255. if(dstsd->status.manner < 0 && battle_config.manner_system)
  3256. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3257. // pvp circle for duel [LuzZza]
  3258. /*
  3259. if(dstsd->duel_group)
  3260. clif_specialeffect(&dstsd->bl, 159, 4);
  3261. */
  3262. }
  3263. void clif_getareachar_char(struct map_session_data* sd,struct block_list *bl)
  3264. {
  3265. struct unit_data *ud;
  3266. struct view_data *vd;
  3267. int len;
  3268. vd = status_get_viewdata(bl);
  3269. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3270. return;
  3271. ud = unit_bl2ud(bl);
  3272. if (ud && ud->walktimer != -1)
  3273. {
  3274. #if PACKETVER < 4
  3275. WFIFOHEAD(sd->fd, packet_len_table[0x7b]);
  3276. #else
  3277. WFIFOHEAD(sd->fd, packet_len_table[0x1da]);
  3278. #endif
  3279. len = clif_set007b(bl,vd,ud,WFIFOP(sd->fd,0));
  3280. WFIFOSET(sd->fd,len);
  3281. } else {
  3282. #if PACKETVER < 4
  3283. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3284. #else
  3285. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3286. #endif
  3287. len = clif_set0078(bl,vd,WFIFOP(sd->fd,0));
  3288. WFIFOSET(sd->fd,len);
  3289. }
  3290. if (vd->cloth_color)
  3291. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3292. switch (bl->type)
  3293. {
  3294. case BL_PC:
  3295. {
  3296. TBL_PC* tsd = (TBL_PC*)bl;
  3297. clif_getareachar_pc(sd, tsd);
  3298. if(tsd->state.size==2) // tiny/big players [Valaris]
  3299. clif_specialeffect(bl,423,0);
  3300. else if(tsd->state.size==1)
  3301. clif_specialeffect(bl,421,0);
  3302. }
  3303. break;
  3304. case BL_NPC:
  3305. {
  3306. if(((TBL_NPC*)bl)->chat_id)
  3307. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3308. }
  3309. break;
  3310. case BL_MOB:
  3311. {
  3312. TBL_MOB* md = (TBL_MOB*)bl;
  3313. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3314. clif_specialeffect(bl,423,0);
  3315. else if(md->special_state.size==1)
  3316. clif_specialeffect(bl,421,0);
  3317. }
  3318. break;
  3319. }
  3320. }
  3321. /*==========================================
  3322. * Older fix pos packet.
  3323. *------------------------------------------
  3324. */
  3325. int clif_fixpos2(struct block_list* bl)
  3326. {
  3327. struct unit_data *ud;
  3328. struct view_data *vd;
  3329. unsigned char buf[256];
  3330. int len;
  3331. nullpo_retr(0, bl);
  3332. ud = unit_bl2ud(bl);
  3333. vd = status_get_viewdata(bl);
  3334. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3335. return 0;
  3336. if(ud && ud->walktimer != -1)
  3337. len = clif_set007b(bl,vd,ud,buf);
  3338. else
  3339. len = clif_set0078(bl,vd,buf);
  3340. if (disguised(bl)) {
  3341. clif_send(buf,len,bl,AREA_WOS);
  3342. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  3343. clif_setdisguise((TBL_PC*)bl, buf, len, 1);
  3344. } else
  3345. clif_send(buf,len,bl,AREA);
  3346. return 0;
  3347. }
  3348. //Modifies the type of damage according to status changes [Skotlex]
  3349. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3350. /*==========================================
  3351. * Estimates walk delay based on the damage criteria. [Skotlex]
  3352. *------------------------------------------
  3353. */
  3354. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3355. if (type == 4 || type == 9 || damage <=0)
  3356. return 0;
  3357. if (bl->type == BL_PC) {
  3358. if (battle_config.pc_walk_delay_rate != 100)
  3359. delay = delay*battle_config.pc_walk_delay_rate/100;
  3360. } else
  3361. if (battle_config.walk_delay_rate != 100)
  3362. delay = delay*battle_config.walk_delay_rate/100;
  3363. if (div_ > 1) //Multi-hit skills mean higher delays.
  3364. delay += battle_config.multihit_delay*(div_-1);
  3365. if (delay <= 0)
  3366. return 0;
  3367. return delay>0?delay:0;
  3368. }
  3369. /*==========================================
  3370. * 通常攻撃エフェクト&ダメージ
  3371. *------------------------------------------
  3372. */
  3373. 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)
  3374. {
  3375. unsigned char buf[256];
  3376. struct status_change *sc;
  3377. nullpo_retr(0, src);
  3378. nullpo_retr(0, dst);
  3379. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3380. sc = status_get_sc(dst);
  3381. if(sc && sc->count) {
  3382. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3383. if(damage > 0)
  3384. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3385. if(damage2 > 0)
  3386. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3387. }
  3388. }
  3389. WBUFW(buf,0)=0x8a;
  3390. WBUFL(buf,2)=src->id;
  3391. WBUFL(buf,6)=dst->id;
  3392. WBUFL(buf,10)=tick;
  3393. WBUFL(buf,14)=sdelay;
  3394. WBUFL(buf,18)=ddelay;
  3395. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3396. WBUFW(buf,22)=-1;
  3397. WBUFW(buf,27)=-1;
  3398. } else {
  3399. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3400. WBUFW(buf,27)=damage2;
  3401. }
  3402. WBUFW(buf,24)=div;
  3403. WBUFB(buf,26)=type;
  3404. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3405. if(disguised(src)) {
  3406. WBUFL(buf,2)=-src->id;
  3407. if(damage > 0)
  3408. WBUFW(buf,22)=-1;
  3409. if(damage2 > 0)
  3410. WBUFW(buf,27)=-1;
  3411. clif_send(buf,packet_len_table[0x8a],src,SELF);
  3412. }
  3413. if (disguised(dst)) {
  3414. WBUFL(buf,6)=-dst->id;
  3415. if (disguised(src))
  3416. WBUFL(buf,2)=src->id;
  3417. else {
  3418. if(damage > 0)
  3419. WBUFW(buf,22)=-1;
  3420. if(damage2 > 0)
  3421. WBUFW(buf,27)=-1;
  3422. }
  3423. clif_send(buf,packet_len_table[0x8a],dst,SELF);
  3424. }
  3425. //Return adjusted can't walk delay for further processing.
  3426. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3427. }
  3428. /*==========================================
  3429. *
  3430. *------------------------------------------
  3431. */
  3432. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3433. {
  3434. int view,fd;
  3435. fd=sd->fd;
  3436. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3437. WFIFOHEAD(fd,packet_len_table[0x9d]);
  3438. WFIFOW(fd,0)=0x9d;
  3439. WFIFOL(fd,2)=fitem->bl.id;
  3440. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3441. WFIFOW(fd,6)=view;
  3442. else
  3443. WFIFOW(fd,6)=fitem->item_data.nameid;
  3444. WFIFOB(fd,8)=fitem->item_data.identify;
  3445. WFIFOW(fd,9)=fitem->bl.x;
  3446. WFIFOW(fd,11)=fitem->bl.y;
  3447. WFIFOW(fd,13)=fitem->item_data.amount;
  3448. WFIFOB(fd,15)=fitem->subx;
  3449. WFIFOB(fd,16)=fitem->suby;
  3450. WFIFOSET(fd,packet_len_table[0x9d]);
  3451. }
  3452. /*==========================================
  3453. * 場所スキルエフェクトが視界に入る
  3454. *------------------------------------------
  3455. */
  3456. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3457. {
  3458. int fd;
  3459. struct block_list *bl;
  3460. fd=sd->fd;
  3461. bl=map_id2bl(unit->group->src_id);
  3462. #if PACKETVER >= 3
  3463. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3464. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3465. memset(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3466. WFIFOW(fd, 0)=0x1c9;
  3467. WFIFOL(fd, 2)=unit->bl.id;
  3468. WFIFOL(fd, 6)=unit->group->src_id;
  3469. WFIFOW(fd,10)=unit->bl.x;
  3470. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3471. WFIFOB(fd,14)=unit->group->unit_id;
  3472. WFIFOB(fd,15)=1;
  3473. WFIFOB(fd,16)=1;
  3474. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3475. WFIFOSET(fd,packet_len_table[0x1c9]);
  3476. return 0;
  3477. }
  3478. #endif
  3479. WFIFOHEAD(fd,packet_len_table[0x11f]);
  3480. memset(WFIFOP(fd,0),0,packet_len_table[0x11f]);
  3481. WFIFOW(fd, 0)=0x11f;
  3482. WFIFOL(fd, 2)=unit->bl.id;
  3483. WFIFOL(fd, 6)=unit->group->src_id;
  3484. WFIFOW(fd,10)=unit->bl.x;
  3485. WFIFOW(fd,12)=unit->bl.y;
  3486. //Use invisible unit id for traps.
  3487. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3488. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3489. else
  3490. WFIFOB(fd,14)=unit->group->unit_id;
  3491. WFIFOB(fd,15)=0;
  3492. WFIFOSET(fd,packet_len_table[0x11f]);
  3493. if(unit->group->skill_id == WZ_ICEWALL)
  3494. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3495. return 0;
  3496. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3497. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3498. memset(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3499. WFIFOW(fd, 0)=0x1c9;
  3500. WFIFOL(fd, 2)=unit->bl.id;
  3501. WFIFOL(fd, 6)=unit->group->src_id;
  3502. WFIFOW(fd,10)=unit->bl.x;
  3503. WFIFOW(fd,12)=unit->bl.y;
  3504. WFIFOB(fd,14)=unit->group->unit_id;
  3505. WFIFOB(fd,15)=1;
  3506. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3507. WFIFOB(fd,16)=1;
  3508. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3509. } else {
  3510. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3511. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3512. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3513. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3514. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3515. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3516. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3517. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3518. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3519. //37-39
  3520. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3521. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3522. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3523. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3524. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3525. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3526. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3527. //65-68
  3528. //69-72
  3529. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3530. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3531. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3532. }
  3533. WFIFOSET(fd,packet_len_table[0x1c9]);
  3534. #endif
  3535. if(unit->group->skill_id == WZ_ICEWALL)
  3536. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3537. return 0;
  3538. */
  3539. }
  3540. /*==========================================
  3541. * 場所スキルエフェクトが視界から消える
  3542. *------------------------------------------
  3543. */
  3544. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3545. {
  3546. nullpo_retr(0, unit);
  3547. WFIFOHEAD(fd,packet_len_table[0x120]);
  3548. WFIFOW(fd, 0)=0x120;
  3549. WFIFOL(fd, 2)=unit->bl.id;
  3550. WFIFOSET(fd,packet_len_table[0x120]);
  3551. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3552. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3553. return 0;
  3554. }
  3555. /*==========================================
  3556. *
  3557. *------------------------------------------
  3558. */
  3559. int clif_01ac(struct block_list *bl)
  3560. {
  3561. unsigned char buf[32];
  3562. nullpo_retr(0, bl);
  3563. WBUFW(buf, 0) = 0x1ac;
  3564. WBUFL(buf, 2) = bl->id;
  3565. clif_send(buf,packet_len_table[0x1ac],bl,AREA);
  3566. return 0;
  3567. }
  3568. /*==========================================
  3569. *
  3570. *------------------------------------------
  3571. */
  3572. int clif_getareachar(struct block_list* bl,va_list ap)
  3573. {
  3574. struct map_session_data *sd;
  3575. nullpo_retr(0, bl);
  3576. nullpo_retr(0, ap);
  3577. sd=va_arg(ap,struct map_session_data*);
  3578. if (sd == NULL || session[sd->fd] == NULL)
  3579. return 0;
  3580. switch(bl->type){
  3581. case BL_ITEM:
  3582. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3583. break;
  3584. case BL_SKILL:
  3585. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3586. break;
  3587. default:
  3588. if(&sd->bl == bl)
  3589. break;
  3590. clif_getareachar_char(sd,bl);
  3591. break;
  3592. }
  3593. return 0;
  3594. }
  3595. /*==========================================
  3596. * tbl has gone out of view-size of bl
  3597. *------------------------------------------
  3598. */
  3599. int clif_outsight(struct block_list *bl,va_list ap)
  3600. {
  3601. struct block_list *tbl;
  3602. struct view_data *vd;
  3603. TBL_PC *sd, *tsd;
  3604. tbl=va_arg(ap,struct block_list*);
  3605. if(bl == tbl) return 0;
  3606. BL_CAST(BL_PC, bl, sd);
  3607. BL_CAST(BL_PC, tbl, tsd);
  3608. if (tsd && tsd->fd)
  3609. { //tsd has lost sight of the bl object.
  3610. switch(bl->type){
  3611. case BL_PC:
  3612. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3613. clif_clearchar_id(bl->id,0,tsd->fd);
  3614. if(sd->chatID){
  3615. struct chat_data *cd;
  3616. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3617. if(cd->usersd[0]==sd)
  3618. clif_dispchat(cd,tsd->fd);
  3619. }
  3620. if(sd->vender_id)
  3621. clif_closevendingboard(bl,tsd->fd);
  3622. break;
  3623. case BL_ITEM:
  3624. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3625. break;
  3626. case BL_SKILL:
  3627. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3628. break;
  3629. default:
  3630. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3631. clif_clearchar_id(bl->id,0,tsd->fd);
  3632. break;
  3633. }
  3634. }
  3635. if (sd && sd->fd)
  3636. { //sd is watching tbl go out of view.
  3637. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3638. clif_clearchar_id(tbl->id,0,sd->fd);
  3639. }
  3640. return 0;
  3641. }
  3642. /*==========================================
  3643. * tbl has come into view of bl
  3644. *------------------------------------------
  3645. */
  3646. int clif_insight(struct block_list *bl,va_list ap)
  3647. {
  3648. struct block_list *tbl;
  3649. TBL_PC *sd, *tsd;
  3650. tbl=va_arg(ap,struct block_list*);
  3651. if (bl == tbl) return 0;
  3652. BL_CAST(BL_PC, bl, sd);
  3653. BL_CAST(BL_PC, tbl, tsd);
  3654. if (tsd && tsd->fd)
  3655. { //Tell tsd that bl entered into his view
  3656. switch(bl->type){
  3657. case BL_ITEM:
  3658. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3659. break;
  3660. case BL_SKILL:
  3661. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3662. break;
  3663. default:
  3664. clif_getareachar_char(tsd,bl);
  3665. break;
  3666. }
  3667. }
  3668. if (sd && sd->fd)
  3669. { //Tell sd that tbl walked into his view
  3670. clif_getareachar_char(sd,tbl);
  3671. }
  3672. return 0;
  3673. }
  3674. /*==========================================
  3675. *
  3676. *------------------------------------------
  3677. */
  3678. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3679. {
  3680. int fd,id, inf2;
  3681. nullpo_retr(0, sd);
  3682. fd=sd->fd;
  3683. if( (id=sd->status.skill[skillid].id) <= 0 )
  3684. return 0;
  3685. WFIFOHEAD(fd,packet_len_table[0x147]);
  3686. WFIFOW(fd,0)=0x147;
  3687. WFIFOW(fd,2) = id;
  3688. if(type < 0)
  3689. WFIFOW(fd,4) = skill_get_inf(id);
  3690. else
  3691. WFIFOW(fd,4) = type;
  3692. WFIFOW(fd,6) = 0;
  3693. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3694. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3695. if(range < 0)
  3696. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3697. WFIFOW(fd,12)= range;
  3698. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3699. inf2 = skill_get_inf2(id);
  3700. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3701. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3702. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill))
  3703. //WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_get_max(id) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3704. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[skillid].flag ==0 )? 1:0;
  3705. else
  3706. WFIFOB(fd,38) = 0;
  3707. WFIFOSET(fd,packet_len_table[0x147]);
  3708. return 0;
  3709. }
  3710. /*==========================================
  3711. * スキルリストを送信する
  3712. *------------------------------------------
  3713. */
  3714. int clif_skillinfoblock(struct map_session_data *sd)
  3715. {
  3716. int fd;
  3717. int i,c,len=4,id, inf2;
  3718. nullpo_retr(0, sd);
  3719. fd=sd->fd;
  3720. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3721. WFIFOW(fd,0)=0x10f;
  3722. for ( i = c = 0; i < MAX_SKILL; i++){
  3723. if( (id=sd->status.skill[i].id)!=0 ){
  3724. WFIFOW(fd,len ) = id;
  3725. WFIFOW(fd,len+2) = skill_get_inf(id);
  3726. WFIFOW(fd,len+4) = 0;
  3727. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3728. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3729. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3730. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3731. inf2 = skill_get_inf2(id);
  3732. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  3733. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  3734. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill) )
  3735. //WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_get_max(id) && sd->status.skill[i].flag ==0 )? 1:0;
  3736. 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;
  3737. else
  3738. WFIFOB(fd,len+36) = 0;
  3739. len+=37;
  3740. c++;
  3741. }
  3742. }
  3743. WFIFOW(fd,2)=len;
  3744. WFIFOSET(fd,len);
  3745. return 0;
  3746. }
  3747. /*==========================================
  3748. * スキル割り振り通知
  3749. *------------------------------------------
  3750. */
  3751. int clif_skillup(struct map_session_data *sd,int skill_num)
  3752. {
  3753. int fd;
  3754. nullpo_retr(0, sd);
  3755. fd=sd->fd;
  3756. WFIFOHEAD(fd,packet_len_table[0x10e]);
  3757. WFIFOW(fd,0) = 0x10e;
  3758. WFIFOW(fd,2) = skill_num;
  3759. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3760. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3761. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3762. //WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_get_max(sd->status.skill[skill_num].id)) ? 1 : 0;
  3763. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3764. WFIFOSET(fd,packet_len_table[0x10e]);
  3765. return 0;
  3766. }
  3767. /*==========================================
  3768. * スキル詠唱エフェクトを送信する
  3769. *------------------------------------------
  3770. */
  3771. int clif_skillcasting(struct block_list* bl,
  3772. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  3773. {
  3774. int pl = skill_get_pl(skill_num);
  3775. unsigned char buf[32];
  3776. WBUFW(buf,0) = 0x13e;
  3777. WBUFL(buf,2) = src_id;
  3778. WBUFL(buf,6) = dst_id;
  3779. WBUFW(buf,10) = dst_x;
  3780. WBUFW(buf,12) = dst_y;
  3781. WBUFW(buf,14) = skill_num;
  3782. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3783. WBUFL(buf,20) = casttime;
  3784. clif_send(buf,packet_len_table[0x13e], bl, AREA);
  3785. if (disguised(bl)) {
  3786. WBUFL(buf,2) = -src_id;
  3787. WBUFL(buf,20) = 0;
  3788. clif_send(buf,packet_len_table[0x13e], bl, SELF);
  3789. }
  3790. return 0;
  3791. }
  3792. /*==========================================
  3793. *
  3794. *------------------------------------------
  3795. */
  3796. int clif_skillcastcancel(struct block_list* bl)
  3797. {
  3798. unsigned char buf[16];
  3799. nullpo_retr(0, bl);
  3800. WBUFW(buf,0) = 0x1b9;
  3801. WBUFL(buf,2) = bl->id;
  3802. clif_send(buf,packet_len_table[0x1b9], bl, AREA);
  3803. return 0;
  3804. }
  3805. /*==========================================
  3806. * スキル詠唱失敗
  3807. *------------------------------------------
  3808. */
  3809. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3810. {
  3811. int fd;
  3812. nullpo_retr(0, sd);
  3813. fd=sd->fd;
  3814. // reset all variables [celest]
  3815. // Should be handled now by the unit_* code.
  3816. sd->skillitem = sd->skillitemlv = -1;
  3817. if(type==0x4 && !sd->state.showdelay)
  3818. return 0;
  3819. WFIFOHEAD(fd,packet_len_table[0x110]);
  3820. WFIFOW(fd,0) = 0x110;
  3821. WFIFOW(fd,2) = skill_id;
  3822. WFIFOW(fd,4) = btype;
  3823. WFIFOW(fd,6) = 0;
  3824. WFIFOB(fd,8) = 0;
  3825. WFIFOB(fd,9) = type;
  3826. WFIFOSET(fd,packet_len_table[0x110]);
  3827. return 0;
  3828. }
  3829. /*==========================================
  3830. * スキル攻撃エフェクト&ダメージ
  3831. *------------------------------------------
  3832. */
  3833. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  3834. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3835. {
  3836. unsigned char buf[64];
  3837. struct status_change *sc;
  3838. nullpo_retr(0, src);
  3839. nullpo_retr(0, dst);
  3840. type = (type>0)?type:skill_get_hit(skill_id);
  3841. type = clif_calc_delay(type, ddelay);
  3842. sc = status_get_sc(dst);
  3843. if(sc && sc->count) {
  3844. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3845. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3846. }
  3847. #if PACKETVER < 3
  3848. WBUFW(buf,0)=0x114;
  3849. WBUFW(buf,2)=skill_id;
  3850. WBUFL(buf,4)=src->id;
  3851. WBUFL(buf,8)=dst->id;
  3852. WBUFL(buf,12)=tick;
  3853. WBUFL(buf,16)=sdelay;
  3854. WBUFL(buf,20)=ddelay;
  3855. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3856. WBUFW(buf,24)=-1;
  3857. } else {
  3858. WBUFW(buf,24)=damage;
  3859. }
  3860. WBUFW(buf,26)=skill_lv;
  3861. WBUFW(buf,28)=div;
  3862. WBUFB(buf,30)=type;
  3863. clif_send(buf,packet_len_table[0x114],src,AREA);
  3864. if(disguised(src)) {
  3865. WBUFL(buf,4)=-src->id;
  3866. if(damage > 0)
  3867. WBUFW(buf,24)=-1;
  3868. clif_send(buf,packet_len_table[0x114],src,SELF);
  3869. }
  3870. if (disguised(dst)) {
  3871. WBUFL(buf,8)=-dst->id;
  3872. if (disguised(src))
  3873. WBUFL(buf,4)=src->id;
  3874. else if(damage > 0)
  3875. WBUFW(buf,24)=-1;
  3876. clif_send(buf,packet_len_table[0x114],dst,SELF);
  3877. }
  3878. #else
  3879. WBUFW(buf,0)=0x1de;
  3880. WBUFW(buf,2)=skill_id;
  3881. WBUFL(buf,4)=src->id;
  3882. WBUFL(buf,8)=dst->id;
  3883. WBUFL(buf,12)=tick;
  3884. WBUFL(buf,16)=sdelay;
  3885. WBUFL(buf,20)=ddelay;
  3886. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3887. WBUFL(buf,24)=-1;
  3888. } else {
  3889. WBUFL(buf,24)=damage;
  3890. }
  3891. WBUFW(buf,28)=skill_lv;
  3892. WBUFW(buf,30)=div;
  3893. WBUFB(buf,32)=type;
  3894. clif_send(buf,packet_len_table[0x1de],src,AREA);
  3895. if(disguised(src)) {
  3896. WBUFL(buf,4)=-src->id;
  3897. if(damage > 0)
  3898. WBUFW(buf,24)=-1;
  3899. clif_send(buf,packet_len_table[0x1de],src,SELF);
  3900. }
  3901. if (disguised(dst)) {
  3902. WBUFL(buf,8)=-dst->id;
  3903. if (disguised(src))
  3904. WBUFL(buf,4)=src->id;
  3905. else if(damage > 0)
  3906. WBUFW(buf,24)=-1;
  3907. clif_send(buf,packet_len_table[0x1de],dst,SELF);
  3908. }
  3909. #endif
  3910. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3911. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3912. }
  3913. /*==========================================
  3914. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3915. *------------------------------------------
  3916. */
  3917. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  3918. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3919. {
  3920. unsigned char buf[64];
  3921. struct status_change *sc;
  3922. nullpo_retr(0, src);
  3923. nullpo_retr(0, dst);
  3924. type = (type>0)?type:skill_get_hit(skill_id);
  3925. type = clif_calc_delay(type, ddelay);
  3926. sc = status_get_sc(dst);
  3927. if(sc && sc->count) {
  3928. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3929. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3930. }
  3931. WBUFW(buf,0)=0x115;
  3932. WBUFW(buf,2)=skill_id;
  3933. WBUFL(buf,4)=src->id;
  3934. WBUFL(buf,8)=dst->id;
  3935. WBUFL(buf,12)=tick;
  3936. WBUFL(buf,16)=sdelay;
  3937. WBUFL(buf,20)=ddelay;
  3938. WBUFW(buf,24)=dst->x;
  3939. WBUFW(buf,26)=dst->y;
  3940. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3941. WBUFW(buf,28)=-1;
  3942. } else {
  3943. WBUFW(buf,28)=damage;
  3944. }
  3945. WBUFW(buf,30)=skill_lv;
  3946. WBUFW(buf,32)=div;
  3947. WBUFB(buf,34)=type;
  3948. clif_send(buf,packet_len_table[0x115],src,AREA);
  3949. if(disguised(src)) {
  3950. WBUFL(buf,4)=-src->id;
  3951. if(damage > 0)
  3952. WBUFW(buf,28)=-1;
  3953. clif_send(buf,packet_len_table[0x115],src,SELF);
  3954. }
  3955. if (disguised(dst)) {
  3956. WBUFL(buf,8)=-dst->id;
  3957. if (disguised(src))
  3958. WBUFL(buf,4)=src->id;
  3959. else if(damage > 0)
  3960. WBUFW(buf,28)=-1;
  3961. clif_send(buf,packet_len_table[0x115],dst,SELF);
  3962. }
  3963. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3964. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3965. }
  3966. /*==========================================
  3967. * 支援/回復スキルエフェクト
  3968. *------------------------------------------
  3969. */
  3970. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  3971. int skill_id,int heal,int fail)
  3972. {
  3973. unsigned char buf[32];
  3974. nullpo_retr(0, dst);
  3975. WBUFW(buf,0)=0x11a;
  3976. WBUFW(buf,2)=skill_id;
  3977. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  3978. WBUFL(buf,6)=dst->id;
  3979. WBUFL(buf,10)=src?src->id:0;
  3980. WBUFB(buf,14)=fail;
  3981. clif_send(buf,packet_len_table[0x11a],dst,AREA);
  3982. if (disguised(dst)) {
  3983. WBUFL(buf,6)=-dst->id;
  3984. clif_send(buf,packet_len_table[0x115],dst,SELF);
  3985. }
  3986. if(src && disguised(src)) {
  3987. WBUFL(buf,10)=-src->id;
  3988. if (disguised(dst))
  3989. WBUFL(buf,6)=dst->id;
  3990. clif_send(buf,packet_len_table[0x115],src,SELF);
  3991. }
  3992. return fail;
  3993. }
  3994. /*==========================================
  3995. * 場所スキルエフェクト
  3996. *------------------------------------------
  3997. */
  3998. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3999. {
  4000. unsigned char buf[32];
  4001. nullpo_retr(0, src);
  4002. WBUFW(buf,0)=0x117;
  4003. WBUFW(buf,2)=skill_id;
  4004. WBUFL(buf,4)=src->id;
  4005. WBUFW(buf,8)=val;
  4006. WBUFW(buf,10)=x;
  4007. WBUFW(buf,12)=y;
  4008. WBUFL(buf,14)=tick;
  4009. clif_send(buf,packet_len_table[0x117],src,AREA);
  4010. if(disguised(src)) {
  4011. WBUFL(buf,4)=-src->id;
  4012. clif_send(buf,packet_len_table[0x117],src,SELF);
  4013. }
  4014. return 0;
  4015. }
  4016. /*==========================================
  4017. * 場所スキルエフェクト表示
  4018. *------------------------------------------
  4019. */
  4020. int clif_skill_setunit(struct skill_unit *unit)
  4021. {
  4022. unsigned char buf[128];
  4023. struct block_list *bl;
  4024. nullpo_retr(0, unit);
  4025. bl=map_id2bl(unit->group->src_id);
  4026. // These are invisible client-side, but are necessary because
  4027. // otherwise the client will not know who caused the attack.
  4028. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  4029. // return 0;
  4030. #if PACKETVER >= 3
  4031. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4032. memset(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4033. WBUFW(buf, 0)=0x1c9;
  4034. WBUFL(buf, 2)=unit->bl.id;
  4035. WBUFL(buf, 6)=unit->group->src_id;
  4036. WBUFW(buf,10)=unit->bl.x;
  4037. WBUFW(buf,12)=unit->bl.y;
  4038. WBUFB(buf,14)=unit->group->unit_id;
  4039. WBUFB(buf,15)=1;
  4040. WBUFB(buf,16)=1;
  4041. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4042. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4043. return 0;
  4044. }
  4045. #endif
  4046. memset(WBUFP(buf, 0),0,packet_len_table[0x11f]);
  4047. WBUFW(buf, 0)=0x11f;
  4048. WBUFL(buf, 2)=unit->bl.id;
  4049. WBUFL(buf, 6)=unit->group->src_id;
  4050. WBUFW(buf,10)=unit->bl.x;
  4051. WBUFW(buf,12)=unit->bl.y;
  4052. WBUFB(buf,14)=unit->group->unit_id;
  4053. WBUFB(buf,15)=0;
  4054. clif_send(buf,packet_len_table[0x11f],&unit->bl,AREA);
  4055. return 0;
  4056. /* Previous mysterious implementation noone really understands. [Skotlex]
  4057. memset(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4058. WBUFW(buf, 0)=0x1c9;
  4059. WBUFL(buf, 2)=unit->bl.id;
  4060. WBUFL(buf, 6)=unit->group->src_id;
  4061. WBUFW(buf,10)=unit->bl.x;
  4062. WBUFW(buf,12)=unit->bl.y;
  4063. WBUFB(buf,14)=unit->group->unit_id;
  4064. WBUFB(buf,15)=1;
  4065. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4066. WBUFB(buf,16)=1;
  4067. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4068. } else {
  4069. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4070. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4071. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4072. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4073. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4074. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4075. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4076. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4077. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4078. //37-39
  4079. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4080. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4081. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4082. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4083. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4084. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4085. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4086. //65-68
  4087. //69-72
  4088. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4089. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4090. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4091. }
  4092. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4093. #endif
  4094. return 0;
  4095. */
  4096. }
  4097. /*==========================================
  4098. * 場所スキルエフェクト削除
  4099. *------------------------------------------
  4100. */
  4101. int clif_skill_delunit(struct skill_unit *unit)
  4102. {
  4103. unsigned char buf[16];
  4104. nullpo_retr(0, unit);
  4105. WBUFW(buf, 0)=0x120;
  4106. WBUFL(buf, 2)=unit->bl.id;
  4107. clif_send(buf,packet_len_table[0x120],&unit->bl,AREA);
  4108. return 0;
  4109. }
  4110. /*==========================================
  4111. * ワープ場所選択
  4112. *------------------------------------------
  4113. */
  4114. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4115. const char *map1,const char *map2,const char *map3,const char *map4)
  4116. {
  4117. int fd;
  4118. nullpo_retr(0, sd);
  4119. fd=sd->fd;
  4120. WFIFOHEAD(fd,packet_len_table[0x11c]);
  4121. WFIFOW(fd,0)=0x11c;
  4122. WFIFOW(fd,2)=skill_num;
  4123. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4124. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4125. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4126. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4127. WFIFOSET(fd,packet_len_table[0x11c]);
  4128. sd->menuskill_id = skill_num;
  4129. if (skill_num == AL_WARP)
  4130. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4131. else
  4132. sd->menuskill_lv = skill_lv;
  4133. return 0;
  4134. }
  4135. /*==========================================
  4136. * メモ応答
  4137. *------------------------------------------
  4138. */
  4139. int clif_skill_memo(struct map_session_data *sd,int flag)
  4140. {
  4141. int fd;
  4142. nullpo_retr(0, sd);
  4143. fd=sd->fd;
  4144. WFIFOHEAD(fd,packet_len_table[0x11e]);
  4145. WFIFOW(fd,0)=0x11e;
  4146. WFIFOB(fd,2)=flag;
  4147. WFIFOSET(fd,packet_len_table[0x11e]);
  4148. return 0;
  4149. }
  4150. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4151. {
  4152. int fd;
  4153. nullpo_retr(0, sd);
  4154. fd=sd->fd;
  4155. WFIFOHEAD(fd,packet_len_table[0x189]);
  4156. WFIFOW(fd,0)=0x189;
  4157. WFIFOW(fd,2)=flag;
  4158. WFIFOSET(fd,packet_len_table[0x189]);
  4159. return 0;
  4160. }
  4161. /*==========================================
  4162. * モンスター情報
  4163. *------------------------------------------
  4164. */
  4165. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4166. {
  4167. struct mob_data *md;
  4168. unsigned char buf[64];
  4169. int i;//, fix;
  4170. nullpo_retr(0, sd);
  4171. nullpo_retr(0, dst);
  4172. if(dst->type!=BL_MOB )
  4173. return 0;
  4174. if((md=(struct mob_data *)dst) == NULL)
  4175. return 0;
  4176. WBUFW(buf, 0)=0x18c;
  4177. WBUFW(buf, 2)=md->vd->class_;
  4178. WBUFW(buf, 4)=md->level;
  4179. WBUFW(buf, 6)=md->db->size;
  4180. WBUFL(buf, 8)=md->hp;
  4181. WBUFW(buf,12)= (battle_config.estimation_type&1?status_get_def(&md->bl):0)
  4182. +(battle_config.estimation_type&2?status_get_def2(&md->bl):0);
  4183. WBUFW(buf,14)=md->db->race;
  4184. WBUFW(buf,16)= (battle_config.estimation_type&1?status_get_mdef(&md->bl):0)
  4185. +(battle_config.estimation_type&2?status_get_mdef2(&md->bl) - (md->db->vit>>1):0);
  4186. WBUFW(buf,18)=status_get_elem_type(&md->bl);
  4187. for(i=0;i<9;i++)
  4188. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,md->def_ele);
  4189. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4190. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,md->def_ele))<0?0:fix);
  4191. if(sd->status.party_id>0)
  4192. clif_send(buf,packet_len_table[0x18c],&sd->bl,PARTY_AREA);
  4193. else{
  4194. WFIFOHEAD(sd->fd,packet_len_table[0x18c]);
  4195. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x18c]);
  4196. WFIFOSET(sd->fd,packet_len_table[0x18c]);
  4197. }
  4198. return 0;
  4199. }
  4200. /*==========================================
  4201. * アイテム合成可能リスト
  4202. *------------------------------------------
  4203. */
  4204. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4205. {
  4206. int i,c,view,fd;
  4207. nullpo_retr(0, sd);
  4208. if(sd->menuskill_id == AM_PHARMACY)
  4209. return 0; //Avoid resending the menu twice or more times...
  4210. fd=sd->fd;
  4211. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4212. WFIFOW(fd, 0)=0x18d;
  4213. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4214. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4215. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4216. WFIFOW(fd,c*8+ 4)= view;
  4217. else
  4218. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4219. WFIFOW(fd,c*8+ 6)= 0x0012;
  4220. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4221. c++;
  4222. }
  4223. }
  4224. WFIFOW(fd, 2)=c*8+8;
  4225. WFIFOSET(fd,WFIFOW(fd,2));
  4226. if(c > 0) {
  4227. sd->menuskill_id = AM_PHARMACY;
  4228. sd->menuskill_lv = trigger;
  4229. return 1;
  4230. }
  4231. return 0;
  4232. }
  4233. /*==========================================
  4234. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4235. *------------------------------------------
  4236. */
  4237. int clif_status_load(struct block_list *bl,int type, int flag)
  4238. {
  4239. int fd;
  4240. if (type == SI_BLANK) //It shows nothing on the client...
  4241. return 0;
  4242. if (bl->type != BL_PC)
  4243. return 0;
  4244. fd = ((struct map_session_data*)bl)->fd;
  4245. WFIFOHEAD(fd,packet_len_table[0x196]);
  4246. WFIFOW(fd,0)=0x0196;
  4247. WFIFOW(fd,2)=type;
  4248. WFIFOL(fd,4)=bl->id;
  4249. WFIFOB(fd,8)=flag; //Status start
  4250. WFIFOSET(fd, packet_len_table[0x196]);
  4251. return 0;
  4252. }
  4253. /*==========================================
  4254. * 状態異常アイコン/メッセージ表示
  4255. *------------------------------------------
  4256. */
  4257. int clif_status_change(struct block_list *bl,int type,int flag)
  4258. {
  4259. unsigned char buf[16];
  4260. if (type == SI_BLANK) //It shows nothing on the client...
  4261. return 0;
  4262. nullpo_retr(0, bl);
  4263. WBUFW(buf,0)=0x0196;
  4264. WBUFW(buf,2)=type;
  4265. WBUFL(buf,4)=bl->id;
  4266. WBUFB(buf,8)=flag;
  4267. clif_send(buf,packet_len_table[0x196],bl,AREA);
  4268. return 0;
  4269. }
  4270. /*==========================================
  4271. * Send message (modified by [Yor])
  4272. *------------------------------------------
  4273. */
  4274. int clif_displaymessage(const int fd, char* mes)
  4275. {
  4276. // invalid pointer?
  4277. nullpo_retr(-1, mes);
  4278. //Console [Wizputer] //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4279. if (fd == 0)
  4280. return 0;
  4281. else {
  4282. int len_mes = strlen(mes);
  4283. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4284. WFIFOHEAD(fd, 5 + len_mes);
  4285. WFIFOW(fd,0) = 0x8e;
  4286. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4287. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4288. WFIFOSET(fd, 5 + len_mes);
  4289. }
  4290. }
  4291. return 0;
  4292. }
  4293. /*==========================================
  4294. * 天の声を送信する
  4295. *------------------------------------------
  4296. */
  4297. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4298. {
  4299. unsigned char *buf;
  4300. int lp;
  4301. lp = (flag & 0x10) ? 8 : 4;
  4302. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4303. WBUFW(buf,0) = 0x9a;
  4304. WBUFW(buf,2) = len + lp;
  4305. WBUFL(buf,4) = 0x65756c62;
  4306. memcpy(WBUFP(buf,lp), mes, len);
  4307. flag &= 0x07;
  4308. clif_send(buf, WBUFW(buf,2), bl,
  4309. (flag == 1) ? ALL_SAMEMAP :
  4310. (flag == 2) ? AREA :
  4311. (flag == 3) ? SELF :
  4312. ALL_CLIENT);
  4313. if(buf) aFree(buf);
  4314. if(use_irc && irc_announce_flag && !flag)
  4315. irc_announce(mes);
  4316. return 0;
  4317. }
  4318. /*==========================================
  4319. * グローバルメッセージ
  4320. *------------------------------------------
  4321. */
  4322. void clif_GlobalMessage(struct block_list *bl,char *message)
  4323. {
  4324. char buf[100];
  4325. int len;
  4326. nullpo_retv(bl);
  4327. if(!message)
  4328. return;
  4329. len = strlen(message)+1;
  4330. WBUFW(buf,0)=0x8d;
  4331. WBUFW(buf,2)=len+8;
  4332. WBUFL(buf,4)=bl->id;
  4333. strncpy((char *) WBUFP(buf,8),message,len);
  4334. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,AREA_CHAT_WOC);
  4335. }
  4336. /*==========================================
  4337. * Send main chat message [LuzZza]
  4338. *------------------------------------------
  4339. */
  4340. void clif_MainChatMessage(char* message) {
  4341. char buf[200];
  4342. int len;
  4343. if(!message)
  4344. return;
  4345. len = strlen(message)+1;
  4346. if (len+8 > sizeof(buf)) {
  4347. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4348. len = sizeof(buf)-8;
  4349. }
  4350. WBUFW(buf,0)=0x8d;
  4351. WBUFW(buf,2)=len+8;
  4352. WBUFL(buf,4)=0;
  4353. strncpy((char *) WBUFP(buf,8),message,len);
  4354. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4355. }
  4356. /*==========================================
  4357. * Does an announce message in the given color.
  4358. *------------------------------------------
  4359. */
  4360. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4361. {
  4362. unsigned char *buf;
  4363. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4364. WBUFW(buf,0) = 0x1c3;
  4365. WBUFW(buf,2) = len + 16;
  4366. WBUFL(buf,4) = color;
  4367. WBUFW(buf,8) = 0x190; //Font style? Type?
  4368. WBUFW(buf,10) = 0x0c; //12? Font size?
  4369. WBUFL(buf,12) = 0; //Unknown!
  4370. memcpy(WBUFP(buf,16), mes, len);
  4371. flag &= 0x07;
  4372. clif_send(buf, WBUFW(buf,2), bl,
  4373. (flag == 1) ? ALL_SAMEMAP :
  4374. (flag == 2) ? AREA :
  4375. (flag == 3) ? SELF :
  4376. ALL_CLIENT);
  4377. if(buf) aFree(buf);
  4378. return 0;
  4379. }
  4380. /*==========================================
  4381. * HPSP回復エフェクトを送信する
  4382. *------------------------------------------
  4383. */
  4384. int clif_heal(int fd,int type,int val)
  4385. {
  4386. WFIFOHEAD(fd,packet_len_table[0x13d]);
  4387. WFIFOW(fd,0)=0x13d;
  4388. WFIFOW(fd,2)=type;
  4389. WFIFOW(fd,4)=val;
  4390. WFIFOSET(fd,packet_len_table[0x13d]);
  4391. return 0;
  4392. }
  4393. /*==========================================
  4394. * 復活する
  4395. *------------------------------------------
  4396. */
  4397. int clif_resurrection(struct block_list *bl,int type)
  4398. {
  4399. unsigned char buf[16];
  4400. nullpo_retr(0, bl);
  4401. WBUFW(buf,0)=0x148;
  4402. WBUFL(buf,2)=bl->id;
  4403. WBUFW(buf,6)=type;
  4404. clif_send(buf,packet_len_table[0x148],bl,type==1 ? AREA : AREA_WOS);
  4405. if (disguised(bl))
  4406. clif_spawn(bl);
  4407. return 0;
  4408. }
  4409. /*==========================================
  4410. * PVP実装?(仮)
  4411. *------------------------------------------
  4412. */
  4413. int clif_set0199(int fd,int type)
  4414. {
  4415. WFIFOHEAD(fd,packet_len_table[0x199]);
  4416. WFIFOW(fd,0)=0x199;
  4417. WFIFOW(fd,2)=type;
  4418. WFIFOSET(fd,packet_len_table[0x199]);
  4419. return 0;
  4420. }
  4421. /*==========================================
  4422. * PVP実装?(仮)
  4423. *------------------------------------------
  4424. */
  4425. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4426. {
  4427. nullpo_retr(0, sd);
  4428. if(type == 2) {
  4429. WFIFOHEAD(sd->fd,packet_len_table[0x19a]);
  4430. WFIFOW(sd->fd,0) = 0x19a;
  4431. WFIFOL(sd->fd,2) = sd->bl.id;
  4432. if(pvprank<=0)
  4433. pc_calc_pvprank(sd);
  4434. WFIFOL(sd->fd,6) = pvprank;
  4435. WFIFOL(sd->fd,10) = pvpnum;
  4436. WFIFOSET(sd->fd,packet_len_table[0x19a]);
  4437. } else {
  4438. unsigned char buf[32];
  4439. WBUFW(buf,0) = 0x19a;
  4440. WBUFL(buf,2) = sd->bl.id;
  4441. if(sd->sc.option&0x46)
  4442. // WTF? a -1 to an unsigned value...
  4443. WBUFL(buf,6) = 0xFFFFFFFF;
  4444. else
  4445. if(pvprank<=0)
  4446. pc_calc_pvprank(sd);
  4447. WBUFL(buf,6) = pvprank;
  4448. WBUFL(buf,10) = pvpnum;
  4449. if(!type)
  4450. clif_send(buf,packet_len_table[0x19a],&sd->bl,AREA);
  4451. else
  4452. clif_send(buf,packet_len_table[0x19a],&sd->bl,ALL_SAMEMAP);
  4453. }
  4454. return 0;
  4455. }
  4456. /*==========================================
  4457. *
  4458. *------------------------------------------
  4459. */
  4460. int clif_send0199(int map,int type)
  4461. {
  4462. struct block_list bl;
  4463. unsigned char buf[16];
  4464. bl.type = BL_NUL;
  4465. bl.m = map;
  4466. WBUFW(buf,0)=0x199;
  4467. WBUFW(buf,2)=type;
  4468. clif_send(buf,packet_len_table[0x199],&bl,ALL_SAMEMAP);
  4469. return 0;
  4470. }
  4471. /*==========================================
  4472. * 精錬エフェクトを送信する
  4473. *------------------------------------------
  4474. */
  4475. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  4476. {
  4477. WFIFOHEAD(fd,packet_len_table[0x188]);
  4478. WFIFOW(fd,0)=0x188;
  4479. WFIFOW(fd,2)=fail;
  4480. WFIFOW(fd,4)=index+2;
  4481. WFIFOW(fd,6)=val;
  4482. WFIFOSET(fd,packet_len_table[0x188]);
  4483. return 0;
  4484. }
  4485. /*==========================================
  4486. * Wisp/page is transmitted to the destination player
  4487. *------------------------------------------
  4488. */
  4489. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4490. {
  4491. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4492. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4493. WFIFOW(fd,0) = 0x97;
  4494. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4495. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4496. memcpy(WFIFOP(fd,28), mes, mes_len);
  4497. WFIFOSET(fd,WFIFOW(fd,2));
  4498. return 0;
  4499. }
  4500. /*==========================================
  4501. * The transmission result of Wisp/page is transmitted to the source player
  4502. *------------------------------------------
  4503. */
  4504. 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
  4505. {
  4506. WFIFOHEAD(fd,packet_len_table[0x98]);
  4507. WFIFOW(fd,0) = 0x98;
  4508. WFIFOW(fd,2) = flag;
  4509. WFIFOSET(fd,packet_len_table[0x98]);
  4510. return 0;
  4511. }
  4512. /*==========================================
  4513. * キャラID名前引き結果を送信する
  4514. *------------------------------------------
  4515. */
  4516. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4517. {
  4518. char *p= map_charid2nick(char_id);
  4519. int fd;
  4520. nullpo_retr(0, sd);
  4521. fd=sd->fd;
  4522. if(p!=NULL){
  4523. WFIFOHEAD(fd,packet_len_table[0x194]);
  4524. WFIFOW(fd,0)=0x194;
  4525. WFIFOL(fd,2)=char_id;
  4526. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4527. WFIFOSET(fd,packet_len_table[0x194]);
  4528. }else{
  4529. map_reqchariddb(sd,char_id);
  4530. chrif_searchcharid(char_id);
  4531. }
  4532. return 0;
  4533. }
  4534. /*==========================================
  4535. * カードの挿入可能リストを返す
  4536. *------------------------------------------
  4537. */
  4538. int clif_use_card(struct map_session_data *sd,int idx)
  4539. {
  4540. int i,c,ep;
  4541. int fd=sd->fd;
  4542. nullpo_retr(0, sd);
  4543. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4544. return 0;
  4545. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != 6)
  4546. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4547. ep=sd->inventory_data[idx]->equip;
  4548. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4549. WFIFOW(fd,0)=0x017b;
  4550. for(i=c=0;i<MAX_INVENTORY;i++){
  4551. int j;
  4552. if(sd->inventory_data[i] == NULL)
  4553. continue;
  4554. if(sd->inventory_data[i]->type!=4 && sd->inventory_data[i]->type!=5) // 武器防具じゃない
  4555. continue;
  4556. if(sd->status.inventory[i].card[0]==0x00ff || sd->status.inventory[i].card[0]==(short)0xff00 || sd->status.inventory[i].card[0]==0x00fe)
  4557. continue;
  4558. if(sd->status.inventory[i].identify==0 ) // 未鑑定
  4559. continue;
  4560. if((sd->inventory_data[i]->equip&ep)==0) // 装備個所が違う
  4561. continue;
  4562. if(sd->inventory_data[i]->type==4 && ep==32) // 盾カードと両手武器
  4563. continue;
  4564. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4565. if( sd->status.inventory[i].card[j]==0 )
  4566. break;
  4567. }
  4568. if(j==sd->inventory_data[i]->slot) // すでにカードが一杯
  4569. continue;
  4570. WFIFOW(fd,4+c*2)=i+2;
  4571. c++;
  4572. }
  4573. WFIFOW(fd,2)=4+c*2;
  4574. WFIFOSET(fd,WFIFOW(fd,2));
  4575. return 0;
  4576. }
  4577. /*==========================================
  4578. * カードの挿入終了
  4579. *------------------------------------------
  4580. */
  4581. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4582. {
  4583. int fd;
  4584. nullpo_retr(0, sd);
  4585. fd=sd->fd;
  4586. WFIFOHEAD(fd,packet_len_table[0x17d]);
  4587. WFIFOW(fd,0)=0x17d;
  4588. WFIFOW(fd,2)=idx_equip+2;
  4589. WFIFOW(fd,4)=idx_card+2;
  4590. WFIFOB(fd,6)=flag;
  4591. WFIFOSET(fd,packet_len_table[0x17d]);
  4592. return 0;
  4593. }
  4594. /*==========================================
  4595. * 鑑定可能アイテムリスト送信
  4596. *------------------------------------------
  4597. */
  4598. int clif_item_identify_list(struct map_session_data *sd)
  4599. {
  4600. int i,c;
  4601. int fd;
  4602. nullpo_retr(0, sd);
  4603. fd=sd->fd;
  4604. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4605. WFIFOW(fd,0)=0x177;
  4606. for(i=c=0;i<MAX_INVENTORY;i++){
  4607. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4608. WFIFOW(fd,c*2+4)=i+2;
  4609. c++;
  4610. }
  4611. }
  4612. if(c > 0) {
  4613. WFIFOW(fd,2)=c*2+4;
  4614. WFIFOSET(fd,WFIFOW(fd,2));
  4615. sd->menuskill_id = MC_IDENTIFY;
  4616. sd->menuskill_lv = c;
  4617. }
  4618. return 0;
  4619. }
  4620. /*==========================================
  4621. * 鑑定結果
  4622. *------------------------------------------
  4623. */
  4624. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4625. {
  4626. int fd;
  4627. nullpo_retr(0, sd);
  4628. fd=sd->fd;
  4629. WFIFOHEAD(fd,packet_len_table[0x179]);
  4630. WFIFOW(fd, 0)=0x179;
  4631. WFIFOW(fd, 2)=idx+2;
  4632. WFIFOB(fd, 4)=flag;
  4633. WFIFOSET(fd,packet_len_table[0x179]);
  4634. return 0;
  4635. }
  4636. /*==========================================
  4637. * 修理可能アイテムリスト送信
  4638. *------------------------------------------
  4639. */
  4640. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4641. {
  4642. int i,c;
  4643. int fd;
  4644. int nameid;
  4645. nullpo_retr(0, sd);
  4646. nullpo_retr(0, dstsd);
  4647. fd=sd->fd;
  4648. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4649. WFIFOW(fd,0)=0x1fc;
  4650. for(i=c=0;i<MAX_INVENTORY;i++){
  4651. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4652. WFIFOW(fd,c*13+4) = i;
  4653. WFIFOW(fd,c*13+6) = nameid;
  4654. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4655. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4656. WFIFOB(fd,c*13+16)= c;
  4657. c++;
  4658. }
  4659. }
  4660. if(c > 0) {
  4661. WFIFOW(fd,2)=c*13+4;
  4662. WFIFOSET(fd,WFIFOW(fd,2));
  4663. sd->menuskill_id = BS_REPAIRWEAPON;
  4664. sd->menuskill_lv = dstsd->bl.id;
  4665. }else
  4666. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4667. return 0;
  4668. }
  4669. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4670. {
  4671. int view,fd;
  4672. nullpo_retr(0, sd);
  4673. fd=sd->fd;
  4674. WFIFOHEAD(fd,packet_len_table[0x1fe]);
  4675. WFIFOW(fd, 0)=0x1fe;
  4676. if((view = itemdb_viewid(nameid)) > 0)
  4677. WFIFOW(fd, 2)=view;
  4678. else
  4679. WFIFOW(fd, 2)=nameid;
  4680. WFIFOB(fd, 4)=flag;
  4681. WFIFOSET(fd,packet_len_table[0x1fe]);
  4682. return 0;
  4683. }
  4684. /*==========================================
  4685. * Weapon Refining - Taken from jAthena
  4686. *------------------------------------------
  4687. */
  4688. int clif_item_refine_list(struct map_session_data *sd)
  4689. {
  4690. int i,c;
  4691. int fd;
  4692. int skilllv;
  4693. int wlv;
  4694. int refine_item[5];
  4695. nullpo_retr(0, sd);
  4696. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4697. fd=sd->fd;
  4698. refine_item[0] = -1;
  4699. refine_item[1] = pc_search_inventory(sd,1010);
  4700. refine_item[2] = pc_search_inventory(sd,1011);
  4701. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4702. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4703. WFIFOW(fd,0)=0x221;
  4704. for(i=c=0;i<MAX_INVENTORY;i++){
  4705. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4706. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4707. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4708. WFIFOW(fd,c*13+ 4)=i+2;
  4709. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4710. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4711. WFIFOW(fd,c*13+10)=0;
  4712. WFIFOB(fd,c*13+12)=c;
  4713. c++;
  4714. }
  4715. }
  4716. WFIFOW(fd,2)=c*13+4;
  4717. WFIFOSET(fd,WFIFOW(fd,2));
  4718. sd->menuskill_id = WS_WEAPONREFINE;
  4719. sd->menuskill_lv = skilllv;
  4720. return 0;
  4721. }
  4722. /*==========================================
  4723. * アイテムによる一時的なスキル効果
  4724. *------------------------------------------
  4725. */
  4726. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  4727. {
  4728. int fd;
  4729. nullpo_retr(0, sd);
  4730. fd=sd->fd;
  4731. WFIFOHEAD(fd,packet_len_table[0x147]);
  4732. WFIFOW(fd, 0)=0x147;
  4733. WFIFOW(fd, 2)=skillid;
  4734. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4735. WFIFOW(fd, 6)=0;
  4736. WFIFOW(fd, 8)=skilllv;
  4737. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4738. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4739. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  4740. WFIFOB(fd,38)=0;
  4741. WFIFOSET(fd,packet_len_table[0x147]);
  4742. return 0;
  4743. }
  4744. /*==========================================
  4745. * カートにアイテム追加
  4746. *------------------------------------------
  4747. */
  4748. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4749. {
  4750. int view,fd;
  4751. unsigned char *buf;
  4752. nullpo_retr(0, sd);
  4753. fd=sd->fd;
  4754. WFIFOHEAD(fd,packet_len_table[0x124]);
  4755. buf=WFIFOP(fd,0);
  4756. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4757. return 1;
  4758. WBUFW(buf,0)=0x124;
  4759. WBUFW(buf,2)=n+2;
  4760. WBUFL(buf,4)=amount;
  4761. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4762. WBUFW(buf,8)=view;
  4763. else
  4764. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4765. WBUFB(buf,10)=sd->status.cart[n].identify;
  4766. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4767. WBUFB(buf,12)=sd->status.cart[n].refine;
  4768. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4769. WFIFOSET(fd,packet_len_table[0x124]);
  4770. return 0;
  4771. }
  4772. /*==========================================
  4773. * カートからアイテム削除
  4774. *------------------------------------------
  4775. */
  4776. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4777. {
  4778. int fd;
  4779. nullpo_retr(0, sd);
  4780. fd=sd->fd;
  4781. WFIFOHEAD(fd,packet_len_table[0x125]);
  4782. WFIFOW(fd,0)=0x125;
  4783. WFIFOW(fd,2)=n+2;
  4784. WFIFOL(fd,4)=amount;
  4785. WFIFOSET(fd,packet_len_table[0x125]);
  4786. return 0;
  4787. }
  4788. /*==========================================
  4789. * カートのアイテムリスト
  4790. *------------------------------------------
  4791. */
  4792. int clif_cart_itemlist(struct map_session_data *sd)
  4793. {
  4794. struct item_data *id;
  4795. int i,n,fd;
  4796. unsigned char *buf;
  4797. nullpo_retr(0, sd);
  4798. fd=sd->fd;
  4799. WFIFOHEAD(fd, MAX_CART * 18 + 4);
  4800. buf = WFIFOP(fd,0);
  4801. #if PACKETVER < 5
  4802. for(i=0,n=0;i<MAX_CART;i++){
  4803. if(sd->status.cart[i].nameid<=0)
  4804. continue;
  4805. id = itemdb_search(sd->status.cart[i].nameid);
  4806. if(itemdb_isequip2(id))
  4807. continue;
  4808. WBUFW(buf,n*10+4)=i+2;
  4809. if(id->view_id > 0)
  4810. WBUFW(buf,n*10+6)=id->view_id;
  4811. else
  4812. WBUFW(buf,n*10+6)=sd->status.cart[i].nameid;
  4813. WBUFB(buf,n*10+8)=itemtype(id->type);
  4814. WBUFB(buf,n*10+9)=sd->status.cart[i].identify;
  4815. WBUFW(buf,n*10+10)=sd->status.cart[i].amount;
  4816. WBUFW(buf,n*10+12)=0;
  4817. n++;
  4818. }
  4819. if(n){
  4820. WBUFW(buf,0)=0x123;
  4821. WBUFW(buf,2)=4+n*10;
  4822. WFIFOSET(fd,WFIFOW(fd,2));
  4823. }
  4824. #else
  4825. for(i=0,n=0;i<MAX_CART;i++){
  4826. if(sd->status.cart[i].nameid<=0)
  4827. continue;
  4828. id = itemdb_search(sd->status.cart[i].nameid);
  4829. if(itemdb_isequip2(id))
  4830. continue;
  4831. WBUFW(buf,n*18+4)=i+2;
  4832. if(id->view_id > 0)
  4833. WBUFW(buf,n*18+6)=id->view_id;
  4834. else
  4835. WBUFW(buf,n*18+6)=sd->status.cart[i].nameid;
  4836. WBUFB(buf,n*18+8)=itemtype(id->type);
  4837. WBUFB(buf,n*18+9)=sd->status.cart[i].identify;
  4838. WBUFW(buf,n*18+10)=sd->status.cart[i].amount;
  4839. WBUFW(buf,n*18+12)=0; //Here goes the equip location, which seems unnecessary to fill for the cart data.
  4840. clif_addcards(WBUFP(buf,n*18+14), &sd->status.cart[i]);
  4841. n++;
  4842. }
  4843. if(n){
  4844. WBUFW(buf,0)=0x1ef;
  4845. WBUFW(buf,2)=4+n*18;
  4846. WFIFOSET(fd,WFIFOW(fd,2));
  4847. }
  4848. #endif
  4849. return 0;
  4850. }
  4851. /*==========================================
  4852. * カートの装備品リスト
  4853. *------------------------------------------
  4854. */
  4855. int clif_cart_equiplist(struct map_session_data *sd)
  4856. {
  4857. struct item_data *id;
  4858. int i,n,fd;
  4859. unsigned char *buf;
  4860. nullpo_retr(0, sd);
  4861. fd=sd->fd;
  4862. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  4863. buf = WFIFOP(fd,0);
  4864. for(i=0,n=0;i<MAX_INVENTORY;i++){
  4865. if(sd->status.cart[i].nameid<=0)
  4866. continue;
  4867. id = itemdb_search(sd->status.cart[i].nameid);
  4868. if(!itemdb_isequip2(id))
  4869. continue;
  4870. WBUFW(buf,n*20+4)=i+2;
  4871. if(id->view_id > 0)
  4872. WBUFW(buf,n*20+6)=id->view_id;
  4873. else
  4874. WBUFW(buf,n*20+6)=sd->status.cart[i].nameid;
  4875. WBUFB(buf,n*20+8)=itemtype(id->type);
  4876. WBUFB(buf,n*20+9)=sd->status.cart[i].identify;
  4877. WBUFW(buf,n*20+10)=id->equip;
  4878. WBUFW(buf,n*20+12)=sd->status.cart[i].equip;
  4879. WBUFB(buf,n*20+14)=sd->status.cart[i].attribute;
  4880. WBUFB(buf,n*20+15)=sd->status.cart[i].refine;
  4881. clif_addcards(WBUFP(buf, n*20+16), &sd->status.cart[i]);
  4882. n++;
  4883. }
  4884. if(n){
  4885. WBUFW(buf,0)=0x122;
  4886. WBUFW(buf,2)=4+n*20;
  4887. WFIFOSET(fd,WFIFOW(fd,2));
  4888. }
  4889. return 0;
  4890. }
  4891. /*==========================================
  4892. * 露店開設
  4893. *------------------------------------------
  4894. */
  4895. int clif_openvendingreq(struct map_session_data *sd,int num)
  4896. {
  4897. int fd;
  4898. nullpo_retr(0, sd);
  4899. fd=sd->fd;
  4900. WFIFOHEAD(fd,packet_len_table[0x12d]);
  4901. WFIFOW(fd,0)=0x12d;
  4902. WFIFOW(fd,2)=num;
  4903. WFIFOSET(fd,packet_len_table[0x12d]);
  4904. return 0;
  4905. }
  4906. /*==========================================
  4907. * 露店看板表示
  4908. *------------------------------------------
  4909. */
  4910. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  4911. {
  4912. unsigned char buf[128];
  4913. nullpo_retr(0, bl);
  4914. WBUFW(buf,0)=0x131;
  4915. WBUFL(buf,2)=bl->id;
  4916. strncpy((char*)WBUFP(buf,6),message,80);
  4917. if(fd){
  4918. WFIFOHEAD(fd,packet_len_table[0x131]);
  4919. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x131]);
  4920. WFIFOSET(fd,packet_len_table[0x131]);
  4921. }else{
  4922. clif_send(buf,packet_len_table[0x131],bl,AREA_WOS);
  4923. }
  4924. return 0;
  4925. }
  4926. /*==========================================
  4927. * 露店看板消去
  4928. *------------------------------------------
  4929. */
  4930. int clif_closevendingboard(struct block_list* bl,int fd)
  4931. {
  4932. unsigned char buf[16];
  4933. nullpo_retr(0, bl);
  4934. WBUFW(buf,0)=0x132;
  4935. WBUFL(buf,2)=bl->id;
  4936. if(fd){
  4937. WFIFOHEAD(fd,packet_len_table[0x132]);
  4938. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x132]);
  4939. WFIFOSET(fd,packet_len_table[0x132]);
  4940. }else{
  4941. clif_send(buf,packet_len_table[0x132],bl,AREA_WOS);
  4942. }
  4943. return 0;
  4944. }
  4945. /*==========================================
  4946. * 露店アイテムリスト
  4947. *------------------------------------------
  4948. */
  4949. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  4950. {
  4951. struct item_data *data;
  4952. int i,n,index,fd;
  4953. struct map_session_data *vsd;
  4954. unsigned char *buf;
  4955. nullpo_retr(0, sd);
  4956. nullpo_retr(0, vending);
  4957. nullpo_retr(0, vsd=map_id2sd(id));
  4958. fd=sd->fd;
  4959. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  4960. buf = WFIFOP(fd,0);
  4961. for(i=0,n=0;i<vsd->vend_num;i++){
  4962. if(vending[i].amount<=0)
  4963. continue;
  4964. WBUFL(buf,8+n*22)=vending[i].value;
  4965. WBUFW(buf,12+n*22)=vending[i].amount;
  4966. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  4967. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  4968. continue;
  4969. data = itemdb_search(vsd->status.cart[index].nameid);
  4970. WBUFB(buf,16+n*22)=itemtype(data->type);
  4971. if(data->view_id > 0)
  4972. WBUFW(buf,17+n*22)=data->view_id;
  4973. else
  4974. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  4975. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  4976. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  4977. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  4978. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  4979. n++;
  4980. }
  4981. if(n > 0){
  4982. WBUFW(buf,0)=0x133;
  4983. WBUFW(buf,2)=8+n*22;
  4984. WBUFL(buf,4)=id;
  4985. WFIFOSET(fd,WFIFOW(fd,2));
  4986. }
  4987. return 0;
  4988. }
  4989. /*==========================================
  4990. * 露店アイテム購入失敗
  4991. *------------------------------------------
  4992. */
  4993. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  4994. {
  4995. int fd;
  4996. nullpo_retr(0, sd);
  4997. fd=sd->fd;
  4998. WFIFOHEAD(fd,packet_len_table[0x135]);
  4999. WFIFOW(fd,0)=0x135;
  5000. WFIFOW(fd,2)=index+2;
  5001. WFIFOW(fd,4)=amount;
  5002. WFIFOB(fd,6)=fail;
  5003. WFIFOSET(fd,packet_len_table[0x135]);
  5004. return 0;
  5005. }
  5006. /*==========================================
  5007. * 露店開設成功
  5008. *------------------------------------------
  5009. */
  5010. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  5011. {
  5012. struct item_data *data;
  5013. int i,n,index,fd;
  5014. unsigned char *buf;
  5015. nullpo_retr(0, sd);
  5016. fd=sd->fd;
  5017. WFIFOHEAD(fd, 8+sd->vend_num*22);
  5018. buf = WFIFOP(fd,0);
  5019. for(i=0,n=0;i<sd->vend_num;i++){
  5020. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  5021. WBUFL(buf,8+n*22)=vending[i].value;
  5022. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  5023. WBUFW(buf,14+n*22)=vending[i].amount;
  5024. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || !sd->status.cart[index].identify ||
  5025. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  5026. continue;
  5027. data = itemdb_search(sd->status.cart[index].nameid);
  5028. WBUFB(buf,16+n*22)=itemtype(data->type);
  5029. if(data->view_id > 0)
  5030. WBUFW(buf,17+n*22)=data->view_id;
  5031. else
  5032. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  5033. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  5034. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  5035. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  5036. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  5037. n++;
  5038. }
  5039. if(n > 0){
  5040. WBUFW(buf,0)=0x136;
  5041. WBUFW(buf,2)=8+n*22;
  5042. WBUFL(buf,4)=id;
  5043. WFIFOSET(fd,WFIFOW(fd,2));
  5044. }
  5045. return n;
  5046. }
  5047. /*==========================================
  5048. * 露店アイテム販売報告
  5049. *------------------------------------------
  5050. */
  5051. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  5052. {
  5053. int fd;
  5054. nullpo_retr(0, sd);
  5055. fd=sd->fd;
  5056. WFIFOHEAD(fd,packet_len_table[0x137]);
  5057. WFIFOW(fd,0)=0x137;
  5058. WFIFOW(fd,2)=index+2;
  5059. WFIFOW(fd,4)=amount;
  5060. WFIFOSET(fd,packet_len_table[0x137]);
  5061. return 0;
  5062. }
  5063. /*==========================================
  5064. * パーティ作成完了
  5065. *------------------------------------------
  5066. */
  5067. int clif_party_created(struct map_session_data *sd,int flag)
  5068. {
  5069. int fd;
  5070. // printf("clif_party_message(%s, %d, %s)\n", p->name, account_id, mes);
  5071. nullpo_retr(0, sd);
  5072. fd=sd->fd;
  5073. WFIFOHEAD(fd,packet_len_table[0xfa]);
  5074. WFIFOW(fd,0)=0xfa;
  5075. WFIFOB(fd,2)=flag;
  5076. WFIFOSET(fd,packet_len_table[0xfa]);
  5077. return 0;
  5078. }
  5079. int clif_party_main_info(struct party *p, int fd)
  5080. {
  5081. struct map_session_data *sd;
  5082. int i;
  5083. unsigned char buf[96];
  5084. for (i=0; i<MAX_PARTY && !p->member[i].leader; i++);
  5085. if (i >= MAX_PARTY) return 0; //Should never happen...
  5086. sd = p->member[i].sd;
  5087. WBUFW(buf,0)=0x1e9;
  5088. WBUFL(buf,2)= p->member[i].account_id;
  5089. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  5090. WBUFW(buf,10)=sd?sd->bl.x:0;
  5091. WBUFW(buf,12)=sd?sd->bl.y:0;
  5092. WBUFB(buf,14)=(p->member[i].online)?0:1; //This byte is also unconfirmed...
  5093. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5094. memcpy(WBUFP(buf,39), p->member[i].name, NAME_LENGTH);
  5095. memcpy(WBUFP(buf,63), mapindex_id2name(p->member[i].map), MAP_NAME_LENGTH);
  5096. WBUFB(buf,79) = (p->item&1)?1:0;
  5097. WBUFB(buf,80) = (p->item&2)?1:0;
  5098. if(fd>=0){
  5099. WFIFOHEAD(fd,packet_len_table[0x1e9]);
  5100. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x1e9]);
  5101. WFIFOSET(fd,packet_len_table[0x1e9]);
  5102. return 1;
  5103. }
  5104. if (!sd) {
  5105. for (i=0; i<MAX_PARTY && !p->member[i].sd; i++)
  5106. if (i >= MAX_PARTY) return 0; //Should never happen...
  5107. sd=p->member[i].sd;
  5108. }
  5109. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY);
  5110. return 1;
  5111. }
  5112. /*==========================================
  5113. * パーティ情報送信
  5114. *------------------------------------------
  5115. */
  5116. int clif_party_info(struct party *p,int fd)
  5117. {
  5118. unsigned char buf[1024];
  5119. int i,c;
  5120. struct map_session_data *sd=NULL;
  5121. nullpo_retr(0, p);
  5122. WBUFW(buf,0)=0xfb;
  5123. memcpy(WBUFP(buf,4),p->name,NAME_LENGTH);
  5124. for(i=c=0;i<MAX_PARTY;i++){
  5125. struct party_member *m=&p->member[i];
  5126. if(m->account_id>0){
  5127. if(sd==NULL) sd=m->sd;
  5128. WBUFL(buf,28+c*46)=m->account_id;
  5129. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5130. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5131. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5132. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5133. c++;
  5134. }
  5135. }
  5136. WBUFW(buf,2)=28+c*46;
  5137. if(fd>=0){ // fdが設定されてるならそれに送る
  5138. WFIFOHEAD(fd, 28+c*46);
  5139. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5140. WFIFOSET(fd,WFIFOW(fd,2));
  5141. return 9;
  5142. }
  5143. if(sd!=NULL)
  5144. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5145. return 0;
  5146. }
  5147. /*==========================================
  5148. * パーティ勧誘
  5149. *------------------------------------------
  5150. */
  5151. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5152. {
  5153. int fd;
  5154. struct party *p;
  5155. nullpo_retr(0, sd);
  5156. nullpo_retr(0, tsd);
  5157. fd=tsd->fd;
  5158. if( (p=party_search(sd->status.party_id))==NULL )
  5159. return 0;
  5160. WFIFOHEAD(fd,packet_len_table[0xfe]);
  5161. WFIFOW(fd,0)=0xfe;
  5162. WFIFOL(fd,2)=sd->status.account_id;
  5163. memcpy(WFIFOP(fd,6),p->name,NAME_LENGTH);
  5164. WFIFOSET(fd,packet_len_table[0xfe]);
  5165. return 0;
  5166. }
  5167. /*==========================================
  5168. * パーティ勧誘結果
  5169. *------------------------------------------
  5170. */
  5171. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5172. {
  5173. int fd;
  5174. nullpo_retr(0, sd);
  5175. fd=sd->fd;
  5176. WFIFOHEAD(fd,packet_len_table[0xfd]);
  5177. WFIFOW(fd,0)=0xfd;
  5178. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5179. WFIFOB(fd,26)=flag;
  5180. WFIFOSET(fd,packet_len_table[0xfd]);
  5181. return 0;
  5182. }
  5183. /*==========================================
  5184. * パーティ設定送信
  5185. * flag & 0x001=exp変更ミス
  5186. * 0x010=item変更ミス
  5187. * 0x100=一人にのみ送信
  5188. *------------------------------------------
  5189. */
  5190. int clif_party_option(struct party *p,struct map_session_data *sd,int flag)
  5191. {
  5192. unsigned char buf[16];
  5193. nullpo_retr(0, p);
  5194. // if(battle_config.etc_log)
  5195. // printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
  5196. if(sd==NULL && flag==0){
  5197. int i;
  5198. for(i=0;i<MAX_PARTY;i++)
  5199. if((sd=map_id2sd(p->member[i].account_id))!=NULL)
  5200. break;
  5201. }
  5202. if(sd==NULL)
  5203. return 0;
  5204. WBUFW(buf,0)=0x101;
  5205. WBUFW(buf,2)=((flag&0x01)?2:p->exp);
  5206. WBUFW(buf,4)=0; //NOTE: We don't know yet what this is for, it is NOT for item share rules, though. [Skotlex]
  5207. if(flag==0)
  5208. clif_send(buf,packet_len_table[0x101],&sd->bl,PARTY);
  5209. else {
  5210. WFIFOHEAD(sd->fd,packet_len_table[0x101]);
  5211. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x101]);
  5212. WFIFOSET(sd->fd,packet_len_table[0x101]);
  5213. }
  5214. return 0;
  5215. }
  5216. /*==========================================
  5217. * パーティ脱退(脱退前に呼ぶこと)
  5218. *------------------------------------------
  5219. */
  5220. int clif_party_leaved(struct party *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5221. {
  5222. unsigned char buf[64];
  5223. int i;
  5224. nullpo_retr(0, p);
  5225. WBUFW(buf,0)=0x105;
  5226. WBUFL(buf,2)=account_id;
  5227. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5228. WBUFB(buf,30)=flag&0x0f;
  5229. if((flag&0xf0)==0){
  5230. if(sd==NULL)
  5231. for(i=0;i<MAX_PARTY;i++)
  5232. if((sd=p->member[i].sd)!=NULL)
  5233. break;
  5234. if (sd!=NULL)
  5235. clif_send(buf,packet_len_table[0x105],&sd->bl,PARTY);
  5236. } else if (sd!=NULL) {
  5237. WFIFOHEAD(sd->fd,packet_len_table[0x105]);
  5238. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x105]);
  5239. WFIFOSET(sd->fd,packet_len_table[0x105]);
  5240. }
  5241. return 0;
  5242. }
  5243. /*==========================================
  5244. * パーティメッセージ送信
  5245. *------------------------------------------
  5246. */
  5247. int clif_party_message(struct party *p,int account_id,char *mes,int len)
  5248. {
  5249. struct map_session_data *sd;
  5250. int i;
  5251. nullpo_retr(0, p);
  5252. for(i=0;i<MAX_PARTY;i++){
  5253. if((sd=p->member[i].sd)!=NULL)
  5254. break;
  5255. }
  5256. if(sd!=NULL){
  5257. unsigned char buf[1024];
  5258. WBUFW(buf,0)=0x109;
  5259. WBUFW(buf,2)=len+8;
  5260. WBUFL(buf,4)=account_id;
  5261. memcpy(WBUFP(buf,8),mes,len);
  5262. clif_send(buf,len+8,&sd->bl,PARTY);
  5263. }
  5264. return 0;
  5265. }
  5266. /*==========================================
  5267. * パーティ座標通知
  5268. *------------------------------------------
  5269. */
  5270. int clif_party_xy(struct map_session_data *sd)
  5271. {
  5272. unsigned char buf[16];
  5273. nullpo_retr(0, sd);
  5274. WBUFW(buf,0)=0x107;
  5275. WBUFL(buf,2)=sd->status.account_id;
  5276. WBUFW(buf,6)=sd->bl.x;
  5277. WBUFW(buf,8)=sd->bl.y;
  5278. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  5279. return 0;
  5280. }
  5281. /*==========================================
  5282. * Sends x/y dot to a single fd. [Skotlex]
  5283. *------------------------------------------
  5284. */
  5285. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5286. {
  5287. WFIFOHEAD(fd,packet_len_table[0x107]);
  5288. WFIFOW(fd,0)=0x107;
  5289. WFIFOL(fd,2)=sd->status.account_id;
  5290. WFIFOW(fd,6)=sd->bl.x;
  5291. WFIFOW(fd,8)=sd->bl.y;
  5292. WFIFOSET(fd,packet_len_table[0x107]);
  5293. return 0;
  5294. }
  5295. /*==========================================
  5296. * パーティHP通知
  5297. *------------------------------------------
  5298. */
  5299. int clif_party_hp(struct map_session_data *sd)
  5300. {
  5301. unsigned char buf[16];
  5302. nullpo_retr(0, sd);
  5303. WBUFW(buf,0)=0x106;
  5304. WBUFL(buf,2)=sd->status.account_id;
  5305. WBUFW(buf,6)=(sd->status.hp > 0x7fff)? 0x7fff:sd->status.hp;
  5306. WBUFW(buf,8)=(sd->status.max_hp > 0x7fff)? 0x7fff:sd->status.max_hp;
  5307. clif_send(buf,packet_len_table[0x106],&sd->bl,PARTY_AREA_WOS);
  5308. return 0;
  5309. }
  5310. /*==========================================
  5311. * Sends HP bar to a single fd. [Skotlex]
  5312. *------------------------------------------
  5313. */
  5314. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5315. {
  5316. WFIFOHEAD(fd,packet_len_table[0x106]);
  5317. WFIFOW(fd,0) = 0x106;
  5318. WFIFOL(fd,2) = sd->status.account_id;
  5319. WFIFOW(fd,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5320. WFIFOW(fd,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5321. WFIFOSET (fd, packet_len_table[0x106]);
  5322. }
  5323. /*==========================================
  5324. * GMへ場所とHP通知
  5325. *------------------------------------------
  5326. */
  5327. int clif_hpmeter(struct map_session_data *sd)
  5328. {
  5329. struct map_session_data *sd2;
  5330. unsigned char buf[16];
  5331. int i, x0, y0, x1, y1;
  5332. int level;
  5333. nullpo_retr(0, sd);
  5334. x0 = sd->bl.x - AREA_SIZE;
  5335. y0 = sd->bl.y - AREA_SIZE;
  5336. x1 = sd->bl.x + AREA_SIZE;
  5337. y1 = sd->bl.y + AREA_SIZE;
  5338. WBUFW(buf,0) = 0x106;
  5339. WBUFL(buf,2) = sd->status.account_id;
  5340. WBUFW(buf,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5341. WBUFW(buf,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5342. for (i = 0; i < fd_max; i++) {
  5343. if (session[i] && (sd2 = (struct map_session_data*)session[i]->session_data) && sd != sd2 && sd2->state.auth) {
  5344. if (sd2->bl.m != sd->bl.m ||
  5345. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5346. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5347. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5348. level < pc_isGM(sd))
  5349. continue;
  5350. WFIFOHEAD (i, packet_len_table[0x106]);
  5351. memcpy (WFIFOP(i,0), buf, packet_len_table[0x106]);
  5352. WFIFOSET (i, packet_len_table[0x106]);
  5353. }
  5354. }
  5355. return 0;
  5356. }
  5357. /*==========================================
  5358. * パーティ場所移動(未使用)
  5359. *------------------------------------------
  5360. */
  5361. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5362. {
  5363. unsigned char buf[128];
  5364. nullpo_retr(0, sd);
  5365. nullpo_retr(0, p);
  5366. WBUFW(buf, 0)=0x104;
  5367. WBUFL(buf, 2)=sd->status.account_id;
  5368. WBUFL(buf, 6)=0;
  5369. WBUFW(buf,10)=sd->bl.x;
  5370. WBUFW(buf,12)=sd->bl.y;
  5371. WBUFB(buf,14)=!online;
  5372. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5373. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5374. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5375. clif_send(buf,packet_len_table[0x104],&sd->bl,PARTY);
  5376. return 0;
  5377. }
  5378. /*==========================================
  5379. * 攻撃するために移動が必要
  5380. *------------------------------------------
  5381. */
  5382. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5383. {
  5384. int fd;
  5385. nullpo_retr(0, sd);
  5386. nullpo_retr(0, bl);
  5387. fd=sd->fd;
  5388. WFIFOHEAD(fd,packet_len_table[0x139]);
  5389. WFIFOW(fd, 0)=0x139;
  5390. WFIFOL(fd, 2)=bl->id;
  5391. WFIFOW(fd, 6)=bl->x;
  5392. WFIFOW(fd, 8)=bl->y;
  5393. WFIFOW(fd,10)=sd->bl.x;
  5394. WFIFOW(fd,12)=sd->bl.y;
  5395. WFIFOW(fd,14)=sd->attackrange;
  5396. WFIFOSET(fd,packet_len_table[0x139]);
  5397. return 0;
  5398. }
  5399. /*==========================================
  5400. * 製造エフェクト
  5401. *------------------------------------------
  5402. */
  5403. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5404. {
  5405. int view,fd;
  5406. nullpo_retr(0, sd);
  5407. fd=sd->fd;
  5408. // 名前の登録と送信を先にしておく
  5409. if( map_charid2nick(sd->status.char_id)==NULL )
  5410. map_addchariddb(sd->status.char_id,sd->status.name);
  5411. clif_solved_charname(sd,sd->status.char_id);
  5412. WFIFOHEAD(fd,packet_len_table[0x18f]);
  5413. WFIFOW(fd, 0)=0x18f;
  5414. WFIFOW(fd, 2)=flag;
  5415. if((view = itemdb_viewid(nameid)) > 0)
  5416. WFIFOW(fd, 4)=view;
  5417. else
  5418. WFIFOW(fd, 4)=nameid;
  5419. WFIFOSET(fd,packet_len_table[0x18f]);
  5420. return 0;
  5421. }
  5422. // pet
  5423. int clif_catch_process(struct map_session_data *sd)
  5424. {
  5425. int fd;
  5426. nullpo_retr(0, sd);
  5427. fd=sd->fd;
  5428. WFIFOHEAD(fd,packet_len_table[0x19e]);
  5429. WFIFOW(fd,0)=0x19e;
  5430. WFIFOSET(fd,packet_len_table[0x19e]);
  5431. sd->menuskill_id = SA_TAMINGMONSTER;
  5432. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5433. sd->menuskill_lv = 0; //Free catch
  5434. else
  5435. sd->menuskill_lv = sd->itemid; //Consume catch
  5436. return 0;
  5437. }
  5438. int clif_pet_rulet(struct map_session_data *sd,int data)
  5439. {
  5440. int fd;
  5441. nullpo_retr(0, sd);
  5442. fd=sd->fd;
  5443. WFIFOHEAD(fd,packet_len_table[0x1a0]);
  5444. WFIFOW(fd,0)=0x1a0;
  5445. WFIFOB(fd,2)=data;
  5446. WFIFOSET(fd,packet_len_table[0x1a0]);
  5447. return 0;
  5448. }
  5449. /*==========================================
  5450. * pet卵リスト作成
  5451. *------------------------------------------
  5452. */
  5453. int clif_sendegg(struct map_session_data *sd)
  5454. {
  5455. //R 01a6 <len>.w <index>.w*
  5456. int i,n=0,fd;
  5457. nullpo_retr(0, sd);
  5458. fd=sd->fd;
  5459. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5460. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5461. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5462. return 0;
  5463. }
  5464. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5465. WFIFOW(fd,0)=0x1a6;
  5466. if(sd->status.pet_id <= 0) {
  5467. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5468. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5469. sd->inventory_data[i]->type!=7 ||
  5470. sd->status.inventory[i].amount<=0)
  5471. continue;
  5472. WFIFOW(fd,n*2+4)=i+2;
  5473. n++;
  5474. }
  5475. }
  5476. WFIFOW(fd,2)=4+n*2;
  5477. WFIFOSET(fd,WFIFOW(fd,2));
  5478. sd->menuskill_id = SA_TAMINGMONSTER;
  5479. sd->menuskill_lv = -1;
  5480. return 0;
  5481. }
  5482. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5483. {
  5484. int fd;
  5485. nullpo_retr(0, sd);
  5486. nullpo_retr(0, sd->pd);
  5487. fd=sd->fd;
  5488. WFIFOHEAD(fd,packet_len_table[0x1a4]);
  5489. WFIFOW(fd,0)=0x1a4;
  5490. WFIFOB(fd,2)=type;
  5491. WFIFOL(fd,3)=sd->pd->bl.id;
  5492. WFIFOL(fd,7)=param;
  5493. WFIFOSET(fd,packet_len_table[0x1a4]);
  5494. return 0;
  5495. }
  5496. int clif_send_petstatus(struct map_session_data *sd)
  5497. {
  5498. int fd;
  5499. nullpo_retr(0, sd);
  5500. fd=sd->fd;
  5501. WFIFOHEAD(fd,packet_len_table[0x1a2]);
  5502. WFIFOW(fd,0)=0x1a2;
  5503. memcpy(WFIFOP(fd,2),sd->pet.name,NAME_LENGTH);
  5504. WFIFOB(fd,26)=(battle_config.pet_rename == 1)? 0:sd->pet.rename_flag;
  5505. WFIFOW(fd,27)=sd->pet.level;
  5506. WFIFOW(fd,29)=sd->pet.hungry;
  5507. WFIFOW(fd,31)=sd->pet.intimate;
  5508. WFIFOW(fd,33)=sd->pet.equip;
  5509. WFIFOSET(fd,packet_len_table[0x1a2]);
  5510. return 0;
  5511. }
  5512. /*==========================================
  5513. *
  5514. *------------------------------------------
  5515. */
  5516. int clif_pet_emotion(struct pet_data *pd,int param)
  5517. {
  5518. unsigned char buf[16];
  5519. struct map_session_data *sd;
  5520. nullpo_retr(0, pd);
  5521. nullpo_retr(0, sd = pd->msd);
  5522. memset(buf,0,packet_len_table[0x1aa]);
  5523. WBUFW(buf,0)=0x1aa;
  5524. WBUFL(buf,2)=pd->bl.id;
  5525. if(param >= 100 && sd->petDB->talk_convert_class) {
  5526. if(sd->petDB->talk_convert_class < 0)
  5527. return 0;
  5528. else if(sd->petDB->talk_convert_class > 0) {
  5529. param -= (pd->class_ - 100)*100;
  5530. param += (sd->petDB->talk_convert_class - 100)*100;
  5531. }
  5532. }
  5533. WBUFL(buf,6)=param;
  5534. clif_send(buf,packet_len_table[0x1aa],&pd->bl,AREA);
  5535. return 0;
  5536. }
  5537. int clif_pet_performance(struct block_list *bl,int param)
  5538. {
  5539. unsigned char buf[16];
  5540. nullpo_retr(0, bl);
  5541. memset(buf,0,packet_len_table[0x1a4]);
  5542. WBUFW(buf,0)=0x1a4;
  5543. WBUFB(buf,2)=4;
  5544. WBUFL(buf,3)=bl->id;
  5545. WBUFL(buf,7)=param;
  5546. clif_send(buf,packet_len_table[0x1a4],bl,AREA);
  5547. return 0;
  5548. }
  5549. int clif_pet_equip(struct pet_data *pd,int nameid)
  5550. {
  5551. unsigned char buf[16];
  5552. nullpo_retr(0, pd);
  5553. memset(buf,0,packet_len_table[0x1a4]);
  5554. WBUFW(buf,0)=0x1a4;
  5555. WBUFB(buf,2)=3;
  5556. WBUFL(buf,3)=pd->bl.id;
  5557. WBUFL(buf,7)=pd->vd.shield;
  5558. clif_send(buf,packet_len_table[0x1a4],&pd->bl,AREA);
  5559. return 0;
  5560. }
  5561. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5562. {
  5563. int fd;
  5564. nullpo_retr(0, sd);
  5565. fd=sd->fd;
  5566. WFIFOHEAD(fd,packet_len_table[0x1a3]);
  5567. WFIFOW(fd,0)=0x1a3;
  5568. WFIFOB(fd,2)=fail;
  5569. WFIFOW(fd,3)=foodid;
  5570. WFIFOSET(fd,packet_len_table[0x1a3]);
  5571. return 0;
  5572. }
  5573. /*==========================================
  5574. * オートスペル リスト送信
  5575. *------------------------------------------
  5576. */
  5577. int clif_autospell(struct map_session_data *sd,int skilllv)
  5578. {
  5579. int fd;
  5580. nullpo_retr(0, sd);
  5581. fd=sd->fd;
  5582. WFIFOHEAD(fd,packet_len_table[0x1cd]);
  5583. WFIFOW(fd, 0)=0x1cd;
  5584. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5585. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5586. else
  5587. WFIFOL(fd,2)= 0x00000000;
  5588. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5589. WFIFOL(fd,6)= MG_COLDBOLT;
  5590. else
  5591. WFIFOL(fd,6)= 0x00000000;
  5592. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5593. WFIFOL(fd,10)= MG_FIREBOLT;
  5594. else
  5595. WFIFOL(fd,10)= 0x00000000;
  5596. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5597. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5598. else
  5599. WFIFOL(fd,14)= 0x00000000;
  5600. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5601. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5602. else
  5603. WFIFOL(fd,18)= 0x00000000;
  5604. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5605. WFIFOL(fd,22)= MG_FIREBALL;
  5606. else
  5607. WFIFOL(fd,22)= 0x00000000;
  5608. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5609. WFIFOL(fd,26)= MG_FROSTDIVER;
  5610. else
  5611. WFIFOL(fd,26)= 0x00000000;
  5612. WFIFOSET(fd,packet_len_table[0x1cd]);
  5613. sd->menuskill_id = SA_AUTOSPELL;
  5614. sd->menuskill_lv = skilllv;
  5615. return 0;
  5616. }
  5617. /*==========================================
  5618. * ディボーションの青い糸
  5619. *------------------------------------------
  5620. */
  5621. int clif_devotion(struct map_session_data *sd)
  5622. {
  5623. unsigned char buf[56];
  5624. int i,n;
  5625. nullpo_retr(0, sd);
  5626. WBUFW(buf,0)=0x1cf;
  5627. WBUFL(buf,2)=sd->bl.id;
  5628. for(i=0,n=0;i<5;i++) {
  5629. if (!sd->devotion[i])
  5630. continue;
  5631. WBUFL(buf,6+4*n)=sd->devotion[i];
  5632. n++;
  5633. }
  5634. for(;n<5;n++)
  5635. WBUFL(buf,6+4*n)=0;
  5636. WBUFB(buf,26)=8;
  5637. WBUFB(buf,27)=0;
  5638. clif_send(buf,packet_len_table[0x1cf],&sd->bl,AREA);
  5639. return 0;
  5640. }
  5641. int clif_marionette(struct block_list *src, struct block_list *target)
  5642. {
  5643. unsigned char buf[56];
  5644. int n;
  5645. WBUFW(buf,0)=0x1cf;
  5646. WBUFL(buf,2)=src->id;
  5647. for(n=0;n<5;n++)
  5648. WBUFL(buf,6+4*n)=0;
  5649. if (target) //The target goes on the second slot.
  5650. WBUFL(buf,6+4) = target->id;
  5651. WBUFB(buf,26)=8;
  5652. WBUFB(buf,27)=0;
  5653. clif_send(buf,packet_len_table[0x1cf],src,AREA);
  5654. return 0;
  5655. }
  5656. /*==========================================
  5657. * 氣球
  5658. *------------------------------------------
  5659. */
  5660. int clif_spiritball(struct map_session_data *sd)
  5661. {
  5662. unsigned char buf[16];
  5663. nullpo_retr(0, sd);
  5664. WBUFW(buf,0)=0x1d0;
  5665. WBUFL(buf,2)=sd->bl.id;
  5666. WBUFW(buf,6)=sd->spiritball;
  5667. clif_send(buf,packet_len_table[0x1d0],&sd->bl,AREA);
  5668. return 0;
  5669. }
  5670. /*==========================================
  5671. *
  5672. *------------------------------------------
  5673. */
  5674. int clif_combo_delay(struct block_list *bl,int wait)
  5675. {
  5676. unsigned char buf[32];
  5677. nullpo_retr(0, bl);
  5678. WBUFW(buf,0)=0x1d2;
  5679. WBUFL(buf,2)=bl->id;
  5680. WBUFL(buf,6)=wait;
  5681. clif_send(buf,packet_len_table[0x1d2],bl,AREA);
  5682. return 0;
  5683. }
  5684. /*==========================================
  5685. *白刃取り
  5686. *------------------------------------------
  5687. */
  5688. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5689. int _bool)
  5690. {
  5691. unsigned char buf[32];
  5692. nullpo_retr(0, src);
  5693. nullpo_retr(0, dst);
  5694. WBUFW(buf,0)=0x1d1;
  5695. WBUFL(buf,2)=src->id;
  5696. WBUFL(buf,6)=dst->id;
  5697. WBUFL(buf,10)=_bool;
  5698. clif_send(buf,packet_len_table[0x1d1],src,AREA);
  5699. return 0;
  5700. }
  5701. /*==========================================
  5702. *
  5703. *------------------------------------------
  5704. */
  5705. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5706. {
  5707. struct block_list bl;
  5708. unsigned char buf[32];
  5709. bl.type = BL_NUL;
  5710. bl.m = m;
  5711. bl.x = x;
  5712. bl.y = y;
  5713. WBUFW(buf,0) = 0x192;
  5714. WBUFW(buf,2) = x;
  5715. WBUFW(buf,4) = y;
  5716. WBUFW(buf,6) = cell_type;
  5717. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  5718. if(!type)
  5719. clif_send(buf,packet_len_table[0x192],&bl,AREA);
  5720. else
  5721. clif_send(buf,packet_len_table[0x192],&bl,ALL_SAMEMAP);
  5722. return 0;
  5723. }
  5724. /*==========================================
  5725. * MVPエフェクト
  5726. *------------------------------------------
  5727. */
  5728. int clif_mvp_effect(struct map_session_data *sd)
  5729. {
  5730. unsigned char buf[16];
  5731. nullpo_retr(0, sd);
  5732. WBUFW(buf,0)=0x10c;
  5733. WBUFL(buf,2)=sd->bl.id;
  5734. clif_send(buf,packet_len_table[0x10c],&sd->bl,AREA);
  5735. return 0;
  5736. }
  5737. /*==========================================
  5738. * MVPアイテム所得
  5739. *------------------------------------------
  5740. */
  5741. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5742. {
  5743. int view,fd;
  5744. nullpo_retr(0, sd);
  5745. fd=sd->fd;
  5746. WFIFOHEAD(fd,packet_len_table[0x10a]);
  5747. WFIFOW(fd,0)=0x10a;
  5748. if((view = itemdb_viewid(nameid)) > 0)
  5749. WFIFOW(fd,2)=view;
  5750. else
  5751. WFIFOW(fd,2)=nameid;
  5752. WFIFOSET(fd,packet_len_table[0x10a]);
  5753. return 0;
  5754. }
  5755. /*==========================================
  5756. * MVP経験値所得
  5757. *------------------------------------------
  5758. */
  5759. int clif_mvp_exp(struct map_session_data *sd,int exp)
  5760. {
  5761. int fd;
  5762. nullpo_retr(0, sd);
  5763. fd=sd->fd;
  5764. WFIFOHEAD(fd,packet_len_table[0x10b]);
  5765. WFIFOW(fd,0)=0x10b;
  5766. WFIFOL(fd,2)=exp;
  5767. WFIFOSET(fd,packet_len_table[0x10b]);
  5768. return 0;
  5769. }
  5770. /*==========================================
  5771. * ギルド作成可否通知
  5772. *------------------------------------------
  5773. */
  5774. int clif_guild_created(struct map_session_data *sd,int flag)
  5775. {
  5776. int fd;
  5777. nullpo_retr(0, sd);
  5778. fd=sd->fd;
  5779. WFIFOHEAD(fd,packet_len_table[0x167]);
  5780. WFIFOW(fd,0)=0x167;
  5781. WFIFOB(fd,2)=flag;
  5782. WFIFOSET(fd,packet_len_table[0x167]);
  5783. return 0;
  5784. }
  5785. /*==========================================
  5786. * ギルド所属通知
  5787. *------------------------------------------
  5788. */
  5789. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5790. {
  5791. int ps,fd;
  5792. nullpo_retr(0, sd);
  5793. nullpo_retr(0, g);
  5794. fd=sd->fd;
  5795. ps=guild_getposition(sd,g);
  5796. WFIFOHEAD(fd,packet_len_table[0x16c]);
  5797. memset(WFIFOP(fd,0),0,packet_len_table[0x16c]);
  5798. WFIFOW(fd,0)=0x16c;
  5799. WFIFOL(fd,2)=g->guild_id;
  5800. WFIFOL(fd,6)=g->emblem_id;
  5801. WFIFOL(fd,10)=g->position[ps].mode;
  5802. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5803. WFIFOSET(fd,packet_len_table[0x16c]);
  5804. return 0;
  5805. }
  5806. /*==========================================
  5807. * ギルドメンバログイン通知
  5808. *------------------------------------------
  5809. */
  5810. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5811. {
  5812. unsigned char buf[64];
  5813. nullpo_retr(0, g);
  5814. // printf("clif_guild_message(%s, %d, %s)\n", g->name, account_id, mes);
  5815. WBUFW(buf, 0)=0x16d;
  5816. WBUFL(buf, 2)=g->member[idx].account_id;
  5817. WBUFL(buf, 6)=g->member[idx].char_id;
  5818. WBUFL(buf,10)=flag;
  5819. if(g->member[idx].sd==NULL){
  5820. struct map_session_data *sd=guild_getavailablesd(g);
  5821. if(sd!=NULL)
  5822. clif_send(buf,packet_len_table[0x16d],&sd->bl,GUILD);
  5823. }else
  5824. clif_send(buf,packet_len_table[0x16d],&g->member[idx].sd->bl,GUILD_WOS);
  5825. return 0;
  5826. }
  5827. // Function `clif_guild_memberlogin_notice` sends info about
  5828. // logins and logouts of a guild member to the rest members.
  5829. // But at the 1st time (after a player login or map changing)
  5830. // the client won't show the message.
  5831. // So I suggest use this function for sending "first-time-info"
  5832. // to some player on entering the game or changing location.
  5833. // At next time the client would always show the message.
  5834. // The function sends all the statuses in the single packet
  5835. // to economize traffic. [LuzZza]
  5836. int clif_guild_send_onlineinfo(struct map_session_data *sd) {
  5837. struct guild *g;
  5838. char buf[14*128];
  5839. int i, count=0, p_len;
  5840. nullpo_retr(0, sd);
  5841. p_len = packet_len_table[0x16d];
  5842. if(!(g = guild_search(sd->status.guild_id)))
  5843. return 0;
  5844. for(i=0; i<g->max_member; i++) {
  5845. if(g->member[i].account_id > 0 &&
  5846. g->member[i].account_id != sd->status.account_id) {
  5847. WBUFW(buf,count*p_len) = 0x16d;
  5848. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5849. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5850. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5851. count++;
  5852. }
  5853. }
  5854. clif_send(buf,p_len*count,&sd->bl,SELF);
  5855. return 0;
  5856. }
  5857. /*==========================================
  5858. * ギルドマスター通知(14dへの応答)
  5859. *------------------------------------------
  5860. */
  5861. int clif_guild_masterormember(struct map_session_data *sd)
  5862. {
  5863. int type=0x57,fd;
  5864. nullpo_retr(0, sd);
  5865. fd=sd->fd;
  5866. if(sd->state.gmaster_flag)
  5867. type=0xd7;
  5868. WFIFOHEAD(fd,packet_len_table[0x14e]);
  5869. WFIFOW(fd,0)=0x14e;
  5870. WFIFOL(fd,2)=type;
  5871. WFIFOSET(fd,packet_len_table[0x14e]);
  5872. return 0;
  5873. }
  5874. /*==========================================
  5875. * Basic Info (Territories [Valaris])
  5876. *------------------------------------------
  5877. */
  5878. int clif_guild_basicinfo(struct map_session_data *sd)
  5879. {
  5880. int fd,i,t=0;
  5881. struct guild *g;
  5882. struct guild_castle *gc=NULL;
  5883. nullpo_retr(0, sd);
  5884. fd=sd->fd;
  5885. g=guild_search(sd->status.guild_id);
  5886. if(g==NULL)
  5887. return 0;
  5888. WFIFOHEAD(fd,packet_len_table[0x1b6]);
  5889. WFIFOW(fd, 0)=0x1b6;//0x150;
  5890. WFIFOL(fd, 2)=g->guild_id;
  5891. WFIFOL(fd, 6)=g->guild_lv;
  5892. WFIFOL(fd,10)=g->connect_member;
  5893. WFIFOL(fd,14)=g->max_member;
  5894. WFIFOL(fd,18)=g->average_lv;
  5895. WFIFOL(fd,22)=g->exp;
  5896. WFIFOL(fd,26)=g->next_exp;
  5897. WFIFOL(fd,30)=0; // 上納
  5898. WFIFOL(fd,34)=0; // VW(性格の悪さ?:性向グラフ左右)
  5899. WFIFOL(fd,38)=0; // RF(正義の度合い?:性向グラフ上下)
  5900. WFIFOL(fd,42)=0; // 人数?
  5901. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5902. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5903. for(i=0;i<MAX_GUILDCASTLE;i++){
  5904. gc=guild_castle_search(i);
  5905. if(!gc) continue;
  5906. if(g->guild_id == gc->guild_id) t++;
  5907. }
  5908. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  5909. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  5910. else
  5911. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  5912. WFIFOSET(fd,packet_len_table[WFIFOW(fd,0)]);
  5913. clif_guild_emblem(sd,g); // Guild emblem vanish fix [Valaris]
  5914. return 0;
  5915. }
  5916. /*==========================================
  5917. * ギルド同盟/敵対情報
  5918. *------------------------------------------
  5919. */
  5920. int clif_guild_allianceinfo(struct map_session_data *sd)
  5921. {
  5922. int fd,i,c;
  5923. struct guild *g;
  5924. nullpo_retr(0, sd);
  5925. fd=sd->fd;
  5926. g=guild_search(sd->status.guild_id);
  5927. if(g==NULL)
  5928. return 0;
  5929. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5930. WFIFOW(fd, 0)=0x14c;
  5931. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5932. struct guild_alliance *a=&g->alliance[i];
  5933. if(a->guild_id>0){
  5934. WFIFOL(fd,c*32+4)=a->opposition;
  5935. WFIFOL(fd,c*32+8)=a->guild_id;
  5936. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5937. c++;
  5938. }
  5939. }
  5940. WFIFOW(fd, 2)=c*32+4;
  5941. WFIFOSET(fd,WFIFOW(fd,2));
  5942. return 0;
  5943. }
  5944. /*==========================================
  5945. * ギルドメンバーリスト
  5946. *------------------------------------------
  5947. */
  5948. int clif_guild_memberlist(struct map_session_data *sd)
  5949. {
  5950. int fd;
  5951. int i,c;
  5952. struct guild *g;
  5953. nullpo_retr(0, sd);
  5954. fd=sd->fd;
  5955. if (!fd)
  5956. return 0;
  5957. g=guild_search(sd->status.guild_id);
  5958. if(g==NULL)
  5959. return 0;
  5960. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5961. WFIFOW(fd, 0)=0x154;
  5962. for(i=0,c=0;i<g->max_member;i++){
  5963. struct guild_member *m=&g->member[i];
  5964. if(m->account_id==0)
  5965. continue;
  5966. WFIFOL(fd,c*104+ 4)=m->account_id;
  5967. WFIFOL(fd,c*104+ 8)=m->char_id;
  5968. WFIFOW(fd,c*104+12)=m->hair;
  5969. WFIFOW(fd,c*104+14)=m->hair_color;
  5970. WFIFOW(fd,c*104+16)=m->gender;
  5971. WFIFOW(fd,c*104+18)=m->class_;
  5972. WFIFOW(fd,c*104+20)=m->lv;
  5973. WFIFOL(fd,c*104+22)=m->exp;
  5974. WFIFOL(fd,c*104+26)=m->online;
  5975. WFIFOL(fd,c*104+30)=m->position;
  5976. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5977. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5978. c++;
  5979. }
  5980. WFIFOW(fd, 2)=c*104+4;
  5981. WFIFOSET(fd,WFIFOW(fd,2));
  5982. return 0;
  5983. }
  5984. /*==========================================
  5985. * ギルド役職名リスト
  5986. *------------------------------------------
  5987. */
  5988. int clif_guild_positionnamelist(struct map_session_data *sd)
  5989. {
  5990. int i,fd;
  5991. struct guild *g;
  5992. nullpo_retr(0, sd);
  5993. fd=sd->fd;
  5994. g=guild_search(sd->status.guild_id);
  5995. if(g==NULL)
  5996. return 0;
  5997. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5998. WFIFOW(fd, 0)=0x166;
  5999. for(i=0;i<MAX_GUILDPOSITION;i++){
  6000. WFIFOL(fd,i*28+4)=i;
  6001. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6002. }
  6003. WFIFOW(fd,2)=i*28+4;
  6004. WFIFOSET(fd,WFIFOW(fd,2));
  6005. return 0;
  6006. }
  6007. /*==========================================
  6008. * ギルド役職情報リスト
  6009. *------------------------------------------
  6010. */
  6011. int clif_guild_positioninfolist(struct map_session_data *sd)
  6012. {
  6013. int i,fd;
  6014. struct guild *g;
  6015. nullpo_retr(0, sd);
  6016. fd=sd->fd;
  6017. g=guild_search(sd->status.guild_id);
  6018. if(g==NULL)
  6019. return 0;
  6020. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6021. WFIFOW(fd, 0)=0x160;
  6022. for(i=0;i<MAX_GUILDPOSITION;i++){
  6023. struct guild_position *p=&g->position[i];
  6024. WFIFOL(fd,i*16+ 4)=i;
  6025. WFIFOL(fd,i*16+ 8)=p->mode;
  6026. WFIFOL(fd,i*16+12)=i;
  6027. WFIFOL(fd,i*16+16)=p->exp_mode;
  6028. }
  6029. WFIFOW(fd, 2)=i*16+4;
  6030. WFIFOSET(fd,WFIFOW(fd,2));
  6031. return 0;
  6032. }
  6033. /*==========================================
  6034. * ギルド役職変更通知
  6035. *------------------------------------------
  6036. */
  6037. int clif_guild_positionchanged(struct guild *g,int idx)
  6038. {
  6039. struct map_session_data *sd;
  6040. unsigned char buf[128];
  6041. nullpo_retr(0, g);
  6042. WBUFW(buf, 0)=0x174;
  6043. WBUFW(buf, 2)=44;
  6044. WBUFL(buf, 4)=idx;
  6045. WBUFL(buf, 8)=g->position[idx].mode;
  6046. WBUFL(buf,12)=idx;
  6047. WBUFL(buf,16)=g->position[idx].exp_mode;
  6048. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6049. if( (sd=guild_getavailablesd(g))!=NULL )
  6050. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6051. return 0;
  6052. }
  6053. /*==========================================
  6054. * ギルドメンバ変更通知
  6055. *------------------------------------------
  6056. */
  6057. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6058. {
  6059. struct map_session_data *sd;
  6060. unsigned char buf[64];
  6061. nullpo_retr(0, g);
  6062. WBUFW(buf, 0)=0x156;
  6063. WBUFW(buf, 2)=16;
  6064. WBUFL(buf, 4)=g->member[idx].account_id;
  6065. WBUFL(buf, 8)=g->member[idx].char_id;
  6066. WBUFL(buf,12)=g->member[idx].position;
  6067. if( (sd=guild_getavailablesd(g))!=NULL )
  6068. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6069. return 0;
  6070. }
  6071. /*==========================================
  6072. * ギルドエンブレム送信
  6073. *------------------------------------------
  6074. */
  6075. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6076. {
  6077. int fd;
  6078. nullpo_retr(0, sd);
  6079. nullpo_retr(0, g);
  6080. fd=sd->fd;
  6081. if(g->emblem_len<=0)
  6082. return 0;
  6083. WFIFOHEAD(fd,g->emblem_len+12);
  6084. WFIFOW(fd,0)=0x152;
  6085. WFIFOW(fd,2)=g->emblem_len+12;
  6086. WFIFOL(fd,4)=g->guild_id;
  6087. WFIFOL(fd,8)=g->emblem_id;
  6088. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6089. WFIFOSET(fd,WFIFOW(fd,2));
  6090. return 0;
  6091. }
  6092. /*==========================================
  6093. * ギルドスキル送信
  6094. *------------------------------------------
  6095. */
  6096. int clif_guild_skillinfo(struct map_session_data *sd)
  6097. {
  6098. int fd;
  6099. int i,id,c,up=1;
  6100. struct guild *g;
  6101. nullpo_retr(0, sd);
  6102. fd=sd->fd;
  6103. g=guild_search(sd->status.guild_id);
  6104. if(g==NULL)
  6105. return 0;
  6106. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6107. WFIFOW(fd,0)=0x0162;
  6108. WFIFOW(fd,4)=g->skill_point;
  6109. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6110. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6111. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6112. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  6113. WFIFOW(fd,c*37+10) = 0;
  6114. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6115. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6116. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6117. memset(WFIFOP(fd,c*37+18),0,24);
  6118. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6119. up = 1;
  6120. else
  6121. up = 0;
  6122. WFIFOB(fd,c*37+42)= up;
  6123. c++;
  6124. }
  6125. }
  6126. WFIFOW(fd,2)=c*37+6;
  6127. WFIFOSET(fd,WFIFOW(fd,2));
  6128. return 0;
  6129. }
  6130. /*==========================================
  6131. * ギルド告知送信
  6132. *------------------------------------------
  6133. */
  6134. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6135. {
  6136. int fd;
  6137. nullpo_retr(0, sd);
  6138. nullpo_retr(0, g);
  6139. fd = sd->fd;
  6140. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6141. return 0;
  6142. if (fd <= 0)
  6143. return 0;
  6144. if(*g->mes1==0 && *g->mes2==0)
  6145. return 0;
  6146. WFIFOHEAD(fd,packet_len_table[0x16f]);
  6147. WFIFOW(fd,0)=0x16f;
  6148. memcpy(WFIFOP(fd,2),g->mes1,60);
  6149. memcpy(WFIFOP(fd,62),g->mes2,120);
  6150. WFIFOSET(fd,packet_len_table[0x16f]);
  6151. return 0;
  6152. }
  6153. /*==========================================
  6154. * ギルドメンバ勧誘
  6155. *------------------------------------------
  6156. */
  6157. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6158. {
  6159. int fd;
  6160. nullpo_retr(0, sd);
  6161. nullpo_retr(0, g);
  6162. fd=sd->fd;
  6163. WFIFOHEAD(fd,packet_len_table[0x16a]);
  6164. WFIFOW(fd,0)=0x16a;
  6165. WFIFOL(fd,2)=g->guild_id;
  6166. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6167. WFIFOSET(fd,packet_len_table[0x16a]);
  6168. return 0;
  6169. }
  6170. /*==========================================
  6171. * ギルドメンバ勧誘結果
  6172. *------------------------------------------
  6173. */
  6174. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6175. {
  6176. int fd;
  6177. nullpo_retr(0, sd);
  6178. fd=sd->fd;
  6179. WFIFOHEAD(fd,packet_len_table[0x169]);
  6180. WFIFOW(fd,0)=0x169;
  6181. WFIFOB(fd,2)=flag;
  6182. WFIFOSET(fd,packet_len_table[0x169]);
  6183. return 0;
  6184. }
  6185. /*==========================================
  6186. * ギルドメンバ脱退通知
  6187. *------------------------------------------
  6188. */
  6189. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6190. {
  6191. unsigned char buf[128];
  6192. nullpo_retr(0, sd);
  6193. WBUFW(buf, 0)=0x15a;
  6194. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6195. memcpy(WBUFP(buf,26),mes,40);
  6196. clif_send(buf,packet_len_table[0x15a],&sd->bl,GUILD);
  6197. return 0;
  6198. }
  6199. /*==========================================
  6200. * ギルドメンバ追放通知
  6201. *------------------------------------------
  6202. */
  6203. int clif_guild_explusion(struct map_session_data *sd,const char *name,const char *mes,
  6204. int account_id)
  6205. {
  6206. unsigned char buf[128];
  6207. nullpo_retr(0, sd);
  6208. WBUFW(buf, 0)=0x15c;
  6209. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6210. memcpy(WBUFP(buf,26),mes,40);
  6211. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6212. clif_send(buf,packet_len_table[0x15c],&sd->bl,GUILD);
  6213. return 0;
  6214. }
  6215. /*==========================================
  6216. * ギルド追放メンバリスト
  6217. *------------------------------------------
  6218. */
  6219. int clif_guild_explusionlist(struct map_session_data *sd)
  6220. {
  6221. int fd;
  6222. int i,c;
  6223. struct guild *g;
  6224. nullpo_retr(0, sd);
  6225. fd=sd->fd;
  6226. g=guild_search(sd->status.guild_id);
  6227. if(g==NULL)
  6228. return 0;
  6229. WFIFOHEAD(fd,MAX_GUILDEXPLUSION * 88 + 4);
  6230. WFIFOW(fd,0)=0x163;
  6231. for(i=c=0;i<MAX_GUILDEXPLUSION;i++){
  6232. struct guild_explusion *e=&g->explusion[i];
  6233. if(e->account_id>0){
  6234. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6235. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6236. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6237. c++;
  6238. }
  6239. }
  6240. WFIFOW(fd,2)=c*88+4;
  6241. WFIFOSET(fd,WFIFOW(fd,2));
  6242. return 0;
  6243. }
  6244. /*==========================================
  6245. * ギルド会話
  6246. *------------------------------------------
  6247. */
  6248. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6249. {
  6250. struct map_session_data *sd;
  6251. unsigned char *buf;
  6252. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6253. WBUFW(buf, 0) = 0x17f;
  6254. WBUFW(buf, 2) = len + 4;
  6255. memcpy(WBUFP(buf,4), mes, len);
  6256. if ((sd = guild_getavailablesd(g)) != NULL)
  6257. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6258. if(buf) aFree(buf);
  6259. return 0;
  6260. }
  6261. /*==========================================
  6262. * ギルドスキル割り振り通知
  6263. *------------------------------------------
  6264. */
  6265. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6266. {
  6267. int fd;
  6268. nullpo_retr(0, sd);
  6269. fd=sd->fd;
  6270. WFIFOHEAD(fd,11);
  6271. WFIFOW(fd,0) = 0x10e;
  6272. WFIFOW(fd,2) = skill_num;
  6273. WFIFOW(fd,4) = lv;
  6274. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6275. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6276. WFIFOB(fd,10) = 1;
  6277. WFIFOSET(fd,11);
  6278. return 0;
  6279. }
  6280. /*==========================================
  6281. * ギルド同盟要請
  6282. *------------------------------------------
  6283. */
  6284. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6285. {
  6286. int fd;
  6287. nullpo_retr(0, sd);
  6288. fd=sd->fd;
  6289. WFIFOHEAD(fd,packet_len_table[0x171]);
  6290. WFIFOW(fd,0)=0x171;
  6291. WFIFOL(fd,2)=account_id;
  6292. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6293. WFIFOSET(fd,packet_len_table[0x171]);
  6294. return 0;
  6295. }
  6296. /*==========================================
  6297. * ギルド同盟結果
  6298. *------------------------------------------
  6299. */
  6300. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6301. {
  6302. int fd;
  6303. nullpo_retr(0, sd);
  6304. fd=sd->fd;
  6305. WFIFOHEAD(fd,packet_len_table[0x173]);
  6306. WFIFOW(fd,0)=0x173;
  6307. WFIFOL(fd,2)=flag;
  6308. WFIFOSET(fd,packet_len_table[0x173]);
  6309. return 0;
  6310. }
  6311. /*==========================================
  6312. * ギルド関係解消通知
  6313. *------------------------------------------
  6314. */
  6315. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6316. {
  6317. int fd;
  6318. nullpo_retr(0, sd);
  6319. fd = sd->fd;
  6320. if (fd <= 0)
  6321. return 0;
  6322. WFIFOHEAD(fd,packet_len_table[0x184]);
  6323. WFIFOW(fd,0)=0x184;
  6324. WFIFOL(fd,2)=guild_id;
  6325. WFIFOL(fd,6)=flag;
  6326. WFIFOSET(fd,packet_len_table[0x184]);
  6327. return 0;
  6328. }
  6329. /*==========================================
  6330. * ギルド敵対結果
  6331. *------------------------------------------
  6332. */
  6333. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6334. {
  6335. int fd;
  6336. nullpo_retr(0, sd);
  6337. fd=sd->fd;
  6338. WFIFOHEAD(fd,packet_len_table[0x181]);
  6339. WFIFOW(fd,0)=0x181;
  6340. WFIFOB(fd,2)=flag;
  6341. WFIFOSET(fd,packet_len_table[0x181]);
  6342. return 0;
  6343. }
  6344. /*==========================================
  6345. * ギルド関係追加
  6346. *------------------------------------------
  6347. */
  6348. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6349. {
  6350. unsigned char buf[64];
  6351. WBUFW(fd,0)=0x185;
  6352. WBUFL(fd,2)=g->alliance[idx].opposition;
  6353. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6354. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6355. clif_send(buf,packet_len_table[0x185],guild_getavailablesd(g),GUILD);
  6356. return 0;
  6357. }*/
  6358. /*==========================================
  6359. * ギルド解散通知
  6360. *------------------------------------------
  6361. */
  6362. int clif_guild_broken(struct map_session_data *sd,int flag)
  6363. {
  6364. int fd;
  6365. nullpo_retr(0, sd);
  6366. fd=sd->fd;
  6367. WFIFOHEAD(fd,packet_len_table[0x15e]);
  6368. WFIFOW(fd,0)=0x15e;
  6369. WFIFOL(fd,2)=flag;
  6370. WFIFOSET(fd,packet_len_table[0x15e]);
  6371. return 0;
  6372. }
  6373. /*==========================================
  6374. * エモーション
  6375. *------------------------------------------
  6376. */
  6377. void clif_emotion(struct block_list *bl,int type)
  6378. {
  6379. unsigned char buf[8];
  6380. nullpo_retv(bl);
  6381. WBUFW(buf,0)=0xc0;
  6382. WBUFL(buf,2)=bl->id;
  6383. WBUFB(buf,6)=type;
  6384. clif_send(buf,packet_len_table[0xc0],bl,AREA);
  6385. }
  6386. /*==========================================
  6387. * トーキーボックス
  6388. *------------------------------------------
  6389. */
  6390. void clif_talkiebox(struct block_list *bl,char* talkie)
  6391. {
  6392. unsigned char buf[86];
  6393. nullpo_retv(bl);
  6394. WBUFW(buf,0)=0x191;
  6395. WBUFL(buf,2)=bl->id;
  6396. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6397. clif_send(buf,packet_len_table[0x191],bl,AREA);
  6398. }
  6399. /*==========================================
  6400. * 結婚エフェクト
  6401. *------------------------------------------
  6402. */
  6403. void clif_wedding_effect(struct block_list *bl) {
  6404. unsigned char buf[6];
  6405. nullpo_retv(bl);
  6406. WBUFW(buf,0) = 0x1ea;
  6407. WBUFL(buf,2) = bl->id;
  6408. clif_send(buf, packet_len_table[0x1ea], bl, AREA);
  6409. }
  6410. /*==========================================
  6411. * あなたに逢いたい使用時名前叫び
  6412. *------------------------------------------
  6413. void clif_callpartner(struct map_session_data *sd)
  6414. {
  6415. unsigned char buf[26];
  6416. char *p;
  6417. nullpo_retv(sd);
  6418. if(sd->status.partner_id){
  6419. WBUFW(buf,0)=0x1e6;
  6420. p = map_charid2nick(sd->status.partner_id);
  6421. if(p){
  6422. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6423. }else{
  6424. map_reqchariddb(sd,sd->status.partner_id);
  6425. chrif_searchcharid(sd->status.partner_id);
  6426. WBUFB(buf,2) = 0;
  6427. }
  6428. clif_send(buf,packet_len_table[0x1e6],&sd->bl,AREA);
  6429. }
  6430. return;
  6431. }
  6432. */
  6433. /*==========================================
  6434. * Adopt baby [Celest]
  6435. *------------------------------------------
  6436. */
  6437. void clif_adopt_process(struct map_session_data *sd)
  6438. {
  6439. int fd;
  6440. nullpo_retv(sd);
  6441. fd=sd->fd;
  6442. WFIFOHEAD(fd,packet_len_table[0x1f8]);
  6443. WFIFOW(fd,0)=0x1f8;
  6444. WFIFOSET(fd,packet_len_table[0x1f8]);
  6445. }
  6446. /*==========================================
  6447. * Marry [DracoRPG]
  6448. *------------------------------------------
  6449. */
  6450. void clif_marriage_process(struct map_session_data *sd)
  6451. {
  6452. int fd;
  6453. nullpo_retv(sd);
  6454. fd=sd->fd;
  6455. WFIFOHEAD(fd,packet_len_table[0x1e4]);
  6456. WFIFOW(fd,0)=0x1e4;
  6457. WFIFOSET(fd,packet_len_table[0x1e4]);
  6458. }
  6459. /*==========================================
  6460. * Notice of divorce
  6461. *------------------------------------------
  6462. */
  6463. void clif_divorced(struct map_session_data *sd, char *name)
  6464. {
  6465. int fd;
  6466. nullpo_retv(sd);
  6467. fd=sd->fd;
  6468. WFIFOHEAD(fd,packet_len_table[0x205]);
  6469. WFIFOW(fd,0)=0x205;
  6470. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6471. WFIFOSET(fd, packet_len_table[0x205]);
  6472. }
  6473. /*==========================================
  6474. *
  6475. *------------------------------------------
  6476. */
  6477. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6478. nullpo_retv(sd);
  6479. WFIFOHEAD(fd,packet_len_table[0x1f6]);
  6480. WFIFOW(fd,0)=0x1f6;
  6481. WFIFOSET(fd, packet_len_table[0x1f6]);
  6482. }
  6483. /*==========================================
  6484. *
  6485. *------------------------------------------
  6486. */
  6487. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6488. nullpo_retv(sd);
  6489. WFIFOHEAD(fd,packet_len_table[0x1e2]);
  6490. WFIFOW(fd,0)=0x1e2;
  6491. WFIFOSET(fd, packet_len_table[0x1e2]);
  6492. }
  6493. /*==========================================
  6494. * 座る
  6495. *------------------------------------------
  6496. */
  6497. void clif_sitting(struct map_session_data *sd)
  6498. {
  6499. unsigned char buf[64];
  6500. nullpo_retv(sd);
  6501. WBUFW(buf, 0) = 0x8a;
  6502. WBUFL(buf, 2) = sd->bl.id;
  6503. WBUFB(buf,26) = 2;
  6504. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  6505. }
  6506. /*==========================================
  6507. *
  6508. *------------------------------------------
  6509. */
  6510. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  6511. {
  6512. unsigned char *buf;
  6513. nullpo_retr(0, sd);
  6514. buf = (unsigned char*)aMallocA((len + 5)*sizeof(unsigned char));
  6515. WBUFW(buf, 0) = 0x17f;
  6516. WBUFW(buf, 2) = len + 5;
  6517. memcpy(WBUFP(buf,4), mes, len);
  6518. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6519. if(buf) aFree(buf);
  6520. return 0;
  6521. }
  6522. /*==========================================
  6523. *
  6524. *------------------------------------------
  6525. */
  6526. int clif_GM_kickack(struct map_session_data *sd, int id)
  6527. {
  6528. int fd;
  6529. nullpo_retr(0, sd);
  6530. fd = sd->fd;
  6531. WFIFOHEAD(fd,packet_len_table[0xcd]);
  6532. WFIFOW(fd,0) = 0xcd;
  6533. WFIFOL(fd,2) = id;
  6534. WFIFOSET(fd, packet_len_table[0xcd]);
  6535. return 0;
  6536. }
  6537. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6538. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6539. {
  6540. nullpo_retr(0, tsd);
  6541. if(type)
  6542. clif_GM_kickack(sd,tsd->status.account_id);
  6543. WFIFOHEAD(tsd->fd,packet_len_table[0x18b]);
  6544. WFIFOW(tsd->fd,0) = 0x18b;
  6545. WFIFOW(tsd->fd,2) = 0;
  6546. WFIFOSET(tsd->fd,packet_len_table[0x18b]);
  6547. if (tsd->fd)
  6548. {
  6549. ShowDebug("clif_GM_kick: Disconnecting session #%d\n", tsd->fd);
  6550. clif_setwaitclose(tsd->fd);
  6551. } else { //Player has no session attached, delete it right away. [Skotlex]
  6552. map_quit(tsd);
  6553. }
  6554. return 0;
  6555. }
  6556. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6557. {
  6558. int fd;
  6559. nullpo_retr(0, sd);
  6560. nullpo_retr(0, tsd);
  6561. fd = tsd->fd;
  6562. if (fd <= 0)
  6563. return 0;
  6564. WFIFOHEAD(fd,packet_len_table[0x14b]);
  6565. WFIFOW(fd,0) = 0x14b;
  6566. WFIFOB(fd,2) = 0;
  6567. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6568. WFIFOSET(fd, packet_len_table[0x14b]);
  6569. return 0;
  6570. }
  6571. /*==========================================
  6572. *
  6573. *------------------------------------------
  6574. */
  6575. int clif_timedout(struct map_session_data *sd)
  6576. {
  6577. nullpo_retr(0, sd);
  6578. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6579. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6580. clif_setwaitclose(sd->fd); // Set session to EOF
  6581. return 0;
  6582. }
  6583. /*==========================================
  6584. * Wis拒否許可応答
  6585. *------------------------------------------
  6586. */
  6587. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6588. {
  6589. int fd;
  6590. nullpo_retr(0, sd);
  6591. fd=sd->fd;
  6592. WFIFOHEAD(fd,packet_len_table[0xd1]);
  6593. WFIFOW(fd,0)=0xd1;
  6594. WFIFOB(fd,2)=type;
  6595. WFIFOB(fd,3)=flag;
  6596. WFIFOSET(fd,packet_len_table[0xd1]);
  6597. return 0;
  6598. }
  6599. /*==========================================
  6600. * Wis全拒否許可応答
  6601. *------------------------------------------
  6602. */
  6603. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6604. {
  6605. int fd;
  6606. nullpo_retr(0, sd);
  6607. fd=sd->fd;
  6608. WFIFOHEAD(fd,packet_len_table[0xd2]);
  6609. WFIFOW(fd,0)=0xd2;
  6610. WFIFOB(fd,2)=type;
  6611. WFIFOB(fd,3)=flag;
  6612. WFIFOSET(fd,packet_len_table[0xd2]);
  6613. return 0;
  6614. }
  6615. /*==========================================
  6616. * サウンドエフェクト
  6617. *------------------------------------------
  6618. */
  6619. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  6620. {
  6621. int fd;
  6622. nullpo_retv(sd);
  6623. nullpo_retv(bl);
  6624. fd=sd->fd;
  6625. WFIFOHEAD(fd,packet_len_table[0x1d3]);
  6626. WFIFOW(fd,0)=0x1d3;
  6627. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6628. WFIFOB(fd,26)=type;
  6629. WFIFOL(fd,27)=0;
  6630. WFIFOL(fd,31)=bl->id;
  6631. WFIFOSET(fd,packet_len_table[0x1d3]);
  6632. return;
  6633. }
  6634. int clif_soundeffectall(struct block_list *bl, char *name, int type, int coverage)
  6635. {
  6636. unsigned char buf[40];
  6637. memset(buf, 0, packet_len_table[0x1d3]);
  6638. if(coverage < 0 || coverage > 22){
  6639. ShowError("clif_soundeffectall: undefined coverage.\n");
  6640. return 0;
  6641. }
  6642. nullpo_retr(0, bl);
  6643. WBUFW(buf,0)=0x1d3;
  6644. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6645. WBUFB(buf,26)=type;
  6646. WBUFL(buf,27)=0;
  6647. WBUFL(buf,31)=bl->id;
  6648. clif_send(buf, packet_len_table[0x1d3], bl, coverage);
  6649. return 0;
  6650. }
  6651. // displaying special effects (npcs, weather, etc) [Valaris]
  6652. int clif_specialeffect(struct block_list *bl, int type, int flag)
  6653. {
  6654. unsigned char buf[24];
  6655. nullpo_retr(0, bl);
  6656. memset(buf, 0, packet_len_table[0x1f3]);
  6657. WBUFW(buf,0) = 0x1f3;
  6658. WBUFL(buf,2) = bl->id;
  6659. WBUFL(buf,6) = type;
  6660. switch (flag) {
  6661. case 4:
  6662. clif_send(buf, packet_len_table[0x1f3], bl, AREA_WOS);
  6663. break;
  6664. case 3:
  6665. clif_send(buf, packet_len_table[0x1f3], bl, ALL_CLIENT);
  6666. break;
  6667. case 2:
  6668. clif_send(buf, packet_len_table[0x1f3], bl, ALL_SAMEMAP);
  6669. break;
  6670. case 1:
  6671. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  6672. break;
  6673. default:
  6674. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  6675. }
  6676. if (disguised(bl)) {
  6677. WBUFL(buf,2) = -bl->id;
  6678. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  6679. }
  6680. return 0;
  6681. }
  6682. // refresh the client's screen, getting rid of any effects
  6683. int clif_refresh(struct map_session_data *sd) {
  6684. nullpo_retr(-1, sd);
  6685. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6686. map_foreachinarea(clif_getareachar,sd->bl.m,sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,BL_ALL,sd);
  6687. return 0;
  6688. }
  6689. // updates the object's (bl) name on client
  6690. int clif_charnameack (int fd, struct block_list *bl)
  6691. {
  6692. unsigned char buf[103];
  6693. int cmd = 0x95;
  6694. nullpo_retr(0, bl);
  6695. WBUFW(buf,0) = cmd;
  6696. WBUFL(buf,2) = bl->id;
  6697. switch(bl->type) {
  6698. case BL_PC:
  6699. {
  6700. struct map_session_data *ssd = (struct map_session_data *)bl;
  6701. struct party *p = NULL;
  6702. struct guild *g = NULL;
  6703. nullpo_retr(0, ssd);
  6704. if (strlen(ssd->fakename)>1) {
  6705. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6706. break;
  6707. }
  6708. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6709. if (ssd->status.party_id > 0)
  6710. p = party_search(ssd->status.party_id);
  6711. if (ssd->status.guild_id > 0)
  6712. g = guild_search(ssd->status.guild_id);
  6713. if (p == NULL && g == NULL)
  6714. break;
  6715. WBUFW(buf, 0) = cmd = 0x195;
  6716. if (p)
  6717. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  6718. else
  6719. WBUFB(buf,30) = 0;
  6720. if (g)
  6721. {
  6722. int i, ps = -1;
  6723. for(i = 0; i < g->max_member; i++) {
  6724. if (g->member[i].account_id == ssd->status.account_id &&
  6725. g->member[i].char_id == ssd->status.char_id )
  6726. {
  6727. ps = g->member[i].position;
  6728. break;
  6729. }
  6730. }
  6731. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6732. {
  6733. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6734. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6735. } else { //Assume no guild.
  6736. WBUFB(buf,54) = 0;
  6737. WBUFB(buf,78) = 0;
  6738. }
  6739. } else {
  6740. WBUFB(buf,54) = 0;
  6741. WBUFB(buf,78) = 0;
  6742. }
  6743. }
  6744. break;
  6745. case BL_PET:
  6746. memcpy(WBUFP(buf,6), ((struct pet_data*)bl)->name, NAME_LENGTH);
  6747. break;
  6748. case BL_NPC:
  6749. memcpy(WBUFP(buf,6), ((struct npc_data*)bl)->name, NAME_LENGTH);
  6750. break;
  6751. case BL_MOB:
  6752. {
  6753. struct mob_data *md = (struct mob_data *)bl;
  6754. nullpo_retr(0, md);
  6755. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6756. if (md->guardian_data && md->guardian_data->guild_id) {
  6757. WBUFW(buf, 0) = cmd = 0x195;
  6758. WBUFB(buf,30) = 0;
  6759. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6760. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6761. } else if (battle_config.show_mob_hp == 1) {
  6762. char mobhp[50];
  6763. WBUFW(buf, 0) = cmd = 0x195;
  6764. sprintf(mobhp, "HP: %d/%d", md->hp, md->max_hp);
  6765. //Even thought mobhp ain't a name, we send it as one so the client
  6766. //can parse it. [Skotlex]
  6767. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6768. WBUFB(buf,54) = 0;
  6769. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6770. }
  6771. }
  6772. break;
  6773. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6774. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6775. // break;
  6776. return 0;
  6777. default:
  6778. if (battle_config.error_log)
  6779. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6780. return 0;
  6781. }
  6782. // if no receipient specified just update nearby clients
  6783. if (fd == 0)
  6784. clif_send(buf, packet_len_table[cmd], bl, AREA);
  6785. else {
  6786. WFIFOHEAD(fd, packet_len_table[cmd]);
  6787. memcpy(WFIFOP(fd, 0), buf, packet_len_table[cmd]);
  6788. WFIFOSET(fd, packet_len_table[cmd]);
  6789. }
  6790. return 0;
  6791. }
  6792. //Used to update when a char leaves a party/guild. [Skotlex]
  6793. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6794. int clif_charnameupdate (struct map_session_data *ssd)
  6795. {
  6796. unsigned char buf[103];
  6797. int cmd = 0x195;
  6798. struct party *p = NULL;
  6799. struct guild *g = NULL;
  6800. nullpo_retr(0, ssd);
  6801. if (strlen(ssd->fakename)>1)
  6802. return 0; //No need to update as the party/guild was not displayed anyway.
  6803. WBUFW(buf,0) = cmd;
  6804. WBUFL(buf,2) = ssd->bl.id;
  6805. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6806. if (ssd->status.party_id > 0)
  6807. p = party_search(ssd->status.party_id);
  6808. if (ssd->status.guild_id > 0)
  6809. g = guild_search(ssd->status.guild_id);
  6810. if (p)
  6811. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  6812. else
  6813. WBUFB(buf,30) = 0;
  6814. if (g)
  6815. {
  6816. int i, ps = -1;
  6817. for(i = 0; i < g->max_member; i++) {
  6818. if (g->member[i].account_id == ssd->status.account_id &&
  6819. g->member[i].char_id == ssd->status.char_id )
  6820. {
  6821. ps = g->member[i].position;
  6822. break;
  6823. }
  6824. }
  6825. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6826. {
  6827. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6828. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6829. } else { //Assume no guild.
  6830. WBUFB(buf,54) = 0;
  6831. WBUFB(buf,78) = 0;
  6832. }
  6833. } else {
  6834. WBUFB(buf,54) = 0;
  6835. WBUFB(buf,78) = 0;
  6836. }
  6837. // Update nearby clients
  6838. clif_send(buf, packet_len_table[cmd], &ssd->bl, AREA);
  6839. return 0;
  6840. }
  6841. int clif_slide(struct block_list *bl, int x, int y){
  6842. unsigned char buf[10];
  6843. nullpo_retr(0, bl);
  6844. WBUFW(buf, 0) = 0x01ff;
  6845. WBUFL(buf, 2) = bl->id;
  6846. WBUFW(buf, 6) = x;
  6847. WBUFW(buf, 8) = y;
  6848. clif_send(buf, packet_len_table[0x1ff], bl, AREA);
  6849. return 0;
  6850. }
  6851. /*------------------------------------------
  6852. * @me command by lordalfa, rewritten implementation by Skotlex
  6853. *------------------------------------------
  6854. */
  6855. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  6856. {
  6857. unsigned char buf[256]; //This should be more than sufficient, the theorical max is MESSAGE_SIZE+NAME_LENGTH + 8 (pads and extra inserted crap)
  6858. int len_mes = strlen(mes)+1; //Account for \0
  6859. if (len_mes + 8 >= 256) {
  6860. if (battle_config.error_log)
  6861. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6862. len_mes = 247; //Trunk it to avoid problems.
  6863. }
  6864. // send message to others
  6865. WBUFW(buf,0) = 0x8d;
  6866. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6867. WBUFL(buf,4) = sd->bl.id;
  6868. memcpy(WBUFP(buf,8), mes, len_mes);
  6869. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6870. // send back message to the speaker
  6871. WBUFW(buf,0) = 0x8e;
  6872. WBUFW(buf, 2) = len_mes + 4;
  6873. memcpy(WBUFP(buf,4), mes, len_mes);
  6874. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6875. return 0;
  6876. }
  6877. /*==========================
  6878. * Minimap fix [Kevin]
  6879. * Remove dot from minimap
  6880. *--------------------------
  6881. */
  6882. int clif_party_xy_remove(struct map_session_data *sd)
  6883. {
  6884. unsigned char buf[16];
  6885. nullpo_retr(0, sd);
  6886. WBUFW(buf,0)=0x107;
  6887. WBUFL(buf,2)=sd->status.account_id;
  6888. WBUFW(buf,6)=-1;
  6889. WBUFW(buf,8)=-1;
  6890. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  6891. return 0;
  6892. }
  6893. /*==========================================
  6894. * Info about Star Glaldiator save map [Komurka]
  6895. *------------------------------------------
  6896. */
  6897. void clif_feel_info(struct map_session_data *sd, int feel_level)
  6898. {
  6899. int fd=sd->fd;
  6900. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6901. WFIFOW(fd,0)=0x20e;
  6902. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  6903. WFIFOL(fd,26)=sd->bl.id;
  6904. WFIFOW(fd,30)=0x100+feel_level;
  6905. WFIFOSET(fd, packet_len_table[0x20e]);
  6906. }
  6907. /*==========================================
  6908. * Info about Star Glaldiator hate mob [Komurka]
  6909. *------------------------------------------
  6910. */
  6911. void clif_hate_mob(struct map_session_data *sd, int skilllv,int mob_id)
  6912. {
  6913. int fd=sd->fd;
  6914. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6915. WFIFOW(fd,0)=0x20e;
  6916. if (pcdb_checkid(mob_id))
  6917. strncpy(WFIFOP(fd,2),job_name(mob_id), NAME_LENGTH);
  6918. else if (mobdb_checkid(mob_id))
  6919. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6920. else //Really shouldn't happen...
  6921. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6922. WFIFOL(fd,26)=sd->bl.id;
  6923. WFIFOW(fd,30)=0xa00+skilllv-1;
  6924. WFIFOSET(fd, packet_len_table[0x20e]);
  6925. }
  6926. /*==========================================
  6927. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6928. *------------------------------------------
  6929. */
  6930. void clif_mission_mob(struct map_session_data *sd, unsigned short mob_id, unsigned short progress)
  6931. {
  6932. int fd=sd->fd;
  6933. WFIFOHEAD(fd,packet_len_table[0x20e]);
  6934. WFIFOW(fd,0)=0x20e;
  6935. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6936. WFIFOL(fd,26)=mob_id;
  6937. WFIFOW(fd,30)=0x1400+progress; //Message to display
  6938. WFIFOSET(fd, packet_len_table[0x20e]);
  6939. }
  6940. // ---------------------
  6941. // clif_guess_PacketVer
  6942. // ---------------------
  6943. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6944. static int clif_guess_PacketVer(int fd, int get_previous)
  6945. {
  6946. static int packet_ver = -1;
  6947. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6948. RFIFOHEAD(fd);
  6949. 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]
  6950. return packet_ver;
  6951. //By default, start searching on the default one.
  6952. packet_ver = clif_config.packet_db_ver;
  6953. cmd = RFIFOW(fd,0);
  6954. packet_len = RFIFOREST(fd);
  6955. if (
  6956. cmd == clif_config.connect_cmd[packet_ver] &&
  6957. packet_len == packet_db[packet_ver][cmd].len &&
  6958. ((value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) == 0 || value == 1) &&
  6959. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) > 700000 && //Account ID is valid
  6960. value <= max_account_id &&
  6961. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) > 0 && //Char ID is valid
  6962. value <= max_char_id &&
  6963. (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) > 0 //Login 1 is a positive value (?)
  6964. )
  6965. return clif_config.packet_db_ver; //Default packet version found.
  6966. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6967. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6968. if (cmd != clif_config.connect_cmd[packet_ver] || //it is not a wanttoconnection for this version.
  6969. packet_len != packet_db[packet_ver][cmd].len) //The size of the wantoconnection packet does not matches.
  6970. continue;
  6971. if (
  6972. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < 700000 || value > max_account_id
  6973. || (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) < 1 || value > max_char_id
  6974. //What is login 1? In my tests it is a very very high value.
  6975. || (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) < 1
  6976. //This check seems redundant, all wanttoconnection packets have the gender on the very
  6977. //last byte of the packet.
  6978. || (value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) < 0 || value > 1
  6979. )
  6980. continue;
  6981. return packet_ver; //This is our best guess.
  6982. }
  6983. packet_ver = -1;
  6984. return -1;
  6985. }
  6986. // ------------
  6987. // clif_parse_*
  6988. // ------------
  6989. // パケット読み取って色々操作
  6990. /*==========================================
  6991. *
  6992. *------------------------------------------
  6993. */
  6994. void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
  6995. {
  6996. struct map_session_data *old_sd;
  6997. int cmd, account_id, char_id, login_id1, sex;
  6998. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6999. 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])
  7000. RFIFOHEAD(fd);
  7001. if (sd) {
  7002. if (battle_config.error_log)
  7003. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  7004. return;
  7005. }
  7006. packet_ver = clif_guess_PacketVer(fd, 1);
  7007. cmd = RFIFOW(fd,0);
  7008. if (packet_ver > 0)
  7009. {
  7010. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7011. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7012. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7013. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7014. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7015. if ((old_sd = map_id2sd(account_id)) != NULL)
  7016. { // if same account already connected, we disconnect the 2 sessions
  7017. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  7018. if (!old_sd->fd)
  7019. map_quit(old_sd);
  7020. else
  7021. clif_authfail_fd(old_sd->fd, 2); // same id
  7022. clif_authfail_fd(fd, 8); // still recognizes last connection
  7023. } else {
  7024. sd = (struct map_session_data*)aCalloc(1, sizeof(struct map_session_data));
  7025. sd->fd = fd;
  7026. sd->packet_ver = packet_ver;
  7027. session[fd]->session_data = sd;
  7028. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7029. WFIFOHEAD(fd,4);
  7030. WFIFOL(fd,0) = sd->bl.id;
  7031. WFIFOSET(fd,4);
  7032. chrif_authreq(sd);
  7033. }
  7034. }
  7035. return;
  7036. }
  7037. static int clif_nighttimer(int tid, unsigned int tick, int id, int data)
  7038. {
  7039. TBL_PC *sd;
  7040. sd=map_id2sd(id);
  7041. if (!sd) return 0;
  7042. //Check if character didn't instant-warped after logging in.
  7043. if (sd->bl.prev!=NULL) {
  7044. sd->state.night = 1;
  7045. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7046. }
  7047. return 0;
  7048. }
  7049. /*==========================================
  7050. * 007d クライアント側マップ読み込み完了
  7051. * map侵入時に必要なデータを全て送りつける
  7052. *------------------------------------------
  7053. */
  7054. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7055. {
  7056. int i;
  7057. if(sd->bl.prev != NULL)
  7058. return;
  7059. if(sd->npc_id) npc_event_dequeue(sd);
  7060. clif_skillinfoblock(sd);
  7061. pc_checkitem(sd);
  7062. // loadendack時
  7063. // next exp
  7064. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7065. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7066. // skill point
  7067. clif_updatestatus(sd,SP_SKILLPOINT);
  7068. // item
  7069. clif_itemlist(sd);
  7070. clif_equiplist(sd);
  7071. // cart
  7072. if(pc_iscarton(sd)){
  7073. clif_cart_itemlist(sd);
  7074. clif_cart_equiplist(sd);
  7075. clif_updatestatus(sd,SP_CARTINFO);
  7076. }
  7077. // param all
  7078. clif_initialstatus(sd);
  7079. if(battle_config.pc_invincible_time > 0) {
  7080. if(map_flag_gvg(sd->bl.m))
  7081. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7082. else
  7083. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7084. }
  7085. map_addblock(&sd->bl); // ブロック登録
  7086. clif_spawn(&sd->bl); // spawn
  7087. // party
  7088. party_send_movemap(sd);
  7089. // guild
  7090. guild_send_memberinfoshort(sd,1);
  7091. // weight max , now
  7092. clif_updatestatus(sd,SP_MAXWEIGHT);
  7093. clif_updatestatus(sd,SP_WEIGHT);
  7094. // Show hp after displacement [LuzZza]
  7095. if(sd->status.party_id)
  7096. clif_party_hp(sd);
  7097. // pvp
  7098. //if(sd->pvp_timer!=-1 && !battle_config.pk_mode) /PVP Client crash fix* Removed timer deletion
  7099. // delete_timer(sd->pvp_timer,pc_calc_pvprank_timer);
  7100. if(map[sd->bl.m].flag.pvp){
  7101. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7102. if (sd->pvp_timer == -1)
  7103. sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
  7104. sd->pvp_rank=0;
  7105. sd->pvp_lastusers=0;
  7106. sd->pvp_point=5;
  7107. sd->pvp_won=0;
  7108. sd->pvp_lost=0;
  7109. }
  7110. clif_set0199(fd,1);
  7111. } else {
  7112. sd->pvp_timer=-1;
  7113. // set flag, if it's a duel [LuzZza]
  7114. if(sd->duel_group)
  7115. clif_set0199(fd, 1);
  7116. }
  7117. if(map_flag_gvg(sd->bl.m))
  7118. clif_set0199(fd,3);
  7119. // pet
  7120. if(sd->status.pet_id > 0 && sd->pd) {
  7121. map_addblock(&sd->pd->bl);
  7122. clif_spawn(&sd->pd->bl);
  7123. clif_send_petdata(sd,0,0);
  7124. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7125. clif_send_petstatus(sd);
  7126. }
  7127. if(sd->state.connect_new) {
  7128. sd->state.connect_new = 0;
  7129. //Delayed night effect on log-on fix for the glow-issue. Thanks to Larry.
  7130. if (night_flag) {
  7131. char tmpstr[1024];
  7132. strcpy(tmpstr, msg_txt(500)); // Actually, it's the night...
  7133. clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
  7134. if (map[sd->bl.m].flag.nightenabled)
  7135. add_timer(gettick()+1000,clif_nighttimer,sd->bl.id,0);
  7136. }
  7137. // if(sd->status.class_ != sd->vd.class_)
  7138. // clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BASE,sd->vd.class_,SELF);
  7139. if (sd->sc.option&OPTION_FALCON)
  7140. clif_status_load(&sd->bl, SI_FALCON, 1);
  7141. if (sd->sc.option&OPTION_RIDING)
  7142. clif_status_load(&sd->bl, SI_RIDING, 1);
  7143. if(sd->status.pet_id > 0 && sd->pd && sd->pet.intimate > 900)
  7144. clif_pet_emotion(sd->pd,(sd->pd->class_ - 100)*100 + 50 + pet_hungry_val(sd));
  7145. //Removed, for some reason chars get stuck on map-change when you send this packet!? [Skotlex]
  7146. //[LuzZza]
  7147. //clif_guild_send_onlineinfo(sd);
  7148. } else
  7149. //New 'night' effect by dynamix [Skotlex]
  7150. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7151. { //Display night.
  7152. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  7153. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7154. else
  7155. sd->state.night = 1;
  7156. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7157. } else if (sd->state.night) { //Clear night display.
  7158. sd->state.night = 0;
  7159. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7160. }
  7161. // view equipment item
  7162. #if PACKETVER < 4
  7163. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7164. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7165. #else
  7166. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7167. #endif
  7168. if(sd->vd.cloth_color)
  7169. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7170. if(battle_config.muting_players && sd->status.manner < 0 && battle_config.manner_system)
  7171. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7172. // Lance
  7173. if (script_config.event_script_type == 0) {
  7174. struct npc_data *npc;
  7175. if ((npc = npc_name2id(script_config.loadmap_event_name))) {
  7176. run_script(npc->u.scr.script,0,sd->bl.id,npc->bl.id);
  7177. ShowStatus("Event '"CL_WHITE"%s"CL_RESET"' executed.\n", script_config.loadmap_event_name);
  7178. }
  7179. } else {
  7180. ShowStatus("%d '"CL_WHITE"%s"CL_RESET"' events executed.\n",
  7181. npc_event_doall_id(script_config.loadmap_event_name, sd->bl.id), script_config.loadmap_event_name);
  7182. }
  7183. if ((i = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7184. if(sd->bl.m == sd->feel_map[0].m
  7185. || sd->bl.m == sd->feel_map[1].m
  7186. || sd->bl.m == sd->feel_map[2].m)
  7187. sc_start(&sd->bl, SC_KNOWLEDGE, 100, i, skill_get_time(SG_KNOWLEDGE, i));
  7188. }
  7189. if (
  7190. pc_checkskill(sd,SG_SUN_COMFORT) ||
  7191. pc_checkskill(sd,SG_MOON_COMFORT) ||
  7192. pc_checkskill(sd,SG_STAR_COMFORT))
  7193. status_calc_pc(sd,0);
  7194. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7195. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7196. clif_weather_check(sd);
  7197. map_foreachinarea(clif_getareachar,sd->bl.m,
  7198. sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,
  7199. BL_ALL,sd);
  7200. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7201. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7202. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7203. else
  7204. sd->areanpc_id = 0;
  7205. if (pc_isdead(sd)) //In case you warped dead.
  7206. clif_clearchar_area(&sd->bl, 1);
  7207. }
  7208. /*==========================================
  7209. *
  7210. *------------------------------------------
  7211. */
  7212. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7213. RFIFOHEAD(fd);
  7214. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7215. sd->server_tick = gettick();
  7216. clif_servertick(sd);
  7217. }
  7218. static int clif_walktoxy_timer(int tid, unsigned int tick, int id, int data)
  7219. {
  7220. struct map_session_data *sd;
  7221. short x,y;
  7222. if (!session[id] || (sd = session[id]->session_data) == NULL)
  7223. return 0;
  7224. if (!unit_can_move(&sd->bl))
  7225. return 0;
  7226. x = data>>16;
  7227. y = data&0xffff;
  7228. unit_walktoxy(&sd->bl, x, y, 0);
  7229. return 1;
  7230. }
  7231. /*==========================================
  7232. *
  7233. *------------------------------------------
  7234. */
  7235. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7236. int x, y;
  7237. int cmd;
  7238. unsigned int tick;
  7239. RFIFOHEAD(fd);
  7240. if (pc_isdead(sd)) {
  7241. clif_clearchar_area(&sd->bl, 1);
  7242. return;
  7243. }
  7244. if (clif_cant_act(sd) && sd->sc.opt1 != OPT1_STONEWAIT)
  7245. return;
  7246. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7247. return;
  7248. pc_stop_attack(sd);
  7249. if (sd->invincible_timer != -1)
  7250. pc_delinvincibletimer(sd);
  7251. cmd = RFIFOW(fd,0);
  7252. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7253. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7254. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7255. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7256. //Set last idle time... [Skotlex]
  7257. sd->idletime = last_tick;
  7258. tick = gettick();
  7259. if (DIFF_TICK(sd->ud.canmove_tick, tick) > 0 &&
  7260. DIFF_TICK(sd->ud.canmove_tick, tick) < 2000)
  7261. { // Delay walking command. [Skotlex]
  7262. add_timer(sd->ud.canmove_tick+1, clif_walktoxy_timer, fd, (x<<16)|y);
  7263. return;
  7264. }
  7265. if (!unit_can_move(&sd->bl))
  7266. return;
  7267. unit_walktoxy(&sd->bl, x, y, 0);
  7268. }
  7269. /*==========================================
  7270. *
  7271. *------------------------------------------
  7272. */
  7273. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7274. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7275. WFIFOW(fd,0) = 0x18b;
  7276. /* Rovert's prevent logout option fixed [Valaris] */
  7277. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7278. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7279. ) {
  7280. clif_setwaitclose(fd);
  7281. WFIFOW(fd,2)=0;
  7282. } else {
  7283. WFIFOW(fd,2)=1;
  7284. }
  7285. WFIFOSET(fd,packet_len_table[0x18b]);
  7286. }
  7287. /*==========================================
  7288. *
  7289. *------------------------------------------
  7290. */
  7291. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7292. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7293. /* if (target_id == server_char_id) {
  7294. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7295. 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).
  7296. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7297. // if we block people
  7298. if (battle_config.ban_bot < 0) {
  7299. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7300. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7301. // message about the ban
  7302. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7303. // if we ban people
  7304. } else if (battle_config.ban_bot > 0) {
  7305. 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)
  7306. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7307. // message about the ban
  7308. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7309. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7310. // message about the ban
  7311. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7312. }
  7313. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7314. // send this info cause the bot ask until get an answer, damn spam
  7315. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7316. WPACKETW(0) = 0x95;
  7317. WPACKETL(2) = server_char_id;
  7318. strncpy(WPACKETP(6), sd->status.name, 24);
  7319. SENDPACKET(fd, packet_len_table[0x95]);
  7320. // take fake player out of screen
  7321. WPACKETW(0) = 0x80;
  7322. WPACKETL(2) = server_char_id;
  7323. WPACKETB(6) = 0;
  7324. SENDPACKET(fd, packet_len_table[0x80]);
  7325. // take fake mob out of screen
  7326. WPACKETW(0) = 0x80;
  7327. WPACKETL(2) = server_fake_mob_id;
  7328. WPACKETB(6) = 0;
  7329. SENDPACKET(fd, packet_len_table[0x80]);
  7330. }
  7331. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7332. if (target_id == server_fake_mob_id) {
  7333. int fake_mob;
  7334. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7335. 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).
  7336. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7337. // if we block people
  7338. if (battle_config.ban_bot < 0) {
  7339. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7340. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7341. // message about the ban
  7342. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7343. // if we ban people
  7344. } else if (battle_config.ban_bot > 0) {
  7345. 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)
  7346. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7347. // message about the ban
  7348. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7349. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7350. // message about the ban
  7351. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7352. }
  7353. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7354. // send this info cause the bot ask until get an answer, damn spam
  7355. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7356. WPACKETW(0) = 0x95;
  7357. WPACKETL(2) = server_fake_mob_id;
  7358. 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
  7359. if (!mobdb_checkid(fake_mob))
  7360. fake_mob = 1002; // poring (default)
  7361. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7362. SENDPACKET(fd, packet_len_table[0x95]);
  7363. // take fake mob out of screen
  7364. WPACKETW(0) = 0x80;
  7365. WPACKETL(2) = server_fake_mob_id;
  7366. WPACKETB(6) = 0;
  7367. SENDPACKET(fd, packet_len_table[0x80]);
  7368. // take fake player out of screen
  7369. WPACKETW(0) = 0x80;
  7370. WPACKETL(2) = server_char_id;
  7371. WPACKETB(6) = 0;
  7372. SENDPACKET(fd, packet_len_table[0x80]);
  7373. }
  7374. */
  7375. return;
  7376. }
  7377. /*==========================================
  7378. *
  7379. *------------------------------------------
  7380. */
  7381. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7382. int account_id;
  7383. struct block_list* bl;
  7384. struct status_change *sc;
  7385. RFIFOHEAD(fd);
  7386. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7387. if(account_id<0) // for disguises [Valaris]
  7388. account_id-=account_id*2;
  7389. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7390. if ((bl = map_id2bl(account_id)) != NULL) {
  7391. sc = status_get_sc(bl);
  7392. if (sc && (
  7393. (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_CHASEWALK) && !sd->special_state.intravision) ||
  7394. sc->option&OPTION_INVISIBLE)
  7395. ) {
  7396. //Asked name of invisible player, this shouldn't be possible!
  7397. //Possible bot? Thanks to veider and qspirit
  7398. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7399. unsigned char gm_msg[256];
  7400. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requests name of invisible chars.", sd->status.name, sd->status.account_id);
  7401. ShowWarning(gm_msg);
  7402. // information is sended to all online GM
  7403. // intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7404. return;
  7405. }
  7406. clif_charnameack(fd, bl);
  7407. }
  7408. }
  7409. /*==========================================
  7410. *
  7411. *------------------------------------------
  7412. */
  7413. void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
  7414. unsigned char *message, *buf, buf2[128];
  7415. RFIFOHEAD(fd);
  7416. WFIFOHEAD(fd, RFIFOW(fd,2) + 4);
  7417. message = (unsigned char*)RFIFOP(fd,4);
  7418. if (strlen(message) < strlen(sd->status.name) || //If the incoming string is too short...
  7419. strncmp(message, sd->status.name, strlen(sd->status.name)) != 0) //Or the name does not matches...
  7420. {
  7421. unsigned char gm_msg[256];
  7422. ShowWarning("Hack on global message: character '%s' (account: %d), use an other name to send a (normal) message.\n", sd->status.name, sd->status.account_id);
  7423. // information is sended to all online GM
  7424. sprintf(gm_msg, "Hack on global message (normal message): character '%s' (account: %d) uses another name.", sd->status.name, sd->status.account_id);
  7425. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7426. if (strlen(message) == 0)
  7427. strcpy(gm_msg, " This player sends a void name and a void message.");
  7428. else
  7429. snprintf(gm_msg, 255, " This player sends (name:message): '%128s'.", message);
  7430. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7431. // message about the ban
  7432. if (battle_config.ban_spoof_namer > 0)
  7433. sprintf(gm_msg, " This player has been banned for %d minute(s).", battle_config.ban_spoof_namer);
  7434. else
  7435. sprintf(gm_msg, " This player hasn't been banned (Ban option is disabled).");
  7436. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7437. // if we ban people
  7438. if (battle_config.ban_spoof_namer > 0) {
  7439. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_spoof_namer, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7440. clif_setwaitclose(fd); // forced to disconnect because of the hack
  7441. }
  7442. else
  7443. session[fd]->eof = 1; //Disconnect them too, bad packets can cause problems down the road. [Skotlex]
  7444. return;
  7445. }
  7446. if ((is_atcommand(fd, sd, message, 0) != AtCommand_None) ||
  7447. (is_charcommand(fd, sd, message,0) != CharCommand_None))
  7448. return;
  7449. if (sd->sc.count &&
  7450. (sd->sc.data[SC_BERSERK].timer != -1 || sd->sc.data[SC_NOCHAT].timer != -1 ))
  7451. return;
  7452. if (RFIFOW(fd,2)+4 < 128)
  7453. buf = buf2; //Use a static buffer.
  7454. else
  7455. buf = (unsigned char*)aMallocA((RFIFOW(fd,2) + 4)*sizeof(char));
  7456. // send message to others
  7457. WBUFW(buf,0) = 0x8d;
  7458. WBUFW(buf,2) = RFIFOW(fd,2) + 4; // len of message - 4 + 8
  7459. WBUFL(buf,4) = sd->bl.id;
  7460. memcpy(WBUFP(buf,8), message, RFIFOW(fd,2) - 4);
  7461. clif_send(buf, WBUFW(buf,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7462. if(buf != buf2) aFree(buf);
  7463. // send back message to the speaker
  7464. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7465. WFIFOW(fd,0) = 0x8e;
  7466. WFIFOSET(fd, WFIFOW(fd,2));
  7467. #ifdef PCRE_SUPPORT
  7468. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7469. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7470. #endif
  7471. // Celest
  7472. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7473. int next = pc_nextbaseexp(sd);
  7474. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7475. switch (sd->state.snovice_flag) {
  7476. case 0:
  7477. if (strstr(message, msg_txt(504)))
  7478. sd->state.snovice_flag++;
  7479. break;
  7480. case 1:
  7481. sprintf(buf2, msg_txt(505), sd->status.name);
  7482. if (strstr(message, buf2))
  7483. sd->state.snovice_flag++;
  7484. break;
  7485. case 2:
  7486. if (strstr(message, msg_txt(506)))
  7487. sd->state.snovice_flag++;
  7488. break;
  7489. case 3:
  7490. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7491. break; //Do not override the noskill mapflag. [Skotlex]
  7492. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7493. sc_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  7494. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7495. sd->state.snovice_flag = 0;
  7496. break;
  7497. }
  7498. }
  7499. }
  7500. return;
  7501. }
  7502. int clif_message(struct block_list *bl, char* msg)
  7503. {
  7504. unsigned short msg_len = strlen(msg) + 1;
  7505. unsigned char buf[256];
  7506. nullpo_retr(0, bl);
  7507. WBUFW(buf, 0) = 0x8d;
  7508. WBUFW(buf, 2) = msg_len + 8;
  7509. WBUFL(buf, 4) = bl->id;
  7510. memcpy(WBUFP(buf, 8), msg, msg_len);
  7511. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7512. return 0;
  7513. }
  7514. /*==========================================
  7515. *
  7516. *------------------------------------------
  7517. */
  7518. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7519. // /m /mapmove (as @rura GM command)
  7520. char output[30]; // 17+4+4=26, 30 max.
  7521. char map_name[MAP_NAME_LENGTH]; //Err... map names are 15+'\0' in size, not 16+'\0' [Skotlex]
  7522. RFIFOHEAD(fd);
  7523. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7524. (pc_isGM(sd) >= get_atcommand_level(AtCommand_MapMove))) {
  7525. memcpy(map_name, RFIFOP(fd,2), MAP_NAME_LENGTH-1);
  7526. map_name[MAP_NAME_LENGTH-1]='\0';
  7527. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7528. atcommand_rura(fd, sd, "@rura", output);
  7529. }
  7530. return;
  7531. }
  7532. /*==========================================
  7533. *
  7534. *------------------------------------------
  7535. */
  7536. void clif_changed_dir(struct block_list *bl) {
  7537. unsigned char buf[64];
  7538. WBUFW(buf,0) = 0x9c;
  7539. WBUFL(buf,2) = bl->id;
  7540. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7541. WBUFB(buf,8) = unit_getdir(bl);
  7542. clif_send(buf, packet_len_table[0x9c], bl, AREA_WOS);
  7543. if (disguised(bl)) {
  7544. WBUFL(buf,2) = -bl->id;
  7545. WBUFW(buf,6) = 0;
  7546. clif_send(buf, packet_len_table[0x9c], bl, SELF);
  7547. }
  7548. return;
  7549. }
  7550. /*==========================================
  7551. *
  7552. *------------------------------------------
  7553. */
  7554. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7555. unsigned char headdir, dir;
  7556. RFIFOHEAD(fd);
  7557. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7558. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7559. pc_setdir(sd, dir, headdir);
  7560. clif_changed_dir(&sd->bl);
  7561. return;
  7562. }
  7563. /*==========================================
  7564. *
  7565. *------------------------------------------
  7566. */
  7567. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7568. unsigned char buf[64];
  7569. RFIFOHEAD(fd);
  7570. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7571. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7572. clif_skill_fail(sd, 1, 0, 1);
  7573. return;
  7574. }
  7575. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7576. if (sd->emotionlasttime >= time(NULL)) {
  7577. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7578. clif_skill_fail(sd, 1, 0, 1);
  7579. return;
  7580. }
  7581. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7582. WBUFW(buf,0) = 0xc0;
  7583. WBUFL(buf,2) = sd->bl.id;
  7584. WBUFB(buf,6) = RFIFOB(fd,2);
  7585. clif_send(buf, packet_len_table[0xc0], &sd->bl, AREA);
  7586. } else
  7587. clif_skill_fail(sd, 1, 0, 1);
  7588. }
  7589. /*==========================================
  7590. *
  7591. *------------------------------------------
  7592. */
  7593. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7594. WFIFOHEAD(fd,packet_len_table[0xc2]);
  7595. WFIFOW(fd,0) = 0xc2;
  7596. WFIFOL(fd,2) = map_getusers();
  7597. WFIFOSET(fd,packet_len_table[0xc2]);
  7598. }
  7599. /*==========================================
  7600. *
  7601. *------------------------------------------
  7602. */
  7603. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  7604. unsigned int tick;
  7605. unsigned char buf[64];
  7606. int action_type, target_id;
  7607. RFIFOHEAD(fd);
  7608. if (pc_isdead(sd)) {
  7609. clif_clearchar_area(&sd->bl, 1);
  7610. return;
  7611. }
  7612. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7613. return;
  7614. if (sd->sc.count &&
  7615. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7616. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7617. sd->sc.data[SC_BLADESTOP].timer != -1))
  7618. return;
  7619. tick = gettick();
  7620. pc_stop_walking(sd, 1);
  7621. pc_stop_attack(sd);
  7622. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7623. action_type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7624. //Regardless of what they have to do, they have just requested an action, no longer idle. [Skotlex]
  7625. sd->idletime = last_tick;
  7626. if(target_id<0) // for disguises [Valaris]
  7627. target_id-=(target_id*2);
  7628. switch(action_type) {
  7629. case 0x00: // once attack
  7630. case 0x07: // continuous attack
  7631. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  7632. return;
  7633. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7634. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7635. clif_skill_fail(sd, 1, 4, 0);
  7636. return;
  7637. }
  7638. }
  7639. if (sd->invincible_timer != -1)
  7640. pc_delinvincibletimer(sd);
  7641. unit_attack(&sd->bl, target_id, action_type != 0);
  7642. break;
  7643. case 0x02: // sitdown
  7644. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 3) {
  7645. if (sd->ud.skilltimer != -1) //No sitting while casting :P
  7646. break;
  7647. if (sd->sc.count && (
  7648. sd->sc.data[SC_DANCING].timer != -1 ||
  7649. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7650. )) //No sitting during these states neither.
  7651. break;
  7652. pc_setsit(sd);
  7653. skill_gangsterparadise(sd, 1); // ギャングスターパラダイス設定 fixed Valaris
  7654. skill_rest(sd, 1); // TK_HPTIME sitting down mode [Dralnu]
  7655. clif_sitting(sd);
  7656. } else
  7657. clif_skill_fail(sd, 1, 0, 2);
  7658. break;
  7659. case 0x03: // standup
  7660. pc_setstand(sd);
  7661. skill_gangsterparadise(sd, 0); // ギャングスターパラダイス解除 fixed Valaris
  7662. skill_rest(sd, 0); // TK_HPTIME standing up mode [Dralnu]
  7663. WBUFW(buf, 0) = 0x8a;
  7664. WBUFL(buf, 2) = sd->bl.id;
  7665. WBUFB(buf,26) = 3;
  7666. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  7667. break;
  7668. }
  7669. }
  7670. /*==========================================
  7671. *
  7672. *------------------------------------------
  7673. */
  7674. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  7675. RFIFOHEAD(fd);
  7676. switch(RFIFOB(fd,2)) {
  7677. case 0x00:
  7678. if (pc_isdead(sd)) {
  7679. pc_setstand(sd);
  7680. pc_setrestartvalue(sd, 3);
  7681. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  7682. }
  7683. // in case the player's status somehow wasn't updated yet [Celest]
  7684. else if (sd->status.hp <= 0)
  7685. pc_setdead(sd);
  7686. break;
  7687. case 0x01:
  7688. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7689. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7690. {
  7691. //map_quit(sd); //A clif_quitsave is sent inmediately after this, so no need to quit yet. [Skotlex]
  7692. chrif_charselectreq(sd);
  7693. } else {
  7694. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7695. WFIFOW(fd,0)=0x18b;
  7696. WFIFOW(fd,2)=1;
  7697. WFIFOSET(fd,packet_len_table[0x018b]);
  7698. }
  7699. break;
  7700. }
  7701. }
  7702. /*==========================================
  7703. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7704. *------------------------------------------
  7705. */
  7706. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  7707. char *gm_command;
  7708. struct map_session_data *dstsd;
  7709. int i=0;
  7710. struct npc_data *npc;
  7711. char split_data[10][50];
  7712. int j=0,k=0;
  7713. char target[NAME_LENGTH+1];
  7714. char output[256];
  7715. RFIFOHEAD(fd);
  7716. //printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28));
  7717. gm_command = (char*)aMallocA((strlen((const char*)RFIFOP(fd,28)) + 28)*sizeof(char)); // 24+3+(RFIFOW(fd,2)-28)+1 or 24+3+(strlen(RFIFOP(fd,28))+1 (size can be wrong with hacker)
  7718. sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28));
  7719. if ((is_charcommand(fd, sd, gm_command, 0) != CharCommand_None) ||
  7720. (is_atcommand(fd, sd, gm_command, 0) != AtCommand_None)) {
  7721. if(gm_command) aFree(gm_command);
  7722. return;
  7723. }
  7724. if(gm_command) aFree(gm_command);
  7725. if (sd->sc.count &&
  7726. (sd->sc.data[SC_BERSERK].timer!=-1 || sd->sc.data[SC_NOCHAT].timer != -1))
  7727. return;
  7728. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7729. target[NAME_LENGTH]='\0';
  7730. //Chat Logging type 'W' / Whisper
  7731. if(log_config.chat&1 //we log everything then
  7732. || ( log_config.chat&2 //if Whisper bit is on
  7733. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  7734. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, (char*)RFIFOP(fd, 28));
  7735. //-------------------------------------------------------//
  7736. // Lordalfa - Paperboy - To whisper NPC commands //
  7737. //-------------------------------------------------------//
  7738. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7739. char *whisper_tmp = target+4; //Skip the NPC: string part.
  7740. if ((npc = npc_name2id(whisper_tmp)))
  7741. {
  7742. whisper_tmp=(char *)aMallocA((strlen((char *)(RFIFOP(fd,28)))+1)*sizeof(char));
  7743. sprintf(whisper_tmp, "%s", (const char*)RFIFOP(fd,28));
  7744. for( j=0;whisper_tmp[j]!='\0';j++)
  7745. {
  7746. if(whisper_tmp[j]!='#')
  7747. {
  7748. split_data[i][j-k]=whisper_tmp[j];
  7749. }
  7750. else
  7751. {
  7752. split_data[i][j-k]='\0';
  7753. k=j+1;
  7754. i++;
  7755. }
  7756. } // Splits the message using '#' as separators
  7757. split_data[i][j-k]='\0';
  7758. aFree(whisper_tmp);
  7759. whisper_tmp=(char *)aMallocA(15*sizeof(char));
  7760. for (j=0;j<=10;j++)
  7761. {
  7762. sprintf(whisper_tmp, "@whispervar%d$", j);
  7763. set_var(sd,whisper_tmp,(char *) split_data[j]);
  7764. }//You don't need to zero them, just reset them [Kevin]
  7765. aFree(whisper_tmp);
  7766. whisper_tmp=(char *)aMallocA((strlen(npc->name)+18)*sizeof(char));
  7767. sprintf(whisper_tmp, "%s::OnWhisperGlobal", npc->name);
  7768. npc_event(sd,whisper_tmp,0); // Calls the NPC label
  7769. aFree(whisper_tmp); //I rewrote it a little to use memory allocation, a bit more stable =P [Kevin]
  7770. return;
  7771. } //should have just removed the one below that was a my bad =P
  7772. }
  7773. // Main chat [LuzZza]
  7774. if(strcmpi(target, main_chat_nick) == 0) {
  7775. if(!sd->state.mainchat) {
  7776. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7777. return;
  7778. }
  7779. if (sd->sc.data[SC_NOCHAT].timer != -1) {
  7780. clif_displaymessage(fd, msg_txt(387));
  7781. return;
  7782. }
  7783. sprintf(output, msg_txt(386), sd->status.name, (char *)RFIFOP(fd,28));
  7784. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7785. return;
  7786. }
  7787. // searching destination character
  7788. dstsd = map_nick2sd(target);
  7789. // player is not on this map-server
  7790. if (dstsd == NULL ||
  7791. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7792. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7793. // and if we ask for 'Test', we must not contact 'test' player
  7794. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7795. strcmp(dstsd->status.name, target) != 0) // not exactly same name
  7796. // send message to inter-server
  7797. intif_wis_message(sd, target, (char*)RFIFOP(fd,28), RFIFOW(fd,2)-28);
  7798. // player is on this map-server
  7799. else {
  7800. // if you send to your self, don't send anything to others
  7801. if (dstsd->fd == fd) // but, normaly, it's impossible!
  7802. clif_wis_message(fd, wisp_server_name, "You can not page yourself. Sorry.", strlen("You can not page yourself. Sorry.") + 1);
  7803. // otherwise, send message and answer immediatly
  7804. else {
  7805. if (dstsd->ignoreAll == 1) {
  7806. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7807. clif_wis_end(fd, 1); // 1: target character is not loged in
  7808. else
  7809. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7810. } else {
  7811. // if player ignore the source character
  7812. for(i = 0; i < MAX_IGNORE_LIST; i++)
  7813. if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0) {
  7814. clif_wis_end(fd, 2); // 2: ignored by target
  7815. break;
  7816. }
  7817. // if source player not found in ignore list
  7818. if (i == MAX_IGNORE_LIST) {
  7819. if(strlen(dstsd->away_message) > 0) { // Send away automessage [LuzZza]
  7820. //(Automessage has been sent)
  7821. sprintf(output, "%s %s", (char*)RFIFOP(fd,28),msg_txt(543));
  7822. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7823. clif_wis_end(fd, 0); // 0: success to send wisper
  7824. if(dstsd->state.autotrade)
  7825. //"Away [AT] - \"%s\""
  7826. sprintf(output, msg_txt(544), dstsd->away_message);
  7827. else
  7828. //"Away - \"%s\""
  7829. sprintf(output, msg_txt(545), dstsd->away_message);
  7830. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7831. } else { // Normal message
  7832. clif_wis_message(dstsd->fd, sd->status.name, (char*)RFIFOP(fd,28), RFIFOW(fd,2) - 28);
  7833. clif_wis_end(fd, 0); // 0: success to send wisper
  7834. }
  7835. }
  7836. }
  7837. }
  7838. }
  7839. return;
  7840. }
  7841. /*==========================================
  7842. *
  7843. *------------------------------------------
  7844. */
  7845. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  7846. // /b
  7847. RFIFOHEAD(fd);
  7848. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7849. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast)))
  7850. intif_GMmessage((char*)RFIFOP(fd,4), RFIFOW(fd,2)-4, 0);
  7851. }
  7852. /*==========================================
  7853. *
  7854. *------------------------------------------
  7855. */
  7856. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  7857. struct flooritem_data *fitem;
  7858. int map_object_id;
  7859. RFIFOHEAD(fd);
  7860. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7861. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7862. if (pc_isdead(sd)) {
  7863. clif_clearchar_area(&sd->bl, 1);
  7864. return;
  7865. }
  7866. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7867. return;
  7868. if (clif_cant_act(sd))
  7869. return;
  7870. if(pc_iscloaking(sd) || pc_ischasewalk(sd)) //Disable cloaking/chasewalking characters from looting [Skotlex]
  7871. return;
  7872. if(sd->sc.count && (
  7873. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  7874. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  7875. sd->sc.data[SC_NOCHAT].timer!=-1 ) //会話禁止
  7876. ) {
  7877. clif_additem(sd,0,0,6); // send fail packet! [Valaris]
  7878. return;
  7879. }
  7880. pc_takeitem(sd, fitem);
  7881. }
  7882. /*==========================================
  7883. *
  7884. *------------------------------------------
  7885. */
  7886. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  7887. int item_index, item_amount;
  7888. RFIFOHEAD(fd);
  7889. if (pc_isdead(sd)) {
  7890. clif_clearchar_area(&sd->bl, 1);
  7891. return;
  7892. }
  7893. if (clif_cant_act(sd))
  7894. return;
  7895. if (sd->sc.count && (
  7896. sd->sc.data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
  7897. sd->sc.data[SC_BLADESTOP].timer != -1//白刃取り
  7898. ))
  7899. return;
  7900. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7901. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7902. if (!pc_dropitem(sd, item_index, item_amount))
  7903. //Because the client does not likes being ignored.
  7904. clif_delitem(sd, item_index,0);
  7905. }
  7906. /*==========================================
  7907. *
  7908. *------------------------------------------
  7909. */
  7910. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  7911. int n;
  7912. RFIFOHEAD(fd);
  7913. if (pc_isdead(sd)) {
  7914. clif_clearchar_area(&sd->bl, 1);
  7915. return;
  7916. }
  7917. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7918. return;
  7919. //This flag enables you to use items while in an NPC. [Skotlex]
  7920. if (sd->npc_id) {
  7921. if (sd->npc_id != sd->npc_item_flag)
  7922. return;
  7923. } else
  7924. if (clif_trading(sd))
  7925. return;
  7926. if (sd->sc.count && (
  7927. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  7928. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  7929. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク
  7930. sd->sc.data[SC_NOCHAT].timer!=-1 ||
  7931. sd->sc.data[SC_GRAVITATION].timer!=-1 //会話禁止
  7932. ))
  7933. return;
  7934. if (sd->invincible_timer != -1)
  7935. pc_delinvincibletimer(sd);
  7936. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7937. sd->idletime = last_tick;
  7938. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7939. if(n <0 || n >= MAX_INVENTORY)
  7940. return;
  7941. if (!pc_useitem(sd,n))
  7942. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7943. }
  7944. /*==========================================
  7945. *
  7946. *------------------------------------------
  7947. */
  7948. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7949. {
  7950. int index;
  7951. RFIFOHEAD(fd);
  7952. if(pc_isdead(sd)) {
  7953. clif_clearchar_area(&sd->bl,1);
  7954. return;
  7955. }
  7956. index = RFIFOW(fd,2)-2;
  7957. if (index < 0 || index >= MAX_INVENTORY)
  7958. return; //Out of bounds check.
  7959. if(sd->npc_id) {
  7960. if (sd->npc_id != sd->npc_item_flag)
  7961. return;
  7962. } else if (clif_cant_act(sd))
  7963. return;
  7964. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  7965. return;
  7966. if(!sd->status.inventory[index].identify) { // 未鑑定
  7967. clif_equipitemack(sd,index,0,0); // fail
  7968. return;
  7969. }
  7970. //ペット用装備であるかないか
  7971. if(sd->inventory_data[index]) {
  7972. if(sd->inventory_data[index]->type != 8){
  7973. if(sd->inventory_data[index]->type == 10)
  7974. RFIFOW(fd,4)=0x8000; // 矢を無理やり装備できるように(--;
  7975. pc_equipitem(sd,index,RFIFOW(fd,4));
  7976. } else
  7977. pet_equipitem(sd,index);
  7978. }
  7979. }
  7980. /*==========================================
  7981. *
  7982. *------------------------------------------
  7983. */
  7984. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7985. {
  7986. int index;
  7987. RFIFOHEAD(fd);
  7988. if(pc_isdead(sd)) {
  7989. clif_clearchar_area(&sd->bl,1);
  7990. return;
  7991. }
  7992. if (clif_cant_act(sd))
  7993. return;
  7994. index = RFIFOW(fd,2)-2;
  7995. pc_unequipitem(sd,index,1);
  7996. }
  7997. /*==========================================
  7998. *
  7999. *------------------------------------------
  8000. */
  8001. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8002. {
  8003. RFIFOHEAD(fd);
  8004. if(pc_isdead(sd)) {
  8005. clif_clearchar_area(&sd->bl,1);
  8006. return;
  8007. }
  8008. if (clif_cant_act(sd))
  8009. return;
  8010. //Clicked on a negative ID? Player disguised as NPC! [Skotlex]
  8011. if (RFIFOL(fd,2) < 0)
  8012. return;
  8013. npc_click(sd,RFIFOL(fd,2));
  8014. }
  8015. /*==========================================
  8016. *
  8017. *------------------------------------------
  8018. */
  8019. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8020. {
  8021. RFIFOHEAD(fd);
  8022. if (sd->state.trading)
  8023. return;
  8024. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8025. }
  8026. /*==========================================
  8027. *
  8028. *------------------------------------------
  8029. */
  8030. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8031. {
  8032. int fail=0,n, i;
  8033. unsigned short *item_list;
  8034. unsigned char npc_ev[51];
  8035. struct npc_data *nd;
  8036. RFIFOHEAD(fd);
  8037. n = (RFIFOW(fd,2)-4) /4;
  8038. item_list = (unsigned short*)RFIFOP(fd,4);
  8039. if (sd->state.trading|| !sd->npc_shopid){
  8040. fail = 1;
  8041. }else{
  8042. if((nd = ((struct npc_data *)map_id2bl(sd->npc_shopid))->master_nd)){
  8043. sprintf(npc_ev, "%s::OnBuyItem", nd->exname);
  8044. for(i=0;i<n;i++){
  8045. setd_sub(sd, "@bought_nameid", i, (void *)((int)item_list[i*2+1]));
  8046. setd_sub(sd, "@bought_quantity", i, (void *)((int)item_list[i*2]));
  8047. }
  8048. npc_event(sd, npc_ev, 0);
  8049. fail = 0;
  8050. }else{
  8051. fail = npc_buylist(sd,n,item_list);
  8052. }
  8053. }
  8054. sd->npc_shopid = 0; //Clear shop data.
  8055. WFIFOHEAD(fd,packet_len_table[0xca]);
  8056. WFIFOW(fd,0)=0xca;
  8057. WFIFOB(fd,2)=fail;
  8058. WFIFOSET(fd,packet_len_table[0xca]);
  8059. }
  8060. /*==========================================
  8061. *
  8062. *------------------------------------------
  8063. */
  8064. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8065. {
  8066. int fail=0,n,i;
  8067. unsigned short *item_list;
  8068. unsigned char npc_ev[51];
  8069. struct npc_data *nd;
  8070. RFIFOHEAD(fd);
  8071. n = (RFIFOW(fd,2)-4) /4;
  8072. item_list = (unsigned short*)RFIFOP(fd,4);
  8073. if (sd->state.trading|| !sd->npc_shopid){
  8074. fail = 1;
  8075. }else{
  8076. if((nd = ((struct npc_data *)map_id2bl(sd->npc_shopid))->master_nd)){
  8077. sprintf(npc_ev, "%s::OnSellItem", nd->exname);
  8078. for(i=0;i<n;i++){
  8079. setd_sub(sd, "@sold_nameid", i, (void *)((int)sd->status.inventory[item_list[i*2]-2].nameid));
  8080. setd_sub(sd, "@sold_quantity", i, (void *)((int)item_list[i*2+1]));
  8081. }
  8082. npc_event(sd, npc_ev, 0);
  8083. fail = 0;
  8084. }else{
  8085. fail = npc_selllist(sd,n,item_list);
  8086. }
  8087. }
  8088. sd->npc_shopid = 0; //Clear shop data.
  8089. WFIFOHEAD(fd,packet_len_table[0xcb]);
  8090. WFIFOW(fd,0)=0xcb;
  8091. WFIFOB(fd,2)=fail;
  8092. WFIFOSET(fd,packet_len_table[0xcb]);
  8093. }
  8094. /*==========================================
  8095. *
  8096. *------------------------------------------
  8097. */
  8098. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8099. {
  8100. RFIFOHEAD(fd);
  8101. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8102. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8103. } else
  8104. clif_skill_fail(sd,1,0,3);
  8105. }
  8106. /*==========================================
  8107. *
  8108. *------------------------------------------
  8109. */
  8110. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8111. {
  8112. RFIFOHEAD(fd);
  8113. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8114. }
  8115. /*==========================================
  8116. *
  8117. *------------------------------------------
  8118. */
  8119. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8120. {
  8121. RFIFOHEAD(fd);
  8122. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8123. }
  8124. /*==========================================
  8125. *
  8126. *------------------------------------------
  8127. */
  8128. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8129. {
  8130. RFIFOHEAD(fd);
  8131. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8132. }
  8133. /*==========================================
  8134. *
  8135. *------------------------------------------
  8136. */
  8137. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8138. {
  8139. RFIFOHEAD(fd);
  8140. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8141. }
  8142. /*==========================================
  8143. *
  8144. *------------------------------------------
  8145. */
  8146. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8147. {
  8148. chat_leavechat(sd);
  8149. }
  8150. /*==========================================
  8151. * 取引要請を相手に送る
  8152. *------------------------------------------
  8153. */
  8154. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8155. {
  8156. struct map_session_data *t_sd;
  8157. RFIFOHEAD(fd);
  8158. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  8159. // @noask [LuzZza]
  8160. if(t_sd && t_sd->state.noask) {
  8161. // Your request has been rejected by autoreject option.
  8162. clif_displaymessage(fd, msg_txt(392));
  8163. return;
  8164. }
  8165. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8166. trade_traderequest(sd,RFIFOL(sd->fd,2));
  8167. } else
  8168. clif_skill_fail(sd,1,0,0);
  8169. }
  8170. /*==========================================
  8171. * 取引要請
  8172. *------------------------------------------
  8173. */
  8174. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8175. {
  8176. RFIFOHEAD(fd);
  8177. trade_tradeack(sd,RFIFOB(sd->fd,2));
  8178. }
  8179. /*==========================================
  8180. * アイテム追加
  8181. *------------------------------------------
  8182. */
  8183. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8184. {
  8185. RFIFOHEAD(fd);
  8186. trade_tradeadditem(sd,RFIFOW(sd->fd,2),RFIFOL(sd->fd,4));
  8187. }
  8188. /*==========================================
  8189. * アイテム追加完了(ok押し)
  8190. *------------------------------------------
  8191. */
  8192. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8193. {
  8194. trade_tradeok(sd);
  8195. }
  8196. /*==========================================
  8197. * 取引キャンセル
  8198. *------------------------------------------
  8199. */
  8200. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8201. {
  8202. trade_tradecancel(sd);
  8203. }
  8204. /*==========================================
  8205. * 取引許諾(trade押し)
  8206. *------------------------------------------
  8207. */
  8208. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8209. {
  8210. trade_tradecommit(sd);
  8211. }
  8212. /*==========================================
  8213. *
  8214. *------------------------------------------
  8215. */
  8216. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8217. {
  8218. pc_stop_attack(sd);
  8219. }
  8220. /*==========================================
  8221. * カートへアイテムを移す
  8222. *------------------------------------------
  8223. */
  8224. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8225. {
  8226. RFIFOHEAD(fd);
  8227. if (clif_trading(sd))
  8228. return;
  8229. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8230. }
  8231. /*==========================================
  8232. * カートからアイテムを出す
  8233. *------------------------------------------
  8234. */
  8235. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8236. {
  8237. RFIFOHEAD(fd);
  8238. if (clif_trading(sd))
  8239. return;
  8240. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8241. }
  8242. /*==========================================
  8243. * 付属品(鷹,ペコ,カート)をはずす
  8244. *------------------------------------------
  8245. */
  8246. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8247. {
  8248. pc_setoption(sd,0);
  8249. }
  8250. /*==========================================
  8251. * チェンジカート
  8252. *------------------------------------------
  8253. */
  8254. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8255. {
  8256. RFIFOHEAD(fd);
  8257. pc_setcart(sd,RFIFOW(fd,2));
  8258. }
  8259. /*==========================================
  8260. * ステータスアップ
  8261. *------------------------------------------
  8262. */
  8263. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8264. {
  8265. RFIFOHEAD(fd);
  8266. pc_statusup(sd,RFIFOW(fd,2));
  8267. }
  8268. /*==========================================
  8269. * スキルレベルアップ
  8270. *------------------------------------------
  8271. */
  8272. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8273. {
  8274. RFIFOHEAD(fd);
  8275. pc_skillup(sd,RFIFOW(fd,2));
  8276. }
  8277. /*==========================================
  8278. * スキル使用(ID指定)
  8279. *------------------------------------------
  8280. */
  8281. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8282. int skillnum, skilllv, lv, target_id;
  8283. unsigned int tick = gettick();
  8284. RFIFOHEAD(fd);
  8285. if (clif_cant_act(sd))
  8286. return;
  8287. if (pc_issit(sd))
  8288. return;
  8289. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8290. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8291. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8292. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8293. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8294. sd->idletime = last_tick;
  8295. if (skillnotok(skillnum, sd))
  8296. return;
  8297. if (sd->bl.id != target_id &&
  8298. !sd->state.skill_flag &&
  8299. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8300. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8301. if (sd->ud.skilltimer != -1) {
  8302. if (skillnum != SA_CASTCANCEL)
  8303. return;
  8304. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0 &&
  8305. // allow monk combos to ignore this delay [celest]
  8306. !(sd->sc.count && sd->sc.data[SC_COMBO].timer!=-1 &&
  8307. (skillnum == MO_EXTREMITYFIST ||
  8308. skillnum == MO_CHAINCOMBO ||
  8309. skillnum == MO_COMBOFINISH ||
  8310. skillnum == CH_PALMSTRIKE ||
  8311. skillnum == CH_TIGERFIST ||
  8312. skillnum == CH_CHAINCRUSH))) {
  8313. clif_skill_fail(sd, skillnum, 4, 0);
  8314. return;
  8315. }
  8316. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8317. return;
  8318. if (sd->invincible_timer != -1)
  8319. pc_delinvincibletimer(sd);
  8320. if(target_id<0) // for disguises [Valaris]
  8321. target_id*=-1;
  8322. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8323. if (skilllv != sd->skillitemlv)
  8324. skilllv = sd->skillitemlv;
  8325. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8326. } else {
  8327. sd->skillitem = sd->skillitemlv = -1;
  8328. if (skillnum == MO_EXTREMITYFIST) {
  8329. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8330. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8331. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8332. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8333. if (!sd->state.skill_flag ) {
  8334. sd->state.skill_flag = 1;
  8335. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8336. return;
  8337. } else if (sd->bl.id == target_id) {
  8338. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8339. return;
  8340. }
  8341. }
  8342. }
  8343. if (skillnum == TK_JUMPKICK) {
  8344. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8345. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8346. if (!sd->state.skill_flag ) {
  8347. sd->state.skill_flag = 1;
  8348. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8349. return;
  8350. } else if (sd->bl.id == target_id) {
  8351. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8352. return;
  8353. }
  8354. }
  8355. }
  8356. if (skillnum >= GD_SKILLBASE && sd->state.gmaster_flag)
  8357. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8358. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8359. if (skilllv > lv)
  8360. skilllv = lv;
  8361. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8362. if (sd->state.skill_flag)
  8363. sd->state.skill_flag = 0;
  8364. }
  8365. }
  8366. }
  8367. /*==========================================
  8368. * スキル使用(場所指定)
  8369. *------------------------------------------
  8370. */
  8371. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8372. {
  8373. int lv;
  8374. unsigned int tick = gettick();
  8375. RFIFOHEAD(fd);
  8376. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8377. sd->idletime = last_tick;
  8378. if (skillnotok(skillnum, sd))
  8379. return;
  8380. if (skillmoreinfo != -1) {
  8381. if (pc_issit(sd)) {
  8382. clif_skill_fail(sd, skillnum, 0, 0);
  8383. return;
  8384. }
  8385. memcpy(talkie_mes, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8386. talkie_mes[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8387. }
  8388. if (sd->ud.skilltimer != -1)
  8389. return;
  8390. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8391. {
  8392. clif_skill_fail(sd, skillnum, 4, 0);
  8393. return;
  8394. }
  8395. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8396. return;
  8397. if (sd->invincible_timer != -1)
  8398. pc_delinvincibletimer(sd);
  8399. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8400. if (skilllv != sd->skillitemlv)
  8401. skilllv = sd->skillitemlv;
  8402. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8403. } else {
  8404. sd->skillitem = sd->skillitemlv = -1;
  8405. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8406. if (skilllv > lv)
  8407. skilllv = lv;
  8408. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8409. }
  8410. }
  8411. }
  8412. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8413. RFIFOHEAD(fd);
  8414. if (clif_cant_act(sd))
  8415. return;
  8416. if (pc_issit(sd))
  8417. return;
  8418. clif_parse_UseSkillToPosSub(fd, sd,
  8419. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8420. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8421. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8422. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8423. -1 //Skill more info.
  8424. );
  8425. }
  8426. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8427. RFIFOHEAD(fd);
  8428. if (clif_cant_act(sd))
  8429. return;
  8430. if (pc_issit(sd))
  8431. return;
  8432. clif_parse_UseSkillToPosSub(fd, sd,
  8433. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8434. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8435. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8436. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8437. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8438. );
  8439. }
  8440. /*==========================================
  8441. * スキル使用(map指定)
  8442. *------------------------------------------
  8443. */
  8444. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8445. {
  8446. RFIFOHEAD(fd);
  8447. if (clif_cant_act(sd))
  8448. return;
  8449. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8450. return;
  8451. if(sd->invincible_timer != -1)
  8452. pc_delinvincibletimer(sd);
  8453. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8454. }
  8455. /*==========================================
  8456. * メモ要求
  8457. *------------------------------------------
  8458. */
  8459. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8460. {
  8461. if (!pc_isdead(sd))
  8462. pc_memo(sd,-1);
  8463. }
  8464. /*==========================================
  8465. * アイテム合成
  8466. *------------------------------------------
  8467. */
  8468. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8469. {
  8470. RFIFOHEAD(fd);
  8471. if (sd->menuskill_id != AM_PHARMACY)
  8472. return;
  8473. if (clif_trading(sd)) {
  8474. //Make it fail to avoid shop exploits where you sell something different than you see.
  8475. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8476. sd->menuskill_lv = sd->menuskill_id = 0;
  8477. return;
  8478. }
  8479. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8480. sd->menuskill_lv = sd->menuskill_id = 0;
  8481. }
  8482. /*==========================================
  8483. * 武器修理
  8484. *------------------------------------------
  8485. */
  8486. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8487. {
  8488. RFIFOHEAD(fd);
  8489. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8490. return;
  8491. if (clif_trading(sd)) {
  8492. //Make it fail to avoid shop exploits where you sell something different than you see.
  8493. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8494. sd->menuskill_lv = sd->menuskill_id = 0;
  8495. return;
  8496. }
  8497. skill_repairweapon(sd,RFIFOW(fd,2));
  8498. sd->menuskill_lv = sd->menuskill_id = 0;
  8499. }
  8500. /*==========================================
  8501. *
  8502. *------------------------------------------
  8503. */
  8504. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8505. int idx;
  8506. RFIFOHEAD(fd);
  8507. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8508. return;
  8509. if (clif_trading(sd)) {
  8510. //Make it fail to avoid shop exploits where you sell something different than you see.
  8511. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8512. sd->menuskill_lv = sd->menuskill_id = 0;
  8513. return;
  8514. }
  8515. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8516. skill_weaponrefine(sd, idx-2);
  8517. sd->menuskill_lv = sd->menuskill_id = 0;
  8518. }
  8519. /*==========================================
  8520. *
  8521. *------------------------------------------
  8522. */
  8523. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8524. {
  8525. RFIFOHEAD(fd);
  8526. sd->npc_menu=RFIFOB(fd,6);
  8527. npc_scriptcont(sd,RFIFOL(fd,2));
  8528. }
  8529. /*==========================================
  8530. *
  8531. *------------------------------------------
  8532. */
  8533. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8534. {
  8535. RFIFOHEAD(fd);
  8536. #ifdef __WIN32
  8537. //For some extraordinarily eerie reason that noone has figured out yet,
  8538. //windows native compiles NEED this nullpo_retv or the function is not found!
  8539. nullpo_retv(sd);
  8540. #endif
  8541. npc_scriptcont(sd,RFIFOL(fd,2));
  8542. }
  8543. /*==========================================
  8544. *
  8545. *------------------------------------------
  8546. */
  8547. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8548. {
  8549. RFIFOHEAD(fd);
  8550. #define RFIFOL_(fd,pos) (*(int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos)))
  8551. //Input Value overflow Exploit FIX
  8552. sd->npc_amount=RFIFOL_(fd,6); //fixed by Lupus. npc_amount is (int) but was RFIFOL changing it to (unsigned int)
  8553. #undef RFIFOL_
  8554. npc_scriptcont(sd,RFIFOL(fd,2));
  8555. }
  8556. /*==========================================
  8557. *
  8558. *------------------------------------------
  8559. */
  8560. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8561. {
  8562. RFIFOHEAD(fd);
  8563. if(RFIFOW(fd,2)-7 >= sizeof(sd->npc_str)){
  8564. ShowWarning("clif: input string too long !\n");
  8565. memcpy(sd->npc_str,RFIFOP(fd,8),sizeof(sd->npc_str));
  8566. sd->npc_str[sizeof(sd->npc_str)-1]=0;
  8567. } else
  8568. strcpy(sd->npc_str,(char*)RFIFOP(fd,8));
  8569. npc_scriptcont(sd,RFIFOL(fd,4));
  8570. }
  8571. /*==========================================
  8572. *
  8573. *------------------------------------------
  8574. */
  8575. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8576. {
  8577. RFIFOHEAD(fd);
  8578. if (sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8579. npc_scriptcont(sd,RFIFOL(fd,2));
  8580. }
  8581. /*==========================================
  8582. * アイテム鑑定
  8583. *------------------------------------------
  8584. */
  8585. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8586. {
  8587. RFIFOHEAD(fd);
  8588. if (sd->menuskill_id != MC_IDENTIFY)
  8589. return;
  8590. skill_identify(sd,RFIFOW(fd,2)-2);
  8591. sd->menuskill_lv = sd->menuskill_id = 0;
  8592. }
  8593. /*==========================================
  8594. * 矢作成
  8595. *------------------------------------------
  8596. */
  8597. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8598. {
  8599. RFIFOHEAD(fd);
  8600. if (sd->menuskill_id != AC_MAKINGARROW)
  8601. return;
  8602. if (clif_trading(sd)) {
  8603. //Make it fail to avoid shop exploits where you sell something different than you see.
  8604. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8605. sd->menuskill_lv = sd->menuskill_id = 0;
  8606. return;
  8607. }
  8608. skill_arrow_create(sd,RFIFOW(fd,2));
  8609. sd->menuskill_lv = sd->menuskill_id = 0;
  8610. }
  8611. /*==========================================
  8612. * オートスペル受信
  8613. *------------------------------------------
  8614. */
  8615. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8616. {
  8617. RFIFOHEAD(fd);
  8618. if (sd->menuskill_id != SA_AUTOSPELL)
  8619. return;
  8620. skill_autospell(sd,RFIFOW(fd,2));
  8621. sd->menuskill_lv = sd->menuskill_id = 0;
  8622. }
  8623. /*==========================================
  8624. * カード使用
  8625. *------------------------------------------
  8626. */
  8627. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8628. {
  8629. RFIFOHEAD(fd);
  8630. if (sd->state.trading!= 0)
  8631. return;
  8632. clif_use_card(sd,RFIFOW(fd,2)-2);
  8633. }
  8634. /*==========================================
  8635. * カード挿入装備選択
  8636. *------------------------------------------
  8637. */
  8638. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8639. {
  8640. RFIFOHEAD(fd);
  8641. if (sd->state.trading!= 0)
  8642. return;
  8643. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8644. }
  8645. /*==========================================
  8646. * 0193 キャラID名前引き
  8647. *------------------------------------------
  8648. */
  8649. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8650. int char_id;
  8651. RFIFOHEAD(fd);
  8652. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8653. clif_solved_charname(sd, char_id);
  8654. }
  8655. /*==========================================
  8656. * 0197 /resetskill /resetstate
  8657. *------------------------------------------
  8658. */
  8659. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8660. RFIFOHEAD(fd);
  8661. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8662. pc_isGM(sd) >= get_atcommand_level(AtCommand_ResetState)) {
  8663. switch(RFIFOW(fd,2)){
  8664. case 0:
  8665. pc_resetstate(sd);
  8666. break;
  8667. case 1:
  8668. pc_resetskill(sd,1);
  8669. break;
  8670. }
  8671. }
  8672. }
  8673. /*==========================================
  8674. * 019c /lb等
  8675. *------------------------------------------
  8676. */
  8677. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  8678. unsigned char buf[512];
  8679. RFIFOHEAD(fd);
  8680. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8681. (pc_isGM(sd) >= get_atcommand_level(AtCommand_LocalBroadcast))) {
  8682. WBUFW(buf,0) = 0x9a;
  8683. WBUFW(buf,2) = RFIFOW(fd,2);
  8684. memcpy(WBUFP(buf,4), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  8685. clif_send(buf, RFIFOW(fd,2), &sd->bl, ALL_SAMEMAP);
  8686. }
  8687. }
  8688. /*==========================================
  8689. * カプラ倉庫へ入れる
  8690. *------------------------------------------
  8691. */
  8692. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  8693. int item_index, item_amount;
  8694. RFIFOHEAD(fd);
  8695. if (clif_trading(sd))
  8696. return;
  8697. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8698. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8699. if (item_index < 0 || item_index >= MAX_INVENTORY)
  8700. return;
  8701. if (sd->state.storage_flag == 1)
  8702. storage_storageadd(sd, item_index, item_amount);
  8703. else if (sd->state.storage_flag == 2)
  8704. storage_guild_storageadd(sd, item_index, item_amount);
  8705. }
  8706. /*==========================================
  8707. * カプラ倉庫から出す
  8708. *------------------------------------------
  8709. */
  8710. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  8711. int item_index, item_amount;
  8712. RFIFOHEAD(fd);
  8713. if (clif_trading(sd))
  8714. return;
  8715. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8716. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8717. if (sd->state.storage_flag == 1)
  8718. storage_storageget(sd, item_index, item_amount);
  8719. else if(sd->state.storage_flag == 2)
  8720. storage_guild_storageget(sd, item_index, item_amount);
  8721. }
  8722. /*==========================================
  8723. * カプラ倉庫へカートから入れる
  8724. *------------------------------------------
  8725. */
  8726. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  8727. RFIFOHEAD(fd);
  8728. if (clif_trading(sd))
  8729. return;
  8730. if (sd->state.storage_flag == 1)
  8731. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8732. else if (sd->state.storage_flag == 2)
  8733. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8734. }
  8735. /*==========================================
  8736. * カプラ倉庫から出す
  8737. *------------------------------------------
  8738. */
  8739. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  8740. RFIFOHEAD(fd);
  8741. if (clif_trading(sd))
  8742. return;
  8743. if (sd->state.storage_flag == 1)
  8744. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8745. else if (sd->state.storage_flag == 2)
  8746. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8747. }
  8748. /*==========================================
  8749. * カプラ倉庫を閉じる
  8750. *------------------------------------------
  8751. */
  8752. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  8753. if (sd->state.storage_flag == 1)
  8754. storage_storageclose(sd);
  8755. else if (sd->state.storage_flag == 2)
  8756. storage_guild_storageclose(sd);
  8757. }
  8758. /*==========================================
  8759. * パーティを作る
  8760. *------------------------------------------
  8761. */
  8762. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  8763. RFIFOHEAD(fd);
  8764. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8765. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8766. } else
  8767. clif_skill_fail(sd,1,0,4);
  8768. }
  8769. /*==========================================
  8770. * パーティを作る
  8771. *------------------------------------------
  8772. */
  8773. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  8774. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  8775. RFIFOHEAD(fd);
  8776. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8777. } else
  8778. clif_skill_fail(sd,1,0,4);
  8779. }
  8780. /*==========================================
  8781. * パーティに勧誘
  8782. *------------------------------------------
  8783. */
  8784. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  8785. struct map_session_data *t_sd;
  8786. RFIFOHEAD(fd);
  8787. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  8788. // @noask [LuzZza]
  8789. if(t_sd && t_sd->state.noask) {
  8790. // Your request has been rejected by autoreject option.
  8791. clif_displaymessage(fd, msg_txt(392));
  8792. return;
  8793. }
  8794. party_invite(sd, RFIFOL(fd,2));
  8795. }
  8796. /*==========================================
  8797. * パーティ勧誘返答
  8798. *------------------------------------------
  8799. */
  8800. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  8801. RFIFOHEAD(fd);
  8802. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8803. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8804. } else {
  8805. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8806. clif_skill_fail(sd,1,0,4);
  8807. }
  8808. }
  8809. /*==========================================
  8810. * パーティ脱退要求
  8811. *------------------------------------------
  8812. */
  8813. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  8814. party_leave(sd);
  8815. }
  8816. /*==========================================
  8817. * パーティ除名要求
  8818. *------------------------------------------
  8819. */
  8820. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  8821. RFIFOHEAD(fd);
  8822. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8823. }
  8824. /*==========================================
  8825. * パーティ設定変更要求
  8826. *------------------------------------------
  8827. */
  8828. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  8829. RFIFOHEAD(fd);
  8830. party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8831. }
  8832. /*==========================================
  8833. * パーティメッセージ送信要求
  8834. *------------------------------------------
  8835. */
  8836. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  8837. RFIFOHEAD(fd);
  8838. if (is_charcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != CharCommand_None ||
  8839. is_atcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != AtCommand_None)
  8840. return;
  8841. if (sd->sc.count && (
  8842. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  8843. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  8844. ))
  8845. return;
  8846. party_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  8847. }
  8848. /*==========================================
  8849. * 露店閉鎖
  8850. *------------------------------------------
  8851. */
  8852. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  8853. vending_closevending(sd);
  8854. }
  8855. /*==========================================
  8856. * 露店アイテムリスト要求
  8857. *------------------------------------------
  8858. */
  8859. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  8860. RFIFOHEAD(fd);
  8861. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8862. if(sd->npc_id)
  8863. npc_event_dequeue(sd);
  8864. }
  8865. /*==========================================
  8866. * 露店アイテム購入
  8867. *------------------------------------------
  8868. */
  8869. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  8870. RFIFOHEAD(fd);
  8871. if (clif_trading(sd))
  8872. return;
  8873. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  8874. }
  8875. /*==========================================
  8876. * 露店開設
  8877. *------------------------------------------
  8878. */
  8879. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  8880. RFIFOHEAD(fd);
  8881. if (clif_trading(sd))
  8882. return;
  8883. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  8884. }
  8885. /*==========================================
  8886. * ギルドを作る
  8887. *------------------------------------------
  8888. */
  8889. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  8890. RFIFOHEAD(fd);
  8891. guild_create(sd, (char*)RFIFOP(fd,6));
  8892. }
  8893. /*==========================================
  8894. * ギルドマスターかどうか確認
  8895. *------------------------------------------
  8896. */
  8897. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  8898. clif_guild_masterormember(sd);
  8899. }
  8900. /*==========================================
  8901. * ギルド情報要求
  8902. *------------------------------------------
  8903. */
  8904. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  8905. RFIFOHEAD(fd);
  8906. switch(RFIFOL(fd,2)){
  8907. case 0: // ギルド基本情報、同盟敵対情報
  8908. clif_guild_basicinfo(sd);
  8909. clif_guild_allianceinfo(sd);
  8910. break;
  8911. case 1: // メンバーリスト、役職名リスト
  8912. clif_guild_positionnamelist(sd);
  8913. clif_guild_memberlist(sd);
  8914. break;
  8915. case 2: // 役職名リスト、役職情報リスト
  8916. clif_guild_positionnamelist(sd);
  8917. clif_guild_positioninfolist(sd);
  8918. break;
  8919. case 3: // スキルリスト
  8920. clif_guild_skillinfo(sd);
  8921. break;
  8922. case 4: // 追放リスト
  8923. clif_guild_explusionlist(sd);
  8924. break;
  8925. default:
  8926. if (battle_config.error_log)
  8927. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8928. break;
  8929. }
  8930. }
  8931. /*==========================================
  8932. * ギルド役職変更
  8933. *------------------------------------------
  8934. */
  8935. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  8936. int i;
  8937. RFIFOHEAD(fd);
  8938. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8939. guild_change_position(sd, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8940. }
  8941. }
  8942. /*==========================================
  8943. * ギルドメンバ役職変更
  8944. *------------------------------------------
  8945. */
  8946. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  8947. int i;
  8948. RFIFOHEAD(fd);
  8949. for(i=4;i<RFIFOW(fd,2);i+=12){
  8950. guild_change_memberposition(sd->status.guild_id,
  8951. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8952. }
  8953. }
  8954. /*==========================================
  8955. * ギルドエンブレム要求
  8956. *------------------------------------------
  8957. */
  8958. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  8959. struct guild *g;
  8960. RFIFOHEAD(fd);
  8961. g=guild_search(RFIFOL(fd,2));
  8962. if(g!=NULL)
  8963. clif_guild_emblem(sd,g);
  8964. }
  8965. /*==========================================
  8966. * ギルドエンブレム変更
  8967. *------------------------------------------
  8968. */
  8969. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  8970. RFIFOHEAD(fd);
  8971. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8972. }
  8973. /*==========================================
  8974. * ギルド告知変更
  8975. *------------------------------------------
  8976. */
  8977. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  8978. RFIFOHEAD(fd);
  8979. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  8980. }
  8981. /*==========================================
  8982. * ギルド勧誘
  8983. *------------------------------------------
  8984. */
  8985. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  8986. struct map_session_data *t_sd;
  8987. RFIFOHEAD(fd);
  8988. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  8989. // @noask [LuzZza]
  8990. if(t_sd && t_sd->state.noask) {
  8991. // Your request has been rejected by autoreject option.
  8992. clif_displaymessage(fd, msg_txt(392));
  8993. return;
  8994. }
  8995. guild_invite(sd,RFIFOL(fd,2));
  8996. }
  8997. /*==========================================
  8998. * ギルド勧誘返信
  8999. *------------------------------------------
  9000. */
  9001. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9002. RFIFOHEAD(fd);
  9003. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9004. }
  9005. /*==========================================
  9006. * ギルド脱退
  9007. *------------------------------------------
  9008. */
  9009. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9010. RFIFOHEAD(fd);
  9011. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9012. }
  9013. /*==========================================
  9014. * ギルド追放
  9015. *------------------------------------------
  9016. */
  9017. void clif_parse_GuildExplusion(int fd,struct map_session_data *sd) {
  9018. RFIFOHEAD(fd);
  9019. guild_explusion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9020. }
  9021. /*==========================================
  9022. * ギルド会話
  9023. *------------------------------------------
  9024. */
  9025. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9026. RFIFOHEAD(fd);
  9027. if (is_charcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != CharCommand_None ||
  9028. is_atcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != AtCommand_None)
  9029. return;
  9030. if (sd->sc.count && (
  9031. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  9032. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  9033. ))
  9034. return;
  9035. guild_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9036. }
  9037. /*==========================================
  9038. * ギルド同盟要求
  9039. *------------------------------------------
  9040. */
  9041. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9042. struct map_session_data *t_sd;
  9043. RFIFOHEAD(fd);
  9044. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  9045. // @noask [LuzZza]
  9046. if(t_sd && t_sd->state.noask) {
  9047. // Your request has been rejected by autoreject option.
  9048. clif_displaymessage(fd, msg_txt(392));
  9049. return;
  9050. }
  9051. guild_reqalliance(sd,RFIFOL(fd,2));
  9052. }
  9053. /*==========================================
  9054. * ギルド同盟要求返信
  9055. *------------------------------------------
  9056. */
  9057. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9058. RFIFOHEAD(fd);
  9059. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9060. }
  9061. /*==========================================
  9062. * ギルド関係解消
  9063. *------------------------------------------
  9064. */
  9065. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9066. RFIFOHEAD(fd);
  9067. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9068. }
  9069. /*==========================================
  9070. * ギルド敵対
  9071. *------------------------------------------
  9072. */
  9073. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9074. struct map_session_data *t_sd;
  9075. RFIFOHEAD(fd);
  9076. t_sd = map_id2sd(RFIFOL(sd->fd,2));
  9077. // @noask [LuzZza]
  9078. if(t_sd && t_sd->state.noask) {
  9079. // Your request has been rejected by autoreject option.
  9080. clif_displaymessage(fd, msg_txt(392));
  9081. return;
  9082. }
  9083. guild_opposition(sd,RFIFOL(fd,2));
  9084. }
  9085. /*==========================================
  9086. * ギルド解散
  9087. *------------------------------------------
  9088. */
  9089. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9090. RFIFOHEAD(fd);
  9091. guild_break(sd,(char*)RFIFOP(fd,2));
  9092. }
  9093. // pet
  9094. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9095. RFIFOHEAD(fd);
  9096. pet_menu(sd,RFIFOB(fd,2));
  9097. }
  9098. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9099. RFIFOHEAD(fd);
  9100. pet_catch_process2(sd,RFIFOL(fd,2));
  9101. }
  9102. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9103. RFIFOHEAD(fd);
  9104. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  9105. return;
  9106. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9107. sd->menuskill_lv = sd->menuskill_id = 0;
  9108. }
  9109. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9110. if(sd->pd) {
  9111. RFIFOHEAD(fd);
  9112. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9113. }
  9114. }
  9115. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9116. RFIFOHEAD(fd);
  9117. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9118. }
  9119. // Kick (right click menu for GM "(name) force to quit")
  9120. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9121. struct block_list *target;
  9122. int tid;
  9123. RFIFOHEAD(fd);
  9124. tid = RFIFOL(fd,2);
  9125. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9126. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Kick))) {
  9127. target = map_id2bl(tid);
  9128. if (target) {
  9129. if (target->type == BL_PC) {
  9130. struct map_session_data *tsd = (struct map_session_data *)target;
  9131. if (pc_isGM(sd) > pc_isGM(tsd))
  9132. clif_GM_kick(sd, tsd, 1);
  9133. else
  9134. clif_GM_kickack(sd, 0);
  9135. } else if (target->type == BL_MOB) {
  9136. struct mob_data *md = (struct mob_data *)target;
  9137. mob_damage(&sd->bl, md, md->hp, 2);
  9138. } else
  9139. clif_GM_kickack(sd, 0);
  9140. } else
  9141. clif_GM_kickack(sd, 0);
  9142. }
  9143. }
  9144. /*==========================================
  9145. * /shift
  9146. *------------------------------------------
  9147. */
  9148. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9149. char player_name[NAME_LENGTH+1];
  9150. memset(player_name, '\0', sizeof(player_name));
  9151. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9152. (pc_isGM(sd) >= get_atcommand_level(AtCommand_JumpTo))) {
  9153. RFIFOHEAD(fd);
  9154. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9155. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9156. }
  9157. return;
  9158. }
  9159. /*==========================================
  9160. * /recall
  9161. *------------------------------------------
  9162. */
  9163. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9164. char player_name[25];
  9165. memset(player_name, '\0', sizeof(player_name));
  9166. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9167. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Recall))) {
  9168. RFIFOHEAD(fd);
  9169. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9170. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9171. }
  9172. return;
  9173. }
  9174. /*==========================================
  9175. * /monster /item rewriten by [Yor]
  9176. *------------------------------------------
  9177. */
  9178. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9179. char monster_item_name[NAME_LENGTH+10]; //Additional space is for logging, eg: "@monster Poring"
  9180. int level;
  9181. memset(monster_item_name, '\0', sizeof(monster_item_name));
  9182. if (battle_config.atc_gmonly == 0 || pc_isGM(sd)) {
  9183. RFIFOHEAD(fd);
  9184. memcpy(monster_item_name, RFIFOP(fd,2), NAME_LENGTH);
  9185. if (mobdb_searchname(monster_item_name) != 0) {
  9186. if (pc_isGM(sd) >= (level =get_atcommand_level(AtCommand_Monster)))
  9187. {
  9188. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9189. if(log_config.gm && level >= log_config.gm)
  9190. { //Log action. [Skotlex]
  9191. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@spawn %s", RFIFOP(fd,2));
  9192. log_atcommand(sd, monster_item_name);
  9193. }
  9194. }
  9195. } else if (itemdb_searchname(monster_item_name) != NULL) {
  9196. if (pc_isGM(sd) >= (level = get_atcommand_level(AtCommand_Item)))
  9197. {
  9198. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9199. if(log_config.gm && level >= log_config.gm)
  9200. { //Log action. [Skotlex]
  9201. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@item %s", RFIFOP(fd,2));
  9202. log_atcommand(sd, monster_item_name);
  9203. }
  9204. }
  9205. }
  9206. }
  9207. }
  9208. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9209. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9210. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) {
  9211. if (sd->sc.option & OPTION_INVISIBLE) {
  9212. sd->sc.option &= ~OPTION_INVISIBLE;
  9213. if (sd->disguise)
  9214. status_set_viewdata(&sd->bl, sd->disguise);
  9215. else
  9216. status_set_viewdata(&sd->bl, sd->status.class_);
  9217. clif_displaymessage(fd, "Invisible: Off.");
  9218. } else {
  9219. sd->sc.option |= OPTION_INVISIBLE;
  9220. //Experimental hidden mode, changes your view class to invisible [Skotlex]
  9221. sd->vd.class_ = INVISIBLE_CLASS;
  9222. clif_displaymessage(fd, "Invisible: On.");
  9223. }
  9224. clif_changeoption(&sd->bl);
  9225. }
  9226. }
  9227. /*==========================================
  9228. * GMによるチャット禁止時間付与
  9229. *------------------------------------------
  9230. */
  9231. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9232. {
  9233. int type, limit, level;
  9234. struct block_list *bl;
  9235. struct map_session_data *dstsd;
  9236. if(!battle_config.muting_players) {
  9237. clif_displaymessage(fd, "Muting is disabled.");
  9238. return;
  9239. }
  9240. RFIFOHEAD(fd);
  9241. bl = map_id2bl(RFIFOL(fd,2));
  9242. if (!bl || bl->type != BL_PC)
  9243. return;
  9244. nullpo_retv(dstsd =(struct map_session_data *)bl);
  9245. type = RFIFOB(fd,6);
  9246. limit = RFIFOW(fd,7);
  9247. if (type == 0)
  9248. limit = 0 - limit;
  9249. //Temporarily disable chars from muting themselves due to the mysterious "DON'T USE BOT!" message. [Skotlex]
  9250. //Also, if type is 2 and the ids don't match, this is a crafted hacked packet!
  9251. //So for now, type 2is just totally disabled.
  9252. if (type == 2/*&& sd->bl.id != dstsd->bl.id*/)
  9253. return;
  9254. if (
  9255. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9256. || (type == 2 && !level)) {
  9257. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9258. if (battle_config.manner_system)
  9259. {
  9260. dstsd->status.manner -= limit;
  9261. if(dstsd->status.manner < 0)
  9262. sc_start(bl,SC_NOCHAT,100,0,0);
  9263. else
  9264. {
  9265. dstsd->status.manner = 0;
  9266. status_change_end(bl,SC_NOCHAT,-1);
  9267. }
  9268. }
  9269. ShowDebug("GMReqNoChat: name:%s type:%d limit:%d manner:%d\n", dstsd->status.name, type, limit, dstsd->status.manner);
  9270. }
  9271. return;
  9272. }
  9273. /*==========================================
  9274. * GMによるチャット禁止時間参照(?)
  9275. *------------------------------------------
  9276. */
  9277. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9278. {
  9279. int tid;
  9280. RFIFOHEAD(fd);
  9281. tid = RFIFOL(fd,2);
  9282. WFIFOHEAD(fd,packet_len_table[0x1e0]);
  9283. WFIFOW(fd,0) = 0x1e0;
  9284. WFIFOL(fd,2) = tid;
  9285. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9286. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9287. WFIFOSET(fd, packet_len_table[0x1e0]);
  9288. return;
  9289. }
  9290. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9291. char output[512];
  9292. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9293. int i, pos;
  9294. RFIFOHEAD(fd);
  9295. memset(output, '\0', sizeof(output));
  9296. nick = (char*)RFIFOP(fd,2); // speed up
  9297. RFIFOB(fd,NAME_LENGTH+1) = '\0'; // to be sure that the player name have at maximum 23 characters (nick range: [2]->[26])
  9298. //printf("Ignore: char '%s' state: %d\n", nick, RFIFOB(fd,26));
  9299. WFIFOHEAD(fd,packet_len_table[0xd1]);
  9300. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9301. WFIFOB(fd,2) = RFIFOB(fd,26);
  9302. // do nothing only if nick can not exist
  9303. if (strlen(nick) < 4) {
  9304. WFIFOB(fd,3) = 1; // fail
  9305. WFIFOSET(fd, packet_len_table[0x0d1]);
  9306. if (RFIFOB(fd,26) == 0) // type
  9307. clif_wis_message(fd, wisp_server_name, "It's impossible to block this player.", strlen("It's impossible to block this player.") + 1);
  9308. else
  9309. clif_wis_message(fd, wisp_server_name, "It's impossible to unblock this player.", strlen("It's impossible to unblock this player.") + 1);
  9310. return;
  9311. // name can exist
  9312. } else {
  9313. // deny action (we add nick only if it's not already exist
  9314. if (RFIFOB(fd,26) == 0) { // type
  9315. pos = -1;
  9316. for(i = 0; i < MAX_IGNORE_LIST; i++) {
  9317. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9318. WFIFOB(fd,3) = 1; // fail
  9319. WFIFOSET(fd, packet_len_table[0x0d1]);
  9320. clif_wis_message(fd, wisp_server_name, "This player is already blocked.", strlen("This player is already blocked.") + 1);
  9321. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9322. 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);
  9323. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9324. }
  9325. return;
  9326. } else if (pos == -1 && sd->ignore[i].name[0] == '\0')
  9327. pos = i;
  9328. }
  9329. // if a position is found and name not found, we add it in the list
  9330. if (pos != -1) {
  9331. memcpy(sd->ignore[pos].name, nick, NAME_LENGTH-1);
  9332. WFIFOB(fd,3) = 0; // success
  9333. WFIFOSET(fd, packet_len_table[0x0d1]);
  9334. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9335. 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);
  9336. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9337. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9338. clif_wis_message(fd, wisp_server_name, "Add me in your ignore list, doesn't block my wisps.", strlen("Add me in your ignore list, doesn't block my wisps.") + 1);
  9339. }
  9340. } else {
  9341. WFIFOB(fd,3) = 1; // fail
  9342. WFIFOSET(fd, packet_len_table[0x0d1]);
  9343. clif_wis_message(fd, wisp_server_name, "You can not block more people.", strlen("You can not block more people.") + 1);
  9344. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9345. 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);
  9346. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9347. }
  9348. }
  9349. // allow action (we remove all same nicks if they exist)
  9350. } else {
  9351. pos = -1;
  9352. for(i = 0; i < MAX_IGNORE_LIST; i++)
  9353. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9354. memset(sd->ignore[i].name, 0, sizeof(sd->ignore[i].name));
  9355. if (pos == -1) {
  9356. WFIFOB(fd,3) = 0; // success
  9357. WFIFOSET(fd, packet_len_table[0x0d1]);
  9358. pos = i; // don't break, to remove ALL same nick
  9359. }
  9360. }
  9361. if (pos == -1) {
  9362. WFIFOB(fd,3) = 1; // fail
  9363. WFIFOSET(fd, packet_len_table[0x0d1]);
  9364. clif_wis_message(fd, wisp_server_name, "This player is not blocked by you.", strlen("This player is not blocked by you.") + 1);
  9365. }
  9366. }
  9367. }
  9368. // for(i = 0; i < MAX_IGNORE_LIST; i++) // for debug only
  9369. // if (sd->ignore[i].name[0] != '\0')
  9370. // printf("Ignored player: '%s'\n", sd->ignore[i].name);
  9371. return;
  9372. }
  9373. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9374. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9375. RFIFOHEAD(fd);
  9376. if (RFIFOB(fd,2) == 0) {// S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9377. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9378. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9379. WFIFOB(fd,2) = 0;
  9380. if (sd->ignoreAll == 0) {
  9381. sd->ignoreAll = 1;
  9382. WFIFOB(fd,3) = 0; // success
  9383. WFIFOSET(fd, packet_len_table[0x0d2]);
  9384. } else {
  9385. WFIFOB(fd,3) = 1; // fail
  9386. WFIFOSET(fd, packet_len_table[0x0d2]);
  9387. clif_wis_message(fd, wisp_server_name, "You already block everyone.", strlen("You already block everyone.") + 1);
  9388. }
  9389. } else {
  9390. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9391. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9392. WFIFOB(fd,2) = 1;
  9393. if (sd->ignoreAll == 1) {
  9394. sd->ignoreAll = 0;
  9395. WFIFOB(fd,3) = 0; // success
  9396. WFIFOSET(fd, packet_len_table[0x0d2]);
  9397. } else {
  9398. WFIFOB(fd,3) = 1; // fail
  9399. WFIFOSET(fd, packet_len_table[0x0d2]);
  9400. clif_wis_message(fd, wisp_server_name, "You already allow everyone.", strlen("You already allow everyone.") + 1);
  9401. }
  9402. }
  9403. return;
  9404. }
  9405. /*==========================================
  9406. * Wis拒否リスト
  9407. *------------------------------------------
  9408. */
  9409. int pstrcmp(const void *a, const void *b)
  9410. {
  9411. return strcmp((char *)a, (char *)b);
  9412. }
  9413. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9414. {
  9415. int i,j=0,count=0;
  9416. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9417. for(i = 0; i < MAX_IGNORE_LIST; i++){ //中身があるのを数える
  9418. if(sd->ignore[i].name[0] != 0)
  9419. count++;
  9420. }
  9421. WFIFOHEAD(fd, 4 + (NAME_LENGTH * count));
  9422. WFIFOW(fd,0) = 0xd4;
  9423. WFIFOW(fd,2) = 4 + (NAME_LENGTH * count);
  9424. for(i = 0; i < MAX_IGNORE_LIST; i++){
  9425. if(sd->ignore[i].name[0] != 0){
  9426. memcpy(WFIFOP(fd, 4 + j * 24),sd->ignore[i].name, NAME_LENGTH);
  9427. j++;
  9428. }
  9429. }
  9430. WFIFOSET(fd, WFIFOW(fd,2));
  9431. if(count >= MAX_IGNORE_LIST) //満タンなら最後の1個を消す
  9432. sd->ignore[MAX_IGNORE_LIST - 1].name[0] = 0;
  9433. return;
  9434. }
  9435. /*==========================================
  9436. * スパノビの/doridoriによるSPR2倍
  9437. *------------------------------------------
  9438. */
  9439. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9440. int level;
  9441. sd->doridori_counter = 1;
  9442. if ((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON
  9443. && sd->state.rest && (level = pc_checkskill(sd,TK_SPTIME)))
  9444. sc_start(&sd->bl,SkillStatusChangeTable[TK_SPTIME],100,level,skill_get_time(TK_SPTIME, level));
  9445. return;
  9446. }
  9447. /*==========================================
  9448. * スパノビの爆裂波動
  9449. *------------------------------------------
  9450. */
  9451. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9452. {
  9453. if(sd){
  9454. int nextbaseexp=pc_nextbaseexp(sd);
  9455. if (battle_config.etc_log){
  9456. if(nextbaseexp != 0)
  9457. 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));
  9458. else
  9459. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9460. }
  9461. 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){
  9462. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9463. sc_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  9464. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9465. }
  9466. }
  9467. return;
  9468. }
  9469. // random notes:
  9470. // 0x214: monster/player info ?
  9471. /*==========================================
  9472. * Friends List
  9473. *------------------------------------------
  9474. */
  9475. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9476. { //Toggles a single friend online/offline [Skotlex]
  9477. int i;
  9478. //Seek friend.
  9479. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9480. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9481. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9482. return; //Not found
  9483. WFIFOHEAD(sd->fd,packet_len_table[0x206]);
  9484. WFIFOW(sd->fd, 0) = 0x206;
  9485. WFIFOL(sd->fd, 2) = sd->status.friends[i].account_id;
  9486. WFIFOL(sd->fd, 6) = sd->status.friends[i].char_id;
  9487. WFIFOB(sd->fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9488. WFIFOSET(sd->fd, packet_len_table[0x206]);
  9489. }
  9490. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9491. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9492. {
  9493. int account_id, char_id, online;
  9494. account_id = va_arg(ap, int);
  9495. char_id = va_arg(ap, int);
  9496. online = va_arg(ap, int);
  9497. clif_friendslist_toggle(sd, account_id, char_id, online);
  9498. return 0;
  9499. }
  9500. //For sending the whole friends list.
  9501. void clif_friendslist_send(struct map_session_data *sd) {
  9502. int i = 0, n;
  9503. // Send friends list
  9504. WFIFOHEAD(sd->fd, MAX_FRIENDS * 32 + 4);
  9505. WFIFOW(sd->fd, 0) = 0x201;
  9506. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9507. {
  9508. WFIFOL(sd->fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9509. WFIFOL(sd->fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9510. memcpy(WFIFOP(sd->fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9511. }
  9512. if (i) {
  9513. WFIFOW(sd->fd,2) = 4 + 32 * i;
  9514. WFIFOSET(sd->fd, WFIFOW(sd->fd,2));
  9515. }
  9516. for (n = 0; n < i; n++)
  9517. { //Sending the online players
  9518. if (map_charid2sd(sd->status.friends[n].char_id))
  9519. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9520. }
  9521. }
  9522. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9523. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9524. {
  9525. int fd;
  9526. nullpo_retv(sd);
  9527. fd = sd->fd;
  9528. WFIFOHEAD(fd,packet_len_table[0x209]);
  9529. WFIFOW(fd,0) = 0x209;
  9530. WFIFOW(fd,2) = type;
  9531. if (f_sd)
  9532. {
  9533. WFIFOW(fd,4) = f_sd->status.account_id;
  9534. WFIFOW(fd,8) = f_sd->status.char_id;
  9535. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9536. }
  9537. WFIFOSET(fd, packet_len_table[0x209]);
  9538. }
  9539. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9540. struct map_session_data *f_sd;
  9541. int i, f_fd;
  9542. RFIFOHEAD(fd);
  9543. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9544. // Friend doesn't exist (no player with this name)
  9545. if (f_sd == NULL) {
  9546. clif_displaymessage(fd, msg_txt(3));
  9547. return;
  9548. }
  9549. // @noask [LuzZza]
  9550. if(f_sd->state.noask) {
  9551. // Your request has been rejected by autoreject option.
  9552. clif_displaymessage(fd, msg_txt(392));
  9553. return;
  9554. }
  9555. // Friend already exists
  9556. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9557. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9558. clif_displaymessage(fd, "Friend already exists.");
  9559. return;
  9560. }
  9561. }
  9562. if (i == MAX_FRIENDS) {
  9563. //No space, list full.
  9564. clif_friendslist_reqack(sd, f_sd, 2);
  9565. return;
  9566. }
  9567. f_fd = f_sd->fd;
  9568. WFIFOHEAD(f_fd,packet_len_table[0x207]);
  9569. WFIFOW(f_fd,0) = 0x207;
  9570. WFIFOL(f_fd,2) = sd->status.account_id;
  9571. WFIFOL(f_fd,6) = sd->status.char_id;
  9572. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9573. WFIFOSET(f_fd, packet_len_table[0x207]);
  9574. return;
  9575. }
  9576. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9577. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9578. struct map_session_data *f_sd;
  9579. int char_id, account_id;
  9580. char reply;
  9581. RFIFOHEAD(fd);
  9582. account_id = RFIFOL(fd,2);
  9583. char_id = RFIFOL(fd,6);
  9584. reply = RFIFOB(fd,10);
  9585. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9586. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9587. if (f_sd == NULL)
  9588. return;
  9589. if (reply == 0)
  9590. clif_friendslist_reqack(f_sd, sd, 1);
  9591. else {
  9592. int i;
  9593. // Find an empty slot
  9594. for (i = 0; i < MAX_FRIENDS; i++)
  9595. if (f_sd->status.friends[i].char_id == 0)
  9596. break;
  9597. if (i == MAX_FRIENDS) {
  9598. clif_friendslist_reqack(f_sd, sd, 2);
  9599. return;
  9600. }
  9601. f_sd->status.friends[i].account_id = sd->status.account_id;
  9602. f_sd->status.friends[i].char_id = sd->status.char_id;
  9603. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9604. clif_friendslist_reqack(f_sd, sd, 0);
  9605. // clif_friendslist_send(sd); //This is not needed anymore.
  9606. }
  9607. return;
  9608. }
  9609. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9610. // 0x203 </o> <ID to be removed W 4B>
  9611. int account_id, char_id;
  9612. int i, j;
  9613. RFIFOHEAD(fd);
  9614. account_id = RFIFOL(fd,2);
  9615. char_id = RFIFOL(fd,6);
  9616. // Search friend
  9617. for (i = 0; i < MAX_FRIENDS &&
  9618. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9619. if (i == MAX_FRIENDS) {
  9620. clif_displaymessage(fd, "Name not found in list.");
  9621. return;
  9622. }
  9623. // move all chars down
  9624. for(j = i + 1; j < MAX_FRIENDS; j++)
  9625. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9626. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9627. clif_displaymessage(fd, "Friend removed");
  9628. WFIFOHEAD(fd,packet_len_table[0x20a]);
  9629. WFIFOW(fd,0) = 0x20a;
  9630. WFIFOL(fd,2) = account_id;
  9631. WFIFOL(fd,6) = char_id;
  9632. WFIFOSET(fd, packet_len_table[0x20a]);
  9633. // clif_friendslist_send(sd); //This is not needed anymore.
  9634. return;
  9635. }
  9636. /*==========================================
  9637. * /killall
  9638. *------------------------------------------
  9639. */
  9640. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  9641. {
  9642. char message[50];
  9643. strncpy(message,sd->status.name, NAME_LENGTH);
  9644. is_atcommand(fd, sd, strcat(message," : @kickall"),0);
  9645. return;
  9646. }
  9647. /*==========================================
  9648. * /pvpinfo
  9649. *------------------------------------------
  9650. */
  9651. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9652. {
  9653. WFIFOHEAD(fd,packet_len_table[0x210]);
  9654. WFIFOW(fd,0) = 0x210;
  9655. //WFIFOL(fd,2) = 0; // not sure what for yet
  9656. //WFIFOL(fd,6) = 0;
  9657. WFIFOL(fd,10) = sd->pvp_won; // times won
  9658. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9659. WFIFOL(fd,18) = sd->pvp_point;
  9660. WFIFOSET(fd, packet_len_table[0x210]);
  9661. return;
  9662. }
  9663. /*==========================================
  9664. * /blacksmith
  9665. *------------------------------------------
  9666. */
  9667. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9668. {
  9669. int i;
  9670. char *name;
  9671. WFIFOHEAD(fd,packet_len_table[0x219]);
  9672. WFIFOW(fd,0) = 0x219;
  9673. //Packet size limits this list to 10 elements. [Skotlex]
  9674. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9675. if (smith_fame_list[i].id > 0) {
  9676. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9677. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9678. {
  9679. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9680. } else
  9681. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9682. } else
  9683. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9684. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9685. }
  9686. for(;i < 10; i++) { //In case the MAX is less than 10.
  9687. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9688. WFIFOL(fd, 242 + i * 4) = 0;
  9689. }
  9690. WFIFOSET(fd, packet_len_table[0x219]);
  9691. }
  9692. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9693. {
  9694. int fd = sd->fd;
  9695. WFIFOHEAD(fd,packet_len_table[0x21b]);
  9696. WFIFOW(fd,0) = 0x21b;
  9697. WFIFOL(fd,2) = points;
  9698. WFIFOL(fd,6) = sd->status.fame;
  9699. WFIFOSET(fd, packet_len_table[0x21b]);
  9700. return 0;
  9701. }
  9702. /*==========================================
  9703. * /alchemist
  9704. *------------------------------------------
  9705. */
  9706. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9707. {
  9708. int i;
  9709. char *name;
  9710. WFIFOHEAD(fd,packet_len_table[0x21a]);
  9711. WFIFOW(fd,0) = 0x21a;
  9712. //Packet size limits this list to 10 elements. [Skotlex]
  9713. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9714. if (chemist_fame_list[i].id > 0) {
  9715. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9716. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9717. {
  9718. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9719. } else
  9720. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9721. } else
  9722. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9723. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9724. }
  9725. for(;i < 10; i++) { //In case the MAX is less than 10.
  9726. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9727. WFIFOL(fd, 242 + i * 4) = 0;
  9728. }
  9729. WFIFOSET(fd, packet_len_table[0x21a]);
  9730. }
  9731. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9732. {
  9733. int fd = sd->fd;
  9734. WFIFOHEAD(fd,packet_len_table[0x21c]);
  9735. WFIFOW(fd,0) = 0x21c;
  9736. WFIFOL(fd,2) = points;
  9737. WFIFOL(fd,6) = sd->status.fame;
  9738. WFIFOSET(fd, packet_len_table[0x21c]);
  9739. return 0;
  9740. }
  9741. /*==========================================
  9742. * /taekwon
  9743. *------------------------------------------
  9744. */
  9745. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9746. {
  9747. int i;
  9748. char *name;
  9749. WFIFOHEAD(fd,packet_len_table[0x226]);
  9750. WFIFOW(fd,0) = 0x226;
  9751. //Packet size limits this list to 10 elements. [Skotlex]
  9752. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9753. if (taekwon_fame_list[i].id > 0) {
  9754. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9755. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9756. {
  9757. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9758. } else
  9759. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9760. } else
  9761. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9762. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9763. }
  9764. for(;i < 10; i++) { //In case the MAX is less than 10.
  9765. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9766. WFIFOL(fd, 242 + i * 4) = 0;
  9767. }
  9768. WFIFOSET(fd, packet_len_table[0x226]);
  9769. }
  9770. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9771. {
  9772. int fd = sd->fd;
  9773. WFIFOHEAD(fd,packet_len_table[0x224]);
  9774. WFIFOW(fd,0) = 0x224;
  9775. WFIFOL(fd,2) = points;
  9776. WFIFOL(fd,6) = sd->status.fame;
  9777. WFIFOSET(fd, packet_len_table[0x224]);
  9778. return 0;
  9779. }
  9780. /*==========================================
  9781. * PK Ranking table?
  9782. *------------------------------------------
  9783. */
  9784. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9785. {
  9786. int i;
  9787. WFIFOHEAD(fd,packet_len_table[0x238]);
  9788. WFIFOW(fd,0) = 0x238;
  9789. for(i=0;i<10;i++){
  9790. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9791. WFIFOL(fd,i*4+242) = 0;
  9792. }
  9793. WFIFOSET(fd, packet_len_table[0x238]);
  9794. return;
  9795. }
  9796. /*==========================================
  9797. * SG Feel save OK [Komurka]
  9798. *------------------------------------------
  9799. */
  9800. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9801. {
  9802. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  9803. int i;
  9804. if (sd->menuskill_id != SG_FEEL)
  9805. return;
  9806. i = sd->menuskill_lv-1;
  9807. if (i<0 || i > 2) return; //Bug?
  9808. sd->feel_map[i].index = map[sd->bl.m].index;
  9809. sd->feel_map[i].m = sd->bl.m;
  9810. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  9811. WFIFOHEAD(fd,packet_len_table[0x20e]);
  9812. WFIFOW(fd,0)=0x20e;
  9813. memcpy(WFIFOP(fd,2),map[sd->bl.m].name, MAP_NAME_LENGTH);
  9814. WFIFOL(fd,26)=sd->bl.id;
  9815. WFIFOW(fd,30)=i;
  9816. WFIFOSET(fd, packet_len_table[0x20e]);
  9817. if (sd->bl.m == sd->feel_map[i].m &&
  9818. (i = pc_checkskill(sd,SG_KNOWLEDGE)) > 0)
  9819. sc_start(&sd->bl, SC_KNOWLEDGE, 100, i, skill_get_time(SG_KNOWLEDGE, i));
  9820. sd->menuskill_lv = sd->menuskill_id = 0;
  9821. }
  9822. /*==========================================
  9823. * Question about Star Glaldiator save map [Komurka]
  9824. *------------------------------------------
  9825. */
  9826. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  9827. WFIFOHEAD(fd,packet_len_table[0x253]);
  9828. WFIFOW(fd,0)=0x253;
  9829. WFIFOSET(fd, packet_len_table[0x253]);
  9830. sd->menuskill_id=SG_FEEL;
  9831. sd->menuskill_lv=skilllv;
  9832. }
  9833. /*==========================================
  9834. * パケットデバッグ
  9835. *------------------------------------------
  9836. */
  9837. void clif_parse_debug(int fd,struct map_session_data *sd)
  9838. {
  9839. int i, cmd, len;
  9840. RFIFOHEAD(fd);
  9841. cmd = RFIFOW(fd,0);
  9842. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  9843. ShowDebug("packet debug 0x%4X\n",cmd);
  9844. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9845. for(i=0;i<len;i++){
  9846. if((i&15)==0)
  9847. printf("\n%04X ",i);
  9848. printf("%02X ",RFIFOB(fd,i));
  9849. }
  9850. printf("\n");
  9851. }
  9852. /*==========================================
  9853. * クライアントからのパケット解析
  9854. * socket.cのdo_parsepacketから呼び出される
  9855. *------------------------------------------
  9856. */
  9857. int clif_parse(int fd) {
  9858. int packet_len = 0, cmd, packet_ver, dump = 0;
  9859. struct map_session_data *sd;
  9860. RFIFOHEAD(fd);
  9861. if (fd <= 0)
  9862. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  9863. ShowError("clif_parse: Received invalid session %d\n", fd);
  9864. return 0;
  9865. }
  9866. sd = (struct map_session_data*)session[fd]->session_data;
  9867. // 接続が切れてるので後始末
  9868. if (!chrif_isconnect() && kick_on_disconnect)
  9869. {
  9870. ShowInfo("Closing session #%d (Not connected to Char server)\n", fd);
  9871. if (sd && sd->state.auth)
  9872. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  9873. do_close(fd);
  9874. return 0;
  9875. } else
  9876. if (session[fd]->eof) {
  9877. if (sd && sd->state.autotrade) {
  9878. //Disassociate character from the socket connection.
  9879. session[fd]->session_data = NULL;
  9880. sd->fd = 0;
  9881. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  9882. } else if (sd && sd->state.auth) {
  9883. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  9884. if (sd->status.name != NULL)
  9885. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  9886. else
  9887. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id); // Player logout display [Yor]
  9888. } else {
  9889. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  9890. ShowInfo("Player not identified with IP '"CL_WHITE"%d.%d.%d.%d"CL_RESET"' logged off.\n", ip[0],ip[1],ip[2],ip[3]);
  9891. }
  9892. do_close(fd);
  9893. return 0;
  9894. }
  9895. if (RFIFOREST(fd) < 2)
  9896. return 0;
  9897. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  9898. cmd = RFIFOW(fd,0);
  9899. // 管理用パケット処理
  9900. if (cmd >= 30000) {
  9901. switch(cmd) {
  9902. case 0x7530: { //Why are we letting people know which version we are running?
  9903. WFIFOHEAD(fd, 10);
  9904. WFIFOW(fd,0) = 0x7531;
  9905. WFIFOB(fd,2) = ATHENA_MAJOR_VERSION;
  9906. WFIFOB(fd,3) = ATHENA_MINOR_VERSION;
  9907. WFIFOB(fd,4) = ATHENA_REVISION;
  9908. WFIFOB(fd,5) = ATHENA_RELEASE_FLAG;
  9909. WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG;
  9910. WFIFOB(fd,7) = ATHENA_SERVER_MAP;
  9911. WFIFOW(fd,8) = ATHENA_MOD_VERSION;
  9912. WFIFOSET(fd,10);
  9913. RFIFOSKIP(fd,2);
  9914. break;
  9915. }
  9916. case 0x7532: // 接続の切断
  9917. ShowWarning("clif_parse: session #%d disconnected for sending packet 0x04%x\n", fd, cmd);
  9918. session[fd]->eof=1;
  9919. break;
  9920. default:
  9921. ShowWarning("Unknown incoming packet (command: 0x%04x, session: %d), disconnecting.\n", cmd, fd);
  9922. session[fd]->eof=1;
  9923. break;
  9924. }
  9925. return 0;
  9926. }
  9927. // get packet version before to parse
  9928. packet_ver = 0;
  9929. if (sd) {
  9930. packet_ver = sd->packet_ver;
  9931. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  9932. session[fd]->eof = 1;
  9933. return 0;
  9934. }
  9935. } else {
  9936. // check authentification packet to know packet version
  9937. packet_ver = clif_guess_PacketVer(fd, 0);
  9938. // check if version is accepted
  9939. if (packet_ver < 5 || // reject really old client versions
  9940. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  9941. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
  9942. packet_ver > MAX_PACKET_VER) // no packet version support yet
  9943. {
  9944. ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
  9945. WFIFOHEAD(fd, 23);
  9946. WFIFOW(fd,0) = 0x6a;
  9947. WFIFOB(fd,2) = 5; // 05 = Game's EXE is not the latest version
  9948. WFIFOSET(fd,23);
  9949. packet_len = RFIFOREST(fd);
  9950. RFIFOSKIP(fd, packet_len);
  9951. clif_setwaitclose(fd);
  9952. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  9953. session[fd]->func_send(fd);
  9954. return 0;
  9955. }
  9956. }
  9957. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  9958. 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
  9959. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  9960. session[fd]->eof = 1;
  9961. return 0;
  9962. }
  9963. // パケット長を計算
  9964. packet_len = packet_db[packet_ver][cmd].len;
  9965. if (packet_len == -1) {
  9966. if (RFIFOREST(fd) < 4)
  9967. return 0; // 可変長パケットで長さの所までデータが来てない
  9968. packet_len = RFIFOW(fd,2);
  9969. if (packet_len < 4 || packet_len > 32768) {
  9970. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  9971. session[fd]->eof =1;
  9972. return 0;
  9973. }
  9974. }
  9975. if ((int)RFIFOREST(fd) < packet_len)
  9976. return 0; // まだ1パケット分データが揃ってない
  9977. #if DUMP_ALL_PACKETS
  9978. dump = 1;
  9979. #endif
  9980. if (sd && sd->state.auth == 1 && sd->state.waitingdisconnect == 1) { // 切断待ちの場合パケットを処理しない
  9981. } else if (packet_db[packet_ver][cmd].func) {
  9982. if (sd
  9983. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  9984. || packet_db[packet_ver][cmd].func == clif_parse_debug
  9985. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  9986. packet_db[packet_ver][cmd].func(fd, sd);
  9987. } else {
  9988. // 不明なパケット
  9989. if (battle_config.error_log) {
  9990. #if DUMP_UNKNOWN_PACKET
  9991. {
  9992. int i;
  9993. FILE *fp;
  9994. char packet_txt[256] = "save/packet.txt";
  9995. time_t now;
  9996. dump = 1;
  9997. if ((fp = fopen(packet_txt, "a")) == NULL) {
  9998. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  9999. return 1;
  10000. } else {
  10001. time(&now);
  10002. if (sd && sd->state.auth) {
  10003. if (sd->status.name != NULL)
  10004. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10005. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10006. else
  10007. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10008. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10009. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10010. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10011. for(i = 0; i < packet_len; i++) {
  10012. if ((i & 15) == 0)
  10013. fprintf(fp, "\n\t%04X ", i);
  10014. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10015. }
  10016. fprintf(fp, "\n\n");
  10017. fclose(fp);
  10018. }
  10019. }
  10020. #endif
  10021. }
  10022. }
  10023. if (dump) {
  10024. int i;
  10025. if (fd)
  10026. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10027. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10028. for(i = 0; i < packet_len; i++) {
  10029. if ((i & 15) == 0)
  10030. printf("\n%04X ",i);
  10031. printf("%02X ", RFIFOB(fd,i));
  10032. }
  10033. printf("\n");
  10034. if (sd && sd->state.auth) {
  10035. if (sd->status.name != NULL)
  10036. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10037. sd->status.account_id, sd->status.char_id, sd->status.name);
  10038. else
  10039. printf("\nAccount ID %d.\n", sd->bl.id);
  10040. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10041. printf("\nAccount ID %d.\n", sd->bl.id);
  10042. }
  10043. RFIFOSKIP(fd, packet_len);
  10044. return 0;
  10045. }
  10046. /*==========================================
  10047. * パケットデータベース読み込み
  10048. *------------------------------------------
  10049. */
  10050. static int packetdb_readdb(void)
  10051. {
  10052. FILE *fp;
  10053. char line[1024];
  10054. int ln=0;
  10055. int cmd,i,j,k,packet_ver;
  10056. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10057. struct {
  10058. void (*func)(int, struct map_session_data *);
  10059. char *name;
  10060. } clif_parse_func[]={
  10061. {clif_parse_WantToConnection,"wanttoconnection"},
  10062. {clif_parse_LoadEndAck,"loadendack"},
  10063. {clif_parse_TickSend,"ticksend"},
  10064. {clif_parse_WalkToXY,"walktoxy"},
  10065. {clif_parse_QuitGame,"quitgame"},
  10066. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10067. {clif_parse_GlobalMessage,"globalmessage"},
  10068. {clif_parse_MapMove,"mapmove"},
  10069. {clif_parse_ChangeDir,"changedir"},
  10070. {clif_parse_Emotion,"emotion"},
  10071. {clif_parse_HowManyConnections,"howmanyconnections"},
  10072. {clif_parse_ActionRequest,"actionrequest"},
  10073. {clif_parse_Restart,"restart"},
  10074. {clif_parse_Wis,"wis"},
  10075. {clif_parse_GMmessage,"gmmessage"},
  10076. {clif_parse_TakeItem,"takeitem"},
  10077. {clif_parse_DropItem,"dropitem"},
  10078. {clif_parse_UseItem,"useitem"},
  10079. {clif_parse_EquipItem,"equipitem"},
  10080. {clif_parse_UnequipItem,"unequipitem"},
  10081. {clif_parse_NpcClicked,"npcclicked"},
  10082. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10083. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10084. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10085. {clif_parse_CreateChatRoom,"createchatroom"},
  10086. {clif_parse_ChatAddMember,"chataddmember"},
  10087. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10088. {clif_parse_ChangeChatOwner,"changechatowner"},
  10089. {clif_parse_KickFromChat,"kickfromchat"},
  10090. {clif_parse_ChatLeave,"chatleave"},
  10091. {clif_parse_TradeRequest,"traderequest"},
  10092. {clif_parse_TradeAck,"tradeack"},
  10093. {clif_parse_TradeAddItem,"tradeadditem"},
  10094. {clif_parse_TradeOk,"tradeok"},
  10095. {clif_parse_TradeCancel,"tradecancel"},
  10096. {clif_parse_TradeCommit,"tradecommit"},
  10097. {clif_parse_StopAttack,"stopattack"},
  10098. {clif_parse_PutItemToCart,"putitemtocart"},
  10099. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10100. {clif_parse_RemoveOption,"removeoption"},
  10101. {clif_parse_ChangeCart,"changecart"},
  10102. {clif_parse_StatusUp,"statusup"},
  10103. {clif_parse_SkillUp,"skillup"},
  10104. {clif_parse_UseSkillToId,"useskilltoid"},
  10105. {clif_parse_UseSkillToPos,"useskilltopos"},
  10106. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10107. {clif_parse_UseSkillMap,"useskillmap"},
  10108. {clif_parse_RequestMemo,"requestmemo"},
  10109. {clif_parse_ProduceMix,"producemix"},
  10110. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10111. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10112. {clif_parse_NpcAmountInput,"npcamountinput"},
  10113. {clif_parse_NpcStringInput,"npcstringinput"},
  10114. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10115. {clif_parse_ItemIdentify,"itemidentify"},
  10116. {clif_parse_SelectArrow,"selectarrow"},
  10117. {clif_parse_AutoSpell,"autospell"},
  10118. {clif_parse_UseCard,"usecard"},
  10119. {clif_parse_InsertCard,"insertcard"},
  10120. {clif_parse_RepairItem,"repairitem"},
  10121. {clif_parse_WeaponRefine,"weaponrefine"},
  10122. {clif_parse_SolveCharName,"solvecharname"},
  10123. {clif_parse_ResetChar,"resetchar"},
  10124. {clif_parse_LGMmessage,"lgmmessage"},
  10125. {clif_parse_MoveToKafra,"movetokafra"},
  10126. {clif_parse_MoveFromKafra,"movefromkafra"},
  10127. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10128. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10129. {clif_parse_CloseKafra,"closekafra"},
  10130. {clif_parse_CreateParty,"createparty"},
  10131. {clif_parse_CreateParty2,"createparty2"},
  10132. {clif_parse_PartyInvite,"partyinvite"},
  10133. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10134. {clif_parse_LeaveParty,"leaveparty"},
  10135. {clif_parse_RemovePartyMember,"removepartymember"},
  10136. {clif_parse_PartyChangeOption,"partychangeoption"},
  10137. {clif_parse_PartyMessage,"partymessage"},
  10138. {clif_parse_CloseVending,"closevending"},
  10139. {clif_parse_VendingListReq,"vendinglistreq"},
  10140. {clif_parse_PurchaseReq,"purchasereq"},
  10141. {clif_parse_OpenVending,"openvending"},
  10142. {clif_parse_CreateGuild,"createguild"},
  10143. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10144. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10145. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10146. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10147. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10148. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10149. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10150. {clif_parse_GuildInvite,"guildinvite"},
  10151. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10152. {clif_parse_GuildLeave,"guildleave"},
  10153. {clif_parse_GuildExplusion,"guildexplusion"},
  10154. {clif_parse_GuildMessage,"guildmessage"},
  10155. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10156. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10157. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10158. {clif_parse_GuildOpposition,"guildopposition"},
  10159. {clif_parse_GuildBreak,"guildbreak"},
  10160. {clif_parse_PetMenu,"petmenu"},
  10161. {clif_parse_CatchPet,"catchpet"},
  10162. {clif_parse_SelectEgg,"selectegg"},
  10163. {clif_parse_SendEmotion,"sendemotion"},
  10164. {clif_parse_ChangePetName,"changepetname"},
  10165. {clif_parse_GMKick,"gmkick"},
  10166. {clif_parse_GMHide,"gmhide"},
  10167. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10168. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10169. {clif_parse_NoviceDoriDori,"sndoridori"},
  10170. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10171. {clif_parse_PMIgnore,"wisexin"},
  10172. {clif_parse_PMIgnoreList,"wisexlist"},
  10173. {clif_parse_PMIgnoreAll,"wisall"},
  10174. {clif_parse_FriendsListAdd,"friendslistadd"},
  10175. {clif_parse_FriendsListRemove,"friendslistremove"},
  10176. {clif_parse_FriendsListReply,"friendslistreply"},
  10177. {clif_parse_GMKillAll,"killall"},
  10178. {clif_parse_Recall,"summon"},
  10179. {clif_parse_GM_Monster_Item,"itemmonster"},
  10180. {clif_parse_Shift,"shift"},
  10181. {clif_parse_Blacksmith,"blacksmith"},
  10182. {clif_parse_Alchemist,"alchemist"},
  10183. {clif_parse_Taekwon,"taekwon"},
  10184. {clif_parse_RankingPk,"rankingpk"},
  10185. {clif_parse_FeelSaveOk,"feelsaveok"},
  10186. {clif_parse_debug,"debug"},
  10187. {NULL,NULL}
  10188. };
  10189. sprintf(line, "%s/packet_db.txt", db_path);
  10190. if( (fp=fopen(line,"r"))==NULL ){
  10191. ShowFatalError("can't read %s\n", line);
  10192. exit(1);
  10193. }
  10194. clif_config.packet_db_ver = MAX_PACKET_VER;
  10195. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10196. while(fgets(line,1020,fp)){
  10197. if(line[0]=='/' && line[1]=='/')
  10198. continue;
  10199. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10200. if(strcmpi(w1,"packet_ver")==0) {
  10201. int prev_ver = packet_ver;
  10202. packet_ver = atoi(w2);
  10203. if (packet_ver > MAX_PACKET_VER)
  10204. { //Check to avoid overflowing. [Skotlex]
  10205. ShowWarning("The packet_db table only has support up to version %d\n", MAX_PACKET_VER);
  10206. break;
  10207. }
  10208. // copy from previous version into new version and continue
  10209. // - indicating all following packets should be read into the newer version
  10210. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10211. continue;
  10212. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10213. //This is the preferred version.
  10214. if(strcmpi(w2,"default")==0)
  10215. clif_config.packet_db_ver = MAX_PACKET_VER;
  10216. else {
  10217. // to manually set the packet DB version
  10218. clif_config.packet_db_ver = atoi(w2);
  10219. // check for invalid version
  10220. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10221. clif_config.packet_db_ver < 0)
  10222. clif_config.packet_db_ver = MAX_PACKET_VER;
  10223. }
  10224. continue;
  10225. }
  10226. }
  10227. memset(str,0,sizeof(str));
  10228. for(j=0,p=line;j<4 && p;j++){
  10229. str[j]=p;
  10230. p=strchr(p,',');
  10231. if(p) *p++=0;
  10232. }
  10233. if(str[0]==NULL)
  10234. continue;
  10235. cmd=strtol(str[0],(char **)NULL,0);
  10236. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10237. continue;
  10238. if(str[1]==NULL){
  10239. ShowError("packet_db: packet len error\n");
  10240. continue;
  10241. }
  10242. k = atoi(str[1]);
  10243. packet_db[packet_ver][cmd].len = k;
  10244. if(str[2]==NULL){
  10245. packet_db[packet_ver][cmd].func = NULL;
  10246. ln++;
  10247. continue;
  10248. }
  10249. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10250. if(clif_parse_func[j].name != NULL &&
  10251. strcmp(str[2],clif_parse_func[j].name)==0)
  10252. {
  10253. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10254. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10255. for(i=0;i<MAX_PACKET_DB;i++){
  10256. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10257. {
  10258. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10259. break;
  10260. }
  10261. }
  10262. }
  10263. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10264. break;
  10265. }
  10266. }
  10267. // set the identifying cmd for the packet_db version
  10268. if (strcmp(str[2],"wanttoconnection")==0)
  10269. clif_config.connect_cmd[packet_ver] = cmd;
  10270. if(str[3]==NULL){
  10271. ShowError("packet_db: packet error\n");
  10272. exit(1);
  10273. }
  10274. for(j=0,p2=str[3];p2;j++){
  10275. str2[j]=p2;
  10276. p2=strchr(p2,':');
  10277. if(p2) *p2++=0;
  10278. k = atoi(str2[j]);
  10279. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10280. packet_db[packet_ver][cmd].pos[j] = k;
  10281. }
  10282. ln++;
  10283. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10284. // 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);
  10285. }
  10286. fclose(fp);
  10287. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10288. { //Locate the nearest version that we still support. [Skotlex]
  10289. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10290. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10291. }
  10292. 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);
  10293. return 0;
  10294. }
  10295. /*==========================================
  10296. *
  10297. *------------------------------------------
  10298. */
  10299. int do_init_clif(void) {
  10300. #ifndef __WIN32
  10301. int i;
  10302. #endif
  10303. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10304. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10305. memset(packet_db,0,sizeof(packet_db));
  10306. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10307. packetdb_readdb();
  10308. set_defaultparse(clif_parse);
  10309. #ifdef __WIN32
  10310. //if (!make_listen_port(map_port)) {
  10311. if (!make_listen_bind(bind_ip,map_port)) {
  10312. ShowFatalError("cant bind game port\n");
  10313. exit(1);
  10314. }
  10315. #else
  10316. for(i = 0; i < 10; i++) {
  10317. //if (make_listen_port(map_port))
  10318. if (make_listen_bind(bind_ip,map_port))
  10319. break;
  10320. sleep(20);
  10321. }
  10322. if (i == 10) {
  10323. ShowFatalError("cant bind game port\n");
  10324. exit(1);
  10325. }
  10326. #endif
  10327. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10328. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10329. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10330. add_timer_func_list(clif_nighttimer, "clif_nighttimer");
  10331. add_timer_func_list(clif_walktoxy_timer, "clif_walktoxy_timer");
  10332. return 0;
  10333. }