clif.c 336 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260
  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. #ifdef __WIN32
  11. #define __USE_W32_SOCKETS
  12. #include <windows.h>
  13. #else
  14. #include <unistd.h>
  15. #include <sys/types.h>
  16. #include <sys/socket.h>
  17. #include <netinet/in.h>
  18. #include <arpa/inet.h>
  19. #endif
  20. #include <time.h>
  21. #include "../common/socket.h"
  22. #include "../common/timer.h"
  23. #include "../common/malloc.h"
  24. #include "../common/version.h"
  25. #include "../common/nullpo.h"
  26. #include "../common/showmsg.h"
  27. #include "map.h"
  28. #include "chrif.h"
  29. #include "clif.h"
  30. #include "pc.h"
  31. #include "status.h"
  32. #include "npc.h"
  33. #include "itemdb.h"
  34. #include "chat.h"
  35. #include "trade.h"
  36. #include "storage.h"
  37. #include "script.h"
  38. #include "skill.h"
  39. #include "atcommand.h"
  40. #include "charcommand.h"
  41. #include "intif.h"
  42. #include "battle.h"
  43. #include "mob.h"
  44. #include "party.h"
  45. #include "guild.h"
  46. #include "vending.h"
  47. #include "pet.h"
  48. #include "log.h"
  49. #include "irc.h"
  50. struct Clif_Config {
  51. int packet_db_ver; //Preferred packet version.
  52. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  53. } clif_config;
  54. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
  55. static const int packet_len_table[MAX_PACKET_DB] = {
  56. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  57. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  58. 0, 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. //#0x0040
  61. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  62. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  63. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  64. #if PACKETVER < 2
  65. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  66. #else // 78-7b 亀島以降 lv99エフェクト用
  67. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  68. #endif
  69. //#0x0080
  70. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  71. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  72. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  73. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  74. //#0x00C0
  75. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  76. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  77. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  78. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  79. //#0x0100
  80. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  81. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  82. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  83. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  84. //#0x0140
  85. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  86. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  87. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  88. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  89. //#0x0180
  90. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  91. #if PACKETVER < 1
  92. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  93. #else // 196 comodo以降 状態表示アイコン用
  94. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  95. #endif
  96. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  97. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  98. //#0x01C0, Set 0x1d5=-1
  99. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  100. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  101. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  102. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  103. //#0x200
  104. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  105. 22, 0, 26, 26, 42, -1, -1, 2, 2,282,282,10, 10, -1, -1, 66,
  106. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 69, 5,
  107. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  108. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  109. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4
  110. };
  111. // local define
  112. enum {
  113. ALL_CLIENT,
  114. ALL_SAMEMAP,
  115. AREA,
  116. AREA_WOS,
  117. AREA_WOC,
  118. AREA_WOSC,
  119. AREA_CHAT_WOC,
  120. CHAT,
  121. CHAT_WOS,
  122. CHAT_MAINCHAT,
  123. PARTY,
  124. PARTY_WOS,
  125. PARTY_SAMEMAP,
  126. PARTY_SAMEMAP_WOS,
  127. PARTY_AREA,
  128. PARTY_AREA_WOS,
  129. GUILD,
  130. GUILD_WOS,
  131. GUILD_SAMEMAP, // [Valaris]
  132. GUILD_SAMEMAP_WOS,
  133. GUILD_AREA,
  134. GUILD_AREA_WOS, // end additions [Valaris]
  135. SELF
  136. };
  137. //Converts item type in case of pet eggs.
  138. #define itemtype(a) (a == 7)?4:a
  139. #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; }
  140. #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); }
  141. #define WFIFOPOS(fd,pos,x,y) { WBUFPOS (WFIFOP(fd,pos),0,x,y); }
  142. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1) { WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1); }
  143. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  144. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  145. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  146. #define clif_cant_act(sd) (sd->npc_id || sd->npc_shopid || sd->vender_id || sd->chatID || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT) || sd->trade_partner || sd->state.storage_flag)
  147. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  148. #define clif_trading(sd) (sd->npc_id || sd->npc_shopid || sd->vender_id || sd->trade_partner)
  149. static char map_ip_str[16];
  150. static in_addr_t map_ip;
  151. static in_addr_t bind_ip = INADDR_ANY;
  152. static int map_port = 5121;
  153. int map_fd;
  154. char talkie_mes[MESSAGE_SIZE];
  155. //These two will be used to verify the incoming player's validity.
  156. //It helps identify their client packet version correctly. [Skotlex]
  157. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  158. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  159. int clif_parse (int fd);
  160. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  161. /*==========================================
  162. * map鯖のip設定
  163. *------------------------------------------
  164. */
  165. void clif_setip(char *ip)
  166. {
  167. memcpy(map_ip_str, ip, 16);
  168. map_ip = inet_addr(map_ip_str);
  169. }
  170. void clif_setbindip(char *ip)
  171. {
  172. bind_ip = inet_addr(ip);
  173. }
  174. /*==========================================
  175. * map鯖のport設定
  176. *------------------------------------------
  177. */
  178. void clif_setport(int port)
  179. {
  180. map_port = port;
  181. }
  182. /*==========================================
  183. * map鯖のip読み出し
  184. *------------------------------------------
  185. */
  186. in_addr_t clif_getip(void)
  187. {
  188. return map_ip;
  189. }
  190. /*==========================================
  191. * map鯖のport読み出し
  192. *------------------------------------------
  193. */
  194. int clif_getport(void)
  195. {
  196. return map_port;
  197. }
  198. /*==========================================
  199. * Counts connected players.
  200. *------------------------------------------
  201. */
  202. int clif_countusers(void)
  203. {
  204. int users = 0, i;
  205. struct map_session_data *sd;
  206. for(i = 0; i < fd_max; i++) {
  207. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) && sd->state.auth &&
  208. !(battle_config.hide_GM_session && pc_isGM(sd)))
  209. users++;
  210. }
  211. return users;
  212. }
  213. /*==========================================
  214. * 全てのclientに対してfunc()実行
  215. *------------------------------------------
  216. */
  217. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  218. {
  219. int i;
  220. va_list ap;
  221. struct map_session_data *sd;
  222. va_start(ap,func);
  223. for(i = 0; i < fd_max; i++) {
  224. if ( session[i] ) {
  225. sd = (struct map_session_data*)session[i]->session_data;
  226. if ( sd && session[i]->func_parse == clif_parse &&
  227. sd->state.auth && !sd->state.waitingdisconnect )
  228. func(sd, ap);
  229. }
  230. }
  231. va_end(ap);
  232. return 0;
  233. }
  234. /*==========================================
  235. * clif_sendでAREA*指定時用
  236. *------------------------------------------
  237. */
  238. int clif_send_sub(struct block_list *bl, va_list ap)
  239. {
  240. struct block_list *src_bl;
  241. struct map_session_data *sd;
  242. unsigned char *buf;
  243. int len, type;
  244. nullpo_retr(0, bl);
  245. nullpo_retr(0, ap);
  246. nullpo_retr(0, sd = (struct map_session_data *)bl);
  247. if (!sd->fd) //Avoid attempting to send to disconnected chars (may prevent buffer overrun errors?) [Skotlex]
  248. return 0;
  249. buf = va_arg(ap,unsigned char*);
  250. len = va_arg(ap,int);
  251. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  252. type = va_arg(ap,int);
  253. switch(type) {
  254. case AREA_WOS:
  255. if (bl == src_bl)
  256. return 0;
  257. break;
  258. case AREA_WOC:
  259. if (sd->chatID || bl == src_bl)
  260. return 0;
  261. break;
  262. case AREA_WOSC:
  263. {
  264. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  265. if ((ssd != 0) && (src_bl->type == BL_PC) && (sd->chatID != 0) && (sd->chatID == ssd->chatID))
  266. return 0;
  267. }
  268. break;
  269. }
  270. if (session[sd->fd] != NULL) {
  271. WFIFOHEAD(sd->fd, len);
  272. if (WFIFOP(sd->fd,0) == buf) {
  273. printf("WARNING: Invalid use of clif_send function\n");
  274. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  275. printf(" Please correct your code.\n");
  276. // don't send to not move the pointer of the packet for next sessions in the loop
  277. } else {
  278. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  279. memcpy(WFIFOP(sd->fd,0), buf, len);
  280. //Check if hidden, better to modify the char's buffer than the
  281. //given buffer to prevent intravision affecting the packet as
  282. //it's being received by everyone. [Skotlex]
  283. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 ) && bl != src_bl) {
  284. struct status_change *sc = status_get_sc(src_bl);
  285. if(sc && (sc->option)&(OPTION_HIDE|OPTION_CLOAK))
  286. { //optionの修正
  287. switch(((unsigned short*)buf)[0])
  288. {
  289. case 0x119:
  290. WFIFOW(sd->fd,10) &= ~(OPTION_HIDE|OPTION_CLOAK);
  291. break;
  292. #if PACKETVER < 4
  293. case 0x78:
  294. #else
  295. case 0x1da:
  296. #endif
  297. case 0x7b:
  298. case 0x7c:
  299. case 0x1d8:
  300. WFIFOW(sd->fd,12) &=~(OPTION_HIDE|OPTION_CLOAK);
  301. break;
  302. }
  303. }
  304. }
  305. WFIFOSET(sd->fd,len);
  306. }
  307. }
  308. }
  309. return 0;
  310. }
  311. /*==========================================
  312. *
  313. *------------------------------------------
  314. */
  315. int clif_send (unsigned char *buf, int len, struct block_list *bl, int type) {
  316. int i;
  317. struct map_session_data *sd = NULL;
  318. struct party *p = NULL;
  319. struct guild *g = NULL;
  320. int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
  321. if (type != ALL_CLIENT &&
  322. type != CHAT_MAINCHAT) {
  323. nullpo_retr(0, bl);
  324. if (bl->type == BL_PC) {
  325. sd = (struct map_session_data *)bl;
  326. }
  327. }
  328. switch(type) {
  329. case ALL_CLIENT: // 全クライアントに送信
  330. for (i = 0; i < fd_max; i++) {
  331. if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL && sd->state.auth) {
  332. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  333. WFIFOHEAD(i, len);
  334. memcpy(WFIFOP(i,0), buf, len);
  335. WFIFOSET(i,len);
  336. }
  337. }
  338. }
  339. break;
  340. case ALL_SAMEMAP: // 同じマップの全クライアントに送信
  341. for(i = 0; i < fd_max; i++) {
  342. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  343. sd->state.auth && sd->bl.m == bl->m) {
  344. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  345. WFIFOHEAD(i,len);
  346. memcpy(WFIFOP(i,0), buf, len);
  347. WFIFOSET(i,len);
  348. }
  349. }
  350. }
  351. break;
  352. case AREA:
  353. case AREA_WOS:
  354. case AREA_WOC:
  355. case AREA_WOSC:
  356. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  357. BL_PC, buf, len, bl, type);
  358. break;
  359. case AREA_CHAT_WOC:
  360. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  361. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  362. break;
  363. case CHAT:
  364. case CHAT_WOS:
  365. {
  366. struct chat_data *cd;
  367. if (sd) {
  368. cd = (struct chat_data*)map_id2bl(sd->chatID);
  369. } else if (bl->type == BL_CHAT) {
  370. cd = (struct chat_data*)bl;
  371. } else break;
  372. if (cd == NULL)
  373. break;
  374. for(i = 0; i < cd->users; i++) {
  375. if (type == CHAT_WOS && cd->usersd[i] == sd)
  376. continue;
  377. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  378. if (cd->usersd[i]->fd >0 && session[cd->usersd[i]->fd]) // Added check to see if session exists [PoW]
  379. {
  380. WFIFOHEAD(cd->usersd[i]->fd,len);
  381. memcpy(WFIFOP(cd->usersd[i]->fd,0), buf, len);
  382. WFIFOSET(cd->usersd[i]->fd,len);
  383. }
  384. }
  385. }
  386. }
  387. break;
  388. case CHAT_MAINCHAT: //[LuzZza]
  389. for(i=1; i<fd_max; i++) {
  390. if(session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  391. sd->state.mainchat && sd->fd) {
  392. WFIFOHEAD(sd->fd, len);
  393. memcpy(WFIFOP(sd->fd,0), buf, len);
  394. WFIFOSET(sd->fd, len);
  395. }
  396. }
  397. break;
  398. case PARTY_AREA: // 同じ画面内の全パーティーメンバに送信
  399. case PARTY_AREA_WOS: // 自分以外の同じ画面内の全パーティーメンバに送信
  400. x0 = bl->x - AREA_SIZE;
  401. y0 = bl->y - AREA_SIZE;
  402. x1 = bl->x + AREA_SIZE;
  403. y1 = bl->y + AREA_SIZE;
  404. case PARTY: // 全パーティーメンバに送信
  405. case PARTY_WOS: // 自分以外の全パーティーメンバに送信
  406. case PARTY_SAMEMAP: // 同じマップの全パーティーメンバに送信
  407. case PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信
  408. if (sd && sd->status.party_id)
  409. p = party_search(sd->status.party_id);
  410. if (p) {
  411. for(i=0;i<MAX_PARTY;i++){
  412. if ((sd = p->member[i].sd) != NULL) {
  413. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  414. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  415. continue;
  416. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  417. continue;
  418. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m) // マップチェック
  419. continue;
  420. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  421. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  422. continue;
  423. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  424. WFIFOHEAD(sd->fd,len);
  425. memcpy(WFIFOP(sd->fd,0), buf, len);
  426. WFIFOSET(sd->fd,len);
  427. }
  428. }
  429. }
  430. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  431. break;
  432. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  433. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL && sd->state.auth && sd->fd && sd->partyspy) {
  434. if (sd->partyspy == p->party_id) {
  435. if (sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  436. WFIFOHEAD(sd->fd,len);
  437. memcpy(WFIFOP(sd->fd,0), buf, len);
  438. WFIFOSET(sd->fd,len);
  439. }
  440. }
  441. }
  442. }
  443. }
  444. break;
  445. case SELF:
  446. if (sd && sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  447. WFIFOHEAD(sd->fd,len);
  448. memcpy(WFIFOP(sd->fd,0), buf, len);
  449. WFIFOSET(sd->fd,len);
  450. }
  451. break;
  452. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  453. case GUILD_AREA:
  454. case GUILD_AREA_WOS:
  455. x0 = bl->x - AREA_SIZE;
  456. y0 = bl->y - AREA_SIZE;
  457. x1 = bl->x + AREA_SIZE;
  458. y1 = bl->y + AREA_SIZE;
  459. case GUILD_SAMEMAP:
  460. case GUILD_SAMEMAP_WOS:
  461. case GUILD:
  462. case GUILD_WOS:
  463. if (sd && sd->status.guild_id)
  464. g = guild_search(sd->status.guild_id);
  465. if (g) {
  466. for(i = 0; i < g->max_member; i++) {
  467. if ((sd = g->member[i].sd) != NULL) {
  468. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  469. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  470. continue;
  471. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  472. continue;
  473. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  474. continue;
  475. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  476. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  477. continue;
  478. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  479. WFIFOHEAD(sd->fd,len);
  480. memcpy(WFIFOP(sd->fd,0), buf, len);
  481. WFIFOSET(sd->fd,len);
  482. }
  483. }
  484. }
  485. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  486. break;
  487. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  488. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL && sd->state.auth && sd->fd && sd->guildspy) {
  489. if (sd->guildspy == g->guild_id) {
  490. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  491. WFIFOHEAD(sd->fd,len);
  492. memcpy(WFIFOP(sd->fd,0), buf, len);
  493. WFIFOSET(sd->fd,len);
  494. }
  495. }
  496. }
  497. }
  498. }
  499. break;
  500. /* End [Valaris] */
  501. default:
  502. if (battle_config.error_log)
  503. ShowError("clif_send: Unrecognized type %d\n",type);
  504. return -1;
  505. }
  506. return 0;
  507. }
  508. //
  509. // パケット作って送信
  510. //
  511. /*==========================================
  512. *
  513. *------------------------------------------
  514. */
  515. int clif_authok(struct map_session_data *sd) {
  516. int fd;
  517. if (!sd->fd)
  518. return 0;
  519. fd = sd->fd;
  520. WFIFOHEAD(fd, packet_len_table[0x73]);
  521. WFIFOW(fd, 0) = 0x73;
  522. WFIFOL(fd, 2) = gettick();
  523. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y);
  524. WFIFOB(fd, 9) = 5;
  525. WFIFOB(fd,10) = 5;
  526. WFIFOSET(fd,packet_len_table[0x73]);
  527. return 0;
  528. }
  529. /*==========================================
  530. *
  531. *------------------------------------------
  532. */
  533. int clif_authfail_fd(int fd, int type) {
  534. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  535. return 0;
  536. WFIFOHEAD(fd, packet_len_table[0x81]);
  537. WFIFOW(fd,0) = 0x81;
  538. WFIFOB(fd,2) = type;
  539. WFIFOSET(fd,packet_len_table[0x81]);
  540. clif_setwaitclose(fd);
  541. return 0;
  542. }
  543. /*==========================================
  544. * Used to know which is the max valid account/char id [Skotlex]
  545. *------------------------------------------
  546. */
  547. void clif_updatemaxid(int account_id, int char_id)
  548. {
  549. max_account_id = account_id;
  550. max_char_id = char_id;
  551. }
  552. /*==========================================
  553. *
  554. *------------------------------------------
  555. */
  556. int clif_charselectok(int id) {
  557. struct map_session_data *sd;
  558. int fd;
  559. if ((sd = map_id2sd(id)) == NULL)
  560. return 1;
  561. if (!sd->fd)
  562. return 1;
  563. fd = sd->fd;
  564. WFIFOHEAD(fd, packet_len_table[0xb3]);
  565. WFIFOW(fd,0) = 0xb3;
  566. WFIFOB(fd,2) = 1;
  567. WFIFOSET(fd,packet_len_table[0xb3]);
  568. return 0;
  569. }
  570. /*==========================================
  571. *
  572. *------------------------------------------
  573. */
  574. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  575. int view;
  576. nullpo_retr(0, fitem);
  577. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  578. WBUFW(buf, 0) = 0x9e;
  579. WBUFL(buf, 2) = fitem->bl.id;
  580. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  581. WBUFW(buf, 6) = view;
  582. else
  583. WBUFW(buf, 6) = fitem->item_data.nameid;
  584. WBUFB(buf, 8) = fitem->item_data.identify;
  585. WBUFW(buf, 9) = fitem->bl.x;
  586. WBUFW(buf,11) = fitem->bl.y;
  587. WBUFB(buf,13) = fitem->subx;
  588. WBUFB(buf,14) = fitem->suby;
  589. WBUFW(buf,15) = fitem->item_data.amount;
  590. return packet_len_table[0x9e];
  591. }
  592. /*==========================================
  593. *
  594. *------------------------------------------
  595. */
  596. int clif_dropflooritem(struct flooritem_data *fitem) {
  597. unsigned char buf[64];
  598. nullpo_retr(0, fitem);
  599. if (fitem->item_data.nameid <= 0)
  600. return 0;
  601. clif_set009e(fitem, buf);
  602. clif_send(buf, packet_len_table[0x9e], &fitem->bl, AREA);
  603. return 0;
  604. }
  605. /*==========================================
  606. *
  607. *------------------------------------------
  608. */
  609. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  610. unsigned char buf[16];
  611. nullpo_retr(0, fitem);
  612. WBUFW(buf,0) = 0xa1;
  613. WBUFL(buf,2) = fitem->bl.id;
  614. if (fd == 0) {
  615. clif_send(buf, packet_len_table[0xa1], &fitem->bl, AREA);
  616. } else {
  617. WFIFOHEAD(fd,packet_len_table[0xa1]);
  618. memcpy(WFIFOP(fd,0), buf, 6);
  619. WFIFOSET(fd,packet_len_table[0xa1]);
  620. }
  621. return 0;
  622. }
  623. /*==========================================
  624. *
  625. *------------------------------------------
  626. */
  627. int clif_clearchar(struct block_list *bl, int type) {
  628. unsigned char buf[16];
  629. nullpo_retr(0, bl);
  630. WBUFW(buf,0) = 0x80;
  631. WBUFL(buf,2) = bl->id;
  632. WBUFB(buf,6) = type;
  633. clif_send(buf, packet_len_table[0x80], bl, type == 1 ? AREA : AREA_WOS);
  634. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise) {
  635. WBUFL(buf,2) = -bl->id;
  636. clif_send(buf, packet_len_table[0x80], bl, AREA);
  637. }
  638. return 0;
  639. }
  640. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  641. struct block_list *bl = (struct block_list *)id;
  642. clif_clearchar(bl,data);
  643. aFree(bl);
  644. return 0;
  645. }
  646. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  647. struct block_list *tbl;
  648. tbl = aCalloc(1, sizeof (struct block_list));
  649. memcpy (tbl, bl, sizeof (struct block_list));
  650. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  651. return 0;
  652. }
  653. /*==========================================
  654. *
  655. *------------------------------------------
  656. */
  657. int clif_clearchar_id(int id, int type, int fd) {
  658. unsigned char buf[16];
  659. WBUFW(buf,0) = 0x80;
  660. WBUFL(buf,2) = id;
  661. WBUFB(buf,6) = type;
  662. WFIFOHEAD(fd, packet_len_table[0x80]);
  663. memcpy(WFIFOP(fd,0), buf, 7);
  664. WFIFOSET(fd, packet_len_table[0x80]);
  665. return 0;
  666. }
  667. //Small define to specify the weapon view sprite, makes code easier to read down below... [Skotlex]
  668. #define clif_weapon_viewid(sd, n) ((sd->equip_index[n] >= 0 && sd->inventory_data[sd->equip_index[n]])?(\
  669. (sd->inventory_data[sd->equip_index[n]]->view_id > 0)?sd->inventory_data[sd->equip_index[n]]->view_id: \
  670. sd->status.inventory[sd->equip_index[n]].nameid):0)
  671. #define clif_deadsit(sd) (((sd)->sc.count && (sd)->sc.data[SC_TRICKDEAD].timer != -1)?1:sd->state.dead_sit)
  672. /*==========================================
  673. *
  674. *------------------------------------------
  675. */
  676. static int clif_set0078(struct map_session_data *sd, unsigned char *buf) {
  677. int sdoption;
  678. nullpo_retr(0, sd);
  679. // Disable showing Falcon when player is hide [LuzZza]
  680. if(sd->disguise)
  681. sdoption = OPTION_INVISIBLE;
  682. else {
  683. sdoption = sd->sc.option;
  684. if(sdoption&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE))
  685. sdoption &= ~OPTION_FALCON;
  686. }
  687. #if PACKETVER < 4
  688. memset(buf,0,packet_len_table[0x78]);
  689. WBUFW(buf,0)=0x78;
  690. WBUFL(buf,2)=sd->bl.id;
  691. WBUFW(buf,6)=sd->speed;
  692. WBUFW(buf,8)=sd->sc.opt1;
  693. WBUFW(buf,10)=sd->sc.opt2;
  694. WBUFW(buf,12)=sdoption;
  695. WBUFW(buf,14)=sd->view_class;
  696. WBUFW(buf,16)=sd->status.hair;
  697. if (sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS)
  698. WBUFW(buf,18) = sd->status.weapon;
  699. else
  700. WBUFW(buf,18)=0;
  701. WBUFW(buf,20)=sd->status.head_bottom;
  702. WBUFW(buf,22)=sd->status.shield;
  703. WBUFW(buf,24)=sd->status.head_top;
  704. WBUFW(buf,26)=sd->status.head_mid;
  705. WBUFW(buf,28)=sd->status.hair_color;
  706. WBUFW(buf,30)=sd->status.clothes_color;
  707. WBUFW(buf,32)=sd->head_dir;
  708. WBUFL(buf,34)=sd->status.guild_id;
  709. WBUFL(buf,38)=sd->guild_emblem_id;
  710. WBUFW(buf,42)=sd->status.manner;
  711. WBUFB(buf,44)=sd->status.karma;
  712. WBUFB(buf,45)=sd->sex;
  713. WBUFPOS(buf,46,sd->bl.x,sd->bl.y);
  714. WBUFB(buf,48)|=sd->dir&0x0f;
  715. WBUFB(buf,49)=5;
  716. WBUFB(buf,50)=5;
  717. WBUFB(buf,51)=clif_deadsit(sd);
  718. WBUFW(buf,52)=clif_setlevel(sd->status.base_level);
  719. return packet_len_table[0x78];
  720. #else
  721. memset(buf,0,packet_len_table[0x1d8]);
  722. WBUFW(buf,0)=0x1d8;
  723. WBUFL(buf,2)=sd->bl.id;
  724. WBUFW(buf,6)=sd->speed;
  725. WBUFW(buf,8)=sd->sc.opt1;
  726. WBUFW(buf,10)=sd->sc.opt2;
  727. WBUFW(buf,12)=sdoption;
  728. WBUFW(buf,14)=sd->view_class;
  729. WBUFW(buf,16)=sd->status.hair;
  730. if (sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS)
  731. WBUFW(buf,18) = clif_weapon_viewid(sd,9);
  732. else
  733. WBUFW(buf,18) = 0;
  734. if (sd->equip_index[8] != sd->equip_index[9] && sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS)
  735. WBUFW(buf,20) = clif_weapon_viewid(sd,8);
  736. else
  737. WBUFW(buf,20) = 0;
  738. WBUFW(buf,22)=sd->status.head_bottom;
  739. WBUFW(buf,24)=sd->status.head_top;
  740. WBUFW(buf,26)=sd->status.head_mid;
  741. WBUFW(buf,28)=sd->status.hair_color;
  742. WBUFW(buf,30)=sd->status.clothes_color;
  743. WBUFW(buf,32)=sd->head_dir;
  744. WBUFL(buf,34)=sd->status.guild_id;
  745. WBUFW(buf,38)=sd->guild_emblem_id;
  746. WBUFW(buf,40)=sd->status.manner;
  747. WBUFW(buf,42)=sd->sc.opt3;
  748. WBUFB(buf,44)=sd->status.karma;
  749. WBUFB(buf,45)=sd->sex;
  750. WBUFPOS(buf,46,sd->bl.x,sd->bl.y);
  751. WBUFB(buf,48)|=sd->dir & 0x0f;
  752. WBUFB(buf,49)=5;
  753. WBUFB(buf,50)=5;
  754. WBUFB(buf,51)=clif_deadsit(sd);
  755. WBUFW(buf,52)=clif_setlevel(sd->status.base_level);
  756. return packet_len_table[0x1d8];
  757. #endif
  758. }
  759. // non-moving function for disguises [Valaris]
  760. static int clif_dis0078(struct map_session_data *sd, unsigned char *buf) {
  761. nullpo_retr(0, sd);
  762. memset(buf,0,packet_len_table[0x78]);
  763. WBUFW(buf,0)=0x78;
  764. WBUFL(buf,2)=-sd->bl.id;
  765. WBUFW(buf,6)=sd->speed;
  766. WBUFW(buf,8)=0;
  767. WBUFW(buf,10)=0;
  768. WBUFW(buf,12)=sd->sc.option;
  769. WBUFW(buf,14)=sd->disguise;
  770. //WBUFL(buf,34)=sd->status.guild_id;
  771. //WBUFL(buf,38)=sd->guild_emblem_id;
  772. WBUFW(buf,42)=0;
  773. WBUFB(buf,44)=0;
  774. WBUFPOS(buf,46,sd->bl.x,sd->bl.y);
  775. WBUFB(buf,48)|=sd->dir&0x0f;
  776. WBUFB(buf,49)=5;
  777. WBUFB(buf,50)=5;
  778. WBUFB(buf,51)=clif_deadsit(sd);
  779. WBUFW(buf,52)=0;
  780. return packet_len_table[0x78];
  781. }
  782. /*==========================================
  783. *
  784. *------------------------------------------
  785. */
  786. static int clif_set007b(struct map_session_data *sd,unsigned char *buf) {
  787. int sdoption;
  788. nullpo_retr(0, sd);
  789. // Disable showing Falcon when player is hide [LuzZza]
  790. if(sd->disguise)
  791. sdoption = OPTION_INVISIBLE;
  792. else {
  793. sdoption = sd->sc.option;
  794. if(sdoption&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE))
  795. sdoption &= ~OPTION_FALCON;
  796. }
  797. #if PACKETVER < 4
  798. memset(buf,0,packet_len_table[0x7b]);
  799. WBUFW(buf,0)=0x7b;
  800. WBUFL(buf,2)=sd->bl.id;
  801. WBUFW(buf,6)=sd->speed;
  802. WBUFW(buf,8)=sd->sc.opt1;
  803. WBUFW(buf,10)=sd->sc.opt2;
  804. WBUFW(buf,12)=sdoption;
  805. WBUFW(buf,14)=sd->view_class;
  806. WBUFW(buf,16)=sd->status.hair;
  807. if(sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS)
  808. WBUFW(buf,18)=sd->status.weapon;
  809. else
  810. WBUFW(buf,18)=0;
  811. WBUFW(buf,20)=sd->status.head_bottom;
  812. WBUFL(buf,22)=gettick();
  813. WBUFW(buf,26)=sd->status.shield;
  814. WBUFW(buf,28)=sd->status.head_top;
  815. WBUFW(buf,30)=sd->status.head_mid;
  816. WBUFW(buf,32)=sd->status.hair_color;
  817. WBUFW(buf,34)=sd->status.clothes_color;
  818. WBUFW(buf,36)=sd->head_dir;
  819. WBUFL(buf,38)=sd->status.guild_id;
  820. WBUFL(buf,42)=sd->guild_emblem_id;
  821. WBUFW(buf,46)=sd->sc.opt3;
  822. WBUFB(buf,48)=sd->status.karma;
  823. WBUFB(buf,49)=sd->sex;
  824. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  825. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  826. WBUFB(buf,56)=5;
  827. WBUFB(buf,57)=5;
  828. WBUFW(buf,58)=clif_setlevel(sd->status.base_level);
  829. return packet_len_table[0x7b];
  830. #else
  831. memset(buf,0,packet_len_table[0x1da]);
  832. WBUFW(buf,0)=0x1da;
  833. WBUFL(buf,2)=sd->bl.id;
  834. WBUFW(buf,6)=sd->speed;
  835. WBUFW(buf,8)=sd->sc.opt1;
  836. WBUFW(buf,10)=sd->sc.opt2;
  837. WBUFW(buf,12)=sdoption;
  838. WBUFW(buf,14)=sd->view_class;
  839. WBUFW(buf,16)=sd->status.hair;
  840. if(sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS)
  841. WBUFW(buf,18)= clif_weapon_viewid(sd, 9);
  842. else
  843. WBUFW(buf,18)=0;
  844. if(sd->equip_index[8] != sd->equip_index[9] && sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS)
  845. WBUFW(buf,20)= clif_weapon_viewid(sd, 8);
  846. else
  847. WBUFW(buf,20)=0;
  848. WBUFW(buf,22)=sd->status.head_bottom;
  849. WBUFL(buf,24)=gettick();
  850. WBUFW(buf,28)=sd->status.head_top;
  851. WBUFW(buf,30)=sd->status.head_mid;
  852. WBUFW(buf,32)=sd->status.hair_color;
  853. WBUFW(buf,34)=sd->status.clothes_color;
  854. WBUFW(buf,36)=sd->head_dir;
  855. WBUFL(buf,38)=sd->status.guild_id;
  856. WBUFW(buf,42)=sd->guild_emblem_id;
  857. WBUFW(buf,44)=sd->status.manner;
  858. WBUFW(buf,46)=sd->sc.opt3;
  859. WBUFB(buf,48)=sd->status.karma;
  860. WBUFB(buf,49)=sd->sex;
  861. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  862. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  863. WBUFB(buf,56)=5;
  864. WBUFB(buf,57)=5;
  865. WBUFW(buf,58)=clif_setlevel(sd->status.base_level);
  866. return packet_len_table[0x1da];
  867. #endif
  868. }
  869. // moving function for disguises [Valaris]
  870. static int clif_dis007b(struct map_session_data *sd,unsigned char *buf) {
  871. nullpo_retr(0, sd);
  872. memset(buf,0,packet_len_table[0x7b]);
  873. WBUFW(buf,0)=0x7b;
  874. WBUFL(buf,2)=-sd->bl.id;
  875. WBUFW(buf,6)=sd->speed;
  876. WBUFW(buf,8)=0;
  877. WBUFW(buf,10)=0;
  878. WBUFW(buf,12)=sd->sc.option;
  879. WBUFW(buf,14)=sd->disguise;
  880. WBUFL(buf,22)=gettick();
  881. //WBUFL(buf,38)=sd->status.guild_id;
  882. //WBUFL(buf,42)=sd->guild_emblem_id;
  883. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  884. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  885. WBUFB(buf,56)=5;
  886. WBUFB(buf,57)=5;
  887. WBUFW(buf,58)=0;
  888. return packet_len_table[0x7b];
  889. }
  890. /*==========================================
  891. * クラスチェンジ typeはMobの場合は1で他は0?
  892. *------------------------------------------
  893. */
  894. int clif_class_change(struct block_list *bl,int class_,int type)
  895. {
  896. unsigned char buf[16];
  897. nullpo_retr(0, bl);
  898. if(class_ >= MAX_PC_CLASS) {
  899. WBUFW(buf,0)=0x1b0;
  900. WBUFL(buf,2)=bl->id;
  901. WBUFB(buf,6)=type;
  902. WBUFL(buf,7)=class_;
  903. clif_send(buf,packet_len_table[0x1b0],bl,AREA);
  904. }
  905. return 0;
  906. }
  907. /*==========================================
  908. *
  909. *------------------------------------------
  910. */
  911. int clif_mob_class_change(struct mob_data *md, int class_) {
  912. unsigned char buf[16];
  913. int view = mob_get_viewclass(class_);
  914. nullpo_retr(0, md);
  915. if(view >= MAX_PC_CLASS) {
  916. WBUFW(buf,0)=0x1b0;
  917. WBUFL(buf,2)=md->bl.id;
  918. WBUFB(buf,6)=1;
  919. WBUFL(buf,7)=view;
  920. clif_send(buf,packet_len_table[0x1b0],&md->bl,AREA);
  921. }
  922. return 0;
  923. }
  924. // mob equipment [Valaris]
  925. int clif_mob_equip(struct mob_data *md, int nameid) {
  926. unsigned char buf[16];
  927. nullpo_retr(0, md);
  928. memset(buf,0,packet_len_table[0x1a4]);
  929. WBUFW(buf,0)=0x1a4;
  930. WBUFB(buf,2)=3;
  931. WBUFL(buf,3)=md->bl.id;
  932. WBUFL(buf,7)=nameid;
  933. clif_send(buf,packet_len_table[0x1a4],&md->bl,AREA);
  934. return 0;
  935. }
  936. /*==========================================
  937. * MOB表示1
  938. *------------------------------------------
  939. */
  940. static int clif_mob0078(struct mob_data *md, unsigned char *buf)
  941. {
  942. int level, view_class;
  943. nullpo_retr(0, md);
  944. level=status_get_lv(&md->bl);
  945. view_class = mob_get_viewclass(md->class_);
  946. if(pcdb_checkid(view_class)) {
  947. #if PACKETVER < 4
  948. memset(buf,0,packet_len_table[0x78]);
  949. WBUFW(buf,0)=0x78;
  950. WBUFL(buf,2)=md->bl.id;
  951. WBUFW(buf,6)=status_get_speed(&md->bl);
  952. WBUFW(buf,8)=md->sc.opt1;
  953. WBUFW(buf,10)=md->sc.opt2;
  954. WBUFW(buf,12)=md->sc.option;
  955. WBUFW(buf,14)=view_class;
  956. WBUFW(buf,16)=mob_get_hair(md->class_);
  957. WBUFW(buf,18)=mob_get_weapon(md->class_);
  958. WBUFW(buf,20)=mob_get_head_buttom(md->class_);
  959. WBUFW(buf,22)=mob_get_shield(md->class_);
  960. WBUFW(buf,24)=mob_get_head_top(md->class_);
  961. WBUFW(buf,26)=mob_get_head_mid(md->class_);
  962. WBUFW(buf,28)=mob_get_hair_color(md->class_);
  963. WBUFW(buf,30)=mob_get_clothes_color(md->class_);
  964. WBUFW(buf,32)|=md->dir&0x0f; // head direction
  965. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  966. WBUFL(buf,34)=md->guardian_data->guild_id;
  967. WBUFL(buf,38)=md->guardian_data->emblem_id;
  968. }
  969. WBUFW(buf,42)=md->sc.opt3;
  970. WBUFB(buf,44)=0; // karma
  971. WBUFB(buf,45)=mob_get_sex(md->class_);
  972. WBUFPOS(buf,46,md->bl.x,md->bl.y);
  973. WBUFB(buf,48)|=md->dir&0x0f;
  974. WBUFB(buf,49)=5;
  975. WBUFB(buf,50)=5;
  976. WBUFB(buf,51)=0; // dead or sit state
  977. WBUFW(buf,52)=clif_setlevel(level);
  978. return packet_len_table[0x78];
  979. #else
  980. // Use 0x1d8 packet for monsters with player sprites [Valaris]
  981. memset(buf,0,packet_len_table[0x1d8]);
  982. WBUFW(buf,0)=0x1d8;
  983. WBUFL(buf,2)=md->bl.id;
  984. WBUFW(buf,6)=status_get_speed(&md->bl);
  985. WBUFW(buf,8)=md->sc.opt1;
  986. WBUFW(buf,10)=md->sc.opt2;
  987. WBUFW(buf,12)=md->sc.option;
  988. WBUFW(buf,14)=view_class;
  989. WBUFW(buf,16)=mob_get_hair(md->class_);
  990. WBUFW(buf,18)=mob_get_weapon(md->class_);
  991. WBUFW(buf,20)=mob_get_shield(md->class_);
  992. WBUFW(buf,22)=mob_get_head_buttom(md->class_);
  993. WBUFW(buf,24)=mob_get_head_top(md->class_);
  994. WBUFW(buf,26)=mob_get_head_mid(md->class_);
  995. WBUFW(buf,28)=mob_get_hair_color(md->class_);
  996. WBUFW(buf,30)=mob_get_clothes_color(md->class_);
  997. WBUFW(buf,32)|=md->dir&0x0f; // head direction
  998. WBUFL(buf,34)=0; // guild id
  999. WBUFW(buf,38)=0; // emblem id
  1000. WBUFW(buf,40)=0; // manner
  1001. WBUFW(buf,42)=md->sc.opt3;
  1002. WBUFB(buf,44)=0; // karma
  1003. WBUFB(buf,45)=mob_get_sex(md->class_);
  1004. WBUFPOS(buf,46,md->bl.x,md->bl.y);
  1005. WBUFB(buf,48)|=md->dir&0x0f;
  1006. WBUFB(buf,49)=5;
  1007. WBUFB(buf,50)=5;
  1008. WBUFB(buf,51)=0; // dead or sit state
  1009. WBUFW(buf,52)=clif_setlevel(level);
  1010. return packet_len_table[0x1d8];
  1011. #endif
  1012. } else {
  1013. // Use 0x78 packet for monsters sprites [Valaris]
  1014. memset(buf,0,packet_len_table[0x78]);
  1015. WBUFW(buf,0)=0x78;
  1016. WBUFL(buf,2)=md->bl.id;
  1017. WBUFW(buf,6)=status_get_speed(&md->bl);
  1018. WBUFW(buf,8)=md->sc.opt1;
  1019. WBUFW(buf,10)=md->sc.opt2;
  1020. WBUFW(buf,12)=md->sc.option;
  1021. WBUFW(buf,14)=view_class;
  1022. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  1023. WBUFL(buf,34)=md->guardian_data->guild_id;
  1024. WBUFL(buf,38)=md->guardian_data->emblem_id;
  1025. } // End addition
  1026. WBUFPOS(buf,46,md->bl.x,md->bl.y);
  1027. WBUFB(buf,48)|=md->dir&0x0f;
  1028. WBUFB(buf,49)=5;
  1029. WBUFB(buf,50)=5;
  1030. WBUFW(buf,52)=clif_setlevel(level);
  1031. return packet_len_table[0x78];
  1032. }
  1033. }
  1034. /*==========================================
  1035. * MOB表示2
  1036. *------------------------------------------
  1037. */
  1038. static int clif_mob007b(struct mob_data *md, unsigned char *buf) {
  1039. int level, view_class;
  1040. nullpo_retr(0, md);
  1041. level=status_get_lv(&md->bl);
  1042. view_class = mob_get_viewclass(md->class_);
  1043. if(pcdb_checkid(view_class)) {
  1044. #if PACKETVER < 4
  1045. memset(buf,0,packet_len_table[0x7b]);
  1046. WBUFW(buf,0)=0x7b;
  1047. WBUFL(buf,2)=md->bl.id;
  1048. WBUFW(buf,6)=status_get_speed(&md->bl);
  1049. WBUFW(buf,8)=md->sc.opt1;
  1050. WBUFW(buf,10)=md->sc.opt2;
  1051. WBUFW(buf,12)=md->sc.option;
  1052. WBUFW(buf,14)=view_class;
  1053. WBUFW(buf,16)=mob_get_hair(md->class_);
  1054. WBUFW(buf,18)=mob_get_weapon(md->class_);
  1055. WBUFW(buf,20)=mob_get_head_buttom(md->class_);
  1056. WBUFL(buf,22)=gettick();
  1057. WBUFW(buf,26)=mob_get_shield(md->class_);
  1058. WBUFW(buf,28)=mob_get_head_top(md->class_);
  1059. WBUFW(buf,30)=mob_get_head_mid(md->class_);
  1060. WBUFW(buf,32)=mob_get_hair_color(md->class_);
  1061. WBUFW(buf,34)=mob_get_clothes_color(md->class_);
  1062. WBUFW(buf,36)=md->dir&0x0f; // head direction
  1063. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  1064. WBUFL(buf,38)=md->guardian_data->guild_id;
  1065. WBUFL(buf,42)=md->guardian_data->emblem_id;
  1066. }
  1067. WBUFW(buf,46)=md->sc.opt3;
  1068. WBUFB(buf,48)=0; // karma
  1069. WBUFB(buf,49)=mob_get_sex(md->class_);
  1070. WBUFPOS2(buf,50,md->bl.x,md->bl.y,md->to_x,md->to_y);
  1071. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1072. WBUFB(buf,56)=5;
  1073. WBUFB(buf,57)=5;
  1074. WBUFW(buf,58)=clif_setlevel(level);
  1075. return packet_len_table[0x7b];
  1076. #else
  1077. // Use 0x1da packet for monsters with player sprites [Valaris]
  1078. memset(buf,0,packet_len_table[0x1da]);
  1079. WBUFW(buf,0)=0x1da;
  1080. WBUFL(buf,2)=md->bl.id;
  1081. WBUFW(buf,6)=status_get_speed(&md->bl);
  1082. WBUFW(buf,8)=md->sc.opt1;
  1083. WBUFW(buf,10)=md->sc.opt2;
  1084. WBUFW(buf,12)=md->sc.option;
  1085. WBUFW(buf,14)=view_class;
  1086. WBUFW(buf,16)=mob_get_hair(md->class_);
  1087. WBUFW(buf,18)=mob_get_weapon(md->class_);
  1088. WBUFW(buf,20)=mob_get_shield(md->class_);
  1089. WBUFW(buf,22)=mob_get_head_buttom(md->class_);
  1090. WBUFL(buf,24)=gettick();
  1091. WBUFW(buf,28)=mob_get_head_top(md->class_);
  1092. WBUFW(buf,30)=mob_get_head_mid(md->class_);
  1093. WBUFW(buf,32)=mob_get_hair_color(md->class_);
  1094. WBUFW(buf,34)=mob_get_clothes_color(md->class_);
  1095. WBUFW(buf,36)=md->dir&0x0f; // head direction
  1096. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  1097. WBUFL(buf,38)=md->guardian_data->guild_id;
  1098. WBUFW(buf,42)=md->guardian_data->emblem_id;
  1099. }
  1100. WBUFW(buf,44)=0; // manner
  1101. WBUFW(buf,46)=md->sc.opt3;
  1102. WBUFB(buf,48)=0; // karma
  1103. WBUFB(buf,49)=mob_get_sex(md->class_);
  1104. WBUFPOS2(buf,50,md->bl.x,md->bl.y,md->to_x,md->to_y);
  1105. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1106. WBUFB(buf,56)=5;
  1107. WBUFB(buf,57)=5;
  1108. WBUFW(buf,58)=clif_setlevel(level);
  1109. return packet_len_table[0x1da];
  1110. #endif
  1111. } else {
  1112. // Use 0x7b packet for monsters sprites [Valaris]
  1113. memset(buf,0,packet_len_table[0x7b]);
  1114. WBUFW(buf,0)=0x7b;
  1115. WBUFL(buf,2)=md->bl.id;
  1116. WBUFW(buf,6)=status_get_speed(&md->bl);
  1117. WBUFW(buf,8)=md->sc.opt1;
  1118. WBUFW(buf,10)=md->sc.opt2;
  1119. WBUFW(buf,12)=md->sc.option;
  1120. WBUFW(buf,14)=view_class;
  1121. WBUFL(buf,22)=gettick();
  1122. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  1123. WBUFL(buf,38)=md->guardian_data->guild_id;
  1124. WBUFL(buf,42)=md->guardian_data->emblem_id;
  1125. } // End addition
  1126. WBUFPOS2(buf,50,md->bl.x,md->bl.y,md->to_x,md->to_y);
  1127. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1128. WBUFB(buf,56)=5;
  1129. WBUFB(buf,57)=5;
  1130. level = status_get_lv(&md->bl);
  1131. WBUFW(buf,58)=clif_setlevel(level);
  1132. return packet_len_table[0x7b];
  1133. }
  1134. }
  1135. /*==========================================
  1136. *
  1137. *------------------------------------------
  1138. */
  1139. static int clif_npc0078(struct npc_data *nd, unsigned char *buf) {
  1140. struct guild *g=NULL;
  1141. int view_class;
  1142. nullpo_retr(0, nd);
  1143. memset(buf,0,packet_len_table[0x78]);
  1144. if (nd->class_ == 722 && nd->u.scr.guild_id > 0)
  1145. g=guild_search(nd->u.scr.guild_id);
  1146. if(mobdb_checkid(nd->class_) &&
  1147. pcdb_checkid((view_class = mob_get_viewclass(nd->class_)))) {
  1148. //Disguised player sprite
  1149. #if PACKETVER < 4
  1150. memset(buf,0,packet_len_table[0x78]);
  1151. WBUFW(buf,0)=0x78;
  1152. WBUFL(buf,2)=nd->bl.id;
  1153. WBUFW(buf,6)=nd->speed;
  1154. WBUFW(buf,8)=nd->sc.opt1;
  1155. WBUFW(buf,10)=nd->sc.opt2;
  1156. WBUFW(buf,12)=nd->sc.option;
  1157. WBUFW(buf,14)=view_class;
  1158. WBUFW(buf,16)=mob_get_hair(nd->class_);
  1159. WBUFW(buf,18)=mob_get_weapon(nd->class_);
  1160. WBUFW(buf,20)=mob_get_head_buttom(nd->class_);
  1161. WBUFW(buf,22)=mob_get_shield(nd->class_);
  1162. WBUFW(buf,24)=mob_get_head_top(nd->class_);
  1163. WBUFW(buf,26)=mob_get_head_mid(nd->class_);
  1164. WBUFW(buf,28)=mob_get_hair_color(nd->class_);
  1165. WBUFW(buf,30)=mob_get_clothes_color(nd->class_);
  1166. WBUFW(buf,32)|=nd->dir&0x0f; // head direction
  1167. if (g) {
  1168. WBUFL(buf,34)=g->guild_id;
  1169. WBUFL(buf,38)=g->emblem_id;
  1170. }
  1171. WBUFW(buf,42)=nd->sc.opt3;
  1172. WBUFB(buf,44)=0; // karma
  1173. WBUFB(buf,45)=mob_get_sex(nd->class_);
  1174. WBUFPOS(buf,46,nd->bl.x,nd->bl.y);
  1175. WBUFB(buf,48)|=nd->dir&0x0f;
  1176. WBUFB(buf,49)=5;
  1177. WBUFB(buf,50)=5;
  1178. WBUFB(buf,51)=0; // dead or sit state
  1179. WBUFW(buf,52)=50; // No level info.
  1180. return packet_len_table[0x78];
  1181. #else
  1182. // Use 0x1d8 packet for monsters with player sprites [Valaris]
  1183. memset(buf,0,packet_len_table[0x1d8]);
  1184. WBUFW(buf,0)=0x1d8;
  1185. WBUFL(buf,2)=nd->bl.id;
  1186. WBUFW(buf,6)=nd->speed;
  1187. WBUFW(buf,8)=nd->sc.opt1;
  1188. WBUFW(buf,10)=nd->sc.opt2;
  1189. WBUFW(buf,12)=nd->sc.option;
  1190. WBUFW(buf,14)=view_class;
  1191. WBUFW(buf,16)=mob_get_hair(nd->class_);
  1192. WBUFW(buf,18)=mob_get_weapon(nd->class_);
  1193. WBUFW(buf,20)=mob_get_shield(nd->class_);
  1194. WBUFW(buf,22)=mob_get_head_buttom(nd->class_);
  1195. WBUFW(buf,24)=mob_get_head_top(nd->class_);
  1196. WBUFW(buf,26)=mob_get_head_mid(nd->class_);
  1197. WBUFW(buf,28)=mob_get_hair_color(nd->class_);
  1198. WBUFW(buf,30)=mob_get_clothes_color(nd->class_);
  1199. WBUFW(buf,32)|=nd->dir&0x0f; // head direction
  1200. WBUFL(buf,34)=0; // guild id
  1201. WBUFW(buf,38)=0; // emblem id
  1202. WBUFW(buf,40)=0; // manner
  1203. WBUFW(buf,42)=nd->sc.opt3;
  1204. WBUFB(buf,44)=0; // karma
  1205. WBUFB(buf,45)=mob_get_sex(nd->class_);
  1206. WBUFPOS(buf,46,nd->bl.x,nd->bl.y);
  1207. WBUFB(buf,48)|=nd->dir&0x0f;
  1208. WBUFB(buf,49)=5;
  1209. WBUFB(buf,50)=5;
  1210. WBUFB(buf,51)=0; // dead or sit state
  1211. WBUFW(buf,52)=50; //No level data.
  1212. return packet_len_table[0x1d8];
  1213. #endif
  1214. }
  1215. WBUFW(buf,0)=0x78;
  1216. WBUFL(buf,2)=nd->bl.id;
  1217. WBUFW(buf,6)=nd->speed;
  1218. WBUFW(buf,14)=nd->class_;
  1219. if (g) {
  1220. WBUFL(buf,22)=g->emblem_id;
  1221. WBUFL(buf,26)=g->guild_id;
  1222. // pc packet says the actual location of these are, but they are not. Why the discordance? [Skotlex]
  1223. // WBUFL(buf,34)=g->emblem_id;
  1224. // WBUFL(buf,38)=g->guild_id;
  1225. }
  1226. WBUFPOS(buf,46,nd->bl.x,nd->bl.y);
  1227. WBUFB(buf,48)|=nd->dir&0x0f;
  1228. WBUFB(buf,49)=5;
  1229. WBUFB(buf,50)=5;
  1230. return packet_len_table[0x78];
  1231. }
  1232. // NPC Walking [Valaris]
  1233. static int clif_npc007b(struct npc_data *nd, unsigned char *buf) {
  1234. struct guild *g=NULL;
  1235. int view_class;
  1236. nullpo_retr(0, nd);
  1237. memset(buf,0,packet_len_table[0x7b]);
  1238. if (nd->class_ == 722 && nd->u.scr.guild_id > 0)
  1239. g=guild_search(nd->u.scr.guild_id);
  1240. if(mobdb_checkid(nd->class_) &&
  1241. pcdb_checkid((view_class = mob_get_viewclass(nd->class_)))) {
  1242. //Disguised player sprite
  1243. #if PACKETVER < 4
  1244. memset(buf,0,packet_len_table[0x7b]);
  1245. WBUFW(buf,0)=0x7b;
  1246. WBUFL(buf,2)=nd->bl.id;
  1247. WBUFW(buf,6)=nd->speed;
  1248. WBUFW(buf,8)=nd->sc.opt1;
  1249. WBUFW(buf,10)=nd->sc.opt2;
  1250. WBUFW(buf,12)=nd->sc.option;
  1251. WBUFW(buf,14)=view_class;
  1252. WBUFW(buf,16)=mob_get_hair(nd->class_);
  1253. WBUFW(buf,18)=mob_get_weapon(nd->class_);
  1254. WBUFW(buf,20)=mob_get_head_buttom(nd->class_);
  1255. WBUFL(buf,22)=gettick();
  1256. WBUFW(buf,26)=mob_get_shield(nd->class_);
  1257. WBUFW(buf,28)=mob_get_head_top(nd->class_);
  1258. WBUFW(buf,30)=mob_get_head_mid(nd->class_);
  1259. WBUFW(buf,32)=mob_get_hair_color(nd->class_);
  1260. WBUFW(buf,34)=mob_get_clothes_color(nd->class_);
  1261. WBUFW(buf,36)=nd->dir&0x0f; // head direction
  1262. if (g) {
  1263. WBUFL(buf,38)=g->guild_id;
  1264. WBUFL(buf,42)=g->emblem_id;
  1265. }
  1266. WBUFW(buf,46)=nd->sc.opt3;
  1267. WBUFB(buf,48)=0; // karma
  1268. WBUFB(buf,49)=mob_get_sex(nd->class_);
  1269. WBUFPOS2(buf,50,nd->bl.x,nd->bl.y,nd->to_x,nd->to_y);
  1270. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1271. WBUFB(buf,56)=5;
  1272. WBUFB(buf,57)=5;
  1273. WBUFW(buf,58)=50; //Ehm.. no level data.
  1274. return packet_len_table[0x7b];
  1275. #else
  1276. // Use 0x1da packet for monsters with player sprites [Valaris]
  1277. memset(buf,0,packet_len_table[0x1da]);
  1278. WBUFW(buf,0)=0x1da;
  1279. WBUFL(buf,2)=nd->bl.id;
  1280. WBUFW(buf,6)=nd->speed;
  1281. WBUFW(buf,8)=nd->sc.opt1;
  1282. WBUFW(buf,10)=nd->sc.opt2;
  1283. WBUFW(buf,12)=nd->sc.option;
  1284. WBUFW(buf,14)=view_class;
  1285. WBUFW(buf,16)=mob_get_hair(nd->class_);
  1286. WBUFW(buf,18)=mob_get_weapon(nd->class_);
  1287. WBUFW(buf,20)=mob_get_shield(nd->class_);
  1288. WBUFW(buf,22)=mob_get_head_buttom(nd->class_);
  1289. WBUFL(buf,24)=gettick();
  1290. WBUFW(buf,28)=mob_get_head_top(nd->class_);
  1291. WBUFW(buf,30)=mob_get_head_mid(nd->class_);
  1292. WBUFW(buf,32)=mob_get_hair_color(nd->class_);
  1293. WBUFW(buf,34)=mob_get_clothes_color(nd->class_);
  1294. WBUFW(buf,36)=nd->dir&0x0f; // head direction
  1295. if (g) {
  1296. WBUFL(buf,38)=g->guild_id;
  1297. WBUFW(buf,42)=g->emblem_id;
  1298. }
  1299. WBUFW(buf,44)=0; // manner
  1300. WBUFW(buf,46)=nd->sc.opt3;
  1301. WBUFB(buf,48)=0; // karma
  1302. WBUFB(buf,49)=mob_get_sex(nd->class_);
  1303. WBUFPOS2(buf,50,nd->bl.x,nd->bl.y,nd->to_x,nd->to_y);
  1304. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1305. WBUFB(buf,56)=5;
  1306. WBUFB(buf,57)=5;
  1307. WBUFW(buf,58)=50; //No level data.
  1308. return packet_len_table[0x1da];
  1309. #endif
  1310. }
  1311. WBUFW(buf,0)=0x7b;
  1312. WBUFL(buf,2)=nd->bl.id;
  1313. WBUFW(buf,6)=nd->speed;
  1314. WBUFW(buf,14)=nd->class_;
  1315. if (g) {
  1316. WBUFL(buf,22)=g->emblem_id;
  1317. WBUFL(buf,26)=g->guild_id;
  1318. // pc packet says the actual location of these are, but they are not. Why the discordance? [Skotlex]
  1319. // WBUFL(buf,38)=g->emblem_id;
  1320. // WBUFL(buf,42)=g->guild_id;
  1321. }
  1322. WBUFL(buf,22)=gettick();
  1323. WBUFPOS2(buf,50,nd->bl.x,nd->bl.y,nd->to_x,nd->to_y);
  1324. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1325. WBUFB(buf,56)=5;
  1326. WBUFB(buf,57)=5;
  1327. return packet_len_table[0x7b];
  1328. }
  1329. /*==========================================
  1330. *
  1331. *------------------------------------------
  1332. */
  1333. static int clif_pet0078(struct pet_data *pd, unsigned char *buf) {
  1334. int view_class,level;
  1335. nullpo_retr(0, pd);
  1336. level = status_get_lv(&pd->bl);
  1337. view_class = mob_get_viewclass(pd->class_);
  1338. if(pcdb_checkid(view_class)) {
  1339. #if PACKETVER < 4
  1340. memset(buf,0,packet_len_table[0x78]);
  1341. WBUFW(buf,0)=0x78;
  1342. WBUFL(buf,2)=pd->bl.id;
  1343. WBUFW(buf,6)=pd->speed;
  1344. WBUFW(buf,8)= 0; //opt1
  1345. WBUFW(buf,10)= 0; //opt2
  1346. WBUFW(buf,12)=pd->db->option;
  1347. WBUFW(buf,14)=view_class;
  1348. WBUFW(buf,16)=mob_get_hair(pd->class_);
  1349. WBUFW(buf,18)=mob_get_weapon(pd->class_);
  1350. WBUFW(buf,20)=mob_get_head_buttom(pd->class_);
  1351. WBUFW(buf,22)=mob_get_shield(pd->class_);
  1352. WBUFW(buf,24)=mob_get_head_top(pd->class_);
  1353. WBUFW(buf,26)=mob_get_head_mid(pd->class_);
  1354. WBUFW(buf,28)=mob_get_hair_color(pd->class_);
  1355. WBUFW(buf,30)=mob_get_clothes_color(pd->class_);
  1356. WBUFW(buf,32)|=pd->dir&0x0f; // head direction
  1357. WBUFL(buf,34)=0; //Guild id
  1358. WBUFL(buf,38)=0; //Guild emblem
  1359. WBUFW(buf,42)=0; //opt3;
  1360. WBUFB(buf,44)=0; // karma
  1361. WBUFB(buf,45)=mob_get_sex(pd->class_);
  1362. WBUFPOS(buf,46,pd->bl.x,pd->bl.y);
  1363. WBUFB(buf,48)|=pd->dir&0x0f;
  1364. WBUFB(buf,49)=5;
  1365. WBUFB(buf,50)=5;
  1366. WBUFB(buf,51)=0; // dead or sit state
  1367. WBUFW(buf,52)=clif_setlevel(level);
  1368. return packet_len_table[0x78];
  1369. #else
  1370. // Use 0x1d8 packet for pets with player sprites [Valaris]
  1371. memset(buf,0,packet_len_table[0x1d8]);
  1372. WBUFW(buf,0)=0x1d8;
  1373. WBUFL(buf,2)=pd->bl.id;
  1374. WBUFW(buf,6)=pd->speed;
  1375. WBUFW(buf,8)=0; // opt1
  1376. WBUFW(buf,10)=0; // opt2
  1377. WBUFW(buf,12)=pd->db->option;
  1378. WBUFW(buf,14)=view_class;
  1379. WBUFW(buf,16)=mob_get_hair(pd->class_);
  1380. WBUFW(buf,18)=mob_get_weapon(pd->class_);
  1381. WBUFW(buf,20)=mob_get_shield(pd->class_);
  1382. WBUFW(buf,22)=mob_get_head_buttom(pd->class_);
  1383. WBUFW(buf,24)=mob_get_head_top(pd->class_);
  1384. WBUFW(buf,26)=mob_get_head_mid(pd->class_);
  1385. WBUFW(buf,28)=mob_get_hair_color(pd->class_);
  1386. WBUFW(buf,30)=mob_get_clothes_color(pd->class_);
  1387. WBUFW(buf,32)|=pd->dir&0x0f; // head direction
  1388. WBUFL(buf,34)=0; // guild id
  1389. WBUFW(buf,38)=0; // emblem id
  1390. WBUFW(buf,40)=0; // manner
  1391. WBUFW(buf,42)=0; // opt3
  1392. WBUFB(buf,44)=0; // karma
  1393. WBUFB(buf,45)=mob_get_sex(pd->class_);
  1394. WBUFPOS(buf,46,pd->bl.x,pd->bl.y);
  1395. WBUFB(buf,48)|=pd->dir&0x0f;
  1396. WBUFB(buf,49)=5;
  1397. WBUFB(buf,50)=5;
  1398. WBUFB(buf,51)=0; // dead or sit state
  1399. WBUFW(buf,52)=clif_setlevel(level);
  1400. return packet_len_table[0x1d8];
  1401. #endif
  1402. } else {
  1403. memset(buf,0,packet_len_table[0x78]);
  1404. WBUFW(buf,0)=0x78;
  1405. WBUFL(buf,2)=pd->bl.id;
  1406. WBUFW(buf,6)=pd->speed;
  1407. WBUFW(buf,14)=view_class;
  1408. WBUFW(buf,16)=battle_config.pet_hair_style;
  1409. if(pd->equip && (view_class = itemdb_viewid(pd->equip)) > 0)
  1410. WBUFW(buf,20)=view_class;
  1411. else
  1412. WBUFW(buf,20)=pd->equip;
  1413. WBUFPOS(buf,46,pd->bl.x,pd->bl.y);
  1414. WBUFB(buf,48)|=pd->dir&0x0f;
  1415. WBUFB(buf,49)=0;
  1416. WBUFB(buf,50)=0;
  1417. WBUFW(buf,52)=clif_setlevel(level);
  1418. return packet_len_table[0x78];
  1419. }
  1420. }
  1421. /*==========================================
  1422. *
  1423. *------------------------------------------
  1424. */
  1425. static int clif_pet007b(struct pet_data *pd, unsigned char *buf) {
  1426. int view_class,level;
  1427. nullpo_retr(0, pd);
  1428. level = status_get_lv(&pd->bl);
  1429. view_class = mob_get_viewclass(pd->class_);
  1430. if(pcdb_checkid(view_class)) {
  1431. #if PACKETVER < 4
  1432. memset(buf,0,packet_len_table[0x7b]);
  1433. WBUFW(buf,0)=0x7b;
  1434. WBUFL(buf,2)=pd->bl.id;
  1435. WBUFW(buf,6)=pd->speed;
  1436. WBUFW(buf,8)= 0; //opt1;
  1437. WBUFW(buf,10)= 0; //opt2;
  1438. WBUFW(buf,12)=pd->db->option;
  1439. WBUFW(buf,14)=view_class;
  1440. WBUFW(buf,16)=mob_get_hair(pd->class_);
  1441. WBUFW(buf,18)=mob_get_weapon(pd->class_);
  1442. WBUFW(buf,20)=mob_get_head_buttom(pd->class_);
  1443. WBUFL(buf,22)=gettick();
  1444. WBUFW(buf,26)=mob_get_shield(pd->class_);
  1445. WBUFW(buf,28)=mob_get_head_top(pd->class_);
  1446. WBUFW(buf,30)=mob_get_head_mid(pd->class_);
  1447. WBUFW(buf,32)=mob_get_hair_color(pd->class_);
  1448. WBUFW(buf,34)=mob_get_clothes_color(pd->class_);
  1449. WBUFW(buf,36)=pd->dir&0x0f; // head direction
  1450. WBUFL(buf,38)=0; // guild id
  1451. WBUFL(buf,42)=0; // emblem id
  1452. WBUFW(buf,46)=0; // opt3;
  1453. WBUFB(buf,48)=0; // karma
  1454. WBUFB(buf,49)=mob_get_sex(pd->class_);
  1455. WBUFPOS2(buf,50,pd->bl.x,pd->bl.y,pd->to_x,pd->to_y);
  1456. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1457. WBUFB(buf,56)=0; //0? These are always five for mobs and pets, /hmm [Skotlex]
  1458. WBUFB(buf,57)=0;
  1459. WBUFW(buf,58)=clif_setlevel(level);
  1460. return packet_len_table[0x7b];
  1461. #else
  1462. // Use 0x1da packet for monsters with player sprites [Valaris]
  1463. memset(buf,0,packet_len_table[0x1da]);
  1464. WBUFW(buf,0)=0x1da;
  1465. WBUFL(buf,2)=pd->bl.id;
  1466. WBUFW(buf,6)=pd->speed;
  1467. WBUFW(buf,8)=0; // opt1
  1468. WBUFW(buf,10)=0; // opt2
  1469. WBUFW(buf,12)=pd->db->option;
  1470. WBUFW(buf,14)=view_class;
  1471. WBUFW(buf,16)=mob_get_hair(pd->class_);
  1472. WBUFW(buf,18)=mob_get_weapon(pd->class_);
  1473. WBUFW(buf,20)=mob_get_shield(pd->class_);
  1474. WBUFW(buf,22)=mob_get_head_buttom(pd->class_);
  1475. WBUFL(buf,24)=gettick();
  1476. WBUFW(buf,28)=mob_get_head_top(pd->class_);
  1477. WBUFW(buf,30)=mob_get_head_mid(pd->class_);
  1478. WBUFW(buf,32)=mob_get_hair_color(pd->class_);
  1479. WBUFW(buf,34)=mob_get_clothes_color(pd->class_);
  1480. WBUFW(buf,36)=pd->dir&0x0f; // head direction
  1481. WBUFL(buf,38)=0; // guild id
  1482. WBUFW(buf,42)=0; // emblem id
  1483. WBUFW(buf,44)=0; // manner
  1484. WBUFW(buf,46)=0; // opt3
  1485. WBUFB(buf,48)=0; // karma
  1486. WBUFB(buf,49)=mob_get_sex(pd->class_);
  1487. WBUFPOS2(buf,50,pd->bl.x,pd->bl.y,pd->to_x,pd->to_y);
  1488. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1489. WBUFB(buf,56)=0;
  1490. WBUFB(buf,57)=0;
  1491. WBUFW(buf,58)=clif_setlevel(level);
  1492. return packet_len_table[0x1da];
  1493. #endif
  1494. } else {
  1495. // Use 0x7b packet for pets sprites [Valaris]
  1496. memset(buf,0,packet_len_table[0x7b]);
  1497. WBUFW(buf,0)=0x7b;
  1498. WBUFL(buf,2)=pd->bl.id;
  1499. WBUFW(buf,6)=pd->speed;
  1500. WBUFW(buf,14)=view_class;
  1501. WBUFW(buf,16)=battle_config.pet_hair_style;
  1502. if (pd->equip && (view_class = itemdb_viewid(pd->equip)) > 0)
  1503. WBUFW(buf,20)=view_class;
  1504. else
  1505. WBUFW(buf,20)=pd->equip;
  1506. WBUFL(buf,22)=gettick();
  1507. WBUFPOS2(buf,50,pd->bl.x,pd->bl.y,pd->to_x,pd->to_y);
  1508. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1509. WBUFB(buf,56)=0;
  1510. WBUFB(buf,57)=0;
  1511. WBUFW(buf,58)=clif_setlevel(level);
  1512. return packet_len_table[0x7b];
  1513. }
  1514. }
  1515. /*==========================================
  1516. *
  1517. *------------------------------------------
  1518. */
  1519. static int clif_set01e1(struct map_session_data *sd, unsigned char *buf) {
  1520. nullpo_retr(0, sd);
  1521. WBUFW(buf,0)=0x1e1;
  1522. WBUFL(buf,2)=sd->bl.id;
  1523. WBUFW(buf,6)=sd->spiritball;
  1524. return packet_len_table[0x1e1];
  1525. }
  1526. /*==========================================
  1527. *
  1528. *------------------------------------------
  1529. */
  1530. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1531. WFIFOHEAD(fd, packet_len_table[0x192]);
  1532. WFIFOW(fd,0) = 0x192;
  1533. WFIFOW(fd,2) = x;
  1534. WFIFOW(fd,4) = y;
  1535. WFIFOW(fd,6) = type;
  1536. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1537. WFIFOSET(fd,packet_len_table[0x192]);
  1538. return 0;
  1539. }
  1540. // new and improved weather display [Valaris]
  1541. int clif_weather_sub(int fd, int type) {
  1542. WFIFOHEAD(fd, packet_len_table[0x1f3]);
  1543. WFIFOW(fd,0) = 0x1f3;
  1544. WFIFOL(fd,2) = -10;
  1545. WFIFOL(fd,6) = type;
  1546. WFIFOSET(fd,packet_len_table[0x1f3]);
  1547. return 0;
  1548. }
  1549. int clif_weather(int m) {
  1550. int i;
  1551. struct map_session_data *sd=NULL;
  1552. for(i = 0; i < fd_max; i++) {
  1553. if (session[i] && (sd = session[i]->session_data) != NULL && sd->state.auth && sd->bl.m == m) {
  1554. WFIFOHEAD(sd->fd, packet_len_table[0x80]);
  1555. WFIFOW(sd->fd,0) = 0x80;
  1556. WFIFOL(sd->fd,2) = -10;
  1557. WFIFOB(sd->fd,6) = 0;
  1558. WFIFOSET(sd->fd,packet_len_table[0x80]);
  1559. if (map[sd->bl.m].flag.snow || map[sd->bl.m].flag.clouds || map[sd->bl.m].flag.fog || map[sd->bl.m].flag.fireworks ||
  1560. map[sd->bl.m].flag.sakura || map[sd->bl.m].flag.leaves || map[sd->bl.m].flag.rain || map[sd->bl.m].flag.clouds2) {
  1561. WFIFOHEAD(sd->fd, packet_len_table[0x7c]);
  1562. WFIFOW(sd->fd,0)=0x7c;
  1563. WFIFOL(sd->fd,2)=-10;
  1564. WFIFOW(sd->fd,6)=0;
  1565. WFIFOW(sd->fd,8)=0;
  1566. WFIFOW(sd->fd,10)=0;
  1567. WFIFOW(sd->fd,12)=OPTION_INVISIBLE;
  1568. WFIFOW(sd->fd,20)=100;
  1569. WFIFOPOS(sd->fd,36,sd->bl.x,sd->bl.y);
  1570. WFIFOSET(sd->fd,packet_len_table[0x7c]);
  1571. if (map[sd->bl.m].flag.snow)
  1572. clif_weather_sub(sd->fd, 162);
  1573. if (map[sd->bl.m].flag.clouds)
  1574. clif_weather_sub(sd->fd, 233);
  1575. if (map[sd->bl.m].flag.clouds2)
  1576. clif_weather_sub(sd->fd, 516);
  1577. if (map[sd->bl.m].flag.fog)
  1578. clif_weather_sub(sd->fd, 515);
  1579. if (map[sd->bl.m].flag.fireworks) {
  1580. clif_weather_sub(sd->fd, 297);
  1581. clif_weather_sub(sd->fd, 299);
  1582. clif_weather_sub(sd->fd, 301);
  1583. }
  1584. if (map[sd->bl.m].flag.sakura)
  1585. clif_weather_sub(sd->fd, 163);
  1586. if (map[sd->bl.m].flag.leaves)
  1587. clif_weather_sub(sd->fd, 333);
  1588. if (map[sd->bl.m].flag.rain)
  1589. clif_weather_sub(sd->fd, 161);
  1590. }
  1591. }
  1592. }
  1593. return 0;
  1594. }
  1595. /*==========================================
  1596. *
  1597. *------------------------------------------
  1598. */
  1599. int clif_spawnpc(struct map_session_data *sd) {
  1600. unsigned char buf[128];
  1601. nullpo_retr(0, sd);
  1602. clif_set0078(sd, buf);
  1603. #if PACKETVER < 4
  1604. WBUFW(buf, 0) = 0x79;
  1605. WBUFW(buf,51) = clif_setlevel(sd->status.base_level);
  1606. clif_send(buf, packet_len_table[0x79], &sd->bl, AREA_WOS);
  1607. #else
  1608. WBUFW(buf, 0) = 0x1d9;
  1609. WBUFW(buf,51) = clif_setlevel(sd->status.base_level);
  1610. clif_send(buf, packet_len_table[0x1d9], &sd->bl, AREA_WOS);
  1611. #endif
  1612. if(sd->disguise > 0) {
  1613. int len;
  1614. memset(buf,0,packet_len_table[0x7c]);
  1615. WBUFW(buf,0)=0x7c;
  1616. WBUFL(buf,2)=-sd->bl.id;
  1617. WBUFW(buf,6)=sd->speed;
  1618. WBUFW(buf,12)=sd->sc.option;
  1619. WBUFW(buf,20)=sd->disguise;
  1620. WBUFPOS(buf,36,sd->bl.x,sd->bl.y);
  1621. clif_send(buf,packet_len_table[0x7c],&sd->bl,AREA);
  1622. len = clif_dis0078(sd,buf);
  1623. clif_send(buf,len,&sd->bl,AREA);
  1624. }
  1625. if (sd->spiritball > 0)
  1626. clif_spiritball(sd);
  1627. if (sd->status.guild_id > 0) { // force display of guild emblem [Valaris]
  1628. struct guild *g = guild_search(sd->status.guild_id);
  1629. if (g)
  1630. clif_guild_emblem(sd,g);
  1631. } // end addition [Valaris]
  1632. if (map[sd->bl.m].flag.snow || map[sd->bl.m].flag.clouds || map[sd->bl.m].flag.fog || map[sd->bl.m].flag.fireworks ||
  1633. map[sd->bl.m].flag.sakura || map[sd->bl.m].flag.leaves || map[sd->bl.m].flag.rain || map[sd->bl.m].flag.clouds2) {
  1634. WFIFOHEAD(sd->fd, packet_len_table[0x7c]);
  1635. WFIFOW(sd->fd,0)=0x7c;
  1636. WFIFOL(sd->fd,2)=-10;
  1637. WFIFOW(sd->fd,6)=0;
  1638. WFIFOW(sd->fd,8)=0;
  1639. WFIFOW(sd->fd,10)=0;
  1640. WFIFOW(sd->fd,12)=OPTION_INVISIBLE;
  1641. WFIFOW(sd->fd,20)=100;
  1642. WFIFOPOS(sd->fd,36,sd->bl.x,sd->bl.y);
  1643. WFIFOSET(sd->fd,packet_len_table[0x7c]);
  1644. if (map[sd->bl.m].flag.snow)
  1645. clif_weather_sub(sd->fd, 162);
  1646. if (map[sd->bl.m].flag.clouds)
  1647. clif_weather_sub(sd->fd, 233);
  1648. if (map[sd->bl.m].flag.clouds2)
  1649. clif_weather_sub(sd->fd, 516);
  1650. if (map[sd->bl.m].flag.fog)
  1651. clif_weather_sub(sd->fd, 515);
  1652. if (map[sd->bl.m].flag.fireworks) {
  1653. clif_weather_sub(sd->fd, 297);
  1654. clif_weather_sub(sd->fd, 299);
  1655. clif_weather_sub(sd->fd, 301);
  1656. }
  1657. if (map[sd->bl.m].flag.sakura)
  1658. clif_weather_sub(sd->fd, 163);
  1659. if (map[sd->bl.m].flag.leaves)
  1660. clif_weather_sub(sd->fd, 333);
  1661. if (map[sd->bl.m].flag.rain)
  1662. clif_weather_sub(sd->fd, 161);
  1663. }
  1664. //New 'night' effect by dynamix [Skotlex]
  1665. if (night_flag && map[sd->bl.m].flag.nightenabled)
  1666. { //Display night.
  1667. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  1668. clif_status_load(&sd->bl, SI_NIGHT, 0);
  1669. else
  1670. sd->state.night = 1;
  1671. clif_status_load(&sd->bl, SI_NIGHT, 1);
  1672. } else if (sd->state.night) { //Clear night display.
  1673. clif_status_load(&sd->bl, SI_NIGHT, 0);
  1674. sd->state.night = 0;
  1675. }
  1676. if(sd->state.size==2) // tiny/big players [Valaris]
  1677. clif_specialeffect(&sd->bl,423,0);
  1678. else if(sd->state.size==1)
  1679. clif_specialeffect(&sd->bl,421,0);
  1680. return 0;
  1681. }
  1682. /*==========================================
  1683. *
  1684. *------------------------------------------
  1685. */
  1686. int clif_spawnnpc(struct npc_data *nd)
  1687. {
  1688. unsigned char buf[64];
  1689. int len;
  1690. nullpo_retr(0, nd);
  1691. if(nd->class_ < 0 || nd->flag&1 || nd->class_ == INVISIBLE_CLASS)
  1692. return 0;
  1693. if(!mobdb_checkid(nd->class_) ||
  1694. !pcdb_checkid(mob_get_viewclass(nd->class_))) {
  1695. //Normal npcs.
  1696. memset(buf,0,packet_len_table[0x7c]);
  1697. WBUFW(buf,0)=0x7c;
  1698. WBUFL(buf,2)=nd->bl.id;
  1699. WBUFW(buf,6)=nd->speed;
  1700. WBUFW(buf,20)=nd->class_;
  1701. WBUFPOS(buf,36,nd->bl.x,nd->bl.y);
  1702. clif_send(buf,packet_len_table[0x7c],&nd->bl,AREA);
  1703. }
  1704. len = clif_npc0078(nd,buf);
  1705. clif_send(buf,len,&nd->bl,AREA);
  1706. return 0;
  1707. }
  1708. /*==========================================
  1709. *
  1710. *------------------------------------------
  1711. */
  1712. int clif_spawnmob(struct mob_data *md)
  1713. {
  1714. unsigned char buf[64];
  1715. int len;
  1716. int viewclass = mob_get_viewclass(md->class_);
  1717. if (!pcdb_checkid(viewclass)) {
  1718. memset(buf,0,packet_len_table[0x7c]);
  1719. WBUFW(buf,0)=0x7c;
  1720. WBUFL(buf,2)=md->bl.id;
  1721. WBUFW(buf,6)=md->speed;
  1722. WBUFW(buf,8)=md->sc.opt1;
  1723. WBUFW(buf,10)=md->sc.opt2;
  1724. WBUFW(buf,12)=md->sc.option;
  1725. WBUFW(buf,20)=viewclass;
  1726. WBUFPOS(buf,36,md->bl.x,md->bl.y);
  1727. clif_send(buf,packet_len_table[0x7c],&md->bl,AREA);
  1728. }
  1729. len = clif_mob0078(md,buf);
  1730. clif_send(buf,len,&md->bl,AREA);
  1731. if(battle_config.save_clothcolor && pcdb_checkid(viewclass) && mob_get_clothes_color(md->class_) > 0) // [Valaris]
  1732. clif_changelook(&md->bl, LOOK_CLOTHES_COLOR, mob_get_clothes_color(md->class_));
  1733. if (mob_get_equip(md->class_) > 0) // mob equipment [Valaris]
  1734. clif_mob_equip(md,mob_get_equip(md->class_));
  1735. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1736. clif_specialeffect(&md->bl,423,0);
  1737. else if(md->special_state.size==1)
  1738. clif_specialeffect(&md->bl,421,0);
  1739. return 0;
  1740. }
  1741. // pet
  1742. /*==========================================
  1743. *
  1744. *------------------------------------------
  1745. */
  1746. int clif_spawnpet(struct pet_data *pd)
  1747. {
  1748. unsigned char buf[64];
  1749. int len;
  1750. int viewclass = mob_get_viewclass(pd->class_);
  1751. if (!pcdb_checkid(viewclass)) {
  1752. memset(buf,0,packet_len_table[0x7c]);
  1753. WBUFW(buf,0)=0x7c;
  1754. WBUFL(buf,2)=pd->bl.id;
  1755. WBUFW(buf,6)=pd->speed;
  1756. WBUFW(buf,20)=viewclass;
  1757. WBUFPOS(buf,36,pd->bl.x,pd->bl.y);
  1758. clif_send(buf,packet_len_table[0x7c],&pd->bl,AREA);
  1759. }
  1760. len = clif_pet0078(pd,buf);
  1761. clif_send(buf,len,&pd->bl,AREA);
  1762. return 0;
  1763. }
  1764. /*==========================================
  1765. *
  1766. *------------------------------------------
  1767. */
  1768. int clif_movepet(struct pet_data *pd) {
  1769. unsigned char buf[256];
  1770. int len;
  1771. nullpo_retr(0, pd);
  1772. len = clif_pet007b(pd,buf);
  1773. clif_send(buf,len,&pd->bl,AREA);
  1774. return 0;
  1775. }
  1776. /*==========================================
  1777. * npc walking [Valaris]
  1778. *------------------------------------------
  1779. */
  1780. int clif_movenpc(struct npc_data *nd) {
  1781. unsigned char buf[256];
  1782. int len;
  1783. nullpo_retr(0, nd);
  1784. len = clif_npc007b(nd,buf);
  1785. clif_send(buf,len,&nd->bl,AREA);
  1786. return 0;
  1787. }
  1788. /*==========================================
  1789. *
  1790. *------------------------------------------
  1791. */
  1792. int clif_servertick(struct map_session_data *sd)
  1793. {
  1794. int fd;
  1795. nullpo_retr(0, sd);
  1796. fd=sd->fd;
  1797. WFIFOHEAD(fd, packet_len_table[0x7f]);
  1798. WFIFOW(fd,0)=0x7f;
  1799. WFIFOL(fd,2)=sd->server_tick;
  1800. WFIFOSET(fd,packet_len_table[0x7f]);
  1801. return 0;
  1802. }
  1803. /*==========================================
  1804. *
  1805. *------------------------------------------
  1806. */
  1807. int clif_walkok(struct map_session_data *sd)
  1808. {
  1809. int fd;
  1810. nullpo_retr(0, sd);
  1811. fd=sd->fd;
  1812. WFIFOHEAD(fd, packet_len_table[0x87]);
  1813. WFIFOW(fd,0)=0x87;
  1814. WFIFOL(fd,2)=gettick();
  1815. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  1816. WFIFOB(fd,11)=0x88;
  1817. WFIFOSET(fd,packet_len_table[0x87]);
  1818. return 0;
  1819. }
  1820. /*==========================================
  1821. *
  1822. *------------------------------------------
  1823. */
  1824. int clif_movechar(struct map_session_data *sd) {
  1825. int fd;
  1826. int len;
  1827. unsigned char buf[256];
  1828. nullpo_retr(0, sd);
  1829. fd = sd->fd;
  1830. len = clif_set007b(sd, buf);
  1831. clif_send(buf, len, &sd->bl, AREA_WOS);
  1832. if (map[sd->bl.m].flag.snow || map[sd->bl.m].flag.clouds || map[sd->bl.m].flag.fog || map[sd->bl.m].flag.fireworks ||
  1833. map[sd->bl.m].flag.sakura || map[sd->bl.m].flag.leaves || map[sd->bl.m].flag.rain || map[sd->bl.m].flag.clouds2) {
  1834. memset(buf,0,packet_len_table[0x7b]);
  1835. WBUFW(buf,0)=0x7b;
  1836. WBUFL(buf,2)=-10;
  1837. WBUFW(buf,6)=sd->speed;
  1838. WBUFW(buf,8)=0;
  1839. WBUFW(buf,10)=0;
  1840. WBUFW(buf,12)=OPTION_INVISIBLE;
  1841. WBUFW(buf,14)=100;
  1842. WBUFL(buf,22)=gettick();
  1843. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  1844. WBUFB(buf,56)=5;
  1845. WBUFB(buf,57)=5;
  1846. clif_send(buf, len, &sd->bl, SELF);
  1847. }
  1848. if(sd->disguise) {
  1849. memset(buf,0,packet_len_table[0x7b]);
  1850. len = clif_dis007b(sd, buf);
  1851. clif_send(buf, len, &sd->bl, AREA);
  1852. return 0;
  1853. }
  1854. //Stupid client that needs this resent every time someone walks :X
  1855. if(battle_config.save_clothcolor && sd->status.clothes_color > 0 && ((sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS) ||
  1856. (sd->view_class==JOB_WEDDING && !battle_config.wedding_ignorepalette) || (sd->view_class==JOB_XMAS && !battle_config.xmas_ignorepalette)))
  1857. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->status.clothes_color);
  1858. if(sd->state.size==2) // tiny/big players [Valaris]
  1859. clif_specialeffect(&sd->bl,423,0);
  1860. else if(sd->state.size==1)
  1861. clif_specialeffect(&sd->bl,421,0);
  1862. return 0;
  1863. }
  1864. /*==========================================
  1865. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1866. *------------------------------------------
  1867. */
  1868. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1869. struct map_session_data *sd = NULL;
  1870. if (chrif_isconnect())
  1871. { //Remove player from map server
  1872. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1873. map_quit(sd);
  1874. } else //Save later.
  1875. add_timer(tick + 10000, clif_delayquit, id, 0);
  1876. return 0;
  1877. }
  1878. /*==========================================
  1879. *
  1880. *------------------------------------------
  1881. */
  1882. void clif_quitsave(int fd,struct map_session_data *sd)
  1883. {
  1884. if (chrif_isconnect() && (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout))
  1885. map_quit(sd);
  1886. else if (sd->fd)
  1887. { //Disassociate session from player (session is deleted after this function was called)
  1888. //And set a timer to delete this player later.
  1889. session[fd]->session_data = NULL;
  1890. sd->fd = 0;
  1891. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1892. }
  1893. }
  1894. /*==========================================
  1895. *
  1896. *------------------------------------------
  1897. */
  1898. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1899. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1900. session[id]->eof = 1;
  1901. return 0;
  1902. }
  1903. /*==========================================
  1904. *
  1905. *------------------------------------------
  1906. */
  1907. void clif_setwaitclose(int fd) {
  1908. struct map_session_data *sd;
  1909. // if player is not already in the game (double connection probably)
  1910. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1911. // limited timer, just to send information.
  1912. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1913. } else
  1914. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1915. }
  1916. /*==========================================
  1917. *
  1918. *------------------------------------------
  1919. */
  1920. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1921. int fd;
  1922. nullpo_retr(0, sd);
  1923. fd = sd->fd;
  1924. WFIFOHEAD(fd, packet_len_table[0x91]);
  1925. WFIFOW(fd,0) = 0x91;
  1926. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1927. WFIFOW(fd,18) = x;
  1928. WFIFOW(fd,20) = y;
  1929. WFIFOSET(fd, packet_len_table[0x91]);
  1930. if(pc_isdead(sd)) // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  1931. clif_clearchar_area(&sd->bl,1);
  1932. return 0;
  1933. }
  1934. /*==========================================
  1935. *
  1936. *------------------------------------------
  1937. */
  1938. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1939. int fd;
  1940. nullpo_retr(0, sd);
  1941. fd = sd->fd;
  1942. WFIFOHEAD(fd, packet_len_table[0x92]);
  1943. WFIFOW(fd,0) = 0x92;
  1944. //Better not trust the null-terminator is there. [Skotlex]
  1945. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1946. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1947. WFIFOW(fd,18) = x;
  1948. WFIFOW(fd,20) = y;
  1949. WFIFOL(fd,22) = ip;
  1950. WFIFOW(fd,26) = port;
  1951. WFIFOSET(fd, packet_len_table[0x92]);
  1952. return 0;
  1953. }
  1954. int clif_blown(struct block_list *bl) {
  1955. //Previous Aegis versions simply used clif_fixpos, but it seems clif_slide works better on current clients.
  1956. // return clif_fixpos(bl);
  1957. return clif_slide(bl, bl->x, bl->y);
  1958. }
  1959. /*==========================================
  1960. *
  1961. *------------------------------------------
  1962. */
  1963. int clif_fixpos(struct block_list *bl) {
  1964. unsigned char buf[16];
  1965. nullpo_retr(0, bl);
  1966. WBUFW(buf,0)=0x88;
  1967. if (bl->type ==BL_PC && ((struct map_session_data *)bl)->disguise)
  1968. WBUFL(buf,2)=-bl->id;
  1969. else
  1970. WBUFL(buf,2)=bl->id;
  1971. WBUFW(buf,6)=bl->x;
  1972. WBUFW(buf,8)=bl->y;
  1973. clif_send(buf, packet_len_table[0x88], bl, AREA);
  1974. return 0;
  1975. }
  1976. /*==========================================
  1977. *
  1978. *------------------------------------------
  1979. */
  1980. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1981. int fd;
  1982. nullpo_retr(0, sd);
  1983. fd=sd->fd;
  1984. WFIFOHEAD(fd, packet_len_table[0xc4]);
  1985. WFIFOW(fd,0)=0xc4;
  1986. WFIFOL(fd,2)=id;
  1987. WFIFOSET(fd,packet_len_table[0xc4]);
  1988. return 0;
  1989. }
  1990. /*==========================================
  1991. *
  1992. *------------------------------------------
  1993. */
  1994. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1995. struct item_data *id;
  1996. int fd,i,val;
  1997. nullpo_retr(0, sd);
  1998. nullpo_retr(0, nd);
  1999. fd=sd->fd;
  2000. WFIFOHEAD(fd, 200 * 11 + 4);
  2001. WFIFOW(fd,0)=0xc6;
  2002. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  2003. id = itemdb_search(nd->u.shop_item[i].nameid);
  2004. val=nd->u.shop_item[i].value;
  2005. WFIFOL(fd,4+i*11)=val;
  2006. if (!id->flag.value_notdc)
  2007. val=pc_modifybuyvalue(sd,val);
  2008. WFIFOL(fd,8+i*11)=val;
  2009. WFIFOB(fd,12+i*11)=itemtype(id->type);
  2010. if (id->view_id > 0)
  2011. WFIFOW(fd,13+i*11)=id->view_id;
  2012. else
  2013. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  2014. }
  2015. WFIFOW(fd,2)=i*11+4;
  2016. WFIFOSET(fd,WFIFOW(fd,2));
  2017. return 0;
  2018. }
  2019. /*==========================================
  2020. *
  2021. *------------------------------------------
  2022. */
  2023. int clif_selllist(struct map_session_data *sd) {
  2024. int fd,i,c=0,val;
  2025. nullpo_retr(0, sd);
  2026. fd=sd->fd;
  2027. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  2028. WFIFOW(fd,0)=0xc7;
  2029. for(i=0;i<MAX_INVENTORY;i++) {
  2030. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  2031. if (!itemdb_cansell(sd->status.inventory[i].nameid, pc_isGM(sd)))
  2032. continue;
  2033. val=sd->inventory_data[i]->value_sell;
  2034. if (val < 0)
  2035. continue;
  2036. WFIFOW(fd,4+c*10)=i+2;
  2037. WFIFOL(fd,6+c*10)=val;
  2038. if (!sd->inventory_data[i]->flag.value_notoc)
  2039. val=pc_modifysellvalue(sd,val);
  2040. WFIFOL(fd,10+c*10)=val;
  2041. c++;
  2042. }
  2043. }
  2044. WFIFOW(fd,2)=c*10+4;
  2045. WFIFOSET(fd,WFIFOW(fd,2));
  2046. return 0;
  2047. }
  2048. /*==========================================
  2049. *
  2050. *------------------------------------------
  2051. */
  2052. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  2053. int fd;
  2054. int slen = strlen(mes) + 9;
  2055. WFIFOHEAD(fd, slen);
  2056. nullpo_retr(0, sd);
  2057. fd=sd->fd;
  2058. WFIFOW(fd,0)=0xb4;
  2059. WFIFOW(fd,2)=slen;
  2060. WFIFOL(fd,4)=npcid;
  2061. strcpy((char*)WFIFOP(fd,8),mes);
  2062. WFIFOSET(fd,WFIFOW(fd,2));
  2063. return 0;
  2064. }
  2065. /*==========================================
  2066. *
  2067. *------------------------------------------
  2068. */
  2069. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  2070. int fd;
  2071. nullpo_retr(0, sd);
  2072. fd=sd->fd;
  2073. WFIFOHEAD(fd, packet_len_table[0xb5]);
  2074. WFIFOW(fd,0)=0xb5;
  2075. WFIFOL(fd,2)=npcid;
  2076. WFIFOSET(fd,packet_len_table[0xb5]);
  2077. return 0;
  2078. }
  2079. /*==========================================
  2080. *
  2081. *------------------------------------------
  2082. */
  2083. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  2084. int fd;
  2085. nullpo_retr(0, sd);
  2086. fd=sd->fd;
  2087. WFIFOHEAD(fd, packet_len_table[0xb6]);
  2088. WFIFOW(fd,0)=0xb6;
  2089. WFIFOL(fd,2)=npcid;
  2090. WFIFOSET(fd,packet_len_table[0xb6]);
  2091. return 0;
  2092. }
  2093. /*==========================================
  2094. *
  2095. *------------------------------------------
  2096. */
  2097. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  2098. int fd;
  2099. int slen = strlen(mes) + 8;
  2100. WFIFOHEAD(fd, slen);
  2101. nullpo_retr(0, sd);
  2102. fd=sd->fd;
  2103. WFIFOW(fd,0)=0xb7;
  2104. WFIFOW(fd,2)=slen;
  2105. WFIFOL(fd,4)=npcid;
  2106. strcpy((char*)WFIFOP(fd,8),mes);
  2107. WFIFOSET(fd,WFIFOW(fd,2));
  2108. return 0;
  2109. }
  2110. /*==========================================
  2111. *
  2112. *------------------------------------------
  2113. */
  2114. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  2115. int fd;
  2116. nullpo_retr(0, sd);
  2117. fd=sd->fd;
  2118. WFIFOHEAD(fd, packet_len_table[0x142]);
  2119. WFIFOW(fd,0)=0x142;
  2120. WFIFOL(fd,2)=npcid;
  2121. WFIFOSET(fd,packet_len_table[0x142]);
  2122. return 0;
  2123. }
  2124. /*==========================================
  2125. *
  2126. *------------------------------------------
  2127. */
  2128. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  2129. int fd;
  2130. nullpo_retr(0, sd);
  2131. fd=sd->fd;
  2132. WFIFOHEAD(fd, packet_len_table[0x1d4]);
  2133. WFIFOW(fd,0)=0x1d4;
  2134. WFIFOL(fd,2)=npcid;
  2135. WFIFOSET(fd,packet_len_table[0x1d4]);
  2136. return 0;
  2137. }
  2138. /*==========================================
  2139. *
  2140. *------------------------------------------
  2141. */
  2142. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  2143. int fd;
  2144. nullpo_retr(0, sd);
  2145. fd=sd->fd;
  2146. WFIFOHEAD(fd, packet_len_table[0x144]);
  2147. WFIFOW(fd,0)=0x144;
  2148. WFIFOL(fd,2)=npc_id;
  2149. WFIFOL(fd,6)=type;
  2150. WFIFOL(fd,10)=x;
  2151. WFIFOL(fd,14)=y;
  2152. WFIFOB(fd,18)=id;
  2153. WFIFOL(fd,19)=color;
  2154. WFIFOSET(fd,packet_len_table[0x144]);
  2155. return 0;
  2156. }
  2157. /*==========================================
  2158. *
  2159. *------------------------------------------
  2160. */
  2161. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  2162. int fd;
  2163. nullpo_retr(0, sd);
  2164. fd=sd->fd;
  2165. WFIFOHEAD(fd, packet_len_table[0x1b3]);
  2166. WFIFOW(fd,0)=0x1b3;
  2167. strncpy((char*)WFIFOP(fd,2),image,64);
  2168. WFIFOB(fd,66)=type;
  2169. WFIFOSET(fd,packet_len_table[0x1b3]);
  2170. return 0;
  2171. }
  2172. /*==========================================
  2173. * Fills in card data from the given item and into the buffer. [Skotlex]
  2174. *------------------------------------------
  2175. */
  2176. static void clif_addcards(unsigned char* buf, struct item* item)
  2177. {
  2178. int i=0,j;
  2179. if (item == NULL) { //Blank data
  2180. WBUFW(buf,0)=0;
  2181. WBUFW(buf,2)=0;
  2182. WBUFW(buf,4)=0;
  2183. WBUFW(buf,6)=0;
  2184. return;
  2185. }
  2186. if(item->card[0]==(short)0xff00) { //pet eggs
  2187. WBUFW(buf,0)=0;
  2188. WBUFW(buf,2)=0;
  2189. WBUFW(buf,4)=0;
  2190. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  2191. return;
  2192. }
  2193. if(item->card[0]==0x00ff || item->card[0]==0x00fe) { //Forged/created items
  2194. WBUFW(buf,0)=item->card[0];
  2195. WBUFW(buf,2)=item->card[1];
  2196. WBUFW(buf,4)=item->card[2];
  2197. WBUFW(buf,6)=item->card[3];
  2198. return;
  2199. }
  2200. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2201. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  2202. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  2203. //Normal items.
  2204. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  2205. WBUFW(buf,0)=j;
  2206. else
  2207. WBUFW(buf,0)= item->card[i];
  2208. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  2209. WBUFW(buf,2)=j;
  2210. else
  2211. WBUFW(buf,2)=item->card[i];
  2212. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  2213. WBUFW(buf,4)=j;
  2214. else
  2215. WBUFW(buf,4)=item->card[i];
  2216. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  2217. WBUFW(buf,6)=j;
  2218. else
  2219. WBUFW(buf,6)=item->card[i];
  2220. }
  2221. /*==========================================
  2222. *
  2223. *------------------------------------------
  2224. */
  2225. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  2226. int fd;
  2227. unsigned char *buf;
  2228. nullpo_retr(0, sd);
  2229. fd = sd->fd;
  2230. if (!session_isActive(fd)) //Sasuke-
  2231. return 0;
  2232. WFIFOHEAD(fd,packet_len_table[0xa0]);
  2233. buf = WFIFOP(fd,0);
  2234. if(fail) {
  2235. WBUFW(buf,0)=0xa0;
  2236. WBUFW(buf,2)=n+2;
  2237. WBUFW(buf,4)=amount;
  2238. WBUFW(buf,6)=0;
  2239. WBUFB(buf,8)=0;
  2240. WBUFB(buf,9)=0;
  2241. WBUFB(buf,10)=0;
  2242. WBUFW(buf,11)=0;
  2243. WBUFW(buf,13)=0;
  2244. WBUFW(buf,15)=0;
  2245. WBUFW(buf,17)=0;
  2246. WBUFW(buf,19)=0;
  2247. WBUFB(buf,21)=0;
  2248. WBUFB(buf,22)=fail;
  2249. } else {
  2250. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  2251. return 1;
  2252. WBUFW(buf,0)=0xa0;
  2253. WBUFW(buf,2)=n+2;
  2254. WBUFW(buf,4)=amount;
  2255. if (sd->inventory_data[n]->view_id > 0)
  2256. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  2257. else
  2258. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  2259. WBUFB(buf,8)=sd->status.inventory[n].identify;
  2260. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  2261. WBUFB(buf,10)=sd->status.inventory[n].refine;
  2262. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  2263. WBUFW(buf,19)=pc_equippoint(sd,n);
  2264. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  2265. WBUFB(buf,22)=fail;
  2266. }
  2267. WFIFOSET(fd,packet_len_table[0xa0]);
  2268. return 0;
  2269. }
  2270. /*==========================================
  2271. *
  2272. *------------------------------------------
  2273. */
  2274. int clif_delitem(struct map_session_data *sd,int n,int amount)
  2275. {
  2276. int fd;
  2277. nullpo_retr(0, sd);
  2278. fd=sd->fd;
  2279. WFIFOHEAD(fd, packet_len_table[0xaf]);
  2280. WFIFOW(fd,0)=0xaf;
  2281. WFIFOW(fd,2)=n+2;
  2282. WFIFOW(fd,4)=amount;
  2283. WFIFOSET(fd,packet_len_table[0xaf]);
  2284. return 0;
  2285. }
  2286. /*==========================================
  2287. *
  2288. *------------------------------------------
  2289. */
  2290. int clif_itemlist(struct map_session_data *sd)
  2291. {
  2292. int i,n,fd,arrow=-1;
  2293. unsigned char *buf;
  2294. nullpo_retr(0, sd);
  2295. fd=sd->fd;
  2296. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  2297. buf = WFIFOP(fd,0);
  2298. #if PACKETVER < 5
  2299. WBUFW(buf,0)=0xa3;
  2300. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2301. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  2302. continue;
  2303. WBUFW(buf,n*10+4)=i+2;
  2304. if (sd->inventory_data[i]->view_id > 0)
  2305. WBUFW(buf,n*10+6)=sd->inventory_data[i]->view_id;
  2306. else
  2307. WBUFW(buf,n*10+6)=sd->status.inventory[i].nameid;
  2308. WBUFB(buf,n*10+8)=itemtype(sd->inventory_data[i]->type);
  2309. WBUFB(buf,n*10+9)=sd->status.inventory[i].identify;
  2310. WBUFW(buf,n*10+10)=sd->status.inventory[i].amount;
  2311. if (sd->inventory_data[i]->equip == 0x8000) {
  2312. WBUFW(buf,n*10+12)=0x8000;
  2313. if (sd->status.inventory[i].equip)
  2314. arrow=i; // ついでに矢装備チェック
  2315. } else
  2316. WBUFW(buf,n*10+12)=0;
  2317. n++;
  2318. }
  2319. if (n) {
  2320. WBUFW(buf,2)=4+n*10;
  2321. WFIFOSET(fd,WFIFOW(fd,2));
  2322. }
  2323. #else
  2324. WBUFW(buf,0)=0x1ee;
  2325. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2326. if(sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  2327. continue;
  2328. WBUFW(buf,n*18+4)=i+2;
  2329. if(sd->inventory_data[i]->view_id > 0)
  2330. WBUFW(buf,n*18+6)=sd->inventory_data[i]->view_id;
  2331. else
  2332. WBUFW(buf,n*18+6)=sd->status.inventory[i].nameid;
  2333. WBUFB(buf,n*18+8)=itemtype(sd->inventory_data[i]->type);
  2334. WBUFB(buf,n*18+9)=sd->status.inventory[i].identify;
  2335. WBUFW(buf,n*18+10)=sd->status.inventory[i].amount;
  2336. if (sd->inventory_data[i]->equip == 0x8000) {
  2337. WBUFW(buf,n*18+12)=0x8000;
  2338. if(sd->status.inventory[i].equip)
  2339. arrow=i; // ついでに矢装備チェック
  2340. } else
  2341. WBUFW(buf,n*18+12)=0;
  2342. clif_addcards(WBUFP(buf, n*18+14), &sd->status.inventory[i]);
  2343. n++;
  2344. }
  2345. if (n) {
  2346. WBUFW(buf,2)=4+n*18;
  2347. WFIFOSET(fd,WFIFOW(fd,2));
  2348. }
  2349. #endif
  2350. if(arrow >= 0)
  2351. clif_arrowequip(sd,arrow);
  2352. return 0;
  2353. }
  2354. /*==========================================
  2355. *
  2356. *------------------------------------------
  2357. */
  2358. int clif_equiplist(struct map_session_data *sd)
  2359. {
  2360. int i,n,fd;
  2361. nullpo_retr(0, sd);
  2362. fd=sd->fd;
  2363. if (!session_isActive(fd))
  2364. return 0;
  2365. WFIFOHEAD(fd, 4 + MAX_INVENTORY * 20);
  2366. WFIFOW(fd,0)=0xa4;
  2367. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2368. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL || !itemdb_isequip2(sd->inventory_data[i]))
  2369. continue;
  2370. WFIFOW(fd,n*20+4)=i+2;
  2371. if(sd->inventory_data[i]->view_id > 0)
  2372. WFIFOW(fd,n*20+6)=sd->inventory_data[i]->view_id;
  2373. else
  2374. WFIFOW(fd,n*20+6)=sd->status.inventory[i].nameid;
  2375. WFIFOB(fd,n*20+8)=itemtype(sd->inventory_data[i]->type);
  2376. WFIFOB(fd,n*20+9)=sd->status.inventory[i].identify;
  2377. WFIFOW(fd,n*20+10)=pc_equippoint(sd,i);
  2378. WFIFOW(fd,n*20+12)=sd->status.inventory[i].equip;
  2379. WFIFOB(fd,n*20+14)=sd->status.inventory[i].attribute;
  2380. WFIFOB(fd,n*20+15)=sd->status.inventory[i].refine;
  2381. clif_addcards(WFIFOP(fd, n*20+16), &sd->status.inventory[i]);
  2382. n++;
  2383. }
  2384. if(n){
  2385. WFIFOW(fd,2)=4+n*20;
  2386. WFIFOSET(fd,WFIFOW(fd,2));
  2387. }
  2388. return 0;
  2389. }
  2390. /*==========================================
  2391. * カプラさんに預けてある消耗品&収集品リスト
  2392. *------------------------------------------
  2393. */
  2394. int clif_storageitemlist(struct map_session_data *sd,struct storage *stor)
  2395. {
  2396. struct item_data *id;
  2397. int i,n,fd;
  2398. unsigned char *buf;
  2399. nullpo_retr(0, sd);
  2400. nullpo_retr(0, stor);
  2401. fd=sd->fd;
  2402. WFIFOHEAD(fd,MAX_STORAGE * 18 + 4);
  2403. buf = WFIFOP(fd,0);
  2404. #if PACKETVER < 5
  2405. WBUFW(buf,0)=0xa5;
  2406. for(i=0,n=0;i<MAX_STORAGE;i++){
  2407. if(stor->storage_[i].nameid<=0)
  2408. continue;
  2409. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2410. if(itemdb_isequip2(id))
  2411. continue;
  2412. WBUFW(buf,n*10+4)=i+1;
  2413. if(id->view_id > 0)
  2414. WBUFW(buf,n*10+6)=id->view_id;
  2415. else
  2416. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  2417. WBUFB(buf,n*10+8)=itemtype(id->type);
  2418. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  2419. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  2420. WBUFW(buf,n*10+12)=0;
  2421. n++;
  2422. }
  2423. if(n){
  2424. WBUFW(buf,2)=4+n*10;
  2425. WFIFOSET(fd,WFIFOW(fd,2));
  2426. }
  2427. #else
  2428. WBUFW(buf,0)=0x1f0;
  2429. for(i=0,n=0;i<MAX_STORAGE;i++){
  2430. if(stor->storage_[i].nameid<=0)
  2431. continue;
  2432. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2433. if(itemdb_isequip2(id))
  2434. continue;
  2435. WBUFW(buf,n*18+4)=i+1;
  2436. if(id->view_id > 0)
  2437. WBUFW(buf,n*18+6)=id->view_id;
  2438. else
  2439. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  2440. WBUFB(buf,n*18+8)=itemtype(id->type);
  2441. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  2442. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  2443. WBUFW(buf,n*18+12)=0;
  2444. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  2445. n++;
  2446. }
  2447. if(n){
  2448. WBUFW(buf,2)=4+n*18;
  2449. WFIFOSET(fd,WFIFOW(fd,2));
  2450. }
  2451. #endif
  2452. return 0;
  2453. }
  2454. /*==========================================
  2455. * カプラさんに預けてある装備リスト
  2456. *------------------------------------------
  2457. */
  2458. int clif_storageequiplist(struct map_session_data *sd,struct storage *stor)
  2459. {
  2460. struct item_data *id;
  2461. int i,n,fd;
  2462. unsigned char *buf;
  2463. nullpo_retr(0, sd);
  2464. nullpo_retr(0, stor);
  2465. fd=sd->fd;
  2466. WFIFOHEAD(fd,MAX_STORAGE * 20 + 4);
  2467. buf = WFIFOP(fd,0);
  2468. WBUFW(buf,0)=0xa6;
  2469. for(i=0,n=0;i<MAX_STORAGE;i++){
  2470. if(stor->storage_[i].nameid<=0)
  2471. continue;
  2472. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2473. if(!itemdb_isequip2(id))
  2474. continue;
  2475. WBUFW(buf,n*20+4)=i+1;
  2476. if(id->view_id > 0)
  2477. WBUFW(buf,n*20+6)=id->view_id;
  2478. else
  2479. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2480. WBUFB(buf,n*20+8)=itemtype(id->type);
  2481. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2482. WBUFW(buf,n*20+10)=id->equip;
  2483. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2484. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2485. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2486. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2487. n++;
  2488. }
  2489. if(n){
  2490. WBUFW(buf,2)=4+n*20;
  2491. WFIFOSET(fd,WFIFOW(fd,2));
  2492. }
  2493. return 0;
  2494. }
  2495. /*==========================================
  2496. *
  2497. *------------------------------------------
  2498. */
  2499. int clif_guildstorageitemlist(struct map_session_data *sd,struct guild_storage *stor)
  2500. {
  2501. struct item_data *id;
  2502. int i,n,fd;
  2503. unsigned char *buf;
  2504. nullpo_retr(0, sd);
  2505. nullpo_retr(0, stor);
  2506. fd=sd->fd;
  2507. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 18 + 4);
  2508. buf=WFIFOP(fd,0);
  2509. #if PACKETVER < 5
  2510. WBUFW(buf,0)=0xa5;
  2511. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2512. if(stor->storage_[i].nameid<=0)
  2513. continue;
  2514. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2515. if(itemdb_isequip2(id))
  2516. continue;
  2517. WBUFW(buf,n*10+4)=i+1;
  2518. if(id->view_id > 0)
  2519. WBUFW(buf,n*10+6)=id->view_id;
  2520. else
  2521. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  2522. WBUFB(buf,n*10+8)=itemtype(id->type);
  2523. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  2524. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  2525. WBUFW(buf,n*10+12)=0;
  2526. n++;
  2527. }
  2528. if(n){
  2529. WBUFW(buf,2)=4+n*10;
  2530. WFIFOSET(fd,WFIFOW(fd,2));
  2531. }
  2532. #else
  2533. WBUFW(buf,0)=0x1f0;
  2534. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2535. if(stor->storage_[i].nameid<=0)
  2536. continue;
  2537. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2538. if(itemdb_isequip2(id))
  2539. continue;
  2540. WBUFW(buf,n*18+4)=i+1;
  2541. if(id->view_id > 0)
  2542. WBUFW(buf,n*18+6)=id->view_id;
  2543. else
  2544. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  2545. WBUFB(buf,n*18+8)=itemtype(id->type);
  2546. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  2547. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  2548. WBUFW(buf,n*18+12)=0;
  2549. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  2550. n++;
  2551. }
  2552. if(n){
  2553. WBUFW(buf,2)=4+n*18;
  2554. WFIFOSET(fd,WFIFOW(fd,2));
  2555. }
  2556. #endif
  2557. return 0;
  2558. }
  2559. /*==========================================
  2560. *
  2561. *------------------------------------------
  2562. */
  2563. int clif_guildstorageequiplist(struct map_session_data *sd,struct guild_storage *stor)
  2564. {
  2565. struct item_data *id;
  2566. int i,n,fd;
  2567. unsigned char *buf;
  2568. nullpo_retr(0, sd);
  2569. fd=sd->fd;
  2570. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 20 + 4);
  2571. buf=WFIFOP(fd,0);
  2572. WBUFW(buf,0)=0xa6;
  2573. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2574. if(stor->storage_[i].nameid<=0)
  2575. continue;
  2576. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2577. if(!itemdb_isequip2(id))
  2578. continue;
  2579. WBUFW(buf,n*20+4)=i+1;
  2580. if(id->view_id > 0)
  2581. WBUFW(buf,n*20+6)=id->view_id;
  2582. else
  2583. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2584. WBUFB(buf,n*20+8)=itemtype(id->type);
  2585. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2586. WBUFW(buf,n*20+10)=id->equip;
  2587. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2588. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2589. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2590. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2591. n++;
  2592. }
  2593. if(n){
  2594. WBUFW(buf,2)=4+n*20;
  2595. WFIFOSET(fd,WFIFOW(fd,2));
  2596. }
  2597. return 0;
  2598. }
  2599. // Guild XY locators [Valaris]
  2600. int clif_guild_xy(struct map_session_data *sd)
  2601. {
  2602. unsigned char buf[10];
  2603. nullpo_retr(0, sd);
  2604. WBUFW(buf,0)=0x1eb;
  2605. WBUFL(buf,2)=sd->status.account_id;
  2606. WBUFW(buf,6)=sd->bl.x;
  2607. WBUFW(buf,8)=sd->bl.y;
  2608. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2609. return 0;
  2610. }
  2611. /*==========================================
  2612. * Sends x/y dot to a single fd. [Skotlex]
  2613. *------------------------------------------
  2614. */
  2615. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2616. {
  2617. WFIFOHEAD(fd,packet_len_table[0x1eb]);
  2618. WFIFOW(fd,0)=0x1eb;
  2619. WFIFOL(fd,2)=sd->status.account_id;
  2620. WFIFOW(fd,6)=sd->bl.x;
  2621. WFIFOW(fd,8)=sd->bl.y;
  2622. WFIFOSET(fd,packet_len_table[0x1eb]);
  2623. return 0;
  2624. }
  2625. // Guild XY locators [Valaris]
  2626. int clif_guild_xy_remove(struct map_session_data *sd)
  2627. {
  2628. unsigned char buf[10];
  2629. nullpo_retr(0, sd);
  2630. WBUFW(buf,0)=0x1eb;
  2631. WBUFL(buf,2)=sd->status.account_id;
  2632. WBUFW(buf,6)=-1;
  2633. WBUFW(buf,8)=-1;
  2634. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2635. return 0;
  2636. }
  2637. /*==========================================
  2638. * ステータスを送りつける
  2639. * 表示専用数字はこの中で計算して送る
  2640. *------------------------------------------
  2641. */
  2642. int clif_updatestatus(struct map_session_data *sd,int type)
  2643. {
  2644. int fd,len=8;
  2645. nullpo_retr(0, sd);
  2646. fd=sd->fd;
  2647. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2648. return 0;
  2649. WFIFOHEAD(fd, 14);
  2650. WFIFOW(fd,0)=0xb0;
  2651. WFIFOW(fd,2)=type;
  2652. switch(type){
  2653. // 00b0
  2654. case SP_WEIGHT:
  2655. pc_checkweighticon(sd);
  2656. WFIFOW(fd,0)=0xb0;
  2657. WFIFOW(fd,2)=type; //Added this packet back, Temp fix to the slow motion [Lupus]
  2658. WFIFOL(fd,4)=sd->weight;
  2659. break;
  2660. case SP_MAXWEIGHT:
  2661. WFIFOL(fd,4)=sd->max_weight;
  2662. break;
  2663. case SP_SPEED:
  2664. WFIFOL(fd,4)=sd->speed;
  2665. break;
  2666. case SP_BASELEVEL:
  2667. WFIFOL(fd,4)=sd->status.base_level;
  2668. break;
  2669. case SP_JOBLEVEL:
  2670. WFIFOL(fd,4)=sd->status.job_level;
  2671. break;
  2672. case SP_MANNER:
  2673. WFIFOL(fd,4)=sd->status.manner;
  2674. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2675. break;
  2676. case SP_STATUSPOINT:
  2677. WFIFOL(fd,4)=sd->status.status_point;
  2678. break;
  2679. case SP_SKILLPOINT:
  2680. WFIFOL(fd,4)=sd->status.skill_point;
  2681. break;
  2682. case SP_HIT:
  2683. WFIFOL(fd,4)=sd->hit;
  2684. break;
  2685. case SP_FLEE1:
  2686. WFIFOL(fd,4)=sd->flee;
  2687. break;
  2688. case SP_FLEE2:
  2689. WFIFOL(fd,4)=sd->flee2/10;
  2690. break;
  2691. case SP_MAXHP:
  2692. WFIFOL(fd,4)=sd->status.max_hp;
  2693. break;
  2694. case SP_MAXSP:
  2695. WFIFOL(fd,4)=sd->status.max_sp;
  2696. break;
  2697. case SP_HP:
  2698. WFIFOL(fd,4)=sd->status.hp;
  2699. if (sd->status.party_id)
  2700. clif_party_hp(sd);
  2701. if (battle_config.disp_hpmeter)
  2702. clif_hpmeter(sd);
  2703. break;
  2704. case SP_SP:
  2705. WFIFOL(fd,4)=sd->status.sp;
  2706. break;
  2707. case SP_ASPD:
  2708. WFIFOL(fd,4)=sd->aspd;
  2709. break;
  2710. case SP_ATK1:
  2711. WFIFOL(fd,4)=sd->base_atk+sd->right_weapon.watk+sd->left_weapon.watk;
  2712. break;
  2713. case SP_DEF1:
  2714. WFIFOL(fd,4)=sd->def;
  2715. break;
  2716. case SP_MDEF1:
  2717. WFIFOL(fd,4)=sd->mdef;
  2718. break;
  2719. case SP_ATK2:
  2720. WFIFOL(fd,4)=sd->right_weapon.watk2 + sd->left_weapon.watk2;
  2721. break;
  2722. case SP_DEF2:
  2723. WFIFOL(fd,4)=sd->def2;
  2724. break;
  2725. case SP_MDEF2:
  2726. WFIFOL(fd,4)=sd->mdef2;
  2727. break;
  2728. case SP_CRITICAL:
  2729. WFIFOL(fd,4)=sd->critical/10;
  2730. break;
  2731. case SP_MATK1:
  2732. WFIFOL(fd,4)=sd->matk1;
  2733. break;
  2734. case SP_MATK2:
  2735. WFIFOL(fd,4)=sd->matk2;
  2736. break;
  2737. case SP_ZENY:
  2738. WFIFOW(fd,0)=0xb1;
  2739. if(sd->status.zeny < 0)
  2740. sd->status.zeny = 0;
  2741. WFIFOL(fd,4)=sd->status.zeny;
  2742. break;
  2743. case SP_BASEEXP:
  2744. WFIFOW(fd,0)=0xb1;
  2745. WFIFOL(fd,4)=sd->status.base_exp;
  2746. break;
  2747. case SP_JOBEXP:
  2748. WFIFOW(fd,0)=0xb1;
  2749. WFIFOL(fd,4)=sd->status.job_exp;
  2750. break;
  2751. case SP_NEXTBASEEXP:
  2752. WFIFOW(fd,0)=0xb1;
  2753. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2754. break;
  2755. case SP_NEXTJOBEXP:
  2756. WFIFOW(fd,0)=0xb1;
  2757. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2758. break;
  2759. // 00be 終了
  2760. case SP_USTR:
  2761. case SP_UAGI:
  2762. case SP_UVIT:
  2763. case SP_UINT:
  2764. case SP_UDEX:
  2765. case SP_ULUK:
  2766. WFIFOW(fd,0)=0xbe;
  2767. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2768. len=5;
  2769. break;
  2770. // 013a 終了
  2771. case SP_ATTACKRANGE:
  2772. WFIFOW(fd,0)=0x13a;
  2773. WFIFOW(fd,2)=sd->attackrange;
  2774. len=4;
  2775. break;
  2776. // 0141 終了
  2777. case SP_STR:
  2778. WFIFOW(fd,0)=0x141;
  2779. WFIFOL(fd,2)=type;
  2780. WFIFOL(fd,6)=sd->status.str;
  2781. WFIFOL(fd,10)=sd->paramb[0] + sd->parame[0];
  2782. len=14;
  2783. break;
  2784. case SP_AGI:
  2785. WFIFOW(fd,0)=0x141;
  2786. WFIFOL(fd,2)=type;
  2787. WFIFOL(fd,6)=sd->status.agi;
  2788. WFIFOL(fd,10)=sd->paramb[1] + sd->parame[1];
  2789. len=14;
  2790. break;
  2791. case SP_VIT:
  2792. WFIFOW(fd,0)=0x141;
  2793. WFIFOL(fd,2)=type;
  2794. WFIFOL(fd,6)=sd->status.vit;
  2795. WFIFOL(fd,10)=sd->paramb[2] + sd->parame[2];
  2796. len=14;
  2797. break;
  2798. case SP_INT:
  2799. WFIFOW(fd,0)=0x141;
  2800. WFIFOL(fd,2)=type;
  2801. WFIFOL(fd,6)=sd->status.int_;
  2802. WFIFOL(fd,10)=sd->paramb[3] + sd->parame[3];
  2803. len=14;
  2804. break;
  2805. case SP_DEX:
  2806. WFIFOW(fd,0)=0x141;
  2807. WFIFOL(fd,2)=type;
  2808. WFIFOL(fd,6)=sd->status.dex;
  2809. WFIFOL(fd,10)=sd->paramb[4] + sd->parame[4];
  2810. len=14;
  2811. break;
  2812. case SP_LUK:
  2813. WFIFOW(fd,0)=0x141;
  2814. WFIFOL(fd,2)=type;
  2815. WFIFOL(fd,6)=sd->status.luk;
  2816. WFIFOL(fd,10)=sd->paramb[5] + sd->parame[5];
  2817. len=14;
  2818. break;
  2819. case SP_CARTINFO:
  2820. WFIFOW(fd,0)=0x121;
  2821. WFIFOW(fd,2)=sd->cart_num;
  2822. WFIFOW(fd,4)=sd->cart_max_num;
  2823. WFIFOL(fd,6)=sd->cart_weight;
  2824. WFIFOL(fd,10)=sd->cart_max_weight;
  2825. len=14;
  2826. break;
  2827. default:
  2828. if(battle_config.error_log)
  2829. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2830. return 1;
  2831. }
  2832. WFIFOSET(fd,len);
  2833. return 0;
  2834. }
  2835. int clif_changestatus(struct block_list *bl,int type,int val)
  2836. {
  2837. unsigned char buf[12];
  2838. struct map_session_data *sd = NULL;
  2839. nullpo_retr(0, bl);
  2840. if(bl->type == BL_PC)
  2841. sd = (struct map_session_data *)bl;
  2842. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2843. if(sd){
  2844. WBUFW(buf,0)=0x1ab;
  2845. WBUFL(buf,2)=bl->id;
  2846. WBUFW(buf,6)=type;
  2847. switch(type){
  2848. case SP_MANNER:
  2849. WBUFL(buf,8)=val;
  2850. break;
  2851. default:
  2852. if(battle_config.error_log)
  2853. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2854. return 1;
  2855. }
  2856. clif_send(buf,packet_len_table[0x1ab],bl,AREA_WOS);
  2857. }
  2858. return 0;
  2859. }
  2860. /*==========================================
  2861. *
  2862. *------------------------------------------
  2863. */
  2864. int clif_changelook(struct block_list *bl,int type,int val)
  2865. {
  2866. unsigned char buf[32];
  2867. struct map_session_data *sd = NULL;
  2868. nullpo_retr(0, bl);
  2869. if(bl->type == BL_PC)
  2870. sd = (struct map_session_data *)bl;
  2871. #if PACKETVER < 4
  2872. if(sd && (type == LOOK_WEAPON || type == LOOK_SHIELD) && (sd->view_class == JOB_WEDDING || sd->view_class == JOB_XMAS))
  2873. val =0;
  2874. WBUFW(buf,0)=0xc3;
  2875. WBUFL(buf,2)=bl->id;
  2876. WBUFB(buf,6)=type;
  2877. WBUFB(buf,7)=val;
  2878. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2879. #else
  2880. if(sd && (type == LOOK_WEAPON || type == LOOK_SHIELD || type == LOOK_SHOES)) {
  2881. WBUFW(buf,0)=0x1d7;
  2882. WBUFL(buf,2)=bl->id;
  2883. if(type == LOOK_SHOES) {
  2884. WBUFB(buf,6)=9;
  2885. if(sd->equip_index[2] >= 0 && sd->inventory_data[sd->equip_index[2]]) {
  2886. if(sd->inventory_data[sd->equip_index[2]]->view_id > 0)
  2887. WBUFW(buf,7)=sd->inventory_data[sd->equip_index[2]]->view_id;
  2888. else
  2889. WBUFW(buf,7)=sd->status.inventory[sd->equip_index[2]].nameid;
  2890. } else
  2891. WBUFW(buf,7)=0;
  2892. WBUFW(buf,9)=0;
  2893. }
  2894. else {
  2895. WBUFB(buf,6)=2;
  2896. if(sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]] && sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS) {
  2897. if(sd->inventory_data[sd->equip_index[9]]->view_id > 0)
  2898. WBUFW(buf,7)=sd->inventory_data[sd->equip_index[9]]->view_id;
  2899. else
  2900. WBUFW(buf,7)=sd->status.inventory[sd->equip_index[9]].nameid;
  2901. } else
  2902. WBUFW(buf,7)=0;
  2903. if(sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9] && sd->inventory_data[sd->equip_index[8]] &&
  2904. sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS) {
  2905. if(sd->inventory_data[sd->equip_index[8]]->view_id > 0)
  2906. WBUFW(buf,9)=sd->inventory_data[sd->equip_index[8]]->view_id;
  2907. else
  2908. WBUFW(buf,9)=sd->status.inventory[sd->equip_index[8]].nameid;
  2909. } else
  2910. WBUFW(buf,9)=0;
  2911. }
  2912. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2913. }
  2914. else if(sd && (type == LOOK_BASE) && (val > 255))
  2915. {
  2916. WBUFW(buf,0)=0x1d7;
  2917. WBUFL(buf,2)=bl->id;
  2918. WBUFB(buf,6)=type;
  2919. WBUFW(buf,7)=val;
  2920. WBUFW(buf,9)=0;
  2921. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2922. } else {
  2923. WBUFW(buf,0)=0xc3;
  2924. WBUFL(buf,2)=bl->id;
  2925. WBUFB(buf,6)=type;
  2926. WBUFB(buf,7)=val;
  2927. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2928. }
  2929. #endif
  2930. return 0;
  2931. }
  2932. /*==========================================
  2933. *
  2934. *------------------------------------------
  2935. */
  2936. int clif_initialstatus(struct map_session_data *sd)
  2937. {
  2938. int fd;
  2939. unsigned char *buf;
  2940. nullpo_retr(0, sd);
  2941. fd=sd->fd;
  2942. WFIFOHEAD(fd,packet_len_table[0xbd]);
  2943. buf=WFIFOP(fd,0);
  2944. WBUFW(buf,0)=0xbd;
  2945. WBUFW(buf,2)=sd->status.status_point;
  2946. WBUFB(buf,4)=(sd->status.str > 255)? 255:sd->status.str;
  2947. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2948. WBUFB(buf,6)=(sd->status.agi > 255)? 255:sd->status.agi;
  2949. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2950. WBUFB(buf,8)=(sd->status.vit > 255)? 255:sd->status.vit;
  2951. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2952. WBUFB(buf,10)=(sd->status.int_ > 255)? 255:sd->status.int_;
  2953. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2954. WBUFB(buf,12)=(sd->status.dex > 255)? 255:sd->status.dex;
  2955. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2956. WBUFB(buf,14)=(sd->status.luk > 255)? 255:sd->status.luk;
  2957. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2958. WBUFW(buf,16) = sd->base_atk + sd->right_weapon.watk + sd->left_weapon.watk;
  2959. WBUFW(buf,18) = sd->right_weapon.watk2 + sd->left_weapon.watk2; //atk bonus
  2960. WBUFW(buf,20) = sd->matk1;
  2961. WBUFW(buf,22) = sd->matk2;
  2962. WBUFW(buf,24) = sd->def; // def
  2963. WBUFW(buf,26) = sd->def2;
  2964. WBUFW(buf,28) = sd->mdef; // mdef
  2965. WBUFW(buf,30) = sd->mdef2;
  2966. WBUFW(buf,32) = sd->hit;
  2967. WBUFW(buf,34) = sd->flee;
  2968. WBUFW(buf,36) = sd->flee2/10;
  2969. WBUFW(buf,38) = sd->critical/10;
  2970. WBUFW(buf,40) = sd->status.karma;
  2971. WBUFW(buf,42) = sd->status.manner;
  2972. WFIFOSET(fd,packet_len_table[0xbd]);
  2973. clif_updatestatus(sd,SP_STR);
  2974. clif_updatestatus(sd,SP_AGI);
  2975. clif_updatestatus(sd,SP_VIT);
  2976. clif_updatestatus(sd,SP_INT);
  2977. clif_updatestatus(sd,SP_DEX);
  2978. clif_updatestatus(sd,SP_LUK);
  2979. clif_updatestatus(sd,SP_ATTACKRANGE);
  2980. clif_updatestatus(sd,SP_ASPD);
  2981. return 0;
  2982. }
  2983. /*==========================================
  2984. *矢装備
  2985. *------------------------------------------
  2986. */
  2987. int clif_arrowequip(struct map_session_data *sd,int val)
  2988. {
  2989. int fd;
  2990. nullpo_retr(0, sd);
  2991. if(sd->attacktarget && sd->attacktarget > 0) // [Valaris]
  2992. sd->attacktarget = 0;
  2993. fd=sd->fd;
  2994. WFIFOHEAD(fd, packet_len_table[0x013c]);
  2995. WFIFOW(fd,0)=0x013c;
  2996. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2997. WFIFOSET(fd,packet_len_table[0x013c]);
  2998. return 0;
  2999. }
  3000. /*==========================================
  3001. *
  3002. *------------------------------------------
  3003. */
  3004. int clif_arrow_fail(struct map_session_data *sd,int type)
  3005. {
  3006. int fd;
  3007. nullpo_retr(0, sd);
  3008. fd=sd->fd;
  3009. WFIFOHEAD(fd, packet_len_table[0x013b]);
  3010. WFIFOW(fd,0)=0x013b;
  3011. WFIFOW(fd,2)=type;
  3012. WFIFOSET(fd,packet_len_table[0x013b]);
  3013. return 0;
  3014. }
  3015. /*==========================================
  3016. * 作成可能 矢リスト送信
  3017. *------------------------------------------
  3018. */
  3019. int clif_arrow_create_list(struct map_session_data *sd)
  3020. {
  3021. int i, c, j;
  3022. int fd;
  3023. nullpo_retr(0, sd);
  3024. fd = sd->fd;
  3025. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3026. WFIFOW(fd,0) = 0x1ad;
  3027. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3028. if (skill_arrow_db[i].nameid > 0 &&
  3029. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  3030. !sd->status.inventory[j].equip)
  3031. {
  3032. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  3033. WFIFOW(fd,c*2+4) = j;
  3034. else
  3035. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  3036. c++;
  3037. }
  3038. }
  3039. WFIFOW(fd,2) = c*2+4;
  3040. WFIFOSET(fd, WFIFOW(fd,2));
  3041. if (c > 0) {
  3042. sd->menuskill_id = AC_MAKINGARROW;
  3043. sd->menuskill_lv = c;
  3044. }
  3045. return 0;
  3046. }
  3047. /*==========================================
  3048. *
  3049. *------------------------------------------
  3050. */
  3051. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  3052. {
  3053. int fd;
  3054. nullpo_retr(0, sd);
  3055. fd=sd->fd;
  3056. WFIFOHEAD(fd,packet_len_table[0xbc]);
  3057. WFIFOW(fd,0)=0xbc;
  3058. WFIFOW(fd,2)=type;
  3059. WFIFOB(fd,4)=ok;
  3060. WFIFOB(fd,5)=val;
  3061. WFIFOSET(fd,packet_len_table[0xbc]);
  3062. return 0;
  3063. }
  3064. /*==========================================
  3065. *
  3066. *------------------------------------------
  3067. */
  3068. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3069. {
  3070. int fd;
  3071. nullpo_retr(0, sd);
  3072. fd=sd->fd;
  3073. WFIFOHEAD(fd,packet_len_table[0xaa]);
  3074. WFIFOW(fd,0)=0xaa;
  3075. WFIFOW(fd,2)=n+2;
  3076. WFIFOW(fd,4)=pos;
  3077. WFIFOB(fd,6)=ok;
  3078. WFIFOSET(fd,packet_len_table[0xaa]);
  3079. return 0;
  3080. }
  3081. /*==========================================
  3082. *
  3083. *------------------------------------------
  3084. */
  3085. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3086. {
  3087. int fd;
  3088. nullpo_retr(0, sd);
  3089. fd=sd->fd;
  3090. WFIFOHEAD(fd,packet_len_table[0xac]);
  3091. WFIFOW(fd,0)=0xac;
  3092. WFIFOW(fd,2)=n+2;
  3093. WFIFOW(fd,4)=pos;
  3094. WFIFOB(fd,6)=ok;
  3095. WFIFOSET(fd,packet_len_table[0xac]);
  3096. return 0;
  3097. }
  3098. /*==========================================
  3099. *
  3100. *------------------------------------------
  3101. */
  3102. int clif_misceffect(struct block_list* bl,int type)
  3103. {
  3104. unsigned char buf[32];
  3105. nullpo_retr(0, bl);
  3106. WBUFW(buf,0) = 0x19b;
  3107. WBUFL(buf,2) = bl->id;
  3108. WBUFL(buf,6) = type;
  3109. clif_send(buf,packet_len_table[0x19b],bl,AREA);
  3110. return 0;
  3111. }
  3112. int clif_misceffect2(struct block_list *bl, int type) {
  3113. unsigned char buf[24];
  3114. nullpo_retr(0, bl);
  3115. memset(buf, 0, packet_len_table[0x1f3]);
  3116. WBUFW(buf,0) = 0x1f3;
  3117. WBUFL(buf,2) = bl->id;
  3118. WBUFL(buf,6) = type;
  3119. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  3120. return 0;
  3121. }
  3122. /*==========================================
  3123. * 表示オプション変更
  3124. *------------------------------------------
  3125. */
  3126. int clif_changeoption(struct block_list* bl)
  3127. {
  3128. unsigned char buf[32];
  3129. struct status_change *sc;
  3130. nullpo_retr(0, bl);
  3131. sc = status_get_sc(bl);
  3132. WBUFW(buf,0) = 0x119;
  3133. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise) {
  3134. WBUFL(buf,2) = bl->id;
  3135. WBUFW(buf,6) = 0;
  3136. WBUFW(buf,8) = 0;
  3137. WBUFW(buf,10) = OPTION_INVISIBLE;
  3138. WBUFB(buf,12) = 0;
  3139. clif_send(buf,packet_len_table[0x119],bl,AREA);
  3140. WBUFL(buf,2) = -bl->id;
  3141. WBUFW(buf,6) = 0;
  3142. WBUFW(buf,8) = 0;
  3143. WBUFW(buf,10) = sc?sc->option:0;
  3144. WBUFB(buf,12) = 0;
  3145. clif_send(buf,packet_len_table[0x119],bl,AREA);
  3146. } else {
  3147. WBUFL(buf,2) = bl->id;
  3148. WBUFW(buf,6) = sc?sc->opt1:0;
  3149. WBUFW(buf,8) = sc?sc->opt2:0;
  3150. WBUFW(buf,10) = sc?sc->option:0;
  3151. WBUFB(buf,12) = 0; // ??
  3152. clif_send(buf,packet_len_table[0x119],bl,AREA);
  3153. }
  3154. return 0;
  3155. }
  3156. /*==========================================
  3157. *
  3158. *------------------------------------------
  3159. */
  3160. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  3161. {
  3162. nullpo_retr(0, sd);
  3163. if(!ok) {
  3164. int fd=sd->fd;
  3165. WFIFOHEAD(fd,packet_len_table[0xa8]);
  3166. WFIFOW(fd,0)=0xa8;
  3167. WFIFOW(fd,2)=index+2;
  3168. WFIFOW(fd,4)=amount;
  3169. WFIFOB(fd,6)=ok;
  3170. WFIFOSET(fd,packet_len_table[0xa8]);
  3171. }
  3172. else {
  3173. #if PACKETVER < 3
  3174. int fd=sd->fd;
  3175. WFIFOHEAD(fd,packet_len_table[0xa8]);
  3176. WFIFOW(fd,0)=0xa8;
  3177. WFIFOW(fd,2)=index+2;
  3178. WFIFOW(fd,4)=amount;
  3179. WFIFOB(fd,6)=ok;
  3180. WFIFOSET(fd,packet_len_table[0xa8]);
  3181. #else
  3182. unsigned char buf[32];
  3183. WBUFW(buf,0)=0x1c8;
  3184. WBUFW(buf,2)=index+2;
  3185. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3186. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3187. else
  3188. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3189. WBUFL(buf,6)=sd->bl.id;
  3190. WBUFW(buf,10)=amount;
  3191. WBUFB(buf,12)=ok;
  3192. clif_send(buf,packet_len_table[0x1c8],&sd->bl,AREA);
  3193. #endif
  3194. }
  3195. return 0;
  3196. }
  3197. /*==========================================
  3198. *
  3199. *------------------------------------------
  3200. */
  3201. int clif_createchat(struct map_session_data *sd,int fail)
  3202. {
  3203. int fd;
  3204. nullpo_retr(0, sd);
  3205. fd=sd->fd;
  3206. WFIFOHEAD(fd,packet_len_table[0xd6]);
  3207. WFIFOW(fd,0)=0xd6;
  3208. WFIFOB(fd,2)=fail;
  3209. WFIFOSET(fd,packet_len_table[0xd6]);
  3210. return 0;
  3211. }
  3212. /*==========================================
  3213. *
  3214. *------------------------------------------
  3215. */
  3216. int clif_dispchat(struct chat_data *cd,int fd)
  3217. {
  3218. unsigned char buf[128]; // 最大title(60バイト)+17
  3219. if(cd==NULL || *cd->owner==NULL)
  3220. return 1;
  3221. WBUFW(buf,0)=0xd7;
  3222. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  3223. WBUFL(buf,4)=(*cd->owner)->id;
  3224. WBUFL(buf,8)=cd->bl.id;
  3225. WBUFW(buf,12)=cd->limit;
  3226. WBUFW(buf,14)=cd->users;
  3227. WBUFB(buf,16)=cd->pub;
  3228. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  3229. if(fd){
  3230. WFIFOHEAD(fd, WBUFW(buf,2));
  3231. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3232. WFIFOSET(fd,WBUFW(buf,2));
  3233. } else {
  3234. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  3235. }
  3236. return 0;
  3237. }
  3238. /*==========================================
  3239. * chatの状態変更成功
  3240. * 外部の人用と命令コード(d7->df)が違うだけ
  3241. *------------------------------------------
  3242. */
  3243. int clif_changechatstatus(struct chat_data *cd)
  3244. {
  3245. unsigned char buf[128]; // 最大title(60バイト)+17
  3246. if(cd==NULL || cd->usersd[0]==NULL)
  3247. return 1;
  3248. WBUFW(buf,0)=0xdf;
  3249. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  3250. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  3251. WBUFL(buf,8)=cd->bl.id;
  3252. WBUFW(buf,12)=cd->limit;
  3253. WBUFW(buf,14)=cd->users;
  3254. WBUFB(buf,16)=cd->pub;
  3255. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  3256. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  3257. return 0;
  3258. }
  3259. /*==========================================
  3260. *
  3261. *------------------------------------------
  3262. */
  3263. int clif_clearchat(struct chat_data *cd,int fd)
  3264. {
  3265. unsigned char buf[32];
  3266. nullpo_retr(0, cd);
  3267. WBUFW(buf,0)=0xd8;
  3268. WBUFL(buf,2)=cd->bl.id;
  3269. if(fd){
  3270. WFIFOHEAD(fd,packet_len_table[0xd8]);
  3271. memcpy(WFIFOP(fd,0),buf,packet_len_table[0xd8]);
  3272. WFIFOSET(fd,packet_len_table[0xd8]);
  3273. } else {
  3274. clif_send(buf,packet_len_table[0xd8],*cd->owner,AREA_WOSC);
  3275. }
  3276. return 0;
  3277. }
  3278. /*==========================================
  3279. *
  3280. *------------------------------------------
  3281. */
  3282. int clif_joinchatfail(struct map_session_data *sd,int fail)
  3283. {
  3284. int fd;
  3285. nullpo_retr(0, sd);
  3286. fd=sd->fd;
  3287. WFIFOHEAD(fd,packet_len_table[0xda]);
  3288. WFIFOW(fd,0)=0xda;
  3289. WFIFOB(fd,2)=fail;
  3290. WFIFOSET(fd,packet_len_table[0xda]);
  3291. return 0;
  3292. }
  3293. /*==========================================
  3294. *
  3295. *------------------------------------------
  3296. */
  3297. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3298. {
  3299. int fd;
  3300. int i;
  3301. nullpo_retr(0, sd);
  3302. nullpo_retr(0, cd);
  3303. fd = sd->fd;
  3304. if (!session_isActive(fd))
  3305. return 0;
  3306. WFIFOHEAD(fd, 8 + (28*cd->users));
  3307. WFIFOW(fd, 0) = 0xdb;
  3308. WFIFOW(fd, 2) = 8 + (28*cd->users);
  3309. WFIFOL(fd, 4) = cd->bl.id;
  3310. for (i = 0; i < cd->users; i++) {
  3311. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  3312. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3313. }
  3314. WFIFOSET(fd, WFIFOW(fd, 2));
  3315. return 0;
  3316. }
  3317. /*==========================================
  3318. *
  3319. *------------------------------------------
  3320. */
  3321. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3322. {
  3323. unsigned char buf[32];
  3324. nullpo_retr(0, sd);
  3325. nullpo_retr(0, cd);
  3326. WBUFW(buf, 0) = 0x0dc;
  3327. WBUFW(buf, 2) = cd->users;
  3328. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3329. clif_send(buf,packet_len_table[0xdc],&sd->bl,CHAT_WOS);
  3330. return 0;
  3331. }
  3332. /*==========================================
  3333. *
  3334. *------------------------------------------
  3335. */
  3336. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  3337. {
  3338. unsigned char buf[64];
  3339. nullpo_retr(0, sd);
  3340. nullpo_retr(0, cd);
  3341. WBUFW(buf, 0) = 0xe1;
  3342. WBUFL(buf, 2) = 1;
  3343. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3344. WBUFW(buf,30) = 0xe1;
  3345. WBUFL(buf,32) = 0;
  3346. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3347. clif_send(buf,packet_len_table[0xe1]*2,&sd->bl,CHAT);
  3348. return 0;
  3349. }
  3350. /*==========================================
  3351. *
  3352. *------------------------------------------
  3353. */
  3354. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  3355. {
  3356. unsigned char buf[32];
  3357. nullpo_retr(0, sd);
  3358. nullpo_retr(0, cd);
  3359. WBUFW(buf, 0) = 0xdd;
  3360. WBUFW(buf, 2) = cd->users-1;
  3361. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3362. WBUFB(buf,28) = 0;
  3363. clif_send(buf,packet_len_table[0xdd],&sd->bl,CHAT);
  3364. return 0;
  3365. }
  3366. /*==========================================
  3367. * 取り引き要請受け
  3368. *------------------------------------------
  3369. */
  3370. int clif_traderequest(struct map_session_data *sd,char *name)
  3371. {
  3372. int fd;
  3373. nullpo_retr(0, sd);
  3374. fd=sd->fd;
  3375. WFIFOHEAD(fd,packet_len_table[0xe5]);
  3376. WFIFOW(fd,0)=0xe5;
  3377. strcpy((char*)WFIFOP(fd,2),name);
  3378. WFIFOSET(fd,packet_len_table[0xe5]);
  3379. return 0;
  3380. }
  3381. /*==========================================
  3382. * 取り引き要求応答
  3383. *------------------------------------------
  3384. */
  3385. int clif_tradestart(struct map_session_data *sd,int type)
  3386. {
  3387. int fd;
  3388. nullpo_retr(0, sd);
  3389. fd=sd->fd;
  3390. WFIFOHEAD(fd,packet_len_table[0xe7]);
  3391. WFIFOW(fd,0)=0xe7;
  3392. WFIFOB(fd,2)=type;
  3393. WFIFOSET(fd,packet_len_table[0xe7]);
  3394. return 0;
  3395. }
  3396. /*==========================================
  3397. * 相手方からのアイテム追加
  3398. *------------------------------------------
  3399. */
  3400. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  3401. {
  3402. int fd;
  3403. nullpo_retr(0, sd);
  3404. nullpo_retr(0, tsd);
  3405. fd=tsd->fd;
  3406. WFIFOHEAD(fd,packet_len_table[0xe9]);
  3407. WFIFOW(fd,0)=0xe9;
  3408. WFIFOL(fd,2)=amount;
  3409. if(index==0){
  3410. WFIFOW(fd,6) = 0; // type id
  3411. WFIFOB(fd,8) = 0; //identify flag
  3412. WFIFOB(fd,9) = 0; // attribute
  3413. WFIFOB(fd,10)= 0; //refine
  3414. WFIFOW(fd,11)= 0; //card (4w)
  3415. WFIFOW(fd,13)= 0; //card (4w)
  3416. WFIFOW(fd,15)= 0; //card (4w)
  3417. WFIFOW(fd,17)= 0; //card (4w)
  3418. }
  3419. else{
  3420. index-=2; //index fix
  3421. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3422. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3423. else
  3424. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3425. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3426. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3427. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3428. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3429. }
  3430. WFIFOSET(fd,packet_len_table[0xe9]);
  3431. return 0;
  3432. }
  3433. /*==========================================
  3434. * アイテム追加成功/失敗
  3435. *------------------------------------------
  3436. */
  3437. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3438. {
  3439. int fd;
  3440. nullpo_retr(0, sd);
  3441. fd=sd->fd;
  3442. WFIFOHEAD(fd,packet_len_table[0xea]);
  3443. WFIFOW(fd,0)=0xea;
  3444. WFIFOW(fd,2)=index;
  3445. WFIFOB(fd,4)=fail;
  3446. WFIFOSET(fd,packet_len_table[0xea]);
  3447. return 0;
  3448. }
  3449. /*==========================================
  3450. * 取り引きok押し
  3451. *------------------------------------------
  3452. */
  3453. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3454. {
  3455. int fd;
  3456. nullpo_retr(0, sd);
  3457. fd=sd->fd;
  3458. WFIFOHEAD(fd,packet_len_table[0xec]);
  3459. WFIFOW(fd,0)=0xec;
  3460. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3461. WFIFOSET(fd,packet_len_table[0xec]);
  3462. return 0;
  3463. }
  3464. /*==========================================
  3465. * 取り引きがキャンセルされました
  3466. *------------------------------------------
  3467. */
  3468. int clif_tradecancelled(struct map_session_data *sd)
  3469. {
  3470. int fd;
  3471. nullpo_retr(0, sd);
  3472. fd=sd->fd;
  3473. WFIFOHEAD(fd,packet_len_table[0xee]);
  3474. WFIFOW(fd,0)=0xee;
  3475. WFIFOSET(fd,packet_len_table[0xee]);
  3476. return 0;
  3477. }
  3478. /*==========================================
  3479. * 取り引き完了
  3480. *------------------------------------------
  3481. */
  3482. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3483. {
  3484. int fd;
  3485. nullpo_retr(0, sd);
  3486. fd=sd->fd;
  3487. WFIFOHEAD(fd,packet_len_table[0xf0]);
  3488. WFIFOW(fd,0)=0xf0;
  3489. WFIFOB(fd,2)=fail;
  3490. WFIFOSET(fd,packet_len_table[0xf0]);
  3491. return 0;
  3492. }
  3493. /*==========================================
  3494. * カプラ倉庫のアイテム数を更新
  3495. *------------------------------------------
  3496. */
  3497. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3498. {
  3499. int fd;
  3500. nullpo_retr(0, sd);
  3501. nullpo_retr(0, stor);
  3502. fd=sd->fd;
  3503. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3504. WFIFOW(fd,0) = 0xf2; // update storage amount
  3505. WFIFOW(fd,2) = stor->storage_amount; //items
  3506. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3507. WFIFOSET(fd,packet_len_table[0xf2]);
  3508. return 0;
  3509. }
  3510. /*==========================================
  3511. * カプラ倉庫にアイテムを追加する
  3512. *------------------------------------------
  3513. */
  3514. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3515. {
  3516. int view,fd;
  3517. nullpo_retr(0, sd);
  3518. nullpo_retr(0, stor);
  3519. fd=sd->fd;
  3520. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3521. WFIFOW(fd,0) =0xf4; // Storage item added
  3522. WFIFOW(fd,2) =index+1; // index
  3523. WFIFOL(fd,4) =amount; // amount
  3524. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3525. WFIFOW(fd,8) =view;
  3526. else
  3527. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3528. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3529. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3530. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3531. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3532. WFIFOSET(fd,packet_len_table[0xf4]);
  3533. return 0;
  3534. }
  3535. /*==========================================
  3536. *
  3537. *------------------------------------------
  3538. */
  3539. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3540. {
  3541. int fd;
  3542. nullpo_retr(0, sd);
  3543. nullpo_retr(0, stor);
  3544. fd=sd->fd;
  3545. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3546. WFIFOW(fd,0) = 0xf2; // update storage amount
  3547. WFIFOW(fd,2) = stor->storage_amount; //items
  3548. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3549. WFIFOSET(fd,packet_len_table[0xf2]);
  3550. return 0;
  3551. }
  3552. /*==========================================
  3553. *
  3554. *------------------------------------------
  3555. */
  3556. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3557. {
  3558. int view,fd;
  3559. nullpo_retr(0, sd);
  3560. nullpo_retr(0, stor);
  3561. fd=sd->fd;
  3562. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3563. WFIFOW(fd,0) =0xf4; // Storage item added
  3564. WFIFOW(fd,2) =index+1; // index
  3565. WFIFOL(fd,4) =amount; // amount
  3566. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3567. WFIFOW(fd,8) =view;
  3568. else
  3569. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3570. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3571. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3572. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3573. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3574. WFIFOSET(fd,packet_len_table[0xf4]);
  3575. return 0;
  3576. }
  3577. /*==========================================
  3578. * カプラ倉庫からアイテムを取り去る
  3579. *------------------------------------------
  3580. */
  3581. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3582. {
  3583. int fd;
  3584. nullpo_retr(0, sd);
  3585. fd=sd->fd;
  3586. WFIFOHEAD(fd,packet_len_table[0xf6]);
  3587. WFIFOW(fd,0)=0xf6; // Storage item removed
  3588. WFIFOW(fd,2)=index+1;
  3589. WFIFOL(fd,4)=amount;
  3590. WFIFOSET(fd,packet_len_table[0xf6]);
  3591. return 0;
  3592. }
  3593. /*==========================================
  3594. * カプラ倉庫を閉じる
  3595. *------------------------------------------
  3596. */
  3597. int clif_storageclose(struct map_session_data *sd)
  3598. {
  3599. int fd;
  3600. nullpo_retr(0, sd);
  3601. fd=sd->fd;
  3602. WFIFOHEAD(fd,packet_len_table[0xf8]);
  3603. WFIFOW(fd,0)=0xf8; // Storage Closed
  3604. WFIFOSET(fd,packet_len_table[0xf8]);
  3605. return 0;
  3606. }
  3607. //
  3608. // callback系 ?
  3609. //
  3610. /*==========================================
  3611. * PC表示
  3612. *------------------------------------------
  3613. */
  3614. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3615. {
  3616. int len;
  3617. nullpo_retv(sd);
  3618. nullpo_retv(dstsd);
  3619. if(dstsd->walktimer != -1){
  3620. #if PACKETVER < 4
  3621. WFIFOHEAD(sd->fd, packet_len_table[0x7b]);
  3622. #else
  3623. WFIFOHEAD(sd->fd, packet_len_table[0x1da]);
  3624. #endif
  3625. len = clif_set007b(dstsd,WFIFOP(sd->fd,0));
  3626. WFIFOSET(sd->fd,len);
  3627. if(dstsd->disguise) {
  3628. WFIFOHEAD(sd->fd,packet_len_table[0x7b]);
  3629. len = clif_dis007b(dstsd,WFIFOP(sd->fd,0));
  3630. WFIFOSET(sd->fd,len);
  3631. }
  3632. } else {
  3633. #if PACKETVER < 4
  3634. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3635. #else
  3636. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3637. #endif
  3638. len = clif_set0078(dstsd,WFIFOP(sd->fd,0));
  3639. WFIFOSET(sd->fd,len);
  3640. if(dstsd->disguise) {
  3641. WFIFOHEAD(sd->fd,packet_len_table[0x7b]);
  3642. len = clif_dis0078(dstsd,WFIFOP(sd->fd,0));
  3643. WFIFOSET(sd->fd,len);
  3644. }
  3645. }
  3646. if(dstsd->chatID){
  3647. struct chat_data *cd;
  3648. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3649. if(cd->usersd[0]==dstsd)
  3650. clif_dispchat(cd,sd->fd);
  3651. }
  3652. if(dstsd->vender_id){
  3653. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3654. }
  3655. if(dstsd->spiritball > 0) {
  3656. WFIFOHEAD(sd->fd, packet_len_table[0x1e1]);
  3657. clif_set01e1(dstsd,WFIFOP(sd->fd,0));
  3658. WFIFOSET(sd->fd,packet_len_table[0x1e1]);
  3659. }
  3660. if(battle_config.save_clothcolor && dstsd->status.clothes_color > 0 && ((dstsd->view_class != JOB_WEDDING && dstsd->view_class !=JOB_XMAS) ||
  3661. (dstsd->view_class==JOB_WEDDING && !battle_config.wedding_ignorepalette) || (dstsd->view_class==JOB_XMAS && !battle_config.xmas_ignorepalette)))
  3662. clif_changelook(&dstsd->bl, LOOK_CLOTHES_COLOR, dstsd->status.clothes_color);
  3663. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3664. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3665. )
  3666. clif_hpmeter_single(sd->fd, dstsd);
  3667. if(sd->status.manner < 0 && battle_config.manner_system)
  3668. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  3669. if(sd->state.size==2) // tiny/big players [Valaris]
  3670. clif_specialeffect(&sd->bl,423,0);
  3671. else if(sd->state.size==1)
  3672. clif_specialeffect(&sd->bl,421,0);
  3673. // pvp circle for duel [LuzZza]
  3674. /*
  3675. if(dstsd->duel_group)
  3676. clif_specialeffect(&dstsd->bl, 159, 4);
  3677. */
  3678. }
  3679. /*==========================================
  3680. * NPC表示
  3681. *------------------------------------------
  3682. */
  3683. //fixed by Valaris
  3684. void clif_getareachar_npc(struct map_session_data* sd,struct npc_data* nd)
  3685. {
  3686. int len;
  3687. nullpo_retv(sd);
  3688. nullpo_retv(nd);
  3689. if(nd->class_ < 0 || nd->flag&1 || nd->class_ == INVISIBLE_CLASS)
  3690. return;
  3691. if(nd->state.state == MS_WALK){
  3692. WFIFOHEAD(sd->fd, packet_len_table[0x7b]);
  3693. len = clif_npc007b(nd,WFIFOP(sd->fd,0));
  3694. WFIFOSET(sd->fd,len);
  3695. } else {
  3696. WFIFOHEAD(sd->fd, packet_len_table[0x78]);
  3697. len = clif_npc0078(nd,WFIFOP(sd->fd,0));
  3698. WFIFOSET(sd->fd,len);
  3699. }
  3700. if(nd->chat_id){
  3701. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3702. }
  3703. }
  3704. /*==========================================
  3705. * 移動停止
  3706. *------------------------------------------
  3707. */
  3708. int clif_movemob(struct mob_data *md)
  3709. {
  3710. unsigned char buf[256];
  3711. int len;
  3712. nullpo_retr(0, md);
  3713. len = clif_mob007b(md,buf);
  3714. clif_send(buf,len,&md->bl,AREA);
  3715. if(battle_config.save_clothcolor && pcdb_checkid(mob_get_viewclass(md->class_)) && mob_get_clothes_color(md->class_)) // [Valaris]
  3716. clif_changelook(&md->bl, LOOK_CLOTHES_COLOR, mob_get_clothes_color(md->class_));
  3717. if(mob_get_equip(md->class_) > 0) // mob equipment [Valaris]
  3718. clif_mob_equip(md,mob_get_equip(md->class_));
  3719. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3720. clif_specialeffect(&md->bl,423,0);
  3721. else if(md->special_state.size==1)
  3722. clif_specialeffect(&md->bl,421,0);
  3723. return 0;
  3724. }
  3725. /*==========================================
  3726. * モンスターの位置修正
  3727. *------------------------------------------
  3728. */
  3729. int clif_fixmobpos(struct mob_data *md)
  3730. {
  3731. unsigned char buf[256];
  3732. int len;
  3733. nullpo_retr(0, md);
  3734. if(md->state.state == MS_WALK){
  3735. len = clif_mob007b(md,buf);
  3736. clif_send(buf,len,&md->bl,AREA);
  3737. } else {
  3738. len = clif_mob0078(md,buf);
  3739. clif_send(buf,len,&md->bl,AREA);
  3740. }
  3741. return 0;
  3742. }
  3743. /*==========================================
  3744. * PCの位置修正
  3745. *------------------------------------------
  3746. */
  3747. int clif_fixpcpos(struct map_session_data *sd)
  3748. {
  3749. unsigned char buf[256];
  3750. int len;
  3751. nullpo_retr(0, sd);
  3752. if(sd->walktimer != -1){
  3753. len = clif_set007b(sd,buf);
  3754. clif_send(buf,len,&sd->bl,AREA);
  3755. } else {
  3756. len = clif_set0078(sd,buf);
  3757. clif_send(buf,len,&sd->bl,AREA);
  3758. }
  3759. return 0;
  3760. }
  3761. /*==========================================
  3762. *
  3763. *------------------------------------------
  3764. */
  3765. int clif_fixpetpos(struct pet_data *pd)
  3766. {
  3767. unsigned char buf[256];
  3768. int len;
  3769. nullpo_retr(0, pd);
  3770. if(pd->state.state == MS_WALK){
  3771. len = clif_pet007b(pd,buf);
  3772. clif_send(buf,len,&pd->bl,AREA);
  3773. } else {
  3774. len = clif_pet0078(pd,buf);
  3775. clif_send(buf,len,&pd->bl,AREA);
  3776. }
  3777. return 0;
  3778. }
  3779. // npc walking [Valaris]
  3780. int clif_fixnpcpos(struct npc_data *nd)
  3781. {
  3782. unsigned char buf[256];
  3783. int len;
  3784. nullpo_retr(0, nd);
  3785. if(nd->state.state == MS_WALK){
  3786. len = clif_npc007b(nd,buf);
  3787. clif_send(buf,len,&nd->bl,AREA);
  3788. } else {
  3789. len = clif_npc0078(nd,buf);
  3790. clif_send(buf,len,&nd->bl,AREA);
  3791. }
  3792. return 0;
  3793. }
  3794. /*==========================================
  3795. * Modifies the type of damage according to status changes [Skotlex]
  3796. *------------------------------------------
  3797. */
  3798. static int clif_calc_delay(struct block_list *dst, int type, int delay)
  3799. {
  3800. if (type == 1 || type == 4 || type == 0x0a) //Type 1 is the crouching animation, type 4 are non-flinching attacks, 0x0a - crits.
  3801. return type;
  3802. if (delay == 0)
  3803. return 9; //Endure type attack (damage delay is 0)
  3804. return type;
  3805. }
  3806. /*==========================================
  3807. * 通常攻撃エフェクト&ダメージ
  3808. *------------------------------------------
  3809. */
  3810. 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)
  3811. {
  3812. unsigned char buf[256];
  3813. struct status_change *sc;
  3814. nullpo_retr(0, src);
  3815. nullpo_retr(0, dst);
  3816. type = clif_calc_delay(dst, type, ddelay); //Type defaults to 0 for normal attacks.
  3817. sc = status_get_sc(dst);
  3818. if(sc && sc->count) {
  3819. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3820. if(damage > 0)
  3821. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3822. if(damage2 > 0)
  3823. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3824. }
  3825. }
  3826. WBUFW(buf,0)=0x8a;
  3827. if(src->type==BL_PC && ((struct map_session_data *)src)->disguise)
  3828. WBUFL(buf,2)=-src->id;
  3829. else
  3830. WBUFL(buf,2)=src->id;
  3831. if(dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)
  3832. WBUFL(buf,6)=-dst->id;
  3833. else
  3834. WBUFL(buf,6)=dst->id;
  3835. WBUFL(buf,10)=tick;
  3836. WBUFL(buf,14)=sdelay;
  3837. WBUFL(buf,18)=ddelay;
  3838. WBUFW(buf,22)=(damage > 0x7fff)? 0x7fff:damage;
  3839. WBUFW(buf,24)=div;
  3840. WBUFB(buf,26)=type;
  3841. WBUFW(buf,27)=damage2;
  3842. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3843. if((src->type==BL_PC && ((struct map_session_data *)src)->disguise) || (dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)) {
  3844. memset(buf,0,packet_len_table[0x8a]);
  3845. WBUFW(buf,0)=0x8a;
  3846. if(src->type==BL_PC && ((struct map_session_data *)src)->disguise)
  3847. WBUFL(buf,2)=src->id;
  3848. else
  3849. WBUFL(buf,2)=-src->id;
  3850. if(dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)
  3851. WBUFL(buf,6)=dst->id;
  3852. else
  3853. WBUFL(buf,2)=-dst->id;
  3854. WBUFL(buf,10)=tick;
  3855. WBUFL(buf,14)=sdelay;
  3856. WBUFL(buf,18)=ddelay;
  3857. if(damage > 0)
  3858. WBUFW(buf,22)=-1;
  3859. else
  3860. WBUFW(buf,22)=0;
  3861. WBUFW(buf,24)=div;
  3862. WBUFB(buf,26)=type;
  3863. WBUFW(buf,27)=0;
  3864. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3865. }
  3866. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3867. if (type != 4 && type != 9 && damage+damage2 > 0) //Non-endure/Non-flinch attack, update walk delay.
  3868. battle_walkdelay(dst, tick, sdelay, ddelay, div);
  3869. // [Valaris]
  3870. if(battle_config.save_clothcolor && src->type==BL_MOB &&
  3871. pcdb_checkid(mob_get_viewclass(((struct mob_data *)src)->class_)) && mob_get_clothes_color(((struct mob_data *)src)->class_) > 0)
  3872. clif_changelook(src, LOOK_CLOTHES_COLOR, mob_get_clothes_color(((struct mob_data *)src)->class_));
  3873. return 0;
  3874. }
  3875. /*==========================================
  3876. *
  3877. *------------------------------------------
  3878. */
  3879. void clif_getareachar_mob(struct map_session_data* sd,struct mob_data* md)
  3880. {
  3881. int len;
  3882. nullpo_retv(sd);
  3883. nullpo_retv(md);
  3884. if (session[sd->fd] == NULL)
  3885. return;
  3886. if(md->state.state == MS_WALK){
  3887. #if PACKETVER < 4
  3888. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3889. #else
  3890. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3891. #endif
  3892. len = clif_mob007b(md,WFIFOP(sd->fd,0));
  3893. WFIFOSET(sd->fd,len);
  3894. } else {
  3895. #if PACKETVER < 4
  3896. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3897. #else
  3898. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3899. #endif
  3900. len = clif_mob0078(md,WFIFOP(sd->fd,0));
  3901. WFIFOSET(sd->fd,len);
  3902. }
  3903. if(battle_config.save_clothcolor && pcdb_checkid(mob_get_viewclass(md->class_)) && mob_get_clothes_color(md->class_)) // [Valaris]
  3904. clif_changelook(&md->bl, LOOK_CLOTHES_COLOR, mob_get_clothes_color(md->class_));
  3905. if(mob_get_equip(md->class_) > 0) // mob equipment [Valaris]
  3906. clif_mob_equip(md,mob_get_equip(md->class_));
  3907. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3908. clif_specialeffect(&md->bl,423,0);
  3909. else if(md->special_state.size==1)
  3910. clif_specialeffect(&md->bl,421,0);
  3911. }
  3912. /*==========================================
  3913. *
  3914. *------------------------------------------
  3915. */
  3916. void clif_getareachar_pet(struct map_session_data* sd,struct pet_data* pd)
  3917. {
  3918. int len;
  3919. nullpo_retv(sd);
  3920. nullpo_retv(pd);
  3921. if(pd->state.state == MS_WALK){
  3922. #if PACKETVER < 4
  3923. WFIFOHEAD(sd->fd,packet_len_table[0x7b]);
  3924. #else
  3925. WFIFOHEAD(sd->fd,packet_len_table[0x1da]);
  3926. #endif
  3927. len = clif_pet007b(pd,WFIFOP(sd->fd,0));
  3928. WFIFOSET(sd->fd,len);
  3929. } else {
  3930. #if PACKETVER < 4
  3931. WFIFOHEAD(sd->fd,packet_len_table[0x7b]);
  3932. #else
  3933. WFIFOHEAD(sd->fd,packet_len_table[0x1da]);
  3934. #endif
  3935. len = clif_pet0078(pd,WFIFOP(sd->fd,0));
  3936. WFIFOSET(sd->fd,len);
  3937. }
  3938. }
  3939. /*==========================================
  3940. *
  3941. *------------------------------------------
  3942. */
  3943. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3944. {
  3945. int view,fd;
  3946. nullpo_retv(sd);
  3947. nullpo_retv(fitem);
  3948. fd=sd->fd;
  3949. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3950. WFIFOHEAD(fd,packet_len_table[0x9d]);
  3951. WFIFOW(fd,0)=0x9d;
  3952. WFIFOL(fd,2)=fitem->bl.id;
  3953. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3954. WFIFOW(fd,6)=view;
  3955. else
  3956. WFIFOW(fd,6)=fitem->item_data.nameid;
  3957. WFIFOB(fd,8)=fitem->item_data.identify;
  3958. WFIFOW(fd,9)=fitem->bl.x;
  3959. WFIFOW(fd,11)=fitem->bl.y;
  3960. WFIFOW(fd,13)=fitem->item_data.amount;
  3961. WFIFOB(fd,15)=fitem->subx;
  3962. WFIFOB(fd,16)=fitem->suby;
  3963. WFIFOSET(fd,packet_len_table[0x9d]);
  3964. }
  3965. /*==========================================
  3966. * 場所スキルエフェクトが視界に入る
  3967. *------------------------------------------
  3968. */
  3969. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3970. {
  3971. int fd;
  3972. struct block_list *bl;
  3973. nullpo_retr(0, unit);
  3974. fd=sd->fd;
  3975. bl=map_id2bl(unit->group->src_id);
  3976. #if PACKETVER < 3
  3977. WFIFOHEAD(fd,packet_len_table[0x11f]);
  3978. memset(WFIFOP(fd,0),0,packet_len_table[0x11f]);
  3979. WFIFOW(fd, 0)=0x11f;
  3980. WFIFOL(fd, 2)=unit->bl.id;
  3981. WFIFOL(fd, 6)=unit->group->src_id;
  3982. WFIFOW(fd,10)=unit->bl.x;
  3983. WFIFOW(fd,12)=unit->bl.y;
  3984. WFIFOB(fd,14)=unit->group->unit_id;
  3985. WFIFOB(fd,15)=0;
  3986. WFIFOSET(fd,packet_len_table[0x11f]);
  3987. #else
  3988. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3989. memset(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3990. WFIFOW(fd, 0)=0x1c9;
  3991. WFIFOL(fd, 2)=unit->bl.id;
  3992. WFIFOL(fd, 6)=unit->group->src_id;
  3993. WFIFOW(fd,10)=unit->bl.x;
  3994. WFIFOW(fd,12)=unit->bl.y;
  3995. WFIFOB(fd,14)=unit->group->unit_id;
  3996. WFIFOB(fd,15)=1;
  3997. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  3998. WFIFOB(fd,16)=1;
  3999. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  4000. } else {
  4001. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  4002. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  4003. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4004. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4005. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  4006. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  4007. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  4008. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  4009. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  4010. //37-39
  4011. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  4012. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  4013. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  4014. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  4015. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  4016. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  4017. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  4018. //65-68
  4019. //69-72
  4020. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  4021. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4022. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  4023. }
  4024. WFIFOSET(fd,packet_len_table[0x1c9]);
  4025. #endif
  4026. if(unit->group->skill_id == WZ_ICEWALL)
  4027. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  4028. return 0;
  4029. }
  4030. /*==========================================
  4031. * 場所スキルエフェクトが視界から消える
  4032. *------------------------------------------
  4033. */
  4034. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  4035. {
  4036. nullpo_retr(0, unit);
  4037. WFIFOHEAD(fd,packet_len_table[0x120]);
  4038. WFIFOW(fd, 0)=0x120;
  4039. WFIFOL(fd, 2)=unit->bl.id;
  4040. WFIFOSET(fd,packet_len_table[0x120]);
  4041. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4042. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  4043. return 0;
  4044. }
  4045. /*==========================================
  4046. *
  4047. *------------------------------------------
  4048. */
  4049. int clif_01ac(struct block_list *bl)
  4050. {
  4051. unsigned char buf[32];
  4052. nullpo_retr(0, bl);
  4053. WBUFW(buf, 0) = 0x1ac;
  4054. WBUFL(buf, 2) = bl->id;
  4055. clif_send(buf,packet_len_table[0x1ac],bl,AREA);
  4056. return 0;
  4057. }
  4058. /*==========================================
  4059. *
  4060. *------------------------------------------
  4061. */
  4062. int clif_getareachar(struct block_list* bl,va_list ap)
  4063. {
  4064. struct map_session_data *sd;
  4065. nullpo_retr(0, bl);
  4066. nullpo_retr(0, ap);
  4067. sd=va_arg(ap,struct map_session_data*);
  4068. if (sd == NULL || session[sd->fd] == NULL)
  4069. return 0;
  4070. switch(bl->type){
  4071. case BL_PC:
  4072. if(sd==(struct map_session_data*)bl)
  4073. break;
  4074. clif_getareachar_pc(sd,(struct map_session_data*) bl);
  4075. break;
  4076. case BL_NPC:
  4077. clif_getareachar_npc(sd,(struct npc_data*) bl);
  4078. break;
  4079. case BL_MOB:
  4080. clif_getareachar_mob(sd,(struct mob_data*) bl);
  4081. break;
  4082. case BL_PET:
  4083. clif_getareachar_pet(sd,(struct pet_data*) bl);
  4084. break;
  4085. case BL_ITEM:
  4086. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4087. break;
  4088. case BL_SKILL:
  4089. clif_getareachar_skillunit(sd,(struct skill_unit *)bl);
  4090. break;
  4091. default:
  4092. if(battle_config.error_log)
  4093. ShowError("clif_getareachar: Unrecognized type %d.\n",bl->type);
  4094. break;
  4095. }
  4096. return 0;
  4097. }
  4098. /*==========================================
  4099. *
  4100. *------------------------------------------
  4101. */
  4102. int clif_pcoutsight(struct block_list *bl,va_list ap)
  4103. {
  4104. struct map_session_data *sd,*dstsd;
  4105. nullpo_retr(0, bl);
  4106. nullpo_retr(0, ap);
  4107. nullpo_retr(0, sd=va_arg(ap,struct map_session_data*));
  4108. switch(bl->type){
  4109. case BL_PC:
  4110. dstsd = (struct map_session_data*) bl;
  4111. if(sd != dstsd) {
  4112. clif_clearchar_id(dstsd->bl.id,0,sd->fd);
  4113. clif_clearchar_id(sd->bl.id,0,dstsd->fd);
  4114. if(dstsd->disguise || sd->disguise) {
  4115. clif_clearchar_id(-dstsd->bl.id,0,sd->fd);
  4116. clif_clearchar_id(-sd->bl.id,0,dstsd->fd);
  4117. }
  4118. if(dstsd->chatID){
  4119. struct chat_data *cd;
  4120. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  4121. if(cd->usersd[0]==dstsd)
  4122. clif_dispchat(cd,sd->fd);
  4123. }
  4124. if(dstsd->vender_id){
  4125. clif_closevendingboard(&dstsd->bl,sd->fd);
  4126. }
  4127. }
  4128. break;
  4129. case BL_NPC:
  4130. if( ((struct npc_data *)bl)->class_ != INVISIBLE_CLASS )
  4131. clif_clearchar_id(bl->id,0,sd->fd);
  4132. break;
  4133. case BL_MOB:
  4134. case BL_PET:
  4135. clif_clearchar_id(bl->id,0,sd->fd);
  4136. break;
  4137. case BL_ITEM:
  4138. clif_clearflooritem((struct flooritem_data*)bl,sd->fd);
  4139. break;
  4140. case BL_SKILL:
  4141. clif_clearchar_skillunit((struct skill_unit *)bl,sd->fd);
  4142. break;
  4143. }
  4144. return 0;
  4145. }
  4146. /*==========================================
  4147. *
  4148. *------------------------------------------
  4149. */
  4150. int clif_pcinsight(struct block_list *bl,va_list ap)
  4151. {
  4152. struct map_session_data *sd,*dstsd;
  4153. nullpo_retr(0, bl);
  4154. nullpo_retr(0, ap);
  4155. nullpo_retr(0, sd=va_arg(ap,struct map_session_data*));
  4156. switch(bl->type){
  4157. case BL_PC:
  4158. dstsd = (struct map_session_data *)bl;
  4159. if(sd != dstsd) {
  4160. clif_getareachar_pc(sd,dstsd);
  4161. clif_getareachar_pc(dstsd,sd);
  4162. }
  4163. break;
  4164. case BL_NPC:
  4165. clif_getareachar_npc(sd,(struct npc_data*)bl);
  4166. break;
  4167. case BL_MOB:
  4168. clif_getareachar_mob(sd,(struct mob_data*)bl);
  4169. break;
  4170. case BL_PET:
  4171. clif_getareachar_pet(sd,(struct pet_data*)bl);
  4172. break;
  4173. case BL_ITEM:
  4174. clif_getareachar_item(sd,(struct flooritem_data*)bl);
  4175. break;
  4176. case BL_SKILL:
  4177. clif_getareachar_skillunit(sd,(struct skill_unit *)bl);
  4178. break;
  4179. }
  4180. return 0;
  4181. }
  4182. /*==========================================
  4183. *
  4184. *------------------------------------------
  4185. */
  4186. int clif_moboutsight(struct block_list *bl,va_list ap)
  4187. {
  4188. struct map_session_data *sd;
  4189. struct mob_data *md;
  4190. nullpo_retr(0, bl);
  4191. nullpo_retr(0, ap);
  4192. nullpo_retr(0, md=va_arg(ap,struct mob_data*));
  4193. if(bl->type==BL_PC
  4194. && ((sd = (struct map_session_data*) bl) != NULL)
  4195. && session[sd->fd] != NULL) {
  4196. clif_clearchar_id(md->bl.id,0,sd->fd);
  4197. }
  4198. return 0;
  4199. }
  4200. /*==========================================
  4201. *
  4202. *------------------------------------------
  4203. */
  4204. int clif_mobinsight(struct block_list *bl,va_list ap)
  4205. {
  4206. struct map_session_data *sd;
  4207. struct mob_data *md;
  4208. nullpo_retr(0, bl);
  4209. nullpo_retr(0, ap);
  4210. md=va_arg(ap,struct mob_data*);
  4211. if(bl->type==BL_PC
  4212. && ((sd = (struct map_session_data*) bl) != NULL)
  4213. && session[sd->fd] != NULL) {
  4214. clif_getareachar_mob(sd,md);
  4215. }
  4216. return 0;
  4217. }
  4218. /*==========================================
  4219. *
  4220. *------------------------------------------
  4221. */
  4222. int clif_petoutsight(struct block_list *bl,va_list ap)
  4223. {
  4224. struct map_session_data *sd;
  4225. struct pet_data *pd;
  4226. nullpo_retr(0, bl);
  4227. nullpo_retr(0, ap);
  4228. nullpo_retr(0, pd=va_arg(ap,struct pet_data*));
  4229. if(bl->type==BL_PC
  4230. && ((sd = (struct map_session_data*) bl) != NULL)
  4231. && session[sd->fd] != NULL) {
  4232. clif_clearchar_id(pd->bl.id,0,sd->fd);
  4233. }
  4234. return 0;
  4235. }
  4236. // npc walking [Valaris]
  4237. int clif_npcoutsight(struct block_list *bl,va_list ap)
  4238. {
  4239. struct map_session_data *sd;
  4240. struct npc_data *nd;
  4241. nullpo_retr(0, bl);
  4242. nullpo_retr(0, ap);
  4243. nullpo_retr(0, nd=va_arg(ap,struct npc_data*));
  4244. if(bl->type==BL_PC
  4245. && ((sd = (struct map_session_data*) bl) != NULL)
  4246. && session[sd->fd] != NULL) {
  4247. clif_clearchar_id(nd->bl.id,0,sd->fd);
  4248. }
  4249. return 0;
  4250. }
  4251. /*==========================================
  4252. *
  4253. *------------------------------------------
  4254. */
  4255. int clif_petinsight(struct block_list *bl,va_list ap)
  4256. {
  4257. struct map_session_data *sd;
  4258. struct pet_data *pd;
  4259. nullpo_retr(0, bl);
  4260. nullpo_retr(0, ap);
  4261. pd=va_arg(ap,struct pet_data*);
  4262. if(bl->type==BL_PC
  4263. && ((sd = (struct map_session_data*) bl) != NULL)
  4264. && session[sd->fd] != NULL) {
  4265. clif_getareachar_pet(sd,pd);
  4266. }
  4267. return 0;
  4268. }
  4269. // npc walking [Valaris]
  4270. int clif_npcinsight(struct block_list *bl,va_list ap)
  4271. {
  4272. struct map_session_data *sd;
  4273. struct npc_data *nd;
  4274. nullpo_retr(0, bl);
  4275. nullpo_retr(0, ap);
  4276. nd=va_arg(ap,struct npc_data*);
  4277. if(bl->type==BL_PC
  4278. && ((sd = (struct map_session_data*) bl) != NULL)
  4279. && session[sd->fd] != NULL) {
  4280. clif_getareachar_npc(sd,nd);
  4281. }
  4282. return 0;
  4283. }
  4284. /*==========================================
  4285. *
  4286. *------------------------------------------
  4287. */
  4288. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  4289. {
  4290. int fd,id, inf2;
  4291. nullpo_retr(0, sd);
  4292. fd=sd->fd;
  4293. if( (id=sd->status.skill[skillid].id) <= 0 )
  4294. return 0;
  4295. WFIFOHEAD(fd,packet_len_table[0x147]);
  4296. WFIFOW(fd,0)=0x147;
  4297. WFIFOW(fd,2) = id;
  4298. if(type < 0)
  4299. WFIFOW(fd,4) = skill_get_inf(id);
  4300. else
  4301. WFIFOW(fd,4) = type;
  4302. WFIFOW(fd,6) = 0;
  4303. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  4304. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  4305. if(range < 0)
  4306. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  4307. WFIFOW(fd,12)= range;
  4308. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4309. inf2 = skill_get_inf2(id);
  4310. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  4311. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  4312. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill))
  4313. //WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_get_max(id) && sd->status.skill[skillid].flag ==0 )? 1:0;
  4314. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[skillid].flag ==0 )? 1:0;
  4315. else
  4316. WFIFOB(fd,38) = 0;
  4317. WFIFOSET(fd,packet_len_table[0x147]);
  4318. return 0;
  4319. }
  4320. /*==========================================
  4321. * スキルリストを送信する
  4322. *------------------------------------------
  4323. */
  4324. int clif_skillinfoblock(struct map_session_data *sd)
  4325. {
  4326. int fd;
  4327. int i,c,len=4,id, inf2;
  4328. nullpo_retr(0, sd);
  4329. fd=sd->fd;
  4330. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4331. WFIFOW(fd,0)=0x10f;
  4332. for ( i = c = 0; i < MAX_SKILL; i++){
  4333. if( (id=sd->status.skill[i].id)!=0 ){
  4334. WFIFOW(fd,len ) = id;
  4335. WFIFOW(fd,len+2) = skill_get_inf(id);
  4336. WFIFOW(fd,len+4) = 0;
  4337. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4338. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4339. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4340. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4341. inf2 = skill_get_inf2(id);
  4342. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  4343. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  4344. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill) )
  4345. //WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_get_max(id) && sd->status.skill[i].flag ==0 )? 1:0;
  4346. 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;
  4347. else
  4348. WFIFOB(fd,len+36) = 0;
  4349. len+=37;
  4350. c++;
  4351. }
  4352. }
  4353. WFIFOW(fd,2)=len;
  4354. WFIFOSET(fd,len);
  4355. return 0;
  4356. }
  4357. /*==========================================
  4358. * スキル割り振り通知
  4359. *------------------------------------------
  4360. */
  4361. int clif_skillup(struct map_session_data *sd,int skill_num)
  4362. {
  4363. int fd;
  4364. nullpo_retr(0, sd);
  4365. fd=sd->fd;
  4366. WFIFOHEAD(fd,packet_len_table[0x10e]);
  4367. WFIFOW(fd,0) = 0x10e;
  4368. WFIFOW(fd,2) = skill_num;
  4369. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  4370. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  4371. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  4372. //WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_get_max(sd->status.skill[skill_num].id)) ? 1 : 0;
  4373. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  4374. WFIFOSET(fd,packet_len_table[0x10e]);
  4375. return 0;
  4376. }
  4377. /*==========================================
  4378. * スキル詠唱エフェクトを送信する
  4379. *------------------------------------------
  4380. */
  4381. int clif_skillcasting(struct block_list* bl,
  4382. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  4383. {
  4384. int pl = skill_get_pl(skill_num);
  4385. unsigned char buf[32];
  4386. WBUFW(buf,0) = 0x13e;
  4387. WBUFL(buf,2) = src_id;
  4388. WBUFL(buf,6) = dst_id;
  4389. WBUFW(buf,10) = dst_x;
  4390. WBUFW(buf,12) = dst_y;
  4391. WBUFW(buf,14) = skill_num;
  4392. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  4393. WBUFL(buf,20) = casttime;
  4394. clif_send(buf,packet_len_table[0x13e], bl, AREA);
  4395. return 0;
  4396. }
  4397. /*==========================================
  4398. *
  4399. *------------------------------------------
  4400. */
  4401. int clif_skillcastcancel(struct block_list* bl)
  4402. {
  4403. unsigned char buf[16];
  4404. nullpo_retr(0, bl);
  4405. WBUFW(buf,0) = 0x1b9;
  4406. WBUFL(buf,2) = bl->id;
  4407. clif_send(buf,packet_len_table[0x1b9], bl, AREA);
  4408. return 0;
  4409. }
  4410. /*==========================================
  4411. * スキル詠唱失敗
  4412. *------------------------------------------
  4413. */
  4414. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  4415. {
  4416. int fd;
  4417. nullpo_retr(0, sd);
  4418. fd=sd->fd;
  4419. // reset all variables [celest]
  4420. sd->skillx = sd->skilly = -1;
  4421. sd->skillid = sd->skilllv = -1;
  4422. sd->skillitem = sd->skillitemlv = -1;
  4423. if(type==0x4 && !sd->state.showdelay)
  4424. return 0;
  4425. WFIFOHEAD(fd,packet_len_table[0x110]);
  4426. WFIFOW(fd,0) = 0x110;
  4427. WFIFOW(fd,2) = skill_id;
  4428. WFIFOW(fd,4) = btype;
  4429. WFIFOW(fd,6) = 0;
  4430. WFIFOB(fd,8) = 0;
  4431. WFIFOB(fd,9) = type;
  4432. WFIFOSET(fd,packet_len_table[0x110]);
  4433. return 0;
  4434. }
  4435. /*==========================================
  4436. * スキル攻撃エフェクト&ダメージ
  4437. *------------------------------------------
  4438. */
  4439. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  4440. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4441. {
  4442. unsigned char buf[64];
  4443. struct status_change *sc;
  4444. nullpo_retr(0, src);
  4445. nullpo_retr(0, dst);
  4446. type = clif_calc_delay(dst, (type>0)?type:skill_get_hit(skill_id), ddelay);
  4447. sc = status_get_sc(dst);
  4448. if(sc && sc->count) {
  4449. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  4450. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  4451. }
  4452. #if PACKETVER < 3
  4453. WBUFW(buf,0)=0x114;
  4454. WBUFW(buf,2)=skill_id;
  4455. if(src->type==BL_PC && ((struct map_session_data *)src)->disguise)
  4456. WBUFL(buf,4)=-src->id;
  4457. else
  4458. WBUFL(buf,4)=src->id;
  4459. if(dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)
  4460. WBUFL(buf,8)=-dst->id;
  4461. else
  4462. WBUFL(buf,8)=dst->id;
  4463. WBUFL(buf,12)=tick;
  4464. WBUFL(buf,16)=sdelay;
  4465. WBUFL(buf,20)=ddelay;
  4466. WBUFW(buf,24)=damage;
  4467. WBUFW(buf,26)=skill_lv;
  4468. WBUFW(buf,28)=div;
  4469. WBUFB(buf,30)=type;
  4470. clif_send(buf,packet_len_table[0x114],src,AREA);
  4471. #else
  4472. WBUFW(buf,0)=0x1de;
  4473. WBUFW(buf,2)=skill_id;
  4474. if(src->type==BL_PC && ((struct map_session_data *)src)->disguise)
  4475. WBUFL(buf,4)=-src->id;
  4476. else
  4477. WBUFL(buf,4)=src->id;
  4478. if(dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)
  4479. WBUFL(buf,8)=-dst->id;
  4480. else
  4481. WBUFL(buf,8)=dst->id;
  4482. WBUFL(buf,12)=tick;
  4483. WBUFL(buf,16)=sdelay;
  4484. WBUFL(buf,20)=ddelay;
  4485. WBUFL(buf,24)=damage;
  4486. WBUFW(buf,28)=skill_lv;
  4487. WBUFW(buf,30)=div;
  4488. WBUFB(buf,32)=type;
  4489. clif_send(buf,packet_len_table[0x1de],src,AREA);
  4490. #endif
  4491. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4492. if (type != 4 && type != 9 && damage > 0) //Non-endure/Non-flinch attack, update walk delay.
  4493. battle_walkdelay(dst, tick, sdelay, ddelay, div);
  4494. return 0;
  4495. }
  4496. /*==========================================
  4497. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  4498. *------------------------------------------
  4499. */
  4500. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  4501. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4502. {
  4503. unsigned char buf[64];
  4504. struct status_change *sc;
  4505. nullpo_retr(0, src);
  4506. nullpo_retr(0, dst);
  4507. type = clif_calc_delay(dst, (type>0)?type:skill_get_hit(skill_id), ddelay);
  4508. sc = status_get_sc(dst);
  4509. if(sc && sc->count) {
  4510. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  4511. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  4512. }
  4513. WBUFW(buf,0)=0x115;
  4514. WBUFW(buf,2)=skill_id;
  4515. WBUFL(buf,4)=src->id;
  4516. WBUFL(buf,8)=dst->id;
  4517. WBUFL(buf,12)=tick;
  4518. WBUFL(buf,16)=sdelay;
  4519. WBUFL(buf,20)=ddelay;
  4520. WBUFW(buf,24)=dst->x;
  4521. WBUFW(buf,26)=dst->y;
  4522. WBUFW(buf,28)=damage;
  4523. WBUFW(buf,30)=skill_lv;
  4524. WBUFW(buf,32)=div;
  4525. WBUFB(buf,34)=type;
  4526. clif_send(buf,packet_len_table[0x115],src,AREA);
  4527. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4528. if (type != 4 && type != 9 && damage > 0) //Non-endure/Non-flinch attack, update walk delay.
  4529. battle_walkdelay(dst, tick, sdelay, ddelay, div);
  4530. return 0;
  4531. }
  4532. /*==========================================
  4533. * 支援/回復スキルエフェクト
  4534. *------------------------------------------
  4535. */
  4536. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  4537. int skill_id,int heal,int fail)
  4538. {
  4539. unsigned char buf[32];
  4540. nullpo_retr(0, src);
  4541. nullpo_retr(0, dst);
  4542. WBUFW(buf,0)=0x11a;
  4543. WBUFW(buf,2)=skill_id;
  4544. WBUFW(buf,4)=(heal > 0x7fff)? 0x7fff:heal;
  4545. WBUFL(buf,6)=dst->id;
  4546. WBUFL(buf,10)=src->id;
  4547. WBUFB(buf,14)=fail;
  4548. clif_send(buf,packet_len_table[0x11a],src,AREA);
  4549. return fail;
  4550. }
  4551. /*==========================================
  4552. * 場所スキルエフェクト
  4553. *------------------------------------------
  4554. */
  4555. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4556. {
  4557. unsigned char buf[32];
  4558. nullpo_retr(0, src);
  4559. WBUFW(buf,0)=0x117;
  4560. WBUFW(buf,2)=skill_id;
  4561. WBUFL(buf,4)=src->id;
  4562. WBUFW(buf,8)=val;
  4563. WBUFW(buf,10)=x;
  4564. WBUFW(buf,12)=y;
  4565. WBUFL(buf,14)=tick;
  4566. clif_send(buf,packet_len_table[0x117],src,AREA);
  4567. return 0;
  4568. }
  4569. /*==========================================
  4570. * 場所スキルエフェクト表示
  4571. *------------------------------------------
  4572. */
  4573. int clif_skill_setunit(struct skill_unit *unit)
  4574. {
  4575. unsigned char buf[128];
  4576. struct block_list *bl;
  4577. nullpo_retr(0, unit);
  4578. bl=map_id2bl(unit->group->src_id);
  4579. #if PACKETVER < 3
  4580. memset(WBUFP(buf, 0),0,packet_len_table[0x11f]);
  4581. WBUFW(buf, 0)=0x11f;
  4582. WBUFL(buf, 2)=unit->bl.id;
  4583. WBUFL(buf, 6)=unit->group->src_id;
  4584. WBUFW(buf,10)=unit->bl.x;
  4585. WBUFW(buf,12)=unit->bl.y;
  4586. WBUFB(buf,14)=unit->group->unit_id;
  4587. WBUFB(buf,15)=0;
  4588. clif_send(buf,packet_len_table[0x11f],&unit->bl,AREA);
  4589. #else
  4590. memset(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4591. WBUFW(buf, 0)=0x1c9;
  4592. WBUFL(buf, 2)=unit->bl.id;
  4593. WBUFL(buf, 6)=unit->group->src_id;
  4594. WBUFW(buf,10)=unit->bl.x;
  4595. WBUFW(buf,12)=unit->bl.y;
  4596. WBUFB(buf,14)=unit->group->unit_id;
  4597. WBUFB(buf,15)=1;
  4598. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4599. WBUFB(buf,16)=1;
  4600. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4601. } else {
  4602. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4603. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4604. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4605. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4606. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4607. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4608. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4609. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4610. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4611. //37-39
  4612. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4613. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4614. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4615. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4616. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4617. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4618. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4619. //65-68
  4620. //69-72
  4621. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4622. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4623. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4624. }
  4625. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4626. #endif
  4627. return 0;
  4628. }
  4629. /*==========================================
  4630. * 場所スキルエフェクト削除
  4631. *------------------------------------------
  4632. */
  4633. int clif_skill_delunit(struct skill_unit *unit)
  4634. {
  4635. unsigned char buf[16];
  4636. nullpo_retr(0, unit);
  4637. WBUFW(buf, 0)=0x120;
  4638. WBUFL(buf, 2)=unit->bl.id;
  4639. clif_send(buf,packet_len_table[0x120],&unit->bl,AREA);
  4640. return 0;
  4641. }
  4642. /*==========================================
  4643. * ワープ場所選択
  4644. *------------------------------------------
  4645. */
  4646. int clif_skill_warppoint(struct map_session_data *sd,int skill_num, int skill_lv,
  4647. const char *map1,const char *map2,const char *map3,const char *map4)
  4648. {
  4649. int fd;
  4650. nullpo_retr(0, sd);
  4651. fd=sd->fd;
  4652. WFIFOHEAD(fd,packet_len_table[0x11c]);
  4653. WFIFOW(fd,0)=0x11c;
  4654. WFIFOW(fd,2)=skill_num;
  4655. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4656. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4657. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4658. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4659. WFIFOSET(fd,packet_len_table[0x11c]);
  4660. sd->menuskill_id = skill_num;
  4661. sd->menuskill_lv = skill_lv;
  4662. return 0;
  4663. }
  4664. /*==========================================
  4665. * メモ応答
  4666. *------------------------------------------
  4667. */
  4668. int clif_skill_memo(struct map_session_data *sd,int flag)
  4669. {
  4670. int fd;
  4671. nullpo_retr(0, sd);
  4672. fd=sd->fd;
  4673. WFIFOHEAD(fd,packet_len_table[0x11e]);
  4674. WFIFOW(fd,0)=0x11e;
  4675. WFIFOB(fd,2)=flag;
  4676. WFIFOSET(fd,packet_len_table[0x11e]);
  4677. return 0;
  4678. }
  4679. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4680. {
  4681. int fd;
  4682. nullpo_retr(0, sd);
  4683. fd=sd->fd;
  4684. WFIFOHEAD(fd,packet_len_table[0x189]);
  4685. WFIFOW(fd,0)=0x189;
  4686. WFIFOW(fd,2)=flag;
  4687. WFIFOSET(fd,packet_len_table[0x189]);
  4688. return 0;
  4689. }
  4690. /*==========================================
  4691. * モンスター情報
  4692. *------------------------------------------
  4693. */
  4694. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4695. {
  4696. struct mob_data *md;
  4697. unsigned char buf[64];
  4698. int i;//, fix;
  4699. nullpo_retr(0, sd);
  4700. nullpo_retr(0, dst);
  4701. if(dst->type!=BL_MOB )
  4702. return 0;
  4703. if((md=(struct mob_data *)dst) == NULL)
  4704. return 0;
  4705. WBUFW(buf, 0)=0x18c;
  4706. WBUFW(buf, 2)=mob_get_viewclass(md->class_);
  4707. WBUFW(buf, 4)=md->level;
  4708. WBUFW(buf, 6)=md->db->size;
  4709. WBUFL(buf, 8)=md->hp;
  4710. WBUFW(buf,12)= (battle_config.estimation_type&1?status_get_def(&md->bl):0)
  4711. +(battle_config.estimation_type&2?status_get_def2(&md->bl):0);
  4712. WBUFW(buf,14)=md->db->race;
  4713. WBUFW(buf,16)= (battle_config.estimation_type&1?status_get_mdef(&md->bl):0)
  4714. +(battle_config.estimation_type&2?status_get_mdef2(&md->bl) - (md->db->vit>>1):0);
  4715. WBUFW(buf,18)=status_get_elem_type(&md->bl);
  4716. for(i=0;i<9;i++)
  4717. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,md->def_ele);
  4718. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4719. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,md->def_ele))<0?0:fix);
  4720. if(sd->status.party_id>0)
  4721. clif_send(buf,packet_len_table[0x18c],&sd->bl,PARTY_AREA);
  4722. else{
  4723. WFIFOHEAD(sd->fd,packet_len_table[0x18c]);
  4724. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x18c]);
  4725. WFIFOSET(sd->fd,packet_len_table[0x18c]);
  4726. }
  4727. return 0;
  4728. }
  4729. /*==========================================
  4730. * アイテム合成可能リスト
  4731. *------------------------------------------
  4732. */
  4733. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4734. {
  4735. int i,c,view,fd;
  4736. nullpo_retr(0, sd);
  4737. if(sd->menuskill_id == AM_PHARMACY)
  4738. return 0; //Avoid resending the menu twice or more times...
  4739. fd=sd->fd;
  4740. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4741. WFIFOW(fd, 0)=0x18d;
  4742. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4743. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4744. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4745. WFIFOW(fd,c*8+ 4)= view;
  4746. else
  4747. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4748. WFIFOW(fd,c*8+ 6)= 0x0012;
  4749. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4750. c++;
  4751. }
  4752. }
  4753. WFIFOW(fd, 2)=c*8+8;
  4754. WFIFOSET(fd,WFIFOW(fd,2));
  4755. if(c > 0) {
  4756. sd->menuskill_id = AM_PHARMACY;
  4757. sd->menuskill_lv = trigger;
  4758. return 1;
  4759. }
  4760. return 0;
  4761. }
  4762. /*==========================================
  4763. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4764. *------------------------------------------
  4765. */
  4766. int clif_status_load(struct block_list *bl,int type, int flag)
  4767. {
  4768. int fd;
  4769. if (type == SI_BLANK) //It shows nothing on the client...
  4770. return 0;
  4771. if (bl->type != BL_PC)
  4772. return 0;
  4773. fd = ((struct map_session_data*)bl)->fd;
  4774. WFIFOHEAD(fd,packet_len_table[0x196]);
  4775. WFIFOW(fd,0)=0x0196;
  4776. WFIFOW(fd,2)=type;
  4777. WFIFOL(fd,4)=bl->id;
  4778. WFIFOB(fd,8)=flag; //Status start
  4779. WFIFOSET(fd, packet_len_table[0x196]);
  4780. return 0;
  4781. }
  4782. /*==========================================
  4783. * 状態異常アイコン/メッセージ表示
  4784. *------------------------------------------
  4785. */
  4786. int clif_status_change(struct block_list *bl,int type,int flag)
  4787. {
  4788. unsigned char buf[16];
  4789. if (type == SI_BLANK) //It shows nothing on the client...
  4790. return 0;
  4791. nullpo_retr(0, bl);
  4792. WBUFW(buf,0)=0x0196;
  4793. WBUFW(buf,2)=type;
  4794. WBUFL(buf,4)=bl->id;
  4795. WBUFB(buf,8)=flag;
  4796. clif_send(buf,packet_len_table[0x196],bl,AREA);
  4797. return 0;
  4798. }
  4799. /*==========================================
  4800. * Send message (modified by [Yor])
  4801. *------------------------------------------
  4802. */
  4803. int clif_displaymessage(const int fd, char* mes)
  4804. {
  4805. // invalid pointer?
  4806. nullpo_retr(-1, mes);
  4807. //Console [Wizputer] //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4808. if (fd == 0)
  4809. return 0;
  4810. else {
  4811. int len_mes = strlen(mes);
  4812. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4813. WFIFOHEAD(fd, 5 + len_mes);
  4814. WFIFOW(fd,0) = 0x8e;
  4815. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4816. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4817. WFIFOSET(fd, 5 + len_mes);
  4818. }
  4819. }
  4820. return 0;
  4821. }
  4822. /*==========================================
  4823. * 天の声を送信する
  4824. *------------------------------------------
  4825. */
  4826. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4827. {
  4828. unsigned char *buf;
  4829. int lp;
  4830. lp = (flag & 0x10) ? 8 : 4;
  4831. buf = (unsigned char*)aCallocA(len + lp + 8, sizeof(unsigned char));
  4832. WBUFW(buf,0) = 0x9a;
  4833. WBUFW(buf,2) = len + lp;
  4834. WBUFL(buf,4) = 0x65756c62;
  4835. memcpy(WBUFP(buf,lp), mes, len);
  4836. flag &= 0x07;
  4837. clif_send(buf, WBUFW(buf,2), bl,
  4838. (flag == 1) ? ALL_SAMEMAP :
  4839. (flag == 2) ? AREA :
  4840. (flag == 3) ? SELF :
  4841. ALL_CLIENT);
  4842. if(buf) aFree(buf);
  4843. if(use_irc && irc_announce_flag && !flag)
  4844. irc_announce(mes);
  4845. return 0;
  4846. }
  4847. /*==========================================
  4848. * グローバルメッセージ
  4849. *------------------------------------------
  4850. */
  4851. void clif_GlobalMessage(struct block_list *bl,char *message)
  4852. {
  4853. char buf[100];
  4854. int len;
  4855. nullpo_retv(bl);
  4856. if(!message)
  4857. return;
  4858. len = strlen(message)+1;
  4859. WBUFW(buf,0)=0x8d;
  4860. WBUFW(buf,2)=len+8;
  4861. WBUFL(buf,4)=bl->id;
  4862. strncpy((char *) WBUFP(buf,8),message,len);
  4863. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,AREA_CHAT_WOC);
  4864. }
  4865. /*==========================================
  4866. * Send main chat message [LuzZza]
  4867. *------------------------------------------
  4868. */
  4869. void clif_MainChatMessage(char* message) {
  4870. char buf[100];
  4871. int len;
  4872. if(!message)
  4873. return;
  4874. len = strlen(message)+1;
  4875. WBUFW(buf,0)=0x8d;
  4876. WBUFW(buf,2)=len+8;
  4877. WBUFL(buf,4)=0;
  4878. strncpy((char *) WBUFP(buf,8),message,len);
  4879. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4880. }
  4881. /*==========================================
  4882. * Does an announce message in the given color.
  4883. *------------------------------------------
  4884. */
  4885. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4886. {
  4887. unsigned char *buf;
  4888. buf = (unsigned char*)aCallocA(len + 16, sizeof(unsigned char));
  4889. WBUFW(buf,0) = 0x1c3;
  4890. WBUFW(buf,2) = len + 16;
  4891. WBUFL(buf,4) = color;
  4892. WBUFW(buf,8) = 0x190; //Font style? Type?
  4893. WBUFW(buf,10) = 0x0c; //12? Font size?
  4894. WBUFL(buf,12) = 0; //Unknown!
  4895. memcpy(WBUFP(buf,16), mes, len);
  4896. flag &= 0x07;
  4897. clif_send(buf, WBUFW(buf,2), bl,
  4898. (flag == 1) ? ALL_SAMEMAP :
  4899. (flag == 2) ? AREA :
  4900. (flag == 3) ? SELF :
  4901. ALL_CLIENT);
  4902. if(buf) aFree(buf);
  4903. return 0;
  4904. }
  4905. /*==========================================
  4906. * HPSP回復エフェクトを送信する
  4907. *------------------------------------------
  4908. */
  4909. int clif_heal(int fd,int type,int val)
  4910. {
  4911. WFIFOHEAD(fd,packet_len_table[0x13d]);
  4912. WFIFOW(fd,0)=0x13d;
  4913. WFIFOW(fd,2)=type;
  4914. WFIFOW(fd,4)=val;
  4915. WFIFOSET(fd,packet_len_table[0x13d]);
  4916. return 0;
  4917. }
  4918. /*==========================================
  4919. * 復活する
  4920. *------------------------------------------
  4921. */
  4922. int clif_resurrection(struct block_list *bl,int type)
  4923. {
  4924. unsigned char buf[16];
  4925. nullpo_retr(0, bl);
  4926. WBUFW(buf,0)=0x148;
  4927. WBUFL(buf,2)=bl->id;
  4928. WBUFW(buf,6)=type;
  4929. clif_send(buf,packet_len_table[0x148],bl,type==1 ? AREA : AREA_WOS);
  4930. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise)
  4931. clif_spawnpc(((struct map_session_data *)bl));
  4932. return 0;
  4933. }
  4934. /*==========================================
  4935. * PVP実装?(仮)
  4936. *------------------------------------------
  4937. */
  4938. int clif_set0199(int fd,int type)
  4939. {
  4940. WFIFOHEAD(fd,packet_len_table[0x199]);
  4941. WFIFOW(fd,0)=0x199;
  4942. WFIFOW(fd,2)=type;
  4943. WFIFOSET(fd,packet_len_table[0x199]);
  4944. return 0;
  4945. }
  4946. /*==========================================
  4947. * PVP実装?(仮)
  4948. *------------------------------------------
  4949. */
  4950. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4951. {
  4952. nullpo_retr(0, sd);
  4953. if(map[sd->bl.m].flag.nopvp)
  4954. return 0;
  4955. if(type == 2) {
  4956. WFIFOHEAD(sd->fd,packet_len_table[0x19a]);
  4957. WFIFOW(sd->fd,0) = 0x19a;
  4958. WFIFOL(sd->fd,2) = sd->bl.id;
  4959. if(pvprank<=0)
  4960. pc_calc_pvprank(sd);
  4961. WFIFOL(sd->fd,6) = pvprank;
  4962. WFIFOL(sd->fd,10) = pvpnum;
  4963. WFIFOSET(sd->fd,packet_len_table[0x19a]);
  4964. } else {
  4965. unsigned char buf[32];
  4966. WBUFW(buf,0) = 0x19a;
  4967. WBUFL(buf,2) = sd->bl.id;
  4968. if(sd->sc.option&0x46)
  4969. // WTF? a -1 to an unsigned value...
  4970. WBUFL(buf,6) = 0xFFFFFFFF;
  4971. else
  4972. if(pvprank<=0)
  4973. pc_calc_pvprank(sd);
  4974. WBUFL(buf,6) = pvprank;
  4975. WBUFL(buf,10) = pvpnum;
  4976. if(!type)
  4977. clif_send(buf,packet_len_table[0x19a],&sd->bl,AREA);
  4978. else
  4979. clif_send(buf,packet_len_table[0x19a],&sd->bl,ALL_SAMEMAP);
  4980. }
  4981. return 0;
  4982. }
  4983. /*==========================================
  4984. *
  4985. *------------------------------------------
  4986. */
  4987. int clif_send0199(int map,int type)
  4988. {
  4989. struct block_list bl;
  4990. unsigned char buf[16];
  4991. bl.m = map;
  4992. WBUFW(buf,0)=0x199;
  4993. WBUFW(buf,2)=type;
  4994. clif_send(buf,packet_len_table[0x199],&bl,ALL_SAMEMAP);
  4995. return 0;
  4996. }
  4997. /*==========================================
  4998. * 精錬エフェクトを送信する
  4999. *------------------------------------------
  5000. */
  5001. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  5002. {
  5003. WFIFOHEAD(fd,packet_len_table[0x188]);
  5004. WFIFOW(fd,0)=0x188;
  5005. WFIFOW(fd,2)=fail;
  5006. WFIFOW(fd,4)=index+2;
  5007. WFIFOW(fd,6)=val;
  5008. WFIFOSET(fd,packet_len_table[0x188]);
  5009. return 0;
  5010. }
  5011. /*==========================================
  5012. * Wisp/page is transmitted to the destination player
  5013. *------------------------------------------
  5014. */
  5015. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  5016. {
  5017. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  5018. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5019. WFIFOW(fd,0) = 0x97;
  5020. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5021. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  5022. memcpy(WFIFOP(fd,28), mes, mes_len);
  5023. WFIFOSET(fd,WFIFOW(fd,2));
  5024. return 0;
  5025. }
  5026. /*==========================================
  5027. * The transmission result of Wisp/page is transmitted to the source player
  5028. *------------------------------------------
  5029. */
  5030. 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
  5031. {
  5032. WFIFOHEAD(fd,packet_len_table[0x98]);
  5033. WFIFOW(fd,0) = 0x98;
  5034. WFIFOW(fd,2) = flag;
  5035. WFIFOSET(fd,packet_len_table[0x98]);
  5036. return 0;
  5037. }
  5038. /*==========================================
  5039. * キャラID名前引き結果を送信する
  5040. *------------------------------------------
  5041. */
  5042. int clif_solved_charname(struct map_session_data *sd,int char_id)
  5043. {
  5044. char *p= map_charid2nick(char_id);
  5045. int fd;
  5046. nullpo_retr(0, sd);
  5047. fd=sd->fd;
  5048. if(p!=NULL){
  5049. WFIFOHEAD(fd,packet_len_table[0x194]);
  5050. WFIFOW(fd,0)=0x194;
  5051. WFIFOL(fd,2)=char_id;
  5052. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  5053. WFIFOSET(fd,packet_len_table[0x194]);
  5054. }else{
  5055. map_reqchariddb(sd,char_id);
  5056. chrif_searchcharid(char_id);
  5057. }
  5058. return 0;
  5059. }
  5060. /*==========================================
  5061. * カードの挿入可能リストを返す
  5062. *------------------------------------------
  5063. */
  5064. int clif_use_card(struct map_session_data *sd,int idx)
  5065. {
  5066. int i,c,ep;
  5067. int fd=sd->fd;
  5068. nullpo_retr(0, sd);
  5069. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5070. return 0;
  5071. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != 6)
  5072. return 0; //Avoid parsing invalid item indexes (no card/no item)
  5073. ep=sd->inventory_data[idx]->equip;
  5074. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5075. WFIFOW(fd,0)=0x017b;
  5076. for(i=c=0;i<MAX_INVENTORY;i++){
  5077. int j;
  5078. if(sd->inventory_data[i] == NULL)
  5079. continue;
  5080. if(sd->inventory_data[i]->type!=4 && sd->inventory_data[i]->type!=5) // 武器防具じゃない
  5081. continue;
  5082. if(sd->status.inventory[i].card[0]==0x00ff || sd->status.inventory[i].card[0]==(short)0xff00 || sd->status.inventory[i].card[0]==0x00fe)
  5083. continue;
  5084. if(sd->status.inventory[i].identify==0 ) // 未鑑定
  5085. continue;
  5086. if((sd->inventory_data[i]->equip&ep)==0) // 装備個所が違う
  5087. continue;
  5088. if(sd->inventory_data[i]->type==4 && ep==32) // 盾カードと両手武器
  5089. continue;
  5090. for(j=0;j<sd->inventory_data[i]->slot;j++){
  5091. if( sd->status.inventory[i].card[j]==0 )
  5092. break;
  5093. }
  5094. if(j==sd->inventory_data[i]->slot) // すでにカードが一杯
  5095. continue;
  5096. WFIFOW(fd,4+c*2)=i+2;
  5097. c++;
  5098. }
  5099. WFIFOW(fd,2)=4+c*2;
  5100. WFIFOSET(fd,WFIFOW(fd,2));
  5101. return 0;
  5102. }
  5103. /*==========================================
  5104. * カードの挿入終了
  5105. *------------------------------------------
  5106. */
  5107. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5108. {
  5109. int fd;
  5110. nullpo_retr(0, sd);
  5111. fd=sd->fd;
  5112. WFIFOHEAD(fd,packet_len_table[0x17d]);
  5113. WFIFOW(fd,0)=0x17d;
  5114. WFIFOW(fd,2)=idx_equip+2;
  5115. WFIFOW(fd,4)=idx_card+2;
  5116. WFIFOB(fd,6)=flag;
  5117. WFIFOSET(fd,packet_len_table[0x17d]);
  5118. return 0;
  5119. }
  5120. /*==========================================
  5121. * 鑑定可能アイテムリスト送信
  5122. *------------------------------------------
  5123. */
  5124. int clif_item_identify_list(struct map_session_data *sd)
  5125. {
  5126. int i,c;
  5127. int fd;
  5128. nullpo_retr(0, sd);
  5129. fd=sd->fd;
  5130. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5131. WFIFOW(fd,0)=0x177;
  5132. for(i=c=0;i<MAX_INVENTORY;i++){
  5133. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){
  5134. WFIFOW(fd,c*2+4)=i+2;
  5135. c++;
  5136. }
  5137. }
  5138. if(c > 0) {
  5139. WFIFOW(fd,2)=c*2+4;
  5140. WFIFOSET(fd,WFIFOW(fd,2));
  5141. sd->menuskill_id = MC_IDENTIFY;
  5142. sd->menuskill_lv = c;
  5143. }
  5144. return 0;
  5145. }
  5146. /*==========================================
  5147. * 鑑定結果
  5148. *------------------------------------------
  5149. */
  5150. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5151. {
  5152. int fd;
  5153. nullpo_retr(0, sd);
  5154. fd=sd->fd;
  5155. WFIFOHEAD(fd,packet_len_table[0x179]);
  5156. WFIFOW(fd, 0)=0x179;
  5157. WFIFOW(fd, 2)=idx+2;
  5158. WFIFOB(fd, 4)=flag;
  5159. WFIFOSET(fd,packet_len_table[0x179]);
  5160. return 0;
  5161. }
  5162. /*==========================================
  5163. * 修理可能アイテムリスト送信
  5164. *------------------------------------------
  5165. */
  5166. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  5167. {
  5168. int i,c;
  5169. int fd;
  5170. int nameid;
  5171. nullpo_retr(0, sd);
  5172. nullpo_retr(0, dstsd);
  5173. fd=sd->fd;
  5174. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5175. WFIFOW(fd,0)=0x1fc;
  5176. for(i=c=0;i<MAX_INVENTORY;i++){
  5177. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5178. WFIFOW(fd,c*13+4) = i;
  5179. WFIFOW(fd,c*13+6) = nameid;
  5180. WFIFOL(fd,c*13+8) = sd->status.char_id;
  5181. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  5182. WFIFOB(fd,c*13+16)= c;
  5183. c++;
  5184. }
  5185. }
  5186. if(c > 0) {
  5187. WFIFOW(fd,2)=c*13+4;
  5188. WFIFOSET(fd,WFIFOW(fd,2));
  5189. sd->menuskill_id = BS_REPAIRWEAPON;
  5190. sd->menuskill_lv = dstsd->bl.id;
  5191. }else
  5192. clif_skill_fail(sd,sd->skillid,0,0);
  5193. return 0;
  5194. }
  5195. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  5196. {
  5197. int view,fd;
  5198. nullpo_retr(0, sd);
  5199. fd=sd->fd;
  5200. WFIFOHEAD(fd,packet_len_table[0x1fe]);
  5201. WFIFOW(fd, 0)=0x1fe;
  5202. if((view = itemdb_viewid(nameid)) > 0)
  5203. WFIFOW(fd, 2)=view;
  5204. else
  5205. WFIFOW(fd, 2)=nameid;
  5206. WFIFOB(fd, 4)=flag;
  5207. WFIFOSET(fd,packet_len_table[0x1fe]);
  5208. return 0;
  5209. }
  5210. /*==========================================
  5211. * Weapon Refining - Taken from jAthena
  5212. *------------------------------------------
  5213. */
  5214. int clif_item_refine_list(struct map_session_data *sd)
  5215. {
  5216. int i,c;
  5217. int fd;
  5218. int skilllv;
  5219. int wlv;
  5220. int refine_item[5];
  5221. nullpo_retr(0, sd);
  5222. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  5223. fd=sd->fd;
  5224. refine_item[0] = -1;
  5225. refine_item[1] = pc_search_inventory(sd,1010);
  5226. refine_item[2] = pc_search_inventory(sd,1011);
  5227. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5228. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5229. WFIFOW(fd,0)=0x221;
  5230. for(i=c=0;i<MAX_INVENTORY;i++){
  5231. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  5232. sd->status.inventory[i].identify==1 && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5233. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  5234. WFIFOW(fd,c*13+ 4)=i+2;
  5235. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5236. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  5237. WFIFOW(fd,c*13+10)=0;
  5238. WFIFOB(fd,c*13+12)=c;
  5239. c++;
  5240. }
  5241. }
  5242. WFIFOW(fd,2)=c*13+4;
  5243. WFIFOSET(fd,WFIFOW(fd,2));
  5244. sd->menuskill_id = WS_WEAPONREFINE;
  5245. sd->menuskill_lv = skilllv;
  5246. return 0;
  5247. }
  5248. /*==========================================
  5249. * アイテムによる一時的なスキル効果
  5250. *------------------------------------------
  5251. */
  5252. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  5253. {
  5254. int fd;
  5255. nullpo_retr(0, sd);
  5256. fd=sd->fd;
  5257. WFIFOHEAD(fd,packet_len_table[0x147]);
  5258. WFIFOW(fd, 0)=0x147;
  5259. WFIFOW(fd, 2)=skillid;
  5260. WFIFOW(fd, 4)=skill_get_inf(skillid);
  5261. WFIFOW(fd, 6)=0;
  5262. WFIFOW(fd, 8)=skilllv;
  5263. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  5264. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  5265. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  5266. WFIFOB(fd,38)=0;
  5267. WFIFOSET(fd,packet_len_table[0x147]);
  5268. return 0;
  5269. }
  5270. /*==========================================
  5271. * カートにアイテム追加
  5272. *------------------------------------------
  5273. */
  5274. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5275. {
  5276. int view,fd;
  5277. unsigned char *buf;
  5278. nullpo_retr(0, sd);
  5279. fd=sd->fd;
  5280. WFIFOHEAD(fd,packet_len_table[0x124]);
  5281. buf=WFIFOP(fd,0);
  5282. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5283. return 1;
  5284. WBUFW(buf,0)=0x124;
  5285. WBUFW(buf,2)=n+2;
  5286. WBUFL(buf,4)=amount;
  5287. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5288. WBUFW(buf,8)=view;
  5289. else
  5290. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5291. WBUFB(buf,10)=sd->status.cart[n].identify;
  5292. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5293. WBUFB(buf,12)=sd->status.cart[n].refine;
  5294. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5295. WFIFOSET(fd,packet_len_table[0x124]);
  5296. return 0;
  5297. }
  5298. /*==========================================
  5299. * カートからアイテム削除
  5300. *------------------------------------------
  5301. */
  5302. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5303. {
  5304. int fd;
  5305. nullpo_retr(0, sd);
  5306. fd=sd->fd;
  5307. WFIFOHEAD(fd,packet_len_table[0x125]);
  5308. WFIFOW(fd,0)=0x125;
  5309. WFIFOW(fd,2)=n+2;
  5310. WFIFOL(fd,4)=amount;
  5311. WFIFOSET(fd,packet_len_table[0x125]);
  5312. return 0;
  5313. }
  5314. /*==========================================
  5315. * カートのアイテムリスト
  5316. *------------------------------------------
  5317. */
  5318. int clif_cart_itemlist(struct map_session_data *sd)
  5319. {
  5320. struct item_data *id;
  5321. int i,n,fd;
  5322. unsigned char *buf;
  5323. nullpo_retr(0, sd);
  5324. fd=sd->fd;
  5325. WFIFOHEAD(fd, MAX_CART * 18 + 4);
  5326. buf = WFIFOP(fd,0);
  5327. #if PACKETVER < 5
  5328. for(i=0,n=0;i<MAX_CART;i++){
  5329. if(sd->status.cart[i].nameid<=0)
  5330. continue;
  5331. id = itemdb_search(sd->status.cart[i].nameid);
  5332. if(itemdb_isequip2(id))
  5333. continue;
  5334. WBUFW(buf,n*10+4)=i+2;
  5335. if(id->view_id > 0)
  5336. WBUFW(buf,n*10+6)=id->view_id;
  5337. else
  5338. WBUFW(buf,n*10+6)=sd->status.cart[i].nameid;
  5339. WBUFB(buf,n*10+8)=itemtype(id->type);
  5340. WBUFB(buf,n*10+9)=sd->status.cart[i].identify;
  5341. WBUFW(buf,n*10+10)=sd->status.cart[i].amount;
  5342. WBUFW(buf,n*10+12)=0;
  5343. n++;
  5344. }
  5345. if(n){
  5346. WBUFW(buf,0)=0x123;
  5347. WBUFW(buf,2)=4+n*10;
  5348. WFIFOSET(fd,WFIFOW(fd,2));
  5349. }
  5350. #else
  5351. for(i=0,n=0;i<MAX_CART;i++){
  5352. if(sd->status.cart[i].nameid<=0)
  5353. continue;
  5354. id = itemdb_search(sd->status.cart[i].nameid);
  5355. if(itemdb_isequip2(id))
  5356. continue;
  5357. WBUFW(buf,n*18+4)=i+2;
  5358. if(id->view_id > 0)
  5359. WBUFW(buf,n*18+6)=id->view_id;
  5360. else
  5361. WBUFW(buf,n*18+6)=sd->status.cart[i].nameid;
  5362. WBUFB(buf,n*18+8)=itemtype(id->type);
  5363. WBUFB(buf,n*18+9)=sd->status.cart[i].identify;
  5364. WBUFW(buf,n*18+10)=sd->status.cart[i].amount;
  5365. WBUFW(buf,n*18+12)=0; //Here goes the equip location, which seems unnecessary to fill for the cart data.
  5366. clif_addcards(WBUFP(buf,n*18+14), &sd->status.cart[i]);
  5367. n++;
  5368. }
  5369. if(n){
  5370. WBUFW(buf,0)=0x1ef;
  5371. WBUFW(buf,2)=4+n*18;
  5372. WFIFOSET(fd,WFIFOW(fd,2));
  5373. }
  5374. #endif
  5375. return 0;
  5376. }
  5377. /*==========================================
  5378. * カートの装備品リスト
  5379. *------------------------------------------
  5380. */
  5381. int clif_cart_equiplist(struct map_session_data *sd)
  5382. {
  5383. struct item_data *id;
  5384. int i,n,fd;
  5385. unsigned char *buf;
  5386. nullpo_retr(0, sd);
  5387. fd=sd->fd;
  5388. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  5389. buf = WFIFOP(fd,0);
  5390. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5391. if(sd->status.cart[i].nameid<=0)
  5392. continue;
  5393. id = itemdb_search(sd->status.cart[i].nameid);
  5394. if(!itemdb_isequip2(id))
  5395. continue;
  5396. WBUFW(buf,n*20+4)=i+2;
  5397. if(id->view_id > 0)
  5398. WBUFW(buf,n*20+6)=id->view_id;
  5399. else
  5400. WBUFW(buf,n*20+6)=sd->status.cart[i].nameid;
  5401. WBUFB(buf,n*20+8)=itemtype(id->type);
  5402. WBUFB(buf,n*20+9)=sd->status.cart[i].identify;
  5403. WBUFW(buf,n*20+10)=id->equip;
  5404. WBUFW(buf,n*20+12)=sd->status.cart[i].equip;
  5405. WBUFB(buf,n*20+14)=sd->status.cart[i].attribute;
  5406. WBUFB(buf,n*20+15)=sd->status.cart[i].refine;
  5407. clif_addcards(WBUFP(buf, n*20+16), &sd->status.cart[i]);
  5408. n++;
  5409. }
  5410. if(n){
  5411. WBUFW(buf,0)=0x122;
  5412. WBUFW(buf,2)=4+n*20;
  5413. WFIFOSET(fd,WFIFOW(fd,2));
  5414. }
  5415. return 0;
  5416. }
  5417. /*==========================================
  5418. * 露店開設
  5419. *------------------------------------------
  5420. */
  5421. int clif_openvendingreq(struct map_session_data *sd,int num)
  5422. {
  5423. int fd;
  5424. nullpo_retr(0, sd);
  5425. fd=sd->fd;
  5426. WFIFOHEAD(fd,packet_len_table[0x12d]);
  5427. WFIFOW(fd,0)=0x12d;
  5428. WFIFOW(fd,2)=num;
  5429. WFIFOSET(fd,packet_len_table[0x12d]);
  5430. return 0;
  5431. }
  5432. /*==========================================
  5433. * 露店看板表示
  5434. *------------------------------------------
  5435. */
  5436. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  5437. {
  5438. unsigned char buf[128];
  5439. nullpo_retr(0, bl);
  5440. WBUFW(buf,0)=0x131;
  5441. WBUFL(buf,2)=bl->id;
  5442. strncpy((char*)WBUFP(buf,6),message,80);
  5443. if(fd){
  5444. WFIFOHEAD(fd,packet_len_table[0x131]);
  5445. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x131]);
  5446. WFIFOSET(fd,packet_len_table[0x131]);
  5447. }else{
  5448. clif_send(buf,packet_len_table[0x131],bl,AREA_WOS);
  5449. }
  5450. return 0;
  5451. }
  5452. /*==========================================
  5453. * 露店看板消去
  5454. *------------------------------------------
  5455. */
  5456. int clif_closevendingboard(struct block_list* bl,int fd)
  5457. {
  5458. unsigned char buf[16];
  5459. nullpo_retr(0, bl);
  5460. WBUFW(buf,0)=0x132;
  5461. WBUFL(buf,2)=bl->id;
  5462. if(fd){
  5463. WFIFOHEAD(fd,packet_len_table[0x132]);
  5464. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x132]);
  5465. WFIFOSET(fd,packet_len_table[0x132]);
  5466. }else{
  5467. clif_send(buf,packet_len_table[0x132],bl,AREA_WOS);
  5468. }
  5469. return 0;
  5470. }
  5471. /*==========================================
  5472. * 露店アイテムリスト
  5473. *------------------------------------------
  5474. */
  5475. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  5476. {
  5477. struct item_data *data;
  5478. int i,n,index,fd;
  5479. struct map_session_data *vsd;
  5480. unsigned char *buf;
  5481. nullpo_retr(0, sd);
  5482. nullpo_retr(0, vending);
  5483. nullpo_retr(0, vsd=map_id2sd(id));
  5484. fd=sd->fd;
  5485. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  5486. buf = WFIFOP(fd,0);
  5487. for(i=0,n=0;i<vsd->vend_num;i++){
  5488. if(vending[i].amount<=0)
  5489. continue;
  5490. WBUFL(buf,8+n*22)=vending[i].value;
  5491. WBUFW(buf,12+n*22)=vending[i].amount;
  5492. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  5493. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  5494. continue;
  5495. data = itemdb_search(vsd->status.cart[index].nameid);
  5496. WBUFB(buf,16+n*22)=itemtype(data->type);
  5497. if(data->view_id > 0)
  5498. WBUFW(buf,17+n*22)=data->view_id;
  5499. else
  5500. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  5501. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  5502. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  5503. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  5504. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  5505. n++;
  5506. }
  5507. if(n > 0){
  5508. WBUFW(buf,0)=0x133;
  5509. WBUFW(buf,2)=8+n*22;
  5510. WBUFL(buf,4)=id;
  5511. WFIFOSET(fd,WFIFOW(fd,2));
  5512. }
  5513. return 0;
  5514. }
  5515. /*==========================================
  5516. * 露店アイテム購入失敗
  5517. *------------------------------------------
  5518. */
  5519. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  5520. {
  5521. int fd;
  5522. nullpo_retr(0, sd);
  5523. fd=sd->fd;
  5524. WFIFOHEAD(fd,packet_len_table[0x135]);
  5525. WFIFOW(fd,0)=0x135;
  5526. WFIFOW(fd,2)=index+2;
  5527. WFIFOW(fd,4)=amount;
  5528. WFIFOB(fd,6)=fail;
  5529. WFIFOSET(fd,packet_len_table[0x135]);
  5530. return 0;
  5531. }
  5532. /*==========================================
  5533. * 露店開設成功
  5534. *------------------------------------------
  5535. */
  5536. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  5537. {
  5538. struct item_data *data;
  5539. int i,n,index,fd;
  5540. unsigned char *buf;
  5541. nullpo_retr(0, sd);
  5542. fd=sd->fd;
  5543. WFIFOHEAD(fd, 8+sd->vend_num*22);
  5544. buf = WFIFOP(fd,0);
  5545. for(i=0,n=0;i<sd->vend_num;i++){
  5546. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  5547. WBUFL(buf,8+n*22)=vending[i].value;
  5548. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  5549. WBUFW(buf,14+n*22)=vending[i].amount;
  5550. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || sd->status.cart[index].identify==0 ||
  5551. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  5552. continue;
  5553. data = itemdb_search(sd->status.cart[index].nameid);
  5554. WBUFB(buf,16+n*22)=itemtype(data->type);
  5555. if(data->view_id > 0)
  5556. WBUFW(buf,17+n*22)=data->view_id;
  5557. else
  5558. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  5559. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  5560. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  5561. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  5562. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  5563. n++;
  5564. }
  5565. if(n > 0){
  5566. WBUFW(buf,0)=0x136;
  5567. WBUFW(buf,2)=8+n*22;
  5568. WBUFL(buf,4)=id;
  5569. WFIFOSET(fd,WFIFOW(fd,2));
  5570. }
  5571. return n;
  5572. }
  5573. /*==========================================
  5574. * 露店アイテム販売報告
  5575. *------------------------------------------
  5576. */
  5577. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  5578. {
  5579. int fd;
  5580. nullpo_retr(0, sd);
  5581. fd=sd->fd;
  5582. WFIFOHEAD(fd,packet_len_table[0x137]);
  5583. WFIFOW(fd,0)=0x137;
  5584. WFIFOW(fd,2)=index+2;
  5585. WFIFOW(fd,4)=amount;
  5586. WFIFOSET(fd,packet_len_table[0x137]);
  5587. return 0;
  5588. }
  5589. /*==========================================
  5590. * パーティ作成完了
  5591. *------------------------------------------
  5592. */
  5593. int clif_party_created(struct map_session_data *sd,int flag)
  5594. {
  5595. int fd;
  5596. // printf("clif_party_message(%s, %d, %s)\n", p->name, account_id, mes);
  5597. nullpo_retr(0, sd);
  5598. fd=sd->fd;
  5599. WFIFOHEAD(fd,packet_len_table[0xfa]);
  5600. WFIFOW(fd,0)=0xfa;
  5601. WFIFOB(fd,2)=flag;
  5602. WFIFOSET(fd,packet_len_table[0xfa]);
  5603. return 0;
  5604. }
  5605. int clif_party_main_info(struct party *p, int fd)
  5606. {
  5607. struct map_session_data *sd;
  5608. int i;
  5609. unsigned char buf[96];
  5610. for (i=0; i<MAX_PARTY && !p->member[i].leader; i++);
  5611. if (i >= MAX_PARTY) return 0; //Should never happen...
  5612. sd = p->member[i].sd;
  5613. WBUFW(buf,0)=0x1e9;
  5614. WBUFL(buf,2)= p->member[i].account_id;
  5615. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  5616. WBUFW(buf,10)=sd?sd->bl.x:0;
  5617. WBUFW(buf,12)=sd?sd->bl.y:0;
  5618. WBUFB(buf,14)=(p->member[i].online)?0:1; //This byte is also unconfirmed...
  5619. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5620. memcpy(WBUFP(buf,39), p->member[i].name, NAME_LENGTH);
  5621. memcpy(WBUFP(buf,63), mapindex_id2name(p->member[i].map), MAP_NAME_LENGTH);
  5622. WBUFB(buf,79) = (p->item&1)?1:0;
  5623. WBUFB(buf,80) = (p->item&2)?1:0;
  5624. if(fd>=0){
  5625. WFIFOHEAD(fd,packet_len_table[0x1e9]);
  5626. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x1e9]);
  5627. WFIFOSET(fd,packet_len_table[0x1e9]);
  5628. return 1;
  5629. }
  5630. if (!sd) {
  5631. for (i=0; i<MAX_PARTY && !p->member[i].sd; i++)
  5632. if (i >= MAX_PARTY) return 0; //Should never happen...
  5633. sd=p->member[i].sd;
  5634. }
  5635. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY);
  5636. return 1;
  5637. }
  5638. /*==========================================
  5639. * パーティ情報送信
  5640. *------------------------------------------
  5641. */
  5642. int clif_party_info(struct party *p,int fd)
  5643. {
  5644. unsigned char buf[1024];
  5645. int i,c;
  5646. struct map_session_data *sd=NULL;
  5647. nullpo_retr(0, p);
  5648. WBUFW(buf,0)=0xfb;
  5649. memcpy(WBUFP(buf,4),p->name,NAME_LENGTH);
  5650. for(i=c=0;i<MAX_PARTY;i++){
  5651. struct party_member *m=&p->member[i];
  5652. if(m->account_id>0){
  5653. if(sd==NULL) sd=m->sd;
  5654. WBUFL(buf,28+c*46)=m->account_id;
  5655. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5656. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5657. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5658. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5659. c++;
  5660. }
  5661. }
  5662. WBUFW(buf,2)=28+c*46;
  5663. if(fd>=0){ // fdが設定されてるならそれに送る
  5664. WFIFOHEAD(fd, 28+c*46);
  5665. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5666. WFIFOSET(fd,WFIFOW(fd,2));
  5667. return 9;
  5668. }
  5669. if(sd!=NULL)
  5670. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5671. return 0;
  5672. }
  5673. /*==========================================
  5674. * パーティ勧誘
  5675. *------------------------------------------
  5676. */
  5677. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5678. {
  5679. int fd;
  5680. struct party *p;
  5681. nullpo_retr(0, sd);
  5682. nullpo_retr(0, tsd);
  5683. fd=tsd->fd;
  5684. if( (p=party_search(sd->status.party_id))==NULL )
  5685. return 0;
  5686. WFIFOHEAD(fd,packet_len_table[0xfe]);
  5687. WFIFOW(fd,0)=0xfe;
  5688. WFIFOL(fd,2)=sd->status.account_id;
  5689. memcpy(WFIFOP(fd,6),p->name,NAME_LENGTH);
  5690. WFIFOSET(fd,packet_len_table[0xfe]);
  5691. return 0;
  5692. }
  5693. /*==========================================
  5694. * パーティ勧誘結果
  5695. *------------------------------------------
  5696. */
  5697. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5698. {
  5699. int fd;
  5700. nullpo_retr(0, sd);
  5701. fd=sd->fd;
  5702. WFIFOHEAD(fd,packet_len_table[0xfd]);
  5703. WFIFOW(fd,0)=0xfd;
  5704. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5705. WFIFOB(fd,26)=flag;
  5706. WFIFOSET(fd,packet_len_table[0xfd]);
  5707. return 0;
  5708. }
  5709. /*==========================================
  5710. * パーティ設定送信
  5711. * flag & 0x001=exp変更ミス
  5712. * 0x010=item変更ミス
  5713. * 0x100=一人にのみ送信
  5714. *------------------------------------------
  5715. */
  5716. int clif_party_option(struct party *p,struct map_session_data *sd,int flag)
  5717. {
  5718. unsigned char buf[16];
  5719. nullpo_retr(0, p);
  5720. // if(battle_config.etc_log)
  5721. // printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
  5722. if(sd==NULL && flag==0){
  5723. int i;
  5724. for(i=0;i<MAX_PARTY;i++)
  5725. if((sd=map_id2sd(p->member[i].account_id))!=NULL)
  5726. break;
  5727. }
  5728. if(sd==NULL)
  5729. return 0;
  5730. WBUFW(buf,0)=0x101;
  5731. WBUFW(buf,2)=((flag&0x01)?2:p->exp);
  5732. WBUFW(buf,4)=0; //NOTE: We don't know yet what this is for, it is NOT for item share rules, though. [Skotlex]
  5733. if(flag==0)
  5734. clif_send(buf,packet_len_table[0x101],&sd->bl,PARTY);
  5735. else {
  5736. WFIFOHEAD(sd->fd,packet_len_table[0x101]);
  5737. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x101]);
  5738. WFIFOSET(sd->fd,packet_len_table[0x101]);
  5739. }
  5740. return 0;
  5741. }
  5742. /*==========================================
  5743. * パーティ脱退(脱退前に呼ぶこと)
  5744. *------------------------------------------
  5745. */
  5746. int clif_party_leaved(struct party *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5747. {
  5748. unsigned char buf[64];
  5749. int i;
  5750. nullpo_retr(0, p);
  5751. WBUFW(buf,0)=0x105;
  5752. WBUFL(buf,2)=account_id;
  5753. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5754. WBUFB(buf,30)=flag&0x0f;
  5755. if((flag&0xf0)==0){
  5756. if(sd==NULL)
  5757. for(i=0;i<MAX_PARTY;i++)
  5758. if((sd=p->member[i].sd)!=NULL)
  5759. break;
  5760. if (sd!=NULL)
  5761. clif_send(buf,packet_len_table[0x105],&sd->bl,PARTY);
  5762. } else if (sd!=NULL) {
  5763. WFIFOHEAD(sd->fd,packet_len_table[0x105]);
  5764. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x105]);
  5765. WFIFOSET(sd->fd,packet_len_table[0x105]);
  5766. }
  5767. return 0;
  5768. }
  5769. /*==========================================
  5770. * パーティメッセージ送信
  5771. *------------------------------------------
  5772. */
  5773. int clif_party_message(struct party *p,int account_id,char *mes,int len)
  5774. {
  5775. struct map_session_data *sd;
  5776. int i;
  5777. nullpo_retr(0, p);
  5778. for(i=0;i<MAX_PARTY;i++){
  5779. if((sd=p->member[i].sd)!=NULL)
  5780. break;
  5781. }
  5782. if(sd!=NULL){
  5783. unsigned char buf[1024];
  5784. WBUFW(buf,0)=0x109;
  5785. WBUFW(buf,2)=len+8;
  5786. WBUFL(buf,4)=account_id;
  5787. memcpy(WBUFP(buf,8),mes,len);
  5788. clif_send(buf,len+8,&sd->bl,PARTY);
  5789. }
  5790. return 0;
  5791. }
  5792. /*==========================================
  5793. * パーティ座標通知
  5794. *------------------------------------------
  5795. */
  5796. int clif_party_xy(struct map_session_data *sd)
  5797. {
  5798. unsigned char buf[16];
  5799. nullpo_retr(0, sd);
  5800. WBUFW(buf,0)=0x107;
  5801. WBUFL(buf,2)=sd->status.account_id;
  5802. WBUFW(buf,6)=sd->bl.x;
  5803. WBUFW(buf,8)=sd->bl.y;
  5804. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  5805. return 0;
  5806. }
  5807. /*==========================================
  5808. * Sends x/y dot to a single fd. [Skotlex]
  5809. *------------------------------------------
  5810. */
  5811. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5812. {
  5813. WFIFOHEAD(fd,packet_len_table[0x107]);
  5814. WFIFOW(fd,0)=0x107;
  5815. WFIFOL(fd,2)=sd->status.account_id;
  5816. WFIFOW(fd,6)=sd->bl.x;
  5817. WFIFOW(fd,8)=sd->bl.y;
  5818. WFIFOSET(fd,packet_len_table[0x107]);
  5819. return 0;
  5820. }
  5821. /*==========================================
  5822. * パーティHP通知
  5823. *------------------------------------------
  5824. */
  5825. int clif_party_hp(struct map_session_data *sd)
  5826. {
  5827. unsigned char buf[16];
  5828. nullpo_retr(0, sd);
  5829. WBUFW(buf,0)=0x106;
  5830. WBUFL(buf,2)=sd->status.account_id;
  5831. WBUFW(buf,6)=(sd->status.hp > 0x7fff)? 0x7fff:sd->status.hp;
  5832. WBUFW(buf,8)=(sd->status.max_hp > 0x7fff)? 0x7fff:sd->status.max_hp;
  5833. clif_send(buf,packet_len_table[0x106],&sd->bl,PARTY_AREA_WOS);
  5834. return 0;
  5835. }
  5836. /*==========================================
  5837. * Sends HP bar to a single fd. [Skotlex]
  5838. *------------------------------------------
  5839. */
  5840. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5841. {
  5842. WFIFOHEAD(fd,packet_len_table[0x106]);
  5843. WFIFOW(fd,0) = 0x106;
  5844. WFIFOL(fd,2) = sd->status.account_id;
  5845. WFIFOW(fd,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5846. WFIFOW(fd,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5847. WFIFOSET (fd, packet_len_table[0x106]);
  5848. }
  5849. /*==========================================
  5850. * GMへ場所とHP通知
  5851. *------------------------------------------
  5852. */
  5853. int clif_hpmeter(struct map_session_data *sd)
  5854. {
  5855. struct map_session_data *sd2;
  5856. unsigned char buf[16];
  5857. int i, x0, y0, x1, y1;
  5858. int level;
  5859. nullpo_retr(0, sd);
  5860. x0 = sd->bl.x - AREA_SIZE;
  5861. y0 = sd->bl.y - AREA_SIZE;
  5862. x1 = sd->bl.x + AREA_SIZE;
  5863. y1 = sd->bl.y + AREA_SIZE;
  5864. WBUFW(buf,0) = 0x106;
  5865. WBUFL(buf,2) = sd->status.account_id;
  5866. WBUFW(buf,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5867. WBUFW(buf,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5868. for (i = 0; i < fd_max; i++) {
  5869. if (session[i] && (sd2 = (struct map_session_data*)session[i]->session_data) && sd != sd2 && sd2->state.auth) {
  5870. if (sd2->bl.m != sd->bl.m ||
  5871. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5872. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5873. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5874. level < pc_isGM(sd))
  5875. continue;
  5876. WFIFOHEAD (i, packet_len_table[0x106]);
  5877. memcpy (WFIFOP(i,0), buf, packet_len_table[0x106]);
  5878. WFIFOSET (i, packet_len_table[0x106]);
  5879. }
  5880. }
  5881. return 0;
  5882. }
  5883. /*==========================================
  5884. * パーティ場所移動(未使用)
  5885. *------------------------------------------
  5886. */
  5887. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5888. {
  5889. unsigned char buf[128];
  5890. nullpo_retr(0, sd);
  5891. nullpo_retr(0, p);
  5892. WBUFW(buf, 0)=0x104;
  5893. WBUFL(buf, 2)=sd->status.account_id;
  5894. WBUFL(buf, 6)=0;
  5895. WBUFW(buf,10)=sd->bl.x;
  5896. WBUFW(buf,12)=sd->bl.y;
  5897. WBUFB(buf,14)=!online;
  5898. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5899. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5900. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5901. clif_send(buf,packet_len_table[0x104],&sd->bl,PARTY);
  5902. return 0;
  5903. }
  5904. /*==========================================
  5905. * 攻撃するために移動が必要
  5906. *------------------------------------------
  5907. */
  5908. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5909. {
  5910. int fd;
  5911. nullpo_retr(0, sd);
  5912. nullpo_retr(0, bl);
  5913. fd=sd->fd;
  5914. WFIFOHEAD(fd,packet_len_table[0x139]);
  5915. WFIFOW(fd, 0)=0x139;
  5916. WFIFOL(fd, 2)=bl->id;
  5917. WFIFOW(fd, 6)=bl->x;
  5918. WFIFOW(fd, 8)=bl->y;
  5919. WFIFOW(fd,10)=sd->bl.x;
  5920. WFIFOW(fd,12)=sd->bl.y;
  5921. WFIFOW(fd,14)=sd->attackrange;
  5922. WFIFOSET(fd,packet_len_table[0x139]);
  5923. return 0;
  5924. }
  5925. /*==========================================
  5926. * 製造エフェクト
  5927. *------------------------------------------
  5928. */
  5929. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5930. {
  5931. int view,fd;
  5932. nullpo_retr(0, sd);
  5933. fd=sd->fd;
  5934. // 名前の登録と送信を先にしておく
  5935. if( map_charid2nick(sd->status.char_id)==NULL )
  5936. map_addchariddb(sd->status.char_id,sd->status.name);
  5937. clif_solved_charname(sd,sd->status.char_id);
  5938. WFIFOHEAD(fd,packet_len_table[0x18f]);
  5939. WFIFOW(fd, 0)=0x18f;
  5940. WFIFOW(fd, 2)=flag;
  5941. if((view = itemdb_viewid(nameid)) > 0)
  5942. WFIFOW(fd, 4)=view;
  5943. else
  5944. WFIFOW(fd, 4)=nameid;
  5945. WFIFOSET(fd,packet_len_table[0x18f]);
  5946. return 0;
  5947. }
  5948. // pet
  5949. int clif_catch_process(struct map_session_data *sd)
  5950. {
  5951. int fd;
  5952. nullpo_retr(0, sd);
  5953. fd=sd->fd;
  5954. WFIFOHEAD(fd,packet_len_table[0x19e]);
  5955. WFIFOW(fd,0)=0x19e;
  5956. WFIFOSET(fd,packet_len_table[0x19e]);
  5957. return 0;
  5958. }
  5959. int clif_pet_rulet(struct map_session_data *sd,int data)
  5960. {
  5961. int fd;
  5962. nullpo_retr(0, sd);
  5963. fd=sd->fd;
  5964. WFIFOHEAD(fd,packet_len_table[0x1a0]);
  5965. WFIFOW(fd,0)=0x1a0;
  5966. WFIFOB(fd,2)=data;
  5967. WFIFOSET(fd,packet_len_table[0x1a0]);
  5968. return 0;
  5969. }
  5970. /*==========================================
  5971. * pet卵リスト作成
  5972. *------------------------------------------
  5973. */
  5974. int clif_sendegg(struct map_session_data *sd)
  5975. {
  5976. //R 01a6 <len>.w <index>.w*
  5977. int i,n=0,fd;
  5978. nullpo_retr(0, sd);
  5979. fd=sd->fd;
  5980. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5981. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5982. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5983. return 0;
  5984. }
  5985. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5986. WFIFOW(fd,0)=0x1a6;
  5987. if(sd->status.pet_id <= 0) {
  5988. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5989. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5990. sd->inventory_data[i]->type!=7 ||
  5991. sd->status.inventory[i].amount<=0)
  5992. continue;
  5993. WFIFOW(fd,n*2+4)=i+2;
  5994. n++;
  5995. }
  5996. }
  5997. WFIFOW(fd,2)=4+n*2;
  5998. WFIFOSET(fd,WFIFOW(fd,2));
  5999. sd->menuskill_id = SA_TAMINGMONSTER;
  6000. sd->menuskill_lv = n;
  6001. return 0;
  6002. }
  6003. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  6004. {
  6005. int fd;
  6006. nullpo_retr(0, sd);
  6007. nullpo_retr(0, sd->pd);
  6008. fd=sd->fd;
  6009. WFIFOHEAD(fd,packet_len_table[0x1a4]);
  6010. WFIFOW(fd,0)=0x1a4;
  6011. WFIFOB(fd,2)=type;
  6012. WFIFOL(fd,3)=sd->pd->bl.id;
  6013. WFIFOL(fd,7)=param;
  6014. WFIFOSET(fd,packet_len_table[0x1a4]);
  6015. return 0;
  6016. }
  6017. int clif_send_petstatus(struct map_session_data *sd)
  6018. {
  6019. int fd;
  6020. nullpo_retr(0, sd);
  6021. fd=sd->fd;
  6022. WFIFOHEAD(fd,packet_len_table[0x1a2]);
  6023. WFIFOW(fd,0)=0x1a2;
  6024. memcpy(WFIFOP(fd,2),sd->pet.name,NAME_LENGTH);
  6025. WFIFOB(fd,26)=(battle_config.pet_rename == 1)? 0:sd->pet.rename_flag;
  6026. WFIFOW(fd,27)=sd->pet.level;
  6027. WFIFOW(fd,29)=sd->pet.hungry;
  6028. WFIFOW(fd,31)=sd->pet.intimate;
  6029. WFIFOW(fd,33)=sd->pet.equip;
  6030. WFIFOSET(fd,packet_len_table[0x1a2]);
  6031. return 0;
  6032. }
  6033. /*==========================================
  6034. *
  6035. *------------------------------------------
  6036. */
  6037. int clif_pet_emotion(struct pet_data *pd,int param)
  6038. {
  6039. unsigned char buf[16];
  6040. struct map_session_data *sd;
  6041. nullpo_retr(0, pd);
  6042. nullpo_retr(0, sd = pd->msd);
  6043. memset(buf,0,packet_len_table[0x1aa]);
  6044. WBUFW(buf,0)=0x1aa;
  6045. WBUFL(buf,2)=pd->bl.id;
  6046. if(param >= 100 && sd->petDB->talk_convert_class) {
  6047. if(sd->petDB->talk_convert_class < 0)
  6048. return 0;
  6049. else if(sd->petDB->talk_convert_class > 0) {
  6050. param -= (pd->class_ - 100)*100;
  6051. param += (sd->petDB->talk_convert_class - 100)*100;
  6052. }
  6053. }
  6054. WBUFL(buf,6)=param;
  6055. clif_send(buf,packet_len_table[0x1aa],&pd->bl,AREA);
  6056. return 0;
  6057. }
  6058. int clif_pet_performance(struct block_list *bl,int param)
  6059. {
  6060. unsigned char buf[16];
  6061. nullpo_retr(0, bl);
  6062. memset(buf,0,packet_len_table[0x1a4]);
  6063. WBUFW(buf,0)=0x1a4;
  6064. WBUFB(buf,2)=4;
  6065. WBUFL(buf,3)=bl->id;
  6066. WBUFL(buf,7)=param;
  6067. clif_send(buf,packet_len_table[0x1a4],bl,AREA);
  6068. return 0;
  6069. }
  6070. int clif_pet_equip(struct pet_data *pd,int nameid)
  6071. {
  6072. unsigned char buf[16];
  6073. int view;
  6074. nullpo_retr(0, pd);
  6075. memset(buf,0,packet_len_table[0x1a4]);
  6076. WBUFW(buf,0)=0x1a4;
  6077. WBUFB(buf,2)=3;
  6078. WBUFL(buf,3)=pd->bl.id;
  6079. if(nameid && (view = itemdb_viewid(nameid)) > 0)
  6080. WBUFL(buf,7)=view;
  6081. else
  6082. WBUFL(buf,7)=nameid;
  6083. clif_send(buf,packet_len_table[0x1a4],&pd->bl,AREA);
  6084. return 0;
  6085. }
  6086. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6087. {
  6088. int fd;
  6089. nullpo_retr(0, sd);
  6090. fd=sd->fd;
  6091. WFIFOHEAD(fd,packet_len_table[0x1a3]);
  6092. WFIFOW(fd,0)=0x1a3;
  6093. WFIFOB(fd,2)=fail;
  6094. WFIFOW(fd,3)=foodid;
  6095. WFIFOSET(fd,packet_len_table[0x1a3]);
  6096. return 0;
  6097. }
  6098. /*==========================================
  6099. * オートスペル リスト送信
  6100. *------------------------------------------
  6101. */
  6102. int clif_autospell(struct map_session_data *sd,int skilllv)
  6103. {
  6104. int fd;
  6105. nullpo_retr(0, sd);
  6106. fd=sd->fd;
  6107. WFIFOHEAD(fd,packet_len_table[0x1cd]);
  6108. WFIFOW(fd, 0)=0x1cd;
  6109. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6110. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6111. else
  6112. WFIFOL(fd,2)= 0x00000000;
  6113. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6114. WFIFOL(fd,6)= MG_COLDBOLT;
  6115. else
  6116. WFIFOL(fd,6)= 0x00000000;
  6117. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6118. WFIFOL(fd,10)= MG_FIREBOLT;
  6119. else
  6120. WFIFOL(fd,10)= 0x00000000;
  6121. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6122. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6123. else
  6124. WFIFOL(fd,14)= 0x00000000;
  6125. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6126. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6127. else
  6128. WFIFOL(fd,18)= 0x00000000;
  6129. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6130. WFIFOL(fd,22)= MG_FIREBALL;
  6131. else
  6132. WFIFOL(fd,22)= 0x00000000;
  6133. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6134. WFIFOL(fd,26)= MG_FROSTDIVER;
  6135. else
  6136. WFIFOL(fd,26)= 0x00000000;
  6137. WFIFOSET(fd,packet_len_table[0x1cd]);
  6138. sd->menuskill_id = SA_AUTOSPELL;
  6139. sd->menuskill_lv = skilllv;
  6140. return 0;
  6141. }
  6142. /*==========================================
  6143. * ディボーションの青い糸
  6144. *------------------------------------------
  6145. */
  6146. int clif_devotion(struct map_session_data *sd)
  6147. {
  6148. unsigned char buf[56];
  6149. int i,n;
  6150. nullpo_retr(0, sd);
  6151. WBUFW(buf,0)=0x1cf;
  6152. WBUFL(buf,2)=sd->bl.id;
  6153. for(i=0,n=0;i<5;i++) {
  6154. if (!sd->devotion[i])
  6155. continue;
  6156. WBUFL(buf,6+4*n)=sd->devotion[i];
  6157. n++;
  6158. }
  6159. for(;n<5;n++)
  6160. WBUFL(buf,6+4*n)=0;
  6161. WBUFB(buf,26)=8;
  6162. WBUFB(buf,27)=0;
  6163. clif_send(buf,packet_len_table[0x1cf],&sd->bl,AREA);
  6164. return 0;
  6165. }
  6166. int clif_marionette(struct block_list *src, struct block_list *target)
  6167. {
  6168. unsigned char buf[56];
  6169. int n;
  6170. WBUFW(buf,0)=0x1cf;
  6171. WBUFL(buf,2)=src->id;
  6172. for(n=0;n<5;n++)
  6173. WBUFL(buf,6+4*n)=0;
  6174. if (target) //The target goes on the second slot.
  6175. WBUFL(buf,6+4) = target->id;
  6176. WBUFB(buf,26)=8;
  6177. WBUFB(buf,27)=0;
  6178. clif_send(buf,packet_len_table[0x1cf],src,AREA);
  6179. return 0;
  6180. }
  6181. /*==========================================
  6182. * 氣球
  6183. *------------------------------------------
  6184. */
  6185. int clif_spiritball(struct map_session_data *sd)
  6186. {
  6187. unsigned char buf[16];
  6188. nullpo_retr(0, sd);
  6189. WBUFW(buf,0)=0x1d0;
  6190. WBUFL(buf,2)=sd->bl.id;
  6191. WBUFW(buf,6)=sd->spiritball;
  6192. clif_send(buf,packet_len_table[0x1d0],&sd->bl,AREA);
  6193. return 0;
  6194. }
  6195. /*==========================================
  6196. *
  6197. *------------------------------------------
  6198. */
  6199. int clif_combo_delay(struct block_list *bl,int wait)
  6200. {
  6201. unsigned char buf[32];
  6202. nullpo_retr(0, bl);
  6203. WBUFW(buf,0)=0x1d2;
  6204. WBUFL(buf,2)=bl->id;
  6205. WBUFL(buf,6)=wait;
  6206. clif_send(buf,packet_len_table[0x1d2],bl,AREA);
  6207. return 0;
  6208. }
  6209. /*==========================================
  6210. *白刃取り
  6211. *------------------------------------------
  6212. */
  6213. int clif_bladestop(struct block_list *src,struct block_list *dst,
  6214. int _bool)
  6215. {
  6216. unsigned char buf[32];
  6217. nullpo_retr(0, src);
  6218. nullpo_retr(0, dst);
  6219. WBUFW(buf,0)=0x1d1;
  6220. WBUFL(buf,2)=src->id;
  6221. WBUFL(buf,6)=dst->id;
  6222. WBUFL(buf,10)=_bool;
  6223. clif_send(buf,packet_len_table[0x1d1],src,AREA);
  6224. return 0;
  6225. }
  6226. /*==========================================
  6227. *
  6228. *------------------------------------------
  6229. */
  6230. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  6231. {
  6232. struct block_list bl;
  6233. unsigned char buf[32];
  6234. bl.m = m;
  6235. bl.x = x;
  6236. bl.y = y;
  6237. WBUFW(buf,0) = 0x192;
  6238. WBUFW(buf,2) = x;
  6239. WBUFW(buf,4) = y;
  6240. WBUFW(buf,6) = cell_type;
  6241. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  6242. if(!type)
  6243. clif_send(buf,packet_len_table[0x192],&bl,AREA);
  6244. else
  6245. clif_send(buf,packet_len_table[0x192],&bl,ALL_SAMEMAP);
  6246. return 0;
  6247. }
  6248. /*==========================================
  6249. * MVPエフェクト
  6250. *------------------------------------------
  6251. */
  6252. int clif_mvp_effect(struct map_session_data *sd)
  6253. {
  6254. unsigned char buf[16];
  6255. nullpo_retr(0, sd);
  6256. WBUFW(buf,0)=0x10c;
  6257. WBUFL(buf,2)=sd->bl.id;
  6258. clif_send(buf,packet_len_table[0x10c],&sd->bl,AREA);
  6259. return 0;
  6260. }
  6261. /*==========================================
  6262. * MVPアイテム所得
  6263. *------------------------------------------
  6264. */
  6265. int clif_mvp_item(struct map_session_data *sd,int nameid)
  6266. {
  6267. int view,fd;
  6268. nullpo_retr(0, sd);
  6269. fd=sd->fd;
  6270. WFIFOHEAD(fd,packet_len_table[0x10a]);
  6271. WFIFOW(fd,0)=0x10a;
  6272. if((view = itemdb_viewid(nameid)) > 0)
  6273. WFIFOW(fd,2)=view;
  6274. else
  6275. WFIFOW(fd,2)=nameid;
  6276. WFIFOSET(fd,packet_len_table[0x10a]);
  6277. return 0;
  6278. }
  6279. /*==========================================
  6280. * MVP経験値所得
  6281. *------------------------------------------
  6282. */
  6283. int clif_mvp_exp(struct map_session_data *sd,int exp)
  6284. {
  6285. int fd;
  6286. nullpo_retr(0, sd);
  6287. fd=sd->fd;
  6288. WFIFOHEAD(fd,packet_len_table[0x10b]);
  6289. WFIFOW(fd,0)=0x10b;
  6290. WFIFOL(fd,2)=exp;
  6291. WFIFOSET(fd,packet_len_table[0x10b]);
  6292. return 0;
  6293. }
  6294. /*==========================================
  6295. * ギルド作成可否通知
  6296. *------------------------------------------
  6297. */
  6298. int clif_guild_created(struct map_session_data *sd,int flag)
  6299. {
  6300. int fd;
  6301. nullpo_retr(0, sd);
  6302. fd=sd->fd;
  6303. WFIFOHEAD(fd,packet_len_table[0x167]);
  6304. WFIFOW(fd,0)=0x167;
  6305. WFIFOB(fd,2)=flag;
  6306. WFIFOSET(fd,packet_len_table[0x167]);
  6307. return 0;
  6308. }
  6309. /*==========================================
  6310. * ギルド所属通知
  6311. *------------------------------------------
  6312. */
  6313. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  6314. {
  6315. int ps,fd;
  6316. nullpo_retr(0, sd);
  6317. nullpo_retr(0, g);
  6318. fd=sd->fd;
  6319. ps=guild_getposition(sd,g);
  6320. WFIFOHEAD(fd,packet_len_table[0x16c]);
  6321. memset(WFIFOP(fd,0),0,packet_len_table[0x16c]);
  6322. WFIFOW(fd,0)=0x16c;
  6323. WFIFOL(fd,2)=g->guild_id;
  6324. WFIFOL(fd,6)=g->emblem_id;
  6325. WFIFOL(fd,10)=g->position[ps].mode;
  6326. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6327. WFIFOSET(fd,packet_len_table[0x16c]);
  6328. return 0;
  6329. }
  6330. /*==========================================
  6331. * ギルドメンバログイン通知
  6332. *------------------------------------------
  6333. */
  6334. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6335. {
  6336. unsigned char buf[64];
  6337. nullpo_retr(0, g);
  6338. // printf("clif_guild_message(%s, %d, %s)\n", g->name, account_id, mes);
  6339. WBUFW(buf, 0)=0x16d;
  6340. WBUFL(buf, 2)=g->member[idx].account_id;
  6341. WBUFL(buf, 6)=g->member[idx].char_id;
  6342. WBUFL(buf,10)=flag;
  6343. if(g->member[idx].sd==NULL){
  6344. struct map_session_data *sd=guild_getavailablesd(g);
  6345. if(sd!=NULL)
  6346. clif_send(buf,packet_len_table[0x16d],&sd->bl,GUILD);
  6347. }else
  6348. clif_send(buf,packet_len_table[0x16d],&g->member[idx].sd->bl,GUILD_WOS);
  6349. return 0;
  6350. }
  6351. /*==========================================
  6352. * ギルドマスター通知(14dへの応答)
  6353. *------------------------------------------
  6354. */
  6355. int clif_guild_masterormember(struct map_session_data *sd)
  6356. {
  6357. int type=0x57,fd;
  6358. nullpo_retr(0, sd);
  6359. fd=sd->fd;
  6360. if(sd->state.gmaster_flag)
  6361. type=0xd7;
  6362. WFIFOHEAD(fd,packet_len_table[0x14e]);
  6363. WFIFOW(fd,0)=0x14e;
  6364. WFIFOL(fd,2)=type;
  6365. WFIFOSET(fd,packet_len_table[0x14e]);
  6366. return 0;
  6367. }
  6368. /*==========================================
  6369. * Basic Info (Territories [Valaris])
  6370. *------------------------------------------
  6371. */
  6372. int clif_guild_basicinfo(struct map_session_data *sd)
  6373. {
  6374. int fd,i,t=0;
  6375. struct guild *g;
  6376. struct guild_castle *gc=NULL;
  6377. nullpo_retr(0, sd);
  6378. fd=sd->fd;
  6379. g=guild_search(sd->status.guild_id);
  6380. if(g==NULL)
  6381. return 0;
  6382. WFIFOHEAD(fd,packet_len_table[0x1b6]);
  6383. WFIFOW(fd, 0)=0x1b6;//0x150;
  6384. WFIFOL(fd, 2)=g->guild_id;
  6385. WFIFOL(fd, 6)=g->guild_lv;
  6386. WFIFOL(fd,10)=g->connect_member;
  6387. WFIFOL(fd,14)=g->max_member;
  6388. WFIFOL(fd,18)=g->average_lv;
  6389. WFIFOL(fd,22)=g->exp;
  6390. WFIFOL(fd,26)=g->next_exp;
  6391. WFIFOL(fd,30)=0; // 上納
  6392. WFIFOL(fd,34)=0; // VW(性格の悪さ?:性向グラフ左右)
  6393. WFIFOL(fd,38)=0; // RF(正義の度合い?:性向グラフ上下)
  6394. WFIFOL(fd,42)=0; // 人数?
  6395. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6396. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6397. for(i=0;i<MAX_GUILDCASTLE;i++){
  6398. gc=guild_castle_search(i);
  6399. if(!gc) continue;
  6400. if(g->guild_id == gc->guild_id) t++;
  6401. }
  6402. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  6403. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  6404. else
  6405. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  6406. WFIFOSET(fd,packet_len_table[WFIFOW(fd,0)]);
  6407. clif_guild_emblem(sd,g); // Guild emblem vanish fix [Valaris]
  6408. return 0;
  6409. }
  6410. /*==========================================
  6411. * ギルド同盟/敵対情報
  6412. *------------------------------------------
  6413. */
  6414. int clif_guild_allianceinfo(struct map_session_data *sd)
  6415. {
  6416. int fd,i,c;
  6417. struct guild *g;
  6418. nullpo_retr(0, sd);
  6419. fd=sd->fd;
  6420. g=guild_search(sd->status.guild_id);
  6421. if(g==NULL)
  6422. return 0;
  6423. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6424. WFIFOW(fd, 0)=0x14c;
  6425. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6426. struct guild_alliance *a=&g->alliance[i];
  6427. if(a->guild_id>0){
  6428. WFIFOL(fd,c*32+4)=a->opposition;
  6429. WFIFOL(fd,c*32+8)=a->guild_id;
  6430. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6431. c++;
  6432. }
  6433. }
  6434. WFIFOW(fd, 2)=c*32+4;
  6435. WFIFOSET(fd,WFIFOW(fd,2));
  6436. return 0;
  6437. }
  6438. /*==========================================
  6439. * ギルドメンバーリスト
  6440. *------------------------------------------
  6441. */
  6442. int clif_guild_memberlist(struct map_session_data *sd)
  6443. {
  6444. int fd;
  6445. int i,c;
  6446. struct guild *g;
  6447. nullpo_retr(0, sd);
  6448. fd=sd->fd;
  6449. if (!fd)
  6450. return 0;
  6451. g=guild_search(sd->status.guild_id);
  6452. if(g==NULL)
  6453. return 0;
  6454. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6455. WFIFOW(fd, 0)=0x154;
  6456. for(i=0,c=0;i<g->max_member;i++){
  6457. struct guild_member *m=&g->member[i];
  6458. if(m->account_id==0)
  6459. continue;
  6460. WFIFOL(fd,c*104+ 4)=m->account_id;
  6461. WFIFOL(fd,c*104+ 8)=m->char_id;
  6462. WFIFOW(fd,c*104+12)=m->hair;
  6463. WFIFOW(fd,c*104+14)=m->hair_color;
  6464. WFIFOW(fd,c*104+16)=m->gender;
  6465. WFIFOW(fd,c*104+18)=m->class_;
  6466. WFIFOW(fd,c*104+20)=m->lv;
  6467. WFIFOL(fd,c*104+22)=m->exp;
  6468. WFIFOL(fd,c*104+26)=m->online;
  6469. WFIFOL(fd,c*104+30)=m->position;
  6470. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  6471. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6472. c++;
  6473. }
  6474. WFIFOW(fd, 2)=c*104+4;
  6475. WFIFOSET(fd,WFIFOW(fd,2));
  6476. return 0;
  6477. }
  6478. /*==========================================
  6479. * ギルド役職名リスト
  6480. *------------------------------------------
  6481. */
  6482. int clif_guild_positionnamelist(struct map_session_data *sd)
  6483. {
  6484. int i,fd;
  6485. struct guild *g;
  6486. nullpo_retr(0, sd);
  6487. fd=sd->fd;
  6488. g=guild_search(sd->status.guild_id);
  6489. if(g==NULL)
  6490. return 0;
  6491. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6492. WFIFOW(fd, 0)=0x166;
  6493. for(i=0;i<MAX_GUILDPOSITION;i++){
  6494. WFIFOL(fd,i*28+4)=i;
  6495. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6496. }
  6497. WFIFOW(fd,2)=i*28+4;
  6498. WFIFOSET(fd,WFIFOW(fd,2));
  6499. return 0;
  6500. }
  6501. /*==========================================
  6502. * ギルド役職情報リスト
  6503. *------------------------------------------
  6504. */
  6505. int clif_guild_positioninfolist(struct map_session_data *sd)
  6506. {
  6507. int i,fd;
  6508. struct guild *g;
  6509. nullpo_retr(0, sd);
  6510. fd=sd->fd;
  6511. g=guild_search(sd->status.guild_id);
  6512. if(g==NULL)
  6513. return 0;
  6514. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6515. WFIFOW(fd, 0)=0x160;
  6516. for(i=0;i<MAX_GUILDPOSITION;i++){
  6517. struct guild_position *p=&g->position[i];
  6518. WFIFOL(fd,i*16+ 4)=i;
  6519. WFIFOL(fd,i*16+ 8)=p->mode;
  6520. WFIFOL(fd,i*16+12)=i;
  6521. WFIFOL(fd,i*16+16)=p->exp_mode;
  6522. }
  6523. WFIFOW(fd, 2)=i*16+4;
  6524. WFIFOSET(fd,WFIFOW(fd,2));
  6525. return 0;
  6526. }
  6527. /*==========================================
  6528. * ギルド役職変更通知
  6529. *------------------------------------------
  6530. */
  6531. int clif_guild_positionchanged(struct guild *g,int idx)
  6532. {
  6533. struct map_session_data *sd;
  6534. unsigned char buf[128];
  6535. nullpo_retr(0, g);
  6536. WBUFW(buf, 0)=0x174;
  6537. WBUFW(buf, 2)=44;
  6538. WBUFL(buf, 4)=idx;
  6539. WBUFL(buf, 8)=g->position[idx].mode;
  6540. WBUFL(buf,12)=idx;
  6541. WBUFL(buf,16)=g->position[idx].exp_mode;
  6542. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6543. if( (sd=guild_getavailablesd(g))!=NULL )
  6544. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6545. return 0;
  6546. }
  6547. /*==========================================
  6548. * ギルドメンバ変更通知
  6549. *------------------------------------------
  6550. */
  6551. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6552. {
  6553. struct map_session_data *sd;
  6554. unsigned char buf[64];
  6555. nullpo_retr(0, g);
  6556. WBUFW(buf, 0)=0x156;
  6557. WBUFW(buf, 2)=16;
  6558. WBUFL(buf, 4)=g->member[idx].account_id;
  6559. WBUFL(buf, 8)=g->member[idx].char_id;
  6560. WBUFL(buf,12)=g->member[idx].position;
  6561. if( (sd=guild_getavailablesd(g))!=NULL )
  6562. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6563. return 0;
  6564. }
  6565. /*==========================================
  6566. * ギルドエンブレム送信
  6567. *------------------------------------------
  6568. */
  6569. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6570. {
  6571. int fd;
  6572. nullpo_retr(0, sd);
  6573. nullpo_retr(0, g);
  6574. fd=sd->fd;
  6575. if(g->emblem_len<=0)
  6576. return 0;
  6577. WFIFOHEAD(fd,g->emblem_len+12);
  6578. WFIFOW(fd,0)=0x152;
  6579. WFIFOW(fd,2)=g->emblem_len+12;
  6580. WFIFOL(fd,4)=g->guild_id;
  6581. WFIFOL(fd,8)=g->emblem_id;
  6582. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6583. WFIFOSET(fd,WFIFOW(fd,2));
  6584. return 0;
  6585. }
  6586. /*==========================================
  6587. * ギルドスキル送信
  6588. *------------------------------------------
  6589. */
  6590. int clif_guild_skillinfo(struct map_session_data *sd)
  6591. {
  6592. int fd;
  6593. int i,id,c,up=1;
  6594. struct guild *g;
  6595. nullpo_retr(0, sd);
  6596. fd=sd->fd;
  6597. g=guild_search(sd->status.guild_id);
  6598. if(g==NULL)
  6599. return 0;
  6600. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6601. WFIFOW(fd,0)=0x0162;
  6602. WFIFOW(fd,4)=g->skill_point;
  6603. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6604. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6605. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6606. WFIFOW(fd,c*37+ 8) = guild_skill_get_inf(id);
  6607. WFIFOW(fd,c*37+10) = 0;
  6608. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6609. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6610. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6611. memset(WFIFOP(fd,c*37+18),0,24);
  6612. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6613. up = 1;
  6614. else
  6615. up = 0;
  6616. WFIFOB(fd,c*37+42)= up;
  6617. c++;
  6618. }
  6619. }
  6620. WFIFOW(fd,2)=c*37+6;
  6621. WFIFOSET(fd,WFIFOW(fd,2));
  6622. return 0;
  6623. }
  6624. /*==========================================
  6625. * ギルド告知送信
  6626. *------------------------------------------
  6627. */
  6628. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6629. {
  6630. int fd;
  6631. nullpo_retr(0, sd);
  6632. nullpo_retr(0, g);
  6633. fd = sd->fd;
  6634. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6635. return 0;
  6636. if (fd <= 0)
  6637. return 0;
  6638. if(*g->mes1==0 && *g->mes2==0)
  6639. return 0;
  6640. WFIFOHEAD(fd,packet_len_table[0x16f]);
  6641. WFIFOW(fd,0)=0x16f;
  6642. memcpy(WFIFOP(fd,2),g->mes1,60);
  6643. memcpy(WFIFOP(fd,62),g->mes2,120);
  6644. WFIFOSET(fd,packet_len_table[0x16f]);
  6645. return 0;
  6646. }
  6647. /*==========================================
  6648. * ギルドメンバ勧誘
  6649. *------------------------------------------
  6650. */
  6651. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6652. {
  6653. int fd;
  6654. nullpo_retr(0, sd);
  6655. nullpo_retr(0, g);
  6656. fd=sd->fd;
  6657. WFIFOHEAD(fd,packet_len_table[0x16a]);
  6658. WFIFOW(fd,0)=0x16a;
  6659. WFIFOL(fd,2)=g->guild_id;
  6660. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6661. WFIFOSET(fd,packet_len_table[0x16a]);
  6662. return 0;
  6663. }
  6664. /*==========================================
  6665. * ギルドメンバ勧誘結果
  6666. *------------------------------------------
  6667. */
  6668. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6669. {
  6670. int fd;
  6671. nullpo_retr(0, sd);
  6672. fd=sd->fd;
  6673. WFIFOHEAD(fd,packet_len_table[0x169]);
  6674. WFIFOW(fd,0)=0x169;
  6675. WFIFOB(fd,2)=flag;
  6676. WFIFOSET(fd,packet_len_table[0x169]);
  6677. return 0;
  6678. }
  6679. /*==========================================
  6680. * ギルドメンバ脱退通知
  6681. *------------------------------------------
  6682. */
  6683. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6684. {
  6685. unsigned char buf[128];
  6686. nullpo_retr(0, sd);
  6687. WBUFW(buf, 0)=0x15a;
  6688. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6689. memcpy(WBUFP(buf,26),mes,40);
  6690. clif_send(buf,packet_len_table[0x15a],&sd->bl,GUILD);
  6691. return 0;
  6692. }
  6693. /*==========================================
  6694. * ギルドメンバ追放通知
  6695. *------------------------------------------
  6696. */
  6697. int clif_guild_explusion(struct map_session_data *sd,const char *name,const char *mes,
  6698. int account_id)
  6699. {
  6700. unsigned char buf[128];
  6701. nullpo_retr(0, sd);
  6702. WBUFW(buf, 0)=0x15c;
  6703. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6704. memcpy(WBUFP(buf,26),mes,40);
  6705. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6706. clif_send(buf,packet_len_table[0x15c],&sd->bl,GUILD);
  6707. return 0;
  6708. }
  6709. /*==========================================
  6710. * ギルド追放メンバリスト
  6711. *------------------------------------------
  6712. */
  6713. int clif_guild_explusionlist(struct map_session_data *sd)
  6714. {
  6715. int fd;
  6716. int i,c;
  6717. struct guild *g;
  6718. nullpo_retr(0, sd);
  6719. fd=sd->fd;
  6720. g=guild_search(sd->status.guild_id);
  6721. if(g==NULL)
  6722. return 0;
  6723. WFIFOHEAD(fd,MAX_GUILDEXPLUSION * 88 + 4);
  6724. WFIFOW(fd,0)=0x163;
  6725. for(i=c=0;i<MAX_GUILDEXPLUSION;i++){
  6726. struct guild_explusion *e=&g->explusion[i];
  6727. if(e->account_id>0){
  6728. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6729. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6730. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6731. c++;
  6732. }
  6733. }
  6734. WFIFOW(fd,2)=c*88+4;
  6735. WFIFOSET(fd,WFIFOW(fd,2));
  6736. return 0;
  6737. }
  6738. /*==========================================
  6739. * ギルド会話
  6740. *------------------------------------------
  6741. */
  6742. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6743. {
  6744. struct map_session_data *sd;
  6745. unsigned char *buf;
  6746. buf = (unsigned char*)aCallocA(len + 4, sizeof(unsigned char));
  6747. WBUFW(buf, 0) = 0x17f;
  6748. WBUFW(buf, 2) = len + 4;
  6749. memcpy(WBUFP(buf,4), mes, len);
  6750. if ((sd = guild_getavailablesd(g)) != NULL)
  6751. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6752. if(buf) aFree(buf);
  6753. return 0;
  6754. }
  6755. /*==========================================
  6756. * ギルドスキル割り振り通知
  6757. *------------------------------------------
  6758. */
  6759. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6760. {
  6761. int fd;
  6762. nullpo_retr(0, sd);
  6763. fd=sd->fd;
  6764. WFIFOHEAD(fd,11);
  6765. WFIFOW(fd,0) = 0x10e;
  6766. WFIFOW(fd,2) = skill_num;
  6767. WFIFOW(fd,4) = lv;
  6768. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6769. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6770. WFIFOB(fd,10) = 1;
  6771. WFIFOSET(fd,11);
  6772. return 0;
  6773. }
  6774. /*==========================================
  6775. * ギルド同盟要請
  6776. *------------------------------------------
  6777. */
  6778. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6779. {
  6780. int fd;
  6781. nullpo_retr(0, sd);
  6782. fd=sd->fd;
  6783. WFIFOHEAD(fd,packet_len_table[0x171]);
  6784. WFIFOW(fd,0)=0x171;
  6785. WFIFOL(fd,2)=account_id;
  6786. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6787. WFIFOSET(fd,packet_len_table[0x171]);
  6788. return 0;
  6789. }
  6790. /*==========================================
  6791. * ギルド同盟結果
  6792. *------------------------------------------
  6793. */
  6794. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6795. {
  6796. int fd;
  6797. nullpo_retr(0, sd);
  6798. fd=sd->fd;
  6799. WFIFOHEAD(fd,packet_len_table[0x173]);
  6800. WFIFOW(fd,0)=0x173;
  6801. WFIFOL(fd,2)=flag;
  6802. WFIFOSET(fd,packet_len_table[0x173]);
  6803. return 0;
  6804. }
  6805. /*==========================================
  6806. * ギルド関係解消通知
  6807. *------------------------------------------
  6808. */
  6809. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6810. {
  6811. int fd;
  6812. nullpo_retr(0, sd);
  6813. fd = sd->fd;
  6814. if (fd <= 0)
  6815. return 0;
  6816. WFIFOHEAD(fd,packet_len_table[0x184]);
  6817. WFIFOW(fd,0)=0x184;
  6818. WFIFOL(fd,2)=guild_id;
  6819. WFIFOL(fd,6)=flag;
  6820. WFIFOSET(fd,packet_len_table[0x184]);
  6821. return 0;
  6822. }
  6823. /*==========================================
  6824. * ギルド敵対結果
  6825. *------------------------------------------
  6826. */
  6827. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6828. {
  6829. int fd;
  6830. nullpo_retr(0, sd);
  6831. fd=sd->fd;
  6832. WFIFOHEAD(fd,packet_len_table[0x181]);
  6833. WFIFOW(fd,0)=0x181;
  6834. WFIFOB(fd,2)=flag;
  6835. WFIFOSET(fd,packet_len_table[0x181]);
  6836. return 0;
  6837. }
  6838. /*==========================================
  6839. * ギルド関係追加
  6840. *------------------------------------------
  6841. */
  6842. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6843. {
  6844. unsigned char buf[64];
  6845. WBUFW(fd,0)=0x185;
  6846. WBUFL(fd,2)=g->alliance[idx].opposition;
  6847. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6848. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6849. clif_send(buf,packet_len_table[0x185],guild_getavailablesd(g),GUILD);
  6850. return 0;
  6851. }*/
  6852. /*==========================================
  6853. * ギルド解散通知
  6854. *------------------------------------------
  6855. */
  6856. int clif_guild_broken(struct map_session_data *sd,int flag)
  6857. {
  6858. int fd;
  6859. nullpo_retr(0, sd);
  6860. fd=sd->fd;
  6861. WFIFOHEAD(fd,packet_len_table[0x15e]);
  6862. WFIFOW(fd,0)=0x15e;
  6863. WFIFOL(fd,2)=flag;
  6864. WFIFOSET(fd,packet_len_table[0x15e]);
  6865. return 0;
  6866. }
  6867. /*==========================================
  6868. * エモーション
  6869. *------------------------------------------
  6870. */
  6871. void clif_emotion(struct block_list *bl,int type)
  6872. {
  6873. unsigned char buf[8];
  6874. nullpo_retv(bl);
  6875. WBUFW(buf,0)=0xc0;
  6876. WBUFL(buf,2)=bl->id;
  6877. WBUFB(buf,6)=type;
  6878. clif_send(buf,packet_len_table[0xc0],bl,AREA);
  6879. }
  6880. /*==========================================
  6881. * トーキーボックス
  6882. *------------------------------------------
  6883. */
  6884. void clif_talkiebox(struct block_list *bl,char* talkie)
  6885. {
  6886. unsigned char buf[86];
  6887. nullpo_retv(bl);
  6888. WBUFW(buf,0)=0x191;
  6889. WBUFL(buf,2)=bl->id;
  6890. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6891. clif_send(buf,packet_len_table[0x191],bl,AREA);
  6892. }
  6893. /*==========================================
  6894. * 結婚エフェクト
  6895. *------------------------------------------
  6896. */
  6897. void clif_wedding_effect(struct block_list *bl) {
  6898. unsigned char buf[6];
  6899. nullpo_retv(bl);
  6900. WBUFW(buf,0) = 0x1ea;
  6901. WBUFL(buf,2) = bl->id;
  6902. clif_send(buf, packet_len_table[0x1ea], bl, AREA);
  6903. }
  6904. /*==========================================
  6905. * あなたに逢いたい使用時名前叫び
  6906. *------------------------------------------
  6907. void clif_callpartner(struct map_session_data *sd)
  6908. {
  6909. unsigned char buf[26];
  6910. char *p;
  6911. nullpo_retv(sd);
  6912. if(sd->status.partner_id){
  6913. WBUFW(buf,0)=0x1e6;
  6914. p = map_charid2nick(sd->status.partner_id);
  6915. if(p){
  6916. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6917. }else{
  6918. map_reqchariddb(sd,sd->status.partner_id);
  6919. chrif_searchcharid(sd->status.partner_id);
  6920. WBUFB(buf,2) = 0;
  6921. }
  6922. clif_send(buf,packet_len_table[0x1e6],&sd->bl,AREA);
  6923. }
  6924. return;
  6925. }
  6926. */
  6927. /*==========================================
  6928. * Adopt baby [Celest]
  6929. *------------------------------------------
  6930. */
  6931. void clif_adopt_process(struct map_session_data *sd)
  6932. {
  6933. int fd;
  6934. nullpo_retv(sd);
  6935. fd=sd->fd;
  6936. WFIFOHEAD(fd,packet_len_table[0x1f8]);
  6937. WFIFOW(fd,0)=0x1f8;
  6938. WFIFOSET(fd,packet_len_table[0x1f8]);
  6939. }
  6940. /*==========================================
  6941. * Marry [DracoRPG]
  6942. *------------------------------------------
  6943. */
  6944. void clif_marriage_process(struct map_session_data *sd)
  6945. {
  6946. int fd;
  6947. nullpo_retv(sd);
  6948. fd=sd->fd;
  6949. WFIFOHEAD(fd,packet_len_table[0x1e4]);
  6950. WFIFOW(fd,0)=0x1e4;
  6951. WFIFOSET(fd,packet_len_table[0x1e4]);
  6952. }
  6953. /*==========================================
  6954. * Notice of divorce
  6955. *------------------------------------------
  6956. */
  6957. void clif_divorced(struct map_session_data *sd, char *name)
  6958. {
  6959. int fd;
  6960. nullpo_retv(sd);
  6961. fd=sd->fd;
  6962. WFIFOHEAD(fd,packet_len_table[0x205]);
  6963. WFIFOW(fd,0)=0x205;
  6964. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6965. WFIFOSET(fd, packet_len_table[0x205]);
  6966. }
  6967. /*==========================================
  6968. *
  6969. *------------------------------------------
  6970. */
  6971. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6972. nullpo_retv(sd);
  6973. WFIFOHEAD(fd,packet_len_table[0x1f6]);
  6974. WFIFOW(fd,0)=0x1f6;
  6975. WFIFOSET(fd, packet_len_table[0x1f6]);
  6976. }
  6977. /*==========================================
  6978. *
  6979. *------------------------------------------
  6980. */
  6981. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6982. nullpo_retv(sd);
  6983. WFIFOHEAD(fd,packet_len_table[0x1e2]);
  6984. WFIFOW(fd,0)=0x1e2;
  6985. WFIFOSET(fd, packet_len_table[0x1e2]);
  6986. }
  6987. /*==========================================
  6988. * 座る
  6989. *------------------------------------------
  6990. */
  6991. void clif_sitting(struct map_session_data *sd)
  6992. {
  6993. unsigned char buf[64];
  6994. nullpo_retv(sd);
  6995. WBUFW(buf, 0) = 0x8a;
  6996. WBUFL(buf, 2) = sd->bl.id;
  6997. WBUFB(buf,26) = 2;
  6998. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  6999. if(sd->disguise) {
  7000. WBUFL(buf, 2) = -sd->bl.id;
  7001. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  7002. }
  7003. }
  7004. /*==========================================
  7005. *
  7006. *------------------------------------------
  7007. */
  7008. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  7009. {
  7010. unsigned char *buf;
  7011. nullpo_retr(0, sd);
  7012. buf = (unsigned char*)aCallocA(len + 5, sizeof(unsigned char));
  7013. WBUFW(buf, 0) = 0x17f;
  7014. WBUFW(buf, 2) = len + 5;
  7015. memcpy(WBUFP(buf,4), mes, len);
  7016. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7017. if(buf) aFree(buf);
  7018. return 0;
  7019. }
  7020. /*==========================================
  7021. *
  7022. *------------------------------------------
  7023. */
  7024. int clif_GM_kickack(struct map_session_data *sd, int id)
  7025. {
  7026. int fd;
  7027. nullpo_retr(0, sd);
  7028. fd = sd->fd;
  7029. WFIFOHEAD(fd,packet_len_table[0xcd]);
  7030. WFIFOW(fd,0) = 0xcd;
  7031. WFIFOL(fd,2) = id;
  7032. WFIFOSET(fd, packet_len_table[0xcd]);
  7033. return 0;
  7034. }
  7035. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  7036. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  7037. {
  7038. nullpo_retr(0, tsd);
  7039. if(type)
  7040. clif_GM_kickack(sd,tsd->status.account_id);
  7041. WFIFOHEAD(tsd->fd,packet_len_table[0x18b]);
  7042. WFIFOW(tsd->fd,0) = 0x18b;
  7043. WFIFOW(tsd->fd,2) = 0;
  7044. WFIFOSET(tsd->fd,packet_len_table[0x18b]);
  7045. if (tsd->fd)
  7046. {
  7047. ShowDebug("clif_GM_kick: Disconnecting session #%d\n", tsd->fd);
  7048. clif_setwaitclose(tsd->fd);
  7049. } else { //Player has no session attached, delete it right away. [Skotlex]
  7050. map_quit(tsd);
  7051. }
  7052. return 0;
  7053. }
  7054. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  7055. {
  7056. int fd;
  7057. nullpo_retr(0, sd);
  7058. nullpo_retr(0, tsd);
  7059. fd = tsd->fd;
  7060. if (fd <= 0)
  7061. return 0;
  7062. WFIFOHEAD(fd,packet_len_table[0x14b]);
  7063. WFIFOW(fd,0) = 0x14b;
  7064. WFIFOB(fd,2) = 0;
  7065. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7066. WFIFOSET(fd, packet_len_table[0x14b]);
  7067. return 0;
  7068. }
  7069. /*==========================================
  7070. *
  7071. *------------------------------------------
  7072. */
  7073. int clif_timedout(struct map_session_data *sd)
  7074. {
  7075. nullpo_retr(0, sd);
  7076. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  7077. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  7078. clif_setwaitclose(sd->fd); // Set session to EOF
  7079. return 0;
  7080. }
  7081. /*==========================================
  7082. * Wis拒否許可応答
  7083. *------------------------------------------
  7084. */
  7085. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  7086. {
  7087. int fd;
  7088. nullpo_retr(0, sd);
  7089. fd=sd->fd;
  7090. WFIFOHEAD(fd,packet_len_table[0xd1]);
  7091. WFIFOW(fd,0)=0xd1;
  7092. WFIFOB(fd,2)=type;
  7093. WFIFOB(fd,3)=flag;
  7094. WFIFOSET(fd,packet_len_table[0xd1]);
  7095. return 0;
  7096. }
  7097. /*==========================================
  7098. * Wis全拒否許可応答
  7099. *------------------------------------------
  7100. */
  7101. int clif_wisall(struct map_session_data *sd,int type,int flag)
  7102. {
  7103. int fd;
  7104. nullpo_retr(0, sd);
  7105. fd=sd->fd;
  7106. WFIFOHEAD(fd,packet_len_table[0xd2]);
  7107. WFIFOW(fd,0)=0xd2;
  7108. WFIFOB(fd,2)=type;
  7109. WFIFOB(fd,3)=flag;
  7110. WFIFOSET(fd,packet_len_table[0xd2]);
  7111. return 0;
  7112. }
  7113. /*==========================================
  7114. * サウンドエフェクト
  7115. *------------------------------------------
  7116. */
  7117. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  7118. {
  7119. int fd;
  7120. nullpo_retv(sd);
  7121. nullpo_retv(bl);
  7122. fd=sd->fd;
  7123. WFIFOHEAD(fd,packet_len_table[0x1d3]);
  7124. WFIFOW(fd,0)=0x1d3;
  7125. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  7126. WFIFOB(fd,26)=type;
  7127. WFIFOL(fd,27)=0;
  7128. WFIFOL(fd,31)=bl->id;
  7129. WFIFOSET(fd,packet_len_table[0x1d3]);
  7130. return;
  7131. }
  7132. int clif_soundeffectall(struct block_list *bl, char *name, int type)
  7133. {
  7134. unsigned char buf[40];
  7135. memset(buf, 0, packet_len_table[0x1d3]);
  7136. nullpo_retr(0, bl);
  7137. WBUFW(buf,0)=0x1d3;
  7138. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  7139. WBUFB(buf,26)=type;
  7140. WBUFL(buf,27)=0;
  7141. WBUFL(buf,31)=bl->id;
  7142. clif_send(buf, packet_len_table[0x1d3], bl, AREA);
  7143. return 0;
  7144. }
  7145. // displaying special effects (npcs, weather, etc) [Valaris]
  7146. int clif_specialeffect(struct block_list *bl, int type, int flag)
  7147. {
  7148. unsigned char buf[24];
  7149. nullpo_retr(0, bl);
  7150. memset(buf, 0, packet_len_table[0x1f3]);
  7151. WBUFW(buf,0) = 0x1f3;
  7152. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise)
  7153. WBUFL(buf,2) = -bl->id;
  7154. else
  7155. WBUFL(buf,2) = bl->id;
  7156. WBUFL(buf,6) = type;
  7157. switch (flag) {
  7158. case 4:
  7159. clif_send(buf, packet_len_table[0x1f3], bl, AREA_WOS);
  7160. break;
  7161. case 3:
  7162. clif_send(buf, packet_len_table[0x1f3], bl, ALL_CLIENT);
  7163. break;
  7164. case 2:
  7165. clif_send(buf, packet_len_table[0x1f3], bl, ALL_SAMEMAP);
  7166. break;
  7167. case 1:
  7168. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  7169. break;
  7170. default:
  7171. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  7172. }
  7173. return 0;
  7174. }
  7175. // refresh the client's screen, getting rid of any effects
  7176. int clif_refresh(struct map_session_data *sd) {
  7177. nullpo_retr(-1, sd);
  7178. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7179. 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);
  7180. return 0;
  7181. }
  7182. // updates the object's (bl) name on client
  7183. int clif_charnameack (int fd, struct block_list *bl)
  7184. {
  7185. unsigned char buf[103];
  7186. int cmd = 0x95;
  7187. nullpo_retr(0, bl);
  7188. WBUFW(buf,0) = cmd;
  7189. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise)
  7190. WBUFL(buf,2) = -bl->id;
  7191. else
  7192. WBUFL(buf,2) = bl->id;
  7193. switch(bl->type) {
  7194. case BL_PC:
  7195. {
  7196. struct map_session_data *ssd = (struct map_session_data *)bl;
  7197. struct party *p = NULL;
  7198. struct guild *g = NULL;
  7199. nullpo_retr(0, ssd);
  7200. if (strlen(ssd->fakename)>1) {
  7201. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7202. break;
  7203. }
  7204. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7205. if (ssd->status.party_id > 0)
  7206. p = party_search(ssd->status.party_id);
  7207. if (ssd->status.guild_id > 0)
  7208. g = guild_search(ssd->status.guild_id);
  7209. if (p == NULL && g == NULL)
  7210. break;
  7211. WBUFW(buf, 0) = cmd = 0x195;
  7212. if (p)
  7213. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  7214. else
  7215. WBUFB(buf,30) = 0;
  7216. if (g)
  7217. {
  7218. int i, ps = -1;
  7219. for(i = 0; i < g->max_member; i++) {
  7220. if (g->member[i].account_id == ssd->status.account_id &&
  7221. g->member[i].char_id == ssd->status.char_id )
  7222. {
  7223. ps = g->member[i].position;
  7224. break;
  7225. }
  7226. }
  7227. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  7228. {
  7229. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7230. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7231. } else { //Assume no guild.
  7232. WBUFB(buf,54) = 0;
  7233. WBUFB(buf,78) = 0;
  7234. }
  7235. } else {
  7236. WBUFB(buf,54) = 0;
  7237. WBUFB(buf,78) = 0;
  7238. }
  7239. }
  7240. break;
  7241. case BL_PET:
  7242. memcpy(WBUFP(buf,6), ((struct pet_data*)bl)->name, NAME_LENGTH);
  7243. break;
  7244. case BL_NPC:
  7245. memcpy(WBUFP(buf,6), ((struct npc_data*)bl)->name, NAME_LENGTH);
  7246. break;
  7247. case BL_MOB:
  7248. {
  7249. struct mob_data *md = (struct mob_data *)bl;
  7250. nullpo_retr(0, md);
  7251. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7252. if (md->guardian_data && md->guardian_data->guild_id) {
  7253. WBUFW(buf, 0) = cmd = 0x195;
  7254. WBUFB(buf,30) = 0;
  7255. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7256. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7257. } else if (battle_config.show_mob_hp == 1) {
  7258. char mobhp[50];
  7259. WBUFW(buf, 0) = cmd = 0x195;
  7260. sprintf(mobhp, "HP: %d/%d", md->hp, md->max_hp);
  7261. //Even thought mobhp ain't a name, we send it as one so the client
  7262. //can parse it. [Skotlex]
  7263. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7264. WBUFB(buf,54) = 0;
  7265. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  7266. }
  7267. }
  7268. break;
  7269. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7270. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7271. // break;
  7272. return 0;
  7273. default:
  7274. if (battle_config.error_log)
  7275. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  7276. return 0;
  7277. }
  7278. // if no receipient specified just update nearby clients
  7279. if (fd == 0)
  7280. clif_send(buf, packet_len_table[cmd], bl, AREA);
  7281. else {
  7282. WFIFOHEAD(fd, packet_len_table[cmd]);
  7283. memcpy(WFIFOP(fd, 0), buf, packet_len_table[cmd]);
  7284. WFIFOSET(fd, packet_len_table[cmd]);
  7285. }
  7286. return 0;
  7287. }
  7288. //Used to update when a char leaves a party/guild. [Skotlex]
  7289. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7290. int clif_charnameupdate (struct map_session_data *ssd)
  7291. {
  7292. unsigned char buf[103];
  7293. int cmd = 0x195;
  7294. struct party *p = NULL;
  7295. struct guild *g = NULL;
  7296. nullpo_retr(0, ssd);
  7297. if (strlen(ssd->fakename)>1)
  7298. return 0; //No need to update as the party/guild was not displayed anyway.
  7299. WBUFW(buf,0) = cmd;
  7300. if(ssd->disguise)
  7301. WBUFL(buf,2) = -(ssd->bl.id);
  7302. else
  7303. WBUFL(buf,2) = ssd->bl.id;
  7304. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7305. if (ssd->status.party_id > 0)
  7306. p = party_search(ssd->status.party_id);
  7307. if (ssd->status.guild_id > 0)
  7308. g = guild_search(ssd->status.guild_id);
  7309. if (p)
  7310. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  7311. else
  7312. WBUFB(buf,30) = 0;
  7313. if (g)
  7314. {
  7315. int i, ps = -1;
  7316. for(i = 0; i < g->max_member; i++) {
  7317. if (g->member[i].account_id == ssd->status.account_id &&
  7318. g->member[i].char_id == ssd->status.char_id )
  7319. {
  7320. ps = g->member[i].position;
  7321. break;
  7322. }
  7323. }
  7324. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  7325. {
  7326. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7327. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7328. } else { //Assume no guild.
  7329. WBUFB(buf,54) = 0;
  7330. WBUFB(buf,78) = 0;
  7331. }
  7332. } else {
  7333. WBUFB(buf,54) = 0;
  7334. WBUFB(buf,78) = 0;
  7335. }
  7336. // Update nearby clients
  7337. clif_send(buf, packet_len_table[cmd], &ssd->bl, AREA);
  7338. return 0;
  7339. }
  7340. int clif_slide(struct block_list *bl, int x, int y){
  7341. unsigned char buf[10];
  7342. nullpo_retr(0, bl);
  7343. WBUFW(buf, 0) = 0x01ff;
  7344. WBUFL(buf, 2) = bl->id;
  7345. WBUFW(buf, 6) = x;
  7346. WBUFW(buf, 8) = y;
  7347. clif_send(buf, packet_len_table[0x1ff], bl, AREA);
  7348. return 0;
  7349. }
  7350. /*------------------------------------------
  7351. * @me command by lordalfa, rewritten implementation by Skotlex
  7352. *------------------------------------------
  7353. */
  7354. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  7355. {
  7356. unsigned char buf[256]; //This should be more than sufficient, the theorical max is MESSAGE_SIZE+NAME_LENGTH + 8 (pads and extra inserted crap)
  7357. int len_mes = strlen(mes)+1; //Account for \0
  7358. if (len_mes + 8 >= 256) {
  7359. if (battle_config.error_log)
  7360. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7361. len_mes = 247; //Trunk it to avoid problems.
  7362. }
  7363. // send message to others
  7364. WBUFW(buf,0) = 0x8d;
  7365. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7366. WBUFL(buf,4) = sd->bl.id;
  7367. memcpy(WBUFP(buf,8), mes, len_mes);
  7368. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  7369. // send back message to the speaker
  7370. WBUFW(buf,0) = 0x8e;
  7371. WBUFW(buf, 2) = len_mes + 4;
  7372. memcpy(WBUFP(buf,4), mes, len_mes);
  7373. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7374. return 0;
  7375. }
  7376. /*==========================
  7377. * Minimap fix [Kevin]
  7378. * Remove dot from minimap
  7379. *--------------------------
  7380. */
  7381. int clif_party_xy_remove(struct map_session_data *sd)
  7382. {
  7383. unsigned char buf[16];
  7384. nullpo_retr(0, sd);
  7385. WBUFW(buf,0)=0x107;
  7386. WBUFL(buf,2)=sd->status.account_id;
  7387. WBUFW(buf,6)=-1;
  7388. WBUFW(buf,8)=-1;
  7389. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  7390. return 0;
  7391. }
  7392. /*==========================================
  7393. * Info about Star Glaldiator save map [Komurka]
  7394. *------------------------------------------
  7395. */
  7396. void clif_feel_info(struct map_session_data *sd, int feel_level)
  7397. {
  7398. int fd=sd->fd;
  7399. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7400. WFIFOW(fd,0)=0x20e;
  7401. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  7402. WFIFOL(fd,26)=sd->bl.id;
  7403. WFIFOW(fd,30)=0x100+feel_level;
  7404. WFIFOSET(fd, packet_len_table[0x20e]);
  7405. }
  7406. /*==========================================
  7407. * Info about Star Glaldiator hate mob [Komurka]
  7408. *------------------------------------------
  7409. */
  7410. void clif_hate_mob(struct map_session_data *sd, int skilllv,int mob_id)
  7411. {
  7412. int fd=sd->fd;
  7413. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7414. WFIFOW(fd,0)=0x20e;
  7415. if (pcdb_checkid(mob_id))
  7416. strncpy(WFIFOP(fd,2),job_name(mob_id), NAME_LENGTH);
  7417. else if (mobdb_checkid(mob_id))
  7418. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  7419. else //Really shouldn't happen...
  7420. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  7421. WFIFOL(fd,26)=sd->bl.id;
  7422. WFIFOW(fd,30)=0xa00+skilllv-1;
  7423. WFIFOSET(fd, packet_len_table[0x20e]);
  7424. }
  7425. /*==========================================
  7426. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7427. *------------------------------------------
  7428. */
  7429. void clif_mission_mob(struct map_session_data *sd, unsigned short mob_id, unsigned short progress)
  7430. {
  7431. int fd=sd->fd;
  7432. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7433. WFIFOW(fd,0)=0x20e;
  7434. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  7435. WFIFOL(fd,26)=mob_id;
  7436. WFIFOW(fd,30)=0x1400+progress; //Message to display
  7437. WFIFOSET(fd, packet_len_table[0x20e]);
  7438. }
  7439. // ---------------------
  7440. // clif_guess_PacketVer
  7441. // ---------------------
  7442. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7443. static int clif_guess_PacketVer(int fd, int get_previous)
  7444. {
  7445. static int packet_ver = -1;
  7446. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7447. RFIFOHEAD(fd);
  7448. 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]
  7449. return packet_ver;
  7450. //By default, start searching on the default one.
  7451. packet_ver = clif_config.packet_db_ver;
  7452. cmd = RFIFOW(fd,0);
  7453. packet_len = RFIFOREST(fd);
  7454. if (
  7455. cmd == clif_config.connect_cmd[packet_ver] &&
  7456. packet_len == packet_db[packet_ver][cmd].len &&
  7457. ((value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) == 0 || value == 1) &&
  7458. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) > 700000 && //Account ID is valid
  7459. value <= max_account_id &&
  7460. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) > 0 && //Char ID is valid
  7461. value <= max_char_id &&
  7462. (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) > 0 //Login 1 is a positive value (?)
  7463. )
  7464. return clif_config.packet_db_ver; //Default packet version found.
  7465. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7466. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7467. if (cmd != clif_config.connect_cmd[packet_ver] || //it is not a wanttoconnection for this version.
  7468. packet_len != packet_db[packet_ver][cmd].len) //The size of the wantoconnection packet does not matches.
  7469. continue;
  7470. if (
  7471. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < 700000 || value > max_account_id
  7472. || (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) < 1 || value > max_char_id
  7473. //What is login 1? In my tests it is a very very high value.
  7474. || (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) < 1
  7475. //This check seems redundant, all wanttoconnection packets have the gender on the very
  7476. //last byte of the packet.
  7477. || (value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) < 0 || value > 1
  7478. )
  7479. continue;
  7480. return packet_ver; //This is our best guess.
  7481. }
  7482. packet_ver = -1;
  7483. return -1;
  7484. }
  7485. // ------------
  7486. // clif_parse_*
  7487. // ------------
  7488. // パケット読み取って色々操作
  7489. /*==========================================
  7490. *
  7491. *------------------------------------------
  7492. */
  7493. void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
  7494. {
  7495. struct map_session_data *old_sd;
  7496. int cmd, account_id, char_id, login_id1, sex;
  7497. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7498. 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])
  7499. RFIFOHEAD(fd);
  7500. if (sd) {
  7501. if (battle_config.error_log)
  7502. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  7503. return;
  7504. }
  7505. packet_ver = clif_guess_PacketVer(fd, 1);
  7506. cmd = RFIFOW(fd,0);
  7507. if (packet_ver > 0)
  7508. {
  7509. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7510. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7511. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7512. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7513. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7514. if ((old_sd = map_id2sd(account_id)) != NULL)
  7515. { // if same account already connected, we disconnect the 2 sessions
  7516. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  7517. if (!old_sd->fd)
  7518. map_quit(old_sd);
  7519. else
  7520. clif_authfail_fd(old_sd->fd, 2); // same id
  7521. clif_authfail_fd(fd, 8); // still recognizes last connection
  7522. } else {
  7523. sd = (struct map_session_data*)aCalloc(1, sizeof(struct map_session_data));
  7524. sd->fd = fd;
  7525. sd->packet_ver = packet_ver;
  7526. session[fd]->session_data = sd;
  7527. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7528. WFIFOHEAD(fd,4);
  7529. WFIFOL(fd,0) = sd->bl.id;
  7530. WFIFOSET(fd,4);
  7531. chrif_authreq(sd);
  7532. }
  7533. }
  7534. return;
  7535. }
  7536. /*==========================================
  7537. * 007d クライアント側マップ読み込み完了
  7538. * map侵入時に必要なデータを全て送りつける
  7539. *------------------------------------------
  7540. */
  7541. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7542. {
  7543. if(sd->bl.prev != NULL)
  7544. return;
  7545. if(sd->npc_id) npc_event_dequeue(sd);
  7546. clif_skillinfoblock(sd);
  7547. pc_checkitem(sd);
  7548. // loadendack時
  7549. // next exp
  7550. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7551. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7552. // skill point
  7553. clif_updatestatus(sd,SP_SKILLPOINT);
  7554. // item
  7555. clif_itemlist(sd);
  7556. clif_equiplist(sd);
  7557. // cart
  7558. if(pc_iscarton(sd)){
  7559. clif_cart_itemlist(sd);
  7560. clif_cart_equiplist(sd);
  7561. clif_updatestatus(sd,SP_CARTINFO);
  7562. }
  7563. // param all
  7564. clif_initialstatus(sd);
  7565. if(battle_config.pc_invincible_time > 0) {
  7566. if(map_flag_gvg(sd->bl.m))
  7567. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7568. else
  7569. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7570. }
  7571. map_addblock(&sd->bl); // ブロック登録
  7572. clif_spawnpc(sd); // spawn
  7573. // party
  7574. party_send_movemap(sd);
  7575. // guild
  7576. guild_send_memberinfoshort(sd,1);
  7577. // weight max , now
  7578. clif_updatestatus(sd,SP_MAXWEIGHT);
  7579. clif_updatestatus(sd,SP_WEIGHT);
  7580. // Show hp after displacement [LuzZza]
  7581. if(sd->status.party_id)
  7582. clif_party_hp(sd);
  7583. // set flag, if it's a duel [LuzZza]
  7584. if(sd->duel_group) {
  7585. clif_set0199(fd, 1);
  7586. //clif_misceffect2(&sd->bl, 159);
  7587. }
  7588. // pvp
  7589. //if(sd->pvp_timer!=-1 && !battle_config.pk_mode) /PVP Client crash fix* Removed timer deletion
  7590. // delete_timer(sd->pvp_timer,pc_calc_pvprank_timer);
  7591. if(map[sd->bl.m].flag.pvp){
  7592. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7593. if (sd->pvp_timer == -1)
  7594. sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
  7595. sd->pvp_rank=0;
  7596. sd->pvp_lastusers=0;
  7597. sd->pvp_point=5;
  7598. sd->pvp_won=0;
  7599. sd->pvp_lost=0;
  7600. }
  7601. clif_set0199(sd->fd,1);
  7602. } else {
  7603. sd->pvp_timer=-1;
  7604. }
  7605. if(map_flag_gvg(sd->bl.m))
  7606. clif_set0199(sd->fd,3);
  7607. // pet
  7608. if(sd->status.pet_id > 0 && sd->pd && sd->pet.intimate > 0) {
  7609. map_addblock(&sd->pd->bl);
  7610. clif_spawnpet(sd->pd);
  7611. clif_send_petdata(sd,0,0);
  7612. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7613. clif_send_petstatus(sd);
  7614. }
  7615. if(sd->state.connect_new) {
  7616. sd->state.connect_new = 0;
  7617. if(sd->status.class_ != sd->view_class)
  7618. clif_changelook(&sd->bl,LOOK_BASE,sd->view_class);
  7619. if(sd->status.pet_id > 0 && sd->pd && sd->pet.intimate > 900)
  7620. clif_pet_emotion(sd->pd,(sd->pd->class_ - 100)*100 + 50 + pet_hungry_val(sd));
  7621. /* Stop players from spawning inside castles [Valaris] */
  7622. {
  7623. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  7624. if (gc)
  7625. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,2);
  7626. }
  7627. /* End Addition [Valaris] */
  7628. }
  7629. // view equipment item
  7630. #if PACKETVER < 4
  7631. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7632. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7633. #else
  7634. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7635. #endif
  7636. if(battle_config.save_clothcolor && sd->status.clothes_color > 0 && ((sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS) ||
  7637. (sd->view_class==JOB_WEDDING && !battle_config.wedding_ignorepalette) || (sd->view_class==JOB_XMAS && !battle_config.xmas_ignorepalette)))
  7638. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->status.clothes_color);
  7639. if(battle_config.muting_players && sd->status.manner < 0 && battle_config.manner_system)
  7640. status_change_start(&sd->bl,SC_NOCHAT,100,0,0,0,0,0,0);
  7641. // Lance
  7642. if (script_config.event_script_type == 0) {
  7643. struct npc_data *npc;
  7644. if ((npc = npc_name2id(script_config.loadmap_event_name))) {
  7645. run_script(npc->u.scr.script,0,sd->bl.id,npc->bl.id);
  7646. ShowStatus("Event '"CL_WHITE"%s"CL_RESET"' executed.\n", script_config.loadmap_event_name);
  7647. }
  7648. } else {
  7649. ShowStatus("%d '"CL_WHITE"%s"CL_RESET"' events executed.\n",
  7650. npc_event_doall_id(script_config.loadmap_event_name, sd->bl.id), script_config.loadmap_event_name);
  7651. }
  7652. /* These should not be needed anymore. [Skotlex]
  7653. * - the option is sent on every player packet, why send it?
  7654. * - There should be no need to do a signum check on map change, it is done on equipment change.
  7655. * - Trick-dead is finished on pc_setpos
  7656. * - Night effect is handled on clif_spawnpc
  7657. // option
  7658. clif_changeoption(&sd->bl);
  7659. if(sd->sc_data[SC_TRICKDEAD].timer != -1)
  7660. status_change_end(&sd->bl,SC_TRICKDEAD,-1);
  7661. if(sd->sc_data[SC_SIGNUMCRUCIS].timer != -1 && !battle_check_undead(7,sd->def_ele))
  7662. status_change_end(&sd->bl,SC_SIGNUMCRUCIS,-1);
  7663. if(sd->special_state.infinite_endure && sd->sc_data[SC_ENDURE].timer == -1)
  7664. status_change_start(&sd->bl,SC_ENDURE,100,10,1,0,0,0,0);
  7665. // Required to eliminate glow bugs because it's executed before clif_changeoption [Lance]
  7666. //New 'night' effect by dynamix [Skotlex]
  7667. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7668. { //Display night.
  7669. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  7670. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7671. else
  7672. sd->state.night = 1;
  7673. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7674. } else if (sd->state.night) { //Clear night display.
  7675. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7676. sd->state.night = 0;
  7677. }
  7678. */
  7679. if (pc_checkskill(sd,SG_KNOWLEDGE) ||
  7680. pc_checkskill(sd,SG_SUN_COMFORT) ||
  7681. pc_checkskill(sd,SG_MOON_COMFORT) ||
  7682. pc_checkskill(sd,SG_STAR_COMFORT))
  7683. status_calc_pc(sd,0);
  7684. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7685. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7686. 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);
  7687. }
  7688. /*==========================================
  7689. *
  7690. *------------------------------------------
  7691. */
  7692. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7693. RFIFOHEAD(fd);
  7694. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7695. sd->server_tick = gettick();
  7696. clif_servertick(sd);
  7697. }
  7698. /*==========================================
  7699. *
  7700. *------------------------------------------
  7701. */
  7702. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7703. int x, y;
  7704. int cmd;
  7705. RFIFOHEAD(fd);
  7706. if (pc_isdead(sd)) {
  7707. clif_clearchar_area(&sd->bl, 1);
  7708. return;
  7709. }
  7710. if (pc_issit(sd)) //No walking when you are sit!
  7711. return;
  7712. if (clif_cant_act(sd))
  7713. return;
  7714. if (sd->skilltimer != -1 && pc_checkskill(sd, SA_FREECAST) <= 0) // フリーキャスト
  7715. return;
  7716. if (!pc_can_move(sd))
  7717. return;
  7718. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7719. return;
  7720. if (sd->invincible_timer != -1)
  7721. pc_delinvincibletimer(sd);
  7722. pc_stopattack(sd);
  7723. cmd = RFIFOW(fd,0);
  7724. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7725. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7726. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7727. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7728. //Set last idle time... [Skotlex]
  7729. sd->idletime = last_tick;
  7730. pc_walktoxy(sd, x, y);
  7731. }
  7732. /*==========================================
  7733. *
  7734. *------------------------------------------
  7735. */
  7736. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7737. // unsigned int tick=gettick();
  7738. // struct skill_unit_group* sg;
  7739. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7740. WFIFOW(fd,0) = 0x18b;
  7741. /* Rovert's prevent logout option fixed [Valaris] */
  7742. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7743. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7744. ) {
  7745. clif_setwaitclose(fd);
  7746. WFIFOW(fd,2)=0;
  7747. } else {
  7748. WFIFOW(fd,2)=1;
  7749. }
  7750. WFIFOSET(fd,packet_len_table[0x18b]);
  7751. }
  7752. /*==========================================
  7753. *
  7754. *------------------------------------------
  7755. */
  7756. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7757. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7758. /* if (target_id == server_char_id) {
  7759. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7760. 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).
  7761. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7762. // if we block people
  7763. if (battle_config.ban_bot < 0) {
  7764. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7765. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7766. // message about the ban
  7767. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7768. // if we ban people
  7769. } else if (battle_config.ban_bot > 0) {
  7770. 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)
  7771. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7772. // message about the ban
  7773. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7774. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7775. // message about the ban
  7776. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7777. }
  7778. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7779. // send this info cause the bot ask until get an answer, damn spam
  7780. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7781. WPACKETW(0) = 0x95;
  7782. WPACKETL(2) = server_char_id;
  7783. strncpy(WPACKETP(6), sd->status.name, 24);
  7784. SENDPACKET(fd, packet_len_table[0x95]);
  7785. // take fake player out of screen
  7786. WPACKETW(0) = 0x80;
  7787. WPACKETL(2) = server_char_id;
  7788. WPACKETB(6) = 0;
  7789. SENDPACKET(fd, packet_len_table[0x80]);
  7790. // take fake mob out of screen
  7791. WPACKETW(0) = 0x80;
  7792. WPACKETL(2) = server_fake_mob_id;
  7793. WPACKETB(6) = 0;
  7794. SENDPACKET(fd, packet_len_table[0x80]);
  7795. }
  7796. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7797. if (target_id == server_fake_mob_id) {
  7798. int fake_mob;
  7799. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7800. 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).
  7801. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7802. // if we block people
  7803. if (battle_config.ban_bot < 0) {
  7804. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7805. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7806. // message about the ban
  7807. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7808. // if we ban people
  7809. } else if (battle_config.ban_bot > 0) {
  7810. 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)
  7811. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7812. // message about the ban
  7813. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7814. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7815. // message about the ban
  7816. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7817. }
  7818. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7819. // send this info cause the bot ask until get an answer, damn spam
  7820. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7821. WPACKETW(0) = 0x95;
  7822. WPACKETL(2) = server_fake_mob_id;
  7823. 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
  7824. if (!mobdb_checkid(fake_mob))
  7825. fake_mob = 1002; // poring (default)
  7826. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7827. SENDPACKET(fd, packet_len_table[0x95]);
  7828. // take fake mob out of screen
  7829. WPACKETW(0) = 0x80;
  7830. WPACKETL(2) = server_fake_mob_id;
  7831. WPACKETB(6) = 0;
  7832. SENDPACKET(fd, packet_len_table[0x80]);
  7833. // take fake player out of screen
  7834. WPACKETW(0) = 0x80;
  7835. WPACKETL(2) = server_char_id;
  7836. WPACKETB(6) = 0;
  7837. SENDPACKET(fd, packet_len_table[0x80]);
  7838. }
  7839. */
  7840. return;
  7841. }
  7842. /*==========================================
  7843. *
  7844. *------------------------------------------
  7845. */
  7846. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7847. int account_id;
  7848. struct block_list* bl;
  7849. RFIFOHEAD(fd);
  7850. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7851. if(account_id<0) // for disguises [Valaris]
  7852. account_id-=account_id*2;
  7853. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7854. if ((bl = map_id2bl(account_id)) != NULL)
  7855. clif_charnameack(fd, bl);
  7856. }
  7857. /*==========================================
  7858. *
  7859. *------------------------------------------
  7860. */
  7861. void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
  7862. unsigned char *message, *buf, buf2[128];
  7863. RFIFOHEAD(fd);
  7864. WFIFOHEAD(fd, RFIFOW(fd,2) + 4);
  7865. message = (unsigned char*)RFIFOP(fd,4);
  7866. if (strlen(message) < strlen(sd->status.name) || //If the incoming string is too short...
  7867. strncmp(message, sd->status.name, strlen(sd->status.name)) != 0) //Or the name does not matches...
  7868. {
  7869. unsigned char gm_msg[256];
  7870. 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);
  7871. // information is sended to all online GM
  7872. sprintf(gm_msg, "Hack on global message (normal message): character '%s' (account: %d) uses another name.", sd->status.name, sd->status.account_id);
  7873. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7874. if (strlen(message) == 0)
  7875. strcpy(gm_msg, " This player sends a void name and a void message.");
  7876. else
  7877. snprintf(gm_msg, 255, " This player sends (name:message): '%128s'.", message);
  7878. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7879. // message about the ban
  7880. if (battle_config.ban_spoof_namer > 0)
  7881. sprintf(gm_msg, " This player has been banned for %d minute(s).", battle_config.ban_spoof_namer);
  7882. else
  7883. sprintf(gm_msg, " This player hasn't been banned (Ban option is disabled).");
  7884. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7885. // if we ban people
  7886. if (battle_config.ban_spoof_namer > 0) {
  7887. 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)
  7888. clif_setwaitclose(fd); // forced to disconnect because of the hack
  7889. }
  7890. else
  7891. session[fd]->eof = 1; //Disconnect them too, bad packets can cause problems down the road. [Skotlex]
  7892. return;
  7893. }
  7894. if ((is_atcommand(fd, sd, message, 0) != AtCommand_None) ||
  7895. (is_charcommand(fd, sd, message,0) != CharCommand_None))
  7896. return;
  7897. if (sd->sc.count &&
  7898. (sd->sc.data[SC_BERSERK].timer != -1 || sd->sc.data[SC_NOCHAT].timer != -1 ))
  7899. return;
  7900. if (RFIFOW(fd,2)+4 < 128)
  7901. buf = buf2; //Use a static buffer.
  7902. else
  7903. buf = (unsigned char*)aCallocA(RFIFOW(fd,2) + 4, sizeof(char));
  7904. // send message to others
  7905. WBUFW(buf,0) = 0x8d;
  7906. WBUFW(buf,2) = RFIFOW(fd,2) + 4; // len of message - 4 + 8
  7907. WBUFL(buf,4) = sd->bl.id;
  7908. memcpy(WBUFP(buf,8), message, RFIFOW(fd,2) - 4);
  7909. clif_send(buf, WBUFW(buf,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7910. if(buf != buf2) aFree(buf);
  7911. // send back message to the speaker
  7912. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7913. WFIFOW(fd,0) = 0x8e;
  7914. WFIFOSET(fd, WFIFOW(fd,2));
  7915. #ifdef PCRE_SUPPORT
  7916. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7917. #endif
  7918. // Celest
  7919. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7920. int next = pc_nextbaseexp(sd);
  7921. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7922. switch (sd->state.snovice_flag) {
  7923. case 0:
  7924. if (strstr(message, msg_txt(504)))
  7925. sd->state.snovice_flag++;
  7926. break;
  7927. case 1:
  7928. sprintf(buf2, msg_txt(505), sd->status.name);
  7929. if (strstr(message, buf2))
  7930. sd->state.snovice_flag++;
  7931. break;
  7932. case 2:
  7933. if (strstr(message, msg_txt(506)))
  7934. sd->state.snovice_flag++;
  7935. case 3:
  7936. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7937. break; //Do not override the noskill mapflag. [Skotlex]
  7938. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7939. status_change_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  7940. 17,0,0,0,skill_get_time(MO_EXPLOSIONSPIRITS,1),0 )); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7941. sd->state.snovice_flag = 0;
  7942. break;
  7943. }
  7944. }
  7945. }
  7946. return;
  7947. }
  7948. int clif_message(struct block_list *bl, char* msg)
  7949. {
  7950. unsigned short msg_len = strlen(msg) + 1;
  7951. unsigned char buf[256];
  7952. nullpo_retr(0, bl);
  7953. WBUFW(buf, 0) = 0x8d;
  7954. WBUFW(buf, 2) = msg_len + 8;
  7955. WBUFL(buf, 4) = bl->id;
  7956. memcpy(WBUFP(buf, 8), msg, msg_len);
  7957. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7958. return 0;
  7959. }
  7960. /*==========================================
  7961. *
  7962. *------------------------------------------
  7963. */
  7964. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7965. // /m /mapmove (as @rura GM command)
  7966. char output[30]; // 17+4+4=26, 30 max.
  7967. char map_name[MAP_NAME_LENGTH]; //Err... map names are 15+'\0' in size, not 16+'\0' [Skotlex]
  7968. RFIFOHEAD(fd);
  7969. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7970. (pc_isGM(sd) >= get_atcommand_level(AtCommand_MapMove))) {
  7971. memcpy(map_name, RFIFOP(fd,2), MAP_NAME_LENGTH-1);
  7972. map_name[MAP_NAME_LENGTH-1]='\0';
  7973. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7974. atcommand_rura(fd, sd, "@rura", output);
  7975. }
  7976. return;
  7977. }
  7978. /*==========================================
  7979. *
  7980. *------------------------------------------
  7981. */
  7982. void clif_changed_dir(struct block_list *bl) {
  7983. unsigned char buf[64];
  7984. struct map_session_data *sd = NULL;
  7985. if (bl->type == BL_PC)
  7986. nullpo_retv (sd=(struct map_session_data *)bl);
  7987. WBUFW(buf,0) = 0x9c;
  7988. WBUFL(buf,2) = bl->id;
  7989. if (sd)
  7990. WBUFW(buf,6) = sd->head_dir;
  7991. WBUFB(buf,8) = status_get_dir(bl);
  7992. clif_send(buf, packet_len_table[0x9c], bl, AREA_WOS);
  7993. if(sd && sd->disguise) {
  7994. WBUFL(buf,2) = -bl->id;
  7995. WBUFW(buf,6) = 0;
  7996. WBUFB(buf,8) = status_get_dir(bl);
  7997. clif_send(buf, packet_len_table[0x9c], bl, AREA);
  7998. }
  7999. return;
  8000. }
  8001. /*==========================================
  8002. *
  8003. *------------------------------------------
  8004. */
  8005. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  8006. unsigned char headdir, dir;
  8007. RFIFOHEAD(fd);
  8008. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8009. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8010. pc_setdir(sd, dir, headdir);
  8011. clif_changed_dir(&sd->bl);
  8012. return;
  8013. }
  8014. /*==========================================
  8015. *
  8016. *------------------------------------------
  8017. */
  8018. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  8019. unsigned char buf[64];
  8020. RFIFOHEAD(fd);
  8021. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8022. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  8023. clif_skill_fail(sd, 1, 0, 1);
  8024. return;
  8025. }
  8026. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8027. if (sd->emotionlasttime >= time(NULL)) {
  8028. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  8029. clif_skill_fail(sd, 1, 0, 1);
  8030. return;
  8031. }
  8032. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  8033. WBUFW(buf,0) = 0xc0;
  8034. WBUFL(buf,2) = sd->bl.id;
  8035. WBUFB(buf,6) = RFIFOB(fd,2);
  8036. clif_send(buf, packet_len_table[0xc0], &sd->bl, AREA);
  8037. } else
  8038. clif_skill_fail(sd, 1, 0, 1);
  8039. }
  8040. /*==========================================
  8041. *
  8042. *------------------------------------------
  8043. */
  8044. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  8045. WFIFOHEAD(fd,packet_len_table[0xc2]);
  8046. WFIFOW(fd,0) = 0xc2;
  8047. WFIFOL(fd,2) = map_getusers();
  8048. WFIFOSET(fd,packet_len_table[0xc2]);
  8049. }
  8050. /*==========================================
  8051. *
  8052. *------------------------------------------
  8053. */
  8054. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  8055. unsigned int tick;
  8056. unsigned char buf[64];
  8057. int action_type, target_id;
  8058. RFIFOHEAD(fd);
  8059. if (pc_isdead(sd)) {
  8060. clif_clearchar_area(&sd->bl, 1);
  8061. return;
  8062. }
  8063. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  8064. return;
  8065. if (sd->sc.count &&
  8066. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  8067. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  8068. sd->sc.data[SC_BLADESTOP].timer != -1))
  8069. return;
  8070. tick = gettick();
  8071. pc_stop_walking(sd, 0);
  8072. pc_stopattack(sd);
  8073. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8074. action_type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8075. //Regardless of what they have to do, they have just requested an action, no longer idle. [Skotlex]
  8076. sd->idletime = last_tick;
  8077. if(target_id<0) // for disguises [Valaris]
  8078. target_id-=(target_id*2);
  8079. switch(action_type) {
  8080. case 0x00: // once attack
  8081. case 0x07: // continuous attack
  8082. if(sd->view_class==JOB_WEDDING || sd->view_class==JOB_XMAS)
  8083. return;
  8084. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8085. if (DIFF_TICK(tick, sd->canact_tick) < 0) {
  8086. clif_skill_fail(sd, 1, 4, 0);
  8087. return;
  8088. }
  8089. }
  8090. if (sd->invincible_timer != -1)
  8091. pc_delinvincibletimer(sd);
  8092. pc_attack(sd, target_id, action_type != 0);
  8093. break;
  8094. case 0x02: // sitdown
  8095. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 3) {
  8096. if (sd->skilltimer != -1) //No sitting while casting :P
  8097. break;
  8098. if (sd->sc.count && (
  8099. sd->sc.data[SC_DANCING].timer != -1 ||
  8100. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  8101. )) //No sitting during these states neither.
  8102. break;
  8103. pc_stopattack(sd);
  8104. pc_stop_walking(sd, 1);
  8105. pc_setsit(sd);
  8106. skill_gangsterparadise(sd, 1); // ギャングスターパラダイス設定 fixed Valaris
  8107. skill_rest(sd, 1); // TK_HPTIME sitting down mode [Dralnu]
  8108. clif_sitting(sd);
  8109. } else
  8110. clif_skill_fail(sd, 1, 0, 2);
  8111. break;
  8112. case 0x03: // standup
  8113. pc_setstand(sd);
  8114. skill_gangsterparadise(sd, 0); // ギャングスターパラダイス解除 fixed Valaris
  8115. skill_rest(sd, 0); // TK_HPTIME standing up mode [Dralnu]
  8116. WBUFW(buf, 0) = 0x8a;
  8117. WBUFL(buf, 2) = sd->bl.id;
  8118. WBUFB(buf,26) = 3;
  8119. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  8120. if(sd->disguise) {
  8121. WBUFL(buf, 2) = -sd->bl.id;
  8122. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  8123. }
  8124. break;
  8125. }
  8126. }
  8127. /*==========================================
  8128. *
  8129. *------------------------------------------
  8130. */
  8131. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  8132. RFIFOHEAD(fd);
  8133. switch(RFIFOB(fd,2)) {
  8134. case 0x00:
  8135. if (pc_isdead(sd)) {
  8136. pc_setstand(sd);
  8137. pc_setrestartvalue(sd, 3);
  8138. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  8139. }
  8140. // in case the player's status somehow wasn't updated yet [Celest]
  8141. else if (sd->status.hp <= 0)
  8142. pc_setdead(sd);
  8143. break;
  8144. case 0x01:
  8145. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8146. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  8147. {
  8148. //map_quit(sd); //A clif_quitsave is sent inmediately after this, so no need to quit yet. [Skotlex]
  8149. chrif_charselectreq(sd);
  8150. } else {
  8151. WFIFOHEAD(fd,packet_len_table[0x18b]);
  8152. WFIFOW(fd,0)=0x18b;
  8153. WFIFOW(fd,2)=1;
  8154. WFIFOSET(fd,packet_len_table[0x018b]);
  8155. }
  8156. break;
  8157. }
  8158. }
  8159. /*==========================================
  8160. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  8161. *------------------------------------------
  8162. */
  8163. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  8164. char *gm_command;
  8165. struct map_session_data *dstsd;
  8166. int i=0;
  8167. struct npc_data *npc;
  8168. char split_data[10][50];
  8169. int j=0,k=0;
  8170. char *whisper_tmp;
  8171. char output[256];
  8172. RFIFOHEAD(fd);
  8173. //printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28));
  8174. gm_command = (char*)aCallocA(strlen((const char*)RFIFOP(fd,28)) + 28, sizeof(char)); // 24+3+(RFIFOW(fd,2)-28)+1 or 24+3+(strlen(RFIFOP(fd,28))+1 (size can be wrong with hacker)
  8175. sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28));
  8176. if ((is_charcommand(fd, sd, gm_command, 0) != CharCommand_None) ||
  8177. (is_atcommand(fd, sd, gm_command, 0) != AtCommand_None)) {
  8178. if(gm_command) aFree(gm_command);
  8179. return;
  8180. }
  8181. if (sd->sc.count &&
  8182. (sd->sc.data[SC_BERSERK].timer!=-1 || sd->sc.data[SC_NOCHAT].timer != -1))
  8183. {
  8184. if(gm_command) aFree(gm_command);
  8185. return;
  8186. }
  8187. if(gm_command) aFree(gm_command);
  8188. //Chat Logging type 'W' / Whisper
  8189. if(log_config.chat&1 //we log everything then
  8190. || ( log_config.chat&2 //if Whisper bit is on
  8191. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  8192. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, (char*)RFIFOP(fd, 4), (char*)RFIFOP(fd, 28));
  8193. //-------------------------------------------------------//
  8194. // Lordalfa - Paperboy - To whisper NPC commands //
  8195. //-------------------------------------------------------//
  8196. if ((strncasecmp((const char*)RFIFOP(fd,4),"NPC:",4) == 0) && (strlen((const char*)RFIFOP(fd,4)) >4)) {
  8197. whisper_tmp = (char*) RFIFOP(fd,4) + 4;
  8198. if ((npc = npc_name2id(whisper_tmp)))
  8199. {
  8200. whisper_tmp=(char *)aCallocA(strlen((char *)(RFIFOP(fd,28))+1),sizeof(char));
  8201. whisper_tmp[0]=0;
  8202. sprintf(whisper_tmp, "%s", (const char*)RFIFOP(fd,28));
  8203. for( j=0;whisper_tmp[j]!='\0';j++)
  8204. {
  8205. if(whisper_tmp[j]!='#')
  8206. {
  8207. split_data[i][j-k]=whisper_tmp[j];
  8208. }
  8209. else
  8210. {
  8211. split_data[i][j-k]='\0';
  8212. k=j+1;
  8213. i++;
  8214. }
  8215. } // Splits the message using '#' as separators
  8216. split_data[i][j-k]='\0';
  8217. aFree(whisper_tmp);
  8218. whisper_tmp=(char *)aCallocA(15,sizeof(char));
  8219. whisper_tmp[0]=0;
  8220. for (j=0;j<=10;j++)
  8221. {
  8222. sprintf(whisper_tmp, "@whispervar%d$", j);
  8223. set_var(sd,whisper_tmp,(char *) split_data[j]);
  8224. }//You don't need to zero them, just reset them [Kevin]
  8225. aFree(whisper_tmp);
  8226. whisper_tmp=(char *)aCallocA(strlen(npc->name)+18,sizeof(char));
  8227. whisper_tmp[0]=0;
  8228. sprintf(whisper_tmp, "%s::OnWhisperGlobal", npc->name);
  8229. npc_event(sd,whisper_tmp,0); // Calls the NPC label
  8230. return;
  8231. aFree(whisper_tmp); //I rewrote it a little to use memory allocation, a bit more stable =P [Kevin]
  8232. whisper_tmp = NULL;
  8233. } //should have just removed the one below that was a my bad =P
  8234. }
  8235. // Main chat [LuzZza]
  8236. if(strcmpi((const char*)RFIFOP(fd,4), main_chat_nick) == 0) {
  8237. if(!sd->state.mainchat) {
  8238. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8239. return;
  8240. }
  8241. if (sd->sc.data[SC_NOCHAT].timer != -1) {
  8242. clif_displaymessage(fd, msg_txt(387));
  8243. return;
  8244. }
  8245. sprintf(output, msg_txt(386), sd->status.name, (char *)RFIFOP(fd,28));
  8246. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  8247. return;
  8248. }
  8249. // searching destination character
  8250. dstsd = map_nick2sd((char*)RFIFOP(fd,4));
  8251. // player is not on this map-server
  8252. if (dstsd == NULL ||
  8253. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8254. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8255. // and if we ask for 'Test', we must not contact 'test' player
  8256. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8257. strcmp(dstsd->status.name, (const char*)RFIFOP(fd,4)) != 0) // not exactly same name
  8258. // send message to inter-server
  8259. intif_wis_message(sd, (char*)RFIFOP(fd,4), (char*)RFIFOP(fd,28), RFIFOW(fd,2)-28);
  8260. // player is on this map-server
  8261. else {
  8262. // if you send to your self, don't send anything to others
  8263. if (dstsd->fd == fd) // but, normaly, it's impossible!
  8264. clif_wis_message(fd, wisp_server_name, "You can not page yourself. Sorry.", strlen("You can not page yourself. Sorry.") + 1);
  8265. // otherwise, send message and answer immediatly
  8266. else {
  8267. if (dstsd->ignoreAll == 1) {
  8268. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  8269. clif_wis_end(fd, 1); // 1: target character is not loged in
  8270. else
  8271. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8272. } else {
  8273. // if player ignore the source character
  8274. for(i = 0; i < MAX_IGNORE_LIST; i++)
  8275. if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0) {
  8276. clif_wis_end(fd, 2); // 2: ignored by target
  8277. break;
  8278. }
  8279. // if source player not found in ignore list
  8280. if (i == MAX_IGNORE_LIST) {
  8281. if(strlen(dstsd->away_message) > 0) { // Send away automessage [LuzZza]
  8282. //(Automessage has been sent)
  8283. sprintf(output, "%s %s", (char*)RFIFOP(fd,28),msg_txt(543));
  8284. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  8285. clif_wis_end(fd, 0); // 0: success to send wisper
  8286. if(dstsd->state.autotrade)
  8287. //"Away [AT] - \"%s\""
  8288. sprintf(output, msg_txt(544), dstsd->away_message);
  8289. else
  8290. //"Away - \"%s\""
  8291. sprintf(output, msg_txt(545), dstsd->away_message);
  8292. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  8293. } else { // Normal message
  8294. clif_wis_message(dstsd->fd, sd->status.name, (char*)RFIFOP(fd,28), RFIFOW(fd,2) - 28);
  8295. clif_wis_end(fd, 0); // 0: success to send wisper
  8296. }
  8297. }
  8298. }
  8299. }
  8300. }
  8301. return;
  8302. }
  8303. /*==========================================
  8304. *
  8305. *------------------------------------------
  8306. */
  8307. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  8308. // /b
  8309. RFIFOHEAD(fd);
  8310. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8311. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast)))
  8312. intif_GMmessage((char*)RFIFOP(fd,4), RFIFOW(fd,2)-4, 0);
  8313. }
  8314. /*==========================================
  8315. *
  8316. *------------------------------------------
  8317. */
  8318. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  8319. struct flooritem_data *fitem;
  8320. int map_object_id;
  8321. RFIFOHEAD(fd);
  8322. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8323. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8324. if (pc_isdead(sd)) {
  8325. clif_clearchar_area(&sd->bl, 1);
  8326. return;
  8327. }
  8328. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8329. return;
  8330. if (clif_cant_act(sd))
  8331. return;
  8332. if(pc_iscloaking(sd) || pc_ischasewalk(sd)) //Disable cloaking/chasewalking characters from looting [Skotlex]
  8333. return;
  8334. if(sd->sc.count && (
  8335. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  8336. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  8337. sd->sc.data[SC_NOCHAT].timer!=-1 ) //会話禁止
  8338. ) {
  8339. clif_additem(sd,0,0,6); // send fail packet! [Valaris]
  8340. return;
  8341. }
  8342. pc_takeitem(sd, fitem);
  8343. }
  8344. /*==========================================
  8345. *
  8346. *------------------------------------------
  8347. */
  8348. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  8349. int item_index, item_amount;
  8350. RFIFOHEAD(fd);
  8351. if (pc_isdead(sd)) {
  8352. clif_clearchar_area(&sd->bl, 1);
  8353. return;
  8354. }
  8355. if (clif_cant_act(sd))
  8356. return;
  8357. if (sd->sc.count && (
  8358. sd->sc.data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
  8359. sd->sc.data[SC_BLADESTOP].timer != -1//白刃取り
  8360. ))
  8361. return;
  8362. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8363. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8364. pc_dropitem(sd, item_index, item_amount);
  8365. }
  8366. /*==========================================
  8367. *
  8368. *------------------------------------------
  8369. */
  8370. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  8371. int n;
  8372. RFIFOHEAD(fd);
  8373. if (pc_isdead(sd)) {
  8374. clif_clearchar_area(&sd->bl, 1);
  8375. return;
  8376. }
  8377. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8378. return;
  8379. if (clif_trading(sd))
  8380. return;
  8381. //This flag enables you to use items while in an NPC. [Skotlex]
  8382. if (sd->npc_id && sd->npc_id != sd->npc_item_flag)
  8383. return;
  8384. if (sd->sc.count && (
  8385. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  8386. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  8387. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク
  8388. sd->sc.data[SC_NOCHAT].timer!=-1 ||
  8389. sd->sc.data[SC_GRAVITATION].timer!=-1 //会話禁止
  8390. ))
  8391. return;
  8392. if (sd->invincible_timer != -1)
  8393. pc_delinvincibletimer(sd);
  8394. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8395. sd->idletime = last_tick;
  8396. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8397. if(n <0 || n >= MAX_INVENTORY)
  8398. return;
  8399. if (!pc_useitem(sd,n))
  8400. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8401. }
  8402. /*==========================================
  8403. *
  8404. *------------------------------------------
  8405. */
  8406. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8407. {
  8408. int index;
  8409. RFIFOHEAD(fd);
  8410. if(pc_isdead(sd)) {
  8411. clif_clearchar_area(&sd->bl,1);
  8412. return;
  8413. }
  8414. index = RFIFOW(fd,2)-2;
  8415. if (index < 0 || index >= MAX_INVENTORY)
  8416. return; //Out of bounds check.
  8417. if(sd->npc_id) {
  8418. if (sd->npc_id != sd->npc_item_flag)
  8419. return;
  8420. } else if (clif_cant_act(sd))
  8421. return;
  8422. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  8423. return;
  8424. if(sd->status.inventory[index].identify != 1) { // 未鑑定
  8425. clif_equipitemack(sd,index,0,0); // fail
  8426. return;
  8427. }
  8428. //ペット用装備であるかないか
  8429. if(sd->inventory_data[index]) {
  8430. if(sd->inventory_data[index]->type != 8){
  8431. if(sd->inventory_data[index]->type == 10)
  8432. RFIFOW(fd,4)=0x8000; // 矢を無理やり装備できるように(--;
  8433. pc_equipitem(sd,index,RFIFOW(fd,4));
  8434. } else
  8435. pet_equipitem(sd,index);
  8436. }
  8437. }
  8438. /*==========================================
  8439. *
  8440. *------------------------------------------
  8441. */
  8442. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8443. {
  8444. int index;
  8445. RFIFOHEAD(fd);
  8446. if(pc_isdead(sd)) {
  8447. clif_clearchar_area(&sd->bl,1);
  8448. return;
  8449. }
  8450. if (clif_cant_act(sd))
  8451. return;
  8452. index = RFIFOW(fd,2)-2;
  8453. pc_unequipitem(sd,index,1);
  8454. }
  8455. /*==========================================
  8456. *
  8457. *------------------------------------------
  8458. */
  8459. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8460. {
  8461. RFIFOHEAD(fd);
  8462. if(pc_isdead(sd)) {
  8463. clif_clearchar_area(&sd->bl,1);
  8464. return;
  8465. }
  8466. if (clif_cant_act(sd))
  8467. return;
  8468. //Clicked on a negative ID? Player disguised as NPC! [Skotlex]
  8469. if (RFIFOL(fd,2) < 0)
  8470. return;
  8471. npc_click(sd,RFIFOL(fd,2));
  8472. }
  8473. /*==========================================
  8474. *
  8475. *------------------------------------------
  8476. */
  8477. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8478. {
  8479. RFIFOHEAD(fd);
  8480. if (sd->trade_partner != 0)
  8481. return;
  8482. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8483. }
  8484. /*==========================================
  8485. *
  8486. *------------------------------------------
  8487. */
  8488. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8489. {
  8490. int fail=0,n;
  8491. unsigned short *item_list;
  8492. RFIFOHEAD(fd);
  8493. n = (RFIFOW(fd,2)-4) /4;
  8494. item_list = (unsigned short*)RFIFOP(fd,4);
  8495. if (sd->trade_partner || !sd->npc_shopid)
  8496. fail = 1;
  8497. else
  8498. fail = npc_buylist(sd,n,item_list);
  8499. sd->npc_shopid = 0; //Clear shop data.
  8500. WFIFOHEAD(fd,packet_len_table[0xca]);
  8501. WFIFOW(fd,0)=0xca;
  8502. WFIFOB(fd,2)=fail;
  8503. WFIFOSET(fd,packet_len_table[0xca]);
  8504. }
  8505. /*==========================================
  8506. *
  8507. *------------------------------------------
  8508. */
  8509. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8510. {
  8511. int fail=0,n;
  8512. unsigned short *item_list;
  8513. RFIFOHEAD(fd);
  8514. n = (RFIFOW(fd,2)-4) /4;
  8515. item_list = (unsigned short*)RFIFOP(fd,4);
  8516. if (sd->trade_partner || !sd->npc_shopid)
  8517. fail = 1;
  8518. else
  8519. fail = npc_selllist(sd,n,item_list);
  8520. sd->npc_shopid = 0; //Clear shop data.
  8521. WFIFOHEAD(fd,packet_len_table[0xcb]);
  8522. WFIFOW(fd,0)=0xcb;
  8523. WFIFOB(fd,2)=fail;
  8524. WFIFOSET(fd,packet_len_table[0xcb]);
  8525. }
  8526. /*==========================================
  8527. *
  8528. *------------------------------------------
  8529. */
  8530. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8531. {
  8532. RFIFOHEAD(fd);
  8533. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8534. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8535. } else
  8536. clif_skill_fail(sd,1,0,3);
  8537. }
  8538. /*==========================================
  8539. *
  8540. *------------------------------------------
  8541. */
  8542. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8543. {
  8544. RFIFOHEAD(fd);
  8545. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8546. }
  8547. /*==========================================
  8548. *
  8549. *------------------------------------------
  8550. */
  8551. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8552. {
  8553. RFIFOHEAD(fd);
  8554. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8555. }
  8556. /*==========================================
  8557. *
  8558. *------------------------------------------
  8559. */
  8560. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8561. {
  8562. RFIFOHEAD(fd);
  8563. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8564. }
  8565. /*==========================================
  8566. *
  8567. *------------------------------------------
  8568. */
  8569. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8570. {
  8571. RFIFOHEAD(fd);
  8572. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8573. }
  8574. /*==========================================
  8575. *
  8576. *------------------------------------------
  8577. */
  8578. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8579. {
  8580. chat_leavechat(sd);
  8581. }
  8582. /*==========================================
  8583. * 取引要請を相手に送る
  8584. *------------------------------------------
  8585. */
  8586. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8587. {
  8588. RFIFOHEAD(fd);
  8589. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8590. trade_traderequest(sd,RFIFOL(sd->fd,2));
  8591. } else
  8592. clif_skill_fail(sd,1,0,0);
  8593. }
  8594. /*==========================================
  8595. * 取引要請
  8596. *------------------------------------------
  8597. */
  8598. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8599. {
  8600. RFIFOHEAD(fd);
  8601. trade_tradeack(sd,RFIFOB(sd->fd,2));
  8602. }
  8603. /*==========================================
  8604. * アイテム追加
  8605. *------------------------------------------
  8606. */
  8607. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8608. {
  8609. RFIFOHEAD(fd);
  8610. trade_tradeadditem(sd,RFIFOW(sd->fd,2),RFIFOL(sd->fd,4));
  8611. }
  8612. /*==========================================
  8613. * アイテム追加完了(ok押し)
  8614. *------------------------------------------
  8615. */
  8616. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8617. {
  8618. trade_tradeok(sd);
  8619. }
  8620. /*==========================================
  8621. * 取引キャンセル
  8622. *------------------------------------------
  8623. */
  8624. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8625. {
  8626. trade_tradecancel(sd);
  8627. }
  8628. /*==========================================
  8629. * 取引許諾(trade押し)
  8630. *------------------------------------------
  8631. */
  8632. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8633. {
  8634. trade_tradecommit(sd);
  8635. }
  8636. /*==========================================
  8637. *
  8638. *------------------------------------------
  8639. */
  8640. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8641. {
  8642. pc_stopattack(sd);
  8643. }
  8644. /*==========================================
  8645. * カートへアイテムを移す
  8646. *------------------------------------------
  8647. */
  8648. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8649. {
  8650. RFIFOHEAD(fd);
  8651. if (clif_trading(sd))
  8652. return;
  8653. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8654. }
  8655. /*==========================================
  8656. * カートからアイテムを出す
  8657. *------------------------------------------
  8658. */
  8659. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8660. {
  8661. RFIFOHEAD(fd);
  8662. if (clif_trading(sd))
  8663. return;
  8664. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8665. }
  8666. /*==========================================
  8667. * 付属品(鷹,ペコ,カート)をはずす
  8668. *------------------------------------------
  8669. */
  8670. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8671. {
  8672. pc_setoption(sd,0);
  8673. }
  8674. /*==========================================
  8675. * チェンジカート
  8676. *------------------------------------------
  8677. */
  8678. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8679. {
  8680. RFIFOHEAD(fd);
  8681. pc_setcart(sd,RFIFOW(fd,2));
  8682. }
  8683. /*==========================================
  8684. * ステータスアップ
  8685. *------------------------------------------
  8686. */
  8687. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8688. {
  8689. RFIFOHEAD(fd);
  8690. pc_statusup(sd,RFIFOW(fd,2));
  8691. }
  8692. /*==========================================
  8693. * スキルレベルアップ
  8694. *------------------------------------------
  8695. */
  8696. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8697. {
  8698. RFIFOHEAD(fd);
  8699. pc_skillup(sd,RFIFOW(fd,2));
  8700. }
  8701. /*==========================================
  8702. * スキル使用(ID指定)
  8703. *------------------------------------------
  8704. */
  8705. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8706. int skillnum, skilllv, lv, target_id;
  8707. unsigned int tick = gettick();
  8708. RFIFOHEAD(fd);
  8709. if (clif_cant_act(sd))
  8710. return;
  8711. if (pc_issit(sd))
  8712. return;
  8713. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8714. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8715. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8716. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8717. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8718. sd->idletime = last_tick;
  8719. if (skillnotok(skillnum, sd))
  8720. return;
  8721. if (sd->skilltimer != -1) {
  8722. if (skillnum != SA_CASTCANCEL)
  8723. return;
  8724. } else if (DIFF_TICK(tick, sd->canact_tick) < 0 &&
  8725. // allow monk combos to ignore this delay [celest]
  8726. !(sd->sc.count && sd->sc.data[SC_COMBO].timer!=-1 &&
  8727. (skillnum == MO_EXTREMITYFIST ||
  8728. skillnum == MO_CHAINCOMBO ||
  8729. skillnum == MO_COMBOFINISH ||
  8730. skillnum == CH_PALMSTRIKE ||
  8731. skillnum == CH_TIGERFIST ||
  8732. skillnum == CH_CHAINCRUSH))) {
  8733. clif_skill_fail(sd, skillnum, 4, 0);
  8734. return;
  8735. }
  8736. if (sd->view_class == JOB_WEDDING || sd->view_class == JOB_XMAS)
  8737. return;
  8738. if (sd->invincible_timer != -1)
  8739. pc_delinvincibletimer(sd);
  8740. if(target_id<0) // for disguises [Valaris]
  8741. target_id-=target_id*2;
  8742. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8743. if (skilllv != sd->skillitemlv)
  8744. skilllv = sd->skillitemlv;
  8745. skill_use_id(sd, target_id, skillnum, skilllv);
  8746. } else {
  8747. sd->skillitem = sd->skillitemlv = -1;
  8748. if (skillnum == MO_EXTREMITYFIST) {
  8749. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8750. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8751. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8752. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8753. if (!sd->state.skill_flag ) {
  8754. sd->state.skill_flag = 1;
  8755. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8756. return;
  8757. } else if (sd->bl.id == target_id) {
  8758. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8759. return;
  8760. }
  8761. }
  8762. }
  8763. if (skillnum == TK_JUMPKICK) {
  8764. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8765. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8766. if (!sd->state.skill_flag ) {
  8767. sd->state.skill_flag = 1;
  8768. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8769. return;
  8770. } else if (sd->bl.id == target_id) {
  8771. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8772. return;
  8773. }
  8774. }
  8775. }
  8776. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8777. if (skilllv > lv)
  8778. skilllv = lv;
  8779. skill_use_id(sd, target_id, skillnum, skilllv);
  8780. if (sd->state.skill_flag)
  8781. sd->state.skill_flag = 0;
  8782. }
  8783. }
  8784. }
  8785. /*==========================================
  8786. * スキル使用(場所指定)
  8787. *------------------------------------------
  8788. */
  8789. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8790. {
  8791. int lv;
  8792. unsigned int tick = gettick();
  8793. RFIFOHEAD(fd);
  8794. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8795. sd->idletime = last_tick;
  8796. if (skillnotok(skillnum, sd))
  8797. return;
  8798. if (skillmoreinfo != -1) {
  8799. if (pc_issit(sd)) {
  8800. clif_skill_fail(sd, skillnum, 0, 0);
  8801. return;
  8802. }
  8803. memcpy(talkie_mes, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8804. talkie_mes[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8805. }
  8806. if (sd->skilltimer != -1)
  8807. return;
  8808. else if (DIFF_TICK(tick, sd->canact_tick) < 0)
  8809. {
  8810. clif_skill_fail(sd, skillnum, 4, 0);
  8811. return;
  8812. }
  8813. if (sd->view_class == JOB_WEDDING || sd->view_class == JOB_XMAS)
  8814. return;
  8815. if (sd->invincible_timer != -1)
  8816. pc_delinvincibletimer(sd);
  8817. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8818. if (skilllv != sd->skillitemlv)
  8819. skilllv = sd->skillitemlv;
  8820. skill_use_pos(sd, x, y, skillnum, skilllv);
  8821. } else {
  8822. sd->skillitem = sd->skillitemlv = -1;
  8823. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8824. if (skilllv > lv)
  8825. skilllv = lv;
  8826. skill_use_pos(sd, x, y, skillnum,skilllv);
  8827. }
  8828. }
  8829. }
  8830. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8831. RFIFOHEAD(fd);
  8832. if (clif_cant_act(sd))
  8833. return;
  8834. if (pc_issit(sd))
  8835. return;
  8836. clif_parse_UseSkillToPosSub(fd, sd,
  8837. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8838. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8839. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8840. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8841. -1 //Skill more info.
  8842. );
  8843. }
  8844. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8845. RFIFOHEAD(fd);
  8846. if (clif_cant_act(sd))
  8847. return;
  8848. if (pc_issit(sd))
  8849. return;
  8850. clif_parse_UseSkillToPosSub(fd, sd,
  8851. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8852. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8853. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8854. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8855. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8856. );
  8857. }
  8858. /*==========================================
  8859. * スキル使用(map指定)
  8860. *------------------------------------------
  8861. */
  8862. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8863. {
  8864. RFIFOHEAD(fd);
  8865. if (clif_cant_act(sd))
  8866. return;
  8867. if (sd->view_class==JOB_WEDDING || sd->view_class == JOB_XMAS)
  8868. return;
  8869. if(sd->invincible_timer != -1)
  8870. pc_delinvincibletimer(sd);
  8871. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8872. }
  8873. /*==========================================
  8874. * メモ要求
  8875. *------------------------------------------
  8876. */
  8877. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8878. {
  8879. if (!pc_isdead(sd))
  8880. pc_memo(sd,-1);
  8881. }
  8882. /*==========================================
  8883. * アイテム合成
  8884. *------------------------------------------
  8885. */
  8886. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8887. {
  8888. RFIFOHEAD(fd);
  8889. if (sd->menuskill_id != AM_PHARMACY)
  8890. return;
  8891. if (clif_trading(sd)) {
  8892. //Make it fail to avoid shop exploits where you sell something different than you see.
  8893. clif_skill_fail(sd,sd->skillid,0,0);
  8894. sd->menuskill_lv = sd->menuskill_id = 0;
  8895. return;
  8896. }
  8897. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8898. sd->menuskill_lv = sd->menuskill_id = 0;
  8899. }
  8900. /*==========================================
  8901. * 武器修理
  8902. *------------------------------------------
  8903. */
  8904. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8905. {
  8906. RFIFOHEAD(fd);
  8907. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8908. return;
  8909. if (clif_trading(sd)) {
  8910. //Make it fail to avoid shop exploits where you sell something different than you see.
  8911. clif_skill_fail(sd,sd->skillid,0,0);
  8912. sd->menuskill_lv = sd->menuskill_id = 0;
  8913. return;
  8914. }
  8915. skill_repairweapon(sd,RFIFOW(fd,2));
  8916. sd->menuskill_lv = sd->menuskill_id = 0;
  8917. }
  8918. /*==========================================
  8919. *
  8920. *------------------------------------------
  8921. */
  8922. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8923. int idx;
  8924. RFIFOHEAD(fd);
  8925. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8926. return;
  8927. if (clif_trading(sd)) {
  8928. //Make it fail to avoid shop exploits where you sell something different than you see.
  8929. clif_skill_fail(sd,sd->skillid,0,0);
  8930. sd->menuskill_lv = sd->menuskill_id = 0;
  8931. return;
  8932. }
  8933. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8934. skill_weaponrefine(sd, idx-2);
  8935. sd->menuskill_lv = sd->menuskill_id = 0;
  8936. }
  8937. /*==========================================
  8938. *
  8939. *------------------------------------------
  8940. */
  8941. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8942. {
  8943. RFIFOHEAD(fd);
  8944. sd->npc_menu=RFIFOB(fd,6);
  8945. npc_scriptcont(sd,RFIFOL(fd,2));
  8946. }
  8947. /*==========================================
  8948. *
  8949. *------------------------------------------
  8950. */
  8951. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8952. {
  8953. RFIFOHEAD(fd);
  8954. #ifdef __WIN32
  8955. //For some extraordinarily eerie reason that noone has figured out yet,
  8956. //windows native compiles NEED this nullpo_retv or the function is not found!
  8957. nullpo_retv(sd);
  8958. #endif
  8959. npc_scriptcont(sd,RFIFOL(fd,2));
  8960. }
  8961. /*==========================================
  8962. *
  8963. *------------------------------------------
  8964. */
  8965. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8966. {
  8967. RFIFOHEAD(fd);
  8968. #define RFIFOL_(fd,pos) (*(int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos)))
  8969. //Input Value overflow Exploit FIX
  8970. sd->npc_amount=RFIFOL_(fd,6); //fixed by Lupus. npc_amount is (int) but was RFIFOL changing it to (unsigned int)
  8971. #undef RFIFOL_
  8972. npc_scriptcont(sd,RFIFOL(fd,2));
  8973. }
  8974. /*==========================================
  8975. *
  8976. *------------------------------------------
  8977. */
  8978. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8979. {
  8980. RFIFOHEAD(fd);
  8981. if(RFIFOW(fd,2)-7 >= sizeof(sd->npc_str)){
  8982. ShowWarning("clif: input string too long !\n");
  8983. memcpy(sd->npc_str,RFIFOP(fd,8),sizeof(sd->npc_str));
  8984. sd->npc_str[sizeof(sd->npc_str)-1]=0;
  8985. } else
  8986. strcpy(sd->npc_str,(char*)RFIFOP(fd,8));
  8987. npc_scriptcont(sd,RFIFOL(fd,4));
  8988. }
  8989. /*==========================================
  8990. *
  8991. *------------------------------------------
  8992. */
  8993. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8994. {
  8995. RFIFOHEAD(fd);
  8996. npc_scriptcont(sd,RFIFOL(fd,2));
  8997. }
  8998. /*==========================================
  8999. * アイテム鑑定
  9000. *------------------------------------------
  9001. */
  9002. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9003. {
  9004. RFIFOHEAD(fd);
  9005. if (sd->menuskill_id != MC_IDENTIFY)
  9006. return;
  9007. skill_identify(sd,RFIFOW(fd,2)-2);
  9008. sd->menuskill_lv = sd->menuskill_id = 0;
  9009. }
  9010. /*==========================================
  9011. * 矢作成
  9012. *------------------------------------------
  9013. */
  9014. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9015. {
  9016. RFIFOHEAD(fd);
  9017. if (sd->menuskill_id != AC_MAKINGARROW)
  9018. return;
  9019. if (clif_trading(sd)) {
  9020. //Make it fail to avoid shop exploits where you sell something different than you see.
  9021. clif_skill_fail(sd,sd->skillid,0,0);
  9022. sd->menuskill_lv = sd->menuskill_id = 0;
  9023. return;
  9024. }
  9025. skill_arrow_create(sd,RFIFOW(fd,2));
  9026. sd->menuskill_lv = sd->menuskill_id = 0;
  9027. }
  9028. /*==========================================
  9029. * オートスペル受信
  9030. *------------------------------------------
  9031. */
  9032. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9033. {
  9034. RFIFOHEAD(fd);
  9035. if (sd->menuskill_id != SA_AUTOSPELL)
  9036. return;
  9037. skill_autospell(sd,RFIFOW(fd,2));
  9038. sd->menuskill_lv = sd->menuskill_id = 0;
  9039. }
  9040. /*==========================================
  9041. * カード使用
  9042. *------------------------------------------
  9043. */
  9044. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9045. {
  9046. RFIFOHEAD(fd);
  9047. if (sd->trade_partner != 0)
  9048. return;
  9049. clif_use_card(sd,RFIFOW(fd,2)-2);
  9050. }
  9051. /*==========================================
  9052. * カード挿入装備選択
  9053. *------------------------------------------
  9054. */
  9055. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9056. {
  9057. RFIFOHEAD(fd);
  9058. if (sd->trade_partner != 0)
  9059. return;
  9060. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9061. }
  9062. /*==========================================
  9063. * 0193 キャラID名前引き
  9064. *------------------------------------------
  9065. */
  9066. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  9067. int char_id;
  9068. RFIFOHEAD(fd);
  9069. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9070. clif_solved_charname(sd, char_id);
  9071. }
  9072. /*==========================================
  9073. * 0197 /resetskill /resetstate
  9074. *------------------------------------------
  9075. */
  9076. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  9077. RFIFOHEAD(fd);
  9078. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9079. pc_isGM(sd) >= get_atcommand_level(AtCommand_ResetState)) {
  9080. switch(RFIFOW(fd,2)){
  9081. case 0:
  9082. pc_resetstate(sd);
  9083. break;
  9084. case 1:
  9085. pc_resetskill(sd,1);
  9086. break;
  9087. }
  9088. }
  9089. }
  9090. /*==========================================
  9091. * 019c /lb等
  9092. *------------------------------------------
  9093. */
  9094. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  9095. unsigned char buf[512];
  9096. RFIFOHEAD(fd);
  9097. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9098. (pc_isGM(sd) >= get_atcommand_level(AtCommand_LocalBroadcast))) {
  9099. WBUFW(buf,0) = 0x9a;
  9100. WBUFW(buf,2) = RFIFOW(fd,2);
  9101. memcpy(WBUFP(buf,4), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  9102. clif_send(buf, RFIFOW(fd,2), &sd->bl, ALL_SAMEMAP);
  9103. }
  9104. }
  9105. /*==========================================
  9106. * カプラ倉庫へ入れる
  9107. *------------------------------------------
  9108. */
  9109. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  9110. int item_index, item_amount;
  9111. RFIFOHEAD(fd);
  9112. if (clif_trading(sd))
  9113. return;
  9114. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9115. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9116. if (item_index < 0 || item_index >= MAX_INVENTORY)
  9117. return;
  9118. if (sd->state.storage_flag == 1)
  9119. storage_storageadd(sd, item_index, item_amount);
  9120. else if (sd->state.storage_flag == 2)
  9121. storage_guild_storageadd(sd, item_index, item_amount);
  9122. }
  9123. /*==========================================
  9124. * カプラ倉庫から出す
  9125. *------------------------------------------
  9126. */
  9127. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  9128. int item_index, item_amount;
  9129. RFIFOHEAD(fd);
  9130. if (clif_trading(sd))
  9131. return;
  9132. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9133. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9134. if (sd->state.storage_flag == 1)
  9135. storage_storageget(sd, item_index, item_amount);
  9136. else if(sd->state.storage_flag == 2)
  9137. storage_guild_storageget(sd, item_index, item_amount);
  9138. }
  9139. /*==========================================
  9140. * カプラ倉庫へカートから入れる
  9141. *------------------------------------------
  9142. */
  9143. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  9144. RFIFOHEAD(fd);
  9145. if (clif_trading(sd))
  9146. return;
  9147. if (sd->state.storage_flag == 1)
  9148. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9149. else if (sd->state.storage_flag == 2)
  9150. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9151. }
  9152. /*==========================================
  9153. * カプラ倉庫から出す
  9154. *------------------------------------------
  9155. */
  9156. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  9157. RFIFOHEAD(fd);
  9158. if (clif_trading(sd))
  9159. return;
  9160. if (sd->state.storage_flag == 1)
  9161. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9162. else if (sd->state.storage_flag == 2)
  9163. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9164. }
  9165. /*==========================================
  9166. * カプラ倉庫を閉じる
  9167. *------------------------------------------
  9168. */
  9169. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  9170. if (sd->state.storage_flag == 1)
  9171. storage_storageclose(sd);
  9172. else if (sd->state.storage_flag == 2)
  9173. storage_guild_storageclose(sd);
  9174. }
  9175. /*==========================================
  9176. * パーティを作る
  9177. *------------------------------------------
  9178. */
  9179. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  9180. RFIFOHEAD(fd);
  9181. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  9182. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  9183. } else
  9184. clif_skill_fail(sd,1,0,4);
  9185. }
  9186. /*==========================================
  9187. * パーティを作る
  9188. *------------------------------------------
  9189. */
  9190. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  9191. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  9192. RFIFOHEAD(fd);
  9193. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  9194. } else
  9195. clif_skill_fail(sd,1,0,4);
  9196. }
  9197. /*==========================================
  9198. * パーティに勧誘
  9199. *------------------------------------------
  9200. */
  9201. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  9202. RFIFOHEAD(fd);
  9203. party_invite(sd, RFIFOL(fd,2));
  9204. }
  9205. /*==========================================
  9206. * パーティ勧誘返答
  9207. *------------------------------------------
  9208. */
  9209. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  9210. RFIFOHEAD(fd);
  9211. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  9212. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9213. } else {
  9214. party_reply_invite(sd,RFIFOL(fd,2),-1);
  9215. clif_skill_fail(sd,1,0,4);
  9216. }
  9217. }
  9218. /*==========================================
  9219. * パーティ脱退要求
  9220. *------------------------------------------
  9221. */
  9222. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  9223. party_leave(sd);
  9224. }
  9225. /*==========================================
  9226. * パーティ除名要求
  9227. *------------------------------------------
  9228. */
  9229. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  9230. RFIFOHEAD(fd);
  9231. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9232. }
  9233. /*==========================================
  9234. * パーティ設定変更要求
  9235. *------------------------------------------
  9236. */
  9237. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  9238. RFIFOHEAD(fd);
  9239. party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  9240. }
  9241. /*==========================================
  9242. * パーティメッセージ送信要求
  9243. *------------------------------------------
  9244. */
  9245. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  9246. RFIFOHEAD(fd);
  9247. if (is_charcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != CharCommand_None ||
  9248. is_atcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != AtCommand_None)
  9249. return;
  9250. if (sd->sc.count && (
  9251. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  9252. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  9253. ))
  9254. return;
  9255. party_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9256. }
  9257. /*==========================================
  9258. * 露店閉鎖
  9259. *------------------------------------------
  9260. */
  9261. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  9262. vending_closevending(sd);
  9263. }
  9264. /*==========================================
  9265. * 露店アイテムリスト要求
  9266. *------------------------------------------
  9267. */
  9268. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  9269. RFIFOHEAD(fd);
  9270. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9271. if(sd->npc_id)
  9272. npc_event_dequeue(sd);
  9273. }
  9274. /*==========================================
  9275. * 露店アイテム購入
  9276. *------------------------------------------
  9277. */
  9278. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  9279. RFIFOHEAD(fd);
  9280. if (clif_trading(sd))
  9281. return;
  9282. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  9283. }
  9284. /*==========================================
  9285. * 露店開設
  9286. *------------------------------------------
  9287. */
  9288. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  9289. RFIFOHEAD(fd);
  9290. if (clif_trading(sd))
  9291. return;
  9292. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  9293. }
  9294. /*==========================================
  9295. * ギルドを作る
  9296. *------------------------------------------
  9297. */
  9298. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  9299. RFIFOHEAD(fd);
  9300. guild_create(sd, (char*)RFIFOP(fd,6));
  9301. }
  9302. /*==========================================
  9303. * ギルドマスターかどうか確認
  9304. *------------------------------------------
  9305. */
  9306. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  9307. clif_guild_masterormember(sd);
  9308. }
  9309. /*==========================================
  9310. * ギルド情報要求
  9311. *------------------------------------------
  9312. */
  9313. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  9314. RFIFOHEAD(fd);
  9315. switch(RFIFOL(fd,2)){
  9316. case 0: // ギルド基本情報、同盟敵対情報
  9317. clif_guild_basicinfo(sd);
  9318. clif_guild_allianceinfo(sd);
  9319. break;
  9320. case 1: // メンバーリスト、役職名リスト
  9321. clif_guild_positionnamelist(sd);
  9322. clif_guild_memberlist(sd);
  9323. break;
  9324. case 2: // 役職名リスト、役職情報リスト
  9325. clif_guild_positionnamelist(sd);
  9326. clif_guild_positioninfolist(sd);
  9327. break;
  9328. case 3: // スキルリスト
  9329. clif_guild_skillinfo(sd);
  9330. break;
  9331. case 4: // 追放リスト
  9332. clif_guild_explusionlist(sd);
  9333. break;
  9334. default:
  9335. if (battle_config.error_log)
  9336. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9337. break;
  9338. }
  9339. }
  9340. /*==========================================
  9341. * ギルド役職変更
  9342. *------------------------------------------
  9343. */
  9344. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  9345. int i;
  9346. RFIFOHEAD(fd);
  9347. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9348. guild_change_position(sd, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9349. }
  9350. }
  9351. /*==========================================
  9352. * ギルドメンバ役職変更
  9353. *------------------------------------------
  9354. */
  9355. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  9356. int i;
  9357. RFIFOHEAD(fd);
  9358. for(i=4;i<RFIFOW(fd,2);i+=12){
  9359. guild_change_memberposition(sd->status.guild_id,
  9360. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9361. }
  9362. }
  9363. /*==========================================
  9364. * ギルドエンブレム要求
  9365. *------------------------------------------
  9366. */
  9367. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  9368. struct guild *g;
  9369. RFIFOHEAD(fd);
  9370. g=guild_search(RFIFOL(fd,2));
  9371. if(g!=NULL)
  9372. clif_guild_emblem(sd,g);
  9373. }
  9374. /*==========================================
  9375. * ギルドエンブレム変更
  9376. *------------------------------------------
  9377. */
  9378. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  9379. RFIFOHEAD(fd);
  9380. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9381. }
  9382. /*==========================================
  9383. * ギルド告知変更
  9384. *------------------------------------------
  9385. */
  9386. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  9387. RFIFOHEAD(fd);
  9388. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  9389. }
  9390. /*==========================================
  9391. * ギルド勧誘
  9392. *------------------------------------------
  9393. */
  9394. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  9395. RFIFOHEAD(fd);
  9396. guild_invite(sd,RFIFOL(fd,2));
  9397. }
  9398. /*==========================================
  9399. * ギルド勧誘返信
  9400. *------------------------------------------
  9401. */
  9402. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9403. RFIFOHEAD(fd);
  9404. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9405. }
  9406. /*==========================================
  9407. * ギルド脱退
  9408. *------------------------------------------
  9409. */
  9410. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9411. RFIFOHEAD(fd);
  9412. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9413. }
  9414. /*==========================================
  9415. * ギルド追放
  9416. *------------------------------------------
  9417. */
  9418. void clif_parse_GuildExplusion(int fd,struct map_session_data *sd) {
  9419. RFIFOHEAD(fd);
  9420. guild_explusion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9421. }
  9422. /*==========================================
  9423. * ギルド会話
  9424. *------------------------------------------
  9425. */
  9426. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9427. RFIFOHEAD(fd);
  9428. if (is_charcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != CharCommand_None ||
  9429. is_atcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != AtCommand_None)
  9430. return;
  9431. if (sd->sc.count && (
  9432. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  9433. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  9434. ))
  9435. return;
  9436. guild_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9437. }
  9438. /*==========================================
  9439. * ギルド同盟要求
  9440. *------------------------------------------
  9441. */
  9442. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9443. RFIFOHEAD(fd);
  9444. guild_reqalliance(sd,RFIFOL(fd,2));
  9445. }
  9446. /*==========================================
  9447. * ギルド同盟要求返信
  9448. *------------------------------------------
  9449. */
  9450. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9451. RFIFOHEAD(fd);
  9452. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9453. }
  9454. /*==========================================
  9455. * ギルド関係解消
  9456. *------------------------------------------
  9457. */
  9458. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9459. RFIFOHEAD(fd);
  9460. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9461. }
  9462. /*==========================================
  9463. * ギルド敵対
  9464. *------------------------------------------
  9465. */
  9466. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9467. RFIFOHEAD(fd);
  9468. guild_opposition(sd,RFIFOL(fd,2));
  9469. }
  9470. /*==========================================
  9471. * ギルド解散
  9472. *------------------------------------------
  9473. */
  9474. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9475. RFIFOHEAD(fd);
  9476. guild_break(sd,(char*)RFIFOP(fd,2));
  9477. }
  9478. // pet
  9479. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9480. RFIFOHEAD(fd);
  9481. pet_menu(sd,RFIFOB(fd,2));
  9482. }
  9483. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9484. RFIFOHEAD(fd);
  9485. pet_catch_process2(sd,RFIFOL(fd,2));
  9486. }
  9487. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9488. RFIFOHEAD(fd);
  9489. if (sd->menuskill_id != SA_TAMINGMONSTER)
  9490. return;
  9491. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9492. sd->menuskill_lv = sd->menuskill_id = 0;
  9493. }
  9494. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9495. if(sd->pd) {
  9496. RFIFOHEAD(fd);
  9497. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9498. }
  9499. }
  9500. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9501. RFIFOHEAD(fd);
  9502. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9503. }
  9504. // Kick (right click menu for GM "(name) force to quit")
  9505. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9506. struct block_list *target;
  9507. int tid;
  9508. RFIFOHEAD(fd);
  9509. tid = RFIFOL(fd,2);
  9510. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9511. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Kick))) {
  9512. target = map_id2bl(tid);
  9513. if (target) {
  9514. if (target->type == BL_PC) {
  9515. struct map_session_data *tsd = (struct map_session_data *)target;
  9516. if (pc_isGM(sd) > pc_isGM(tsd))
  9517. clif_GM_kick(sd, tsd, 1);
  9518. else
  9519. clif_GM_kickack(sd, 0);
  9520. } else if (target->type == BL_MOB) {
  9521. struct mob_data *md = (struct mob_data *)target;
  9522. sd->state.attack_type = 0;
  9523. mob_damage(&sd->bl, md, md->hp, 2);
  9524. } else
  9525. clif_GM_kickack(sd, 0);
  9526. } else
  9527. clif_GM_kickack(sd, 0);
  9528. }
  9529. }
  9530. /*==========================================
  9531. * /shift
  9532. *------------------------------------------
  9533. */
  9534. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9535. char player_name[NAME_LENGTH+1];
  9536. memset(player_name, '\0', sizeof(player_name));
  9537. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9538. (pc_isGM(sd) >= get_atcommand_level(AtCommand_JumpTo))) {
  9539. RFIFOHEAD(fd);
  9540. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9541. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9542. }
  9543. return;
  9544. }
  9545. /*==========================================
  9546. * /recall
  9547. *------------------------------------------
  9548. */
  9549. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9550. char player_name[25];
  9551. memset(player_name, '\0', sizeof(player_name));
  9552. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9553. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Recall))) {
  9554. RFIFOHEAD(fd);
  9555. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9556. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9557. }
  9558. return;
  9559. }
  9560. /*==========================================
  9561. * /monster /item rewriten by [Yor]
  9562. *------------------------------------------
  9563. */
  9564. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9565. char monster_item_name[NAME_LENGTH+10]; //Additional space is for logging, eg: "@monster Poring"
  9566. int level;
  9567. memset(monster_item_name, '\0', sizeof(monster_item_name));
  9568. if (battle_config.atc_gmonly == 0 || pc_isGM(sd)) {
  9569. RFIFOHEAD(fd);
  9570. memcpy(monster_item_name, RFIFOP(fd,2), NAME_LENGTH);
  9571. if (mobdb_searchname(monster_item_name) != 0) {
  9572. if (pc_isGM(sd) >= (level =get_atcommand_level(AtCommand_Monster)))
  9573. {
  9574. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9575. if(log_config.gm && level >= log_config.gm)
  9576. { //Log action. [Skotlex]
  9577. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@spawn %s", RFIFOP(fd,2));
  9578. log_atcommand(sd, monster_item_name);
  9579. }
  9580. }
  9581. } else if (itemdb_searchname(monster_item_name) != NULL) {
  9582. if (pc_isGM(sd) >= (level = get_atcommand_level(AtCommand_Item)))
  9583. {
  9584. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9585. if(log_config.gm && level >= log_config.gm)
  9586. { //Log action. [Skotlex]
  9587. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@item %s", RFIFOP(fd,2));
  9588. log_atcommand(sd, monster_item_name);
  9589. }
  9590. }
  9591. }
  9592. }
  9593. }
  9594. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9595. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9596. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) {
  9597. if (sd->sc.option & OPTION_INVISIBLE) {
  9598. sd->sc.option &= ~OPTION_INVISIBLE;
  9599. clif_displaymessage(fd, "Invisible: Off.");
  9600. } else {
  9601. sd->sc.option |= OPTION_INVISIBLE;
  9602. clif_displaymessage(fd, "Invisible: On.");
  9603. }
  9604. clif_changeoption(&sd->bl);
  9605. }
  9606. }
  9607. /*==========================================
  9608. * GMによるチャット禁止時間付与
  9609. *------------------------------------------
  9610. */
  9611. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9612. {
  9613. int type, limit, level;
  9614. struct block_list *bl;
  9615. struct map_session_data *dstsd;
  9616. if(!battle_config.muting_players) {
  9617. clif_displaymessage(fd, "Muting is disabled.");
  9618. return;
  9619. }
  9620. RFIFOHEAD(fd);
  9621. bl = map_id2bl(RFIFOL(fd,2));
  9622. if (!bl || bl->type != BL_PC)
  9623. return;
  9624. nullpo_retv(dstsd =(struct map_session_data *)bl);
  9625. type = RFIFOB(fd,6);
  9626. limit = RFIFOW(fd,7);
  9627. if (type == 0)
  9628. limit = 0 - limit;
  9629. //Temporarily disable chars from muting themselves due to the mysterious "DON'T USE BOT!" message. [Skotlex]
  9630. //Also, if type is 2 and the ids don't match, this is a crafted hacked packet!
  9631. //So for now, type 2is just totally disabled.
  9632. if (type == 2/*&& sd->bl.id != dstsd->bl.id*/)
  9633. return;
  9634. if (
  9635. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9636. || (type == 2 && !level)) {
  9637. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9638. if (battle_config.manner_system)
  9639. {
  9640. dstsd->status.manner -= limit;
  9641. if(dstsd->status.manner < 0)
  9642. status_change_start(bl,SC_NOCHAT,100,0,0,0,0,0,0);
  9643. else
  9644. {
  9645. dstsd->status.manner = 0;
  9646. status_change_end(bl,SC_NOCHAT,-1);
  9647. }
  9648. }
  9649. ShowDebug("GMReqNoChat: name:%s type:%d limit:%d manner:%d\n", dstsd->status.name, type, limit, dstsd->status.manner);
  9650. }
  9651. return;
  9652. }
  9653. /*==========================================
  9654. * GMによるチャット禁止時間参照(?)
  9655. *------------------------------------------
  9656. */
  9657. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9658. {
  9659. int tid;
  9660. RFIFOHEAD(fd);
  9661. tid = RFIFOL(fd,2);
  9662. WFIFOHEAD(fd,packet_len_table[0x1e0]);
  9663. WFIFOW(fd,0) = 0x1e0;
  9664. WFIFOL(fd,2) = tid;
  9665. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9666. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9667. WFIFOSET(fd, packet_len_table[0x1e0]);
  9668. return;
  9669. }
  9670. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9671. char output[512];
  9672. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9673. int i, pos;
  9674. RFIFOHEAD(fd);
  9675. memset(output, '\0', sizeof(output));
  9676. nick = (char*)RFIFOP(fd,2); // speed up
  9677. RFIFOB(fd,NAME_LENGTH+1) = '\0'; // to be sure that the player name have at maximum 23 characters (nick range: [2]->[26])
  9678. //printf("Ignore: char '%s' state: %d\n", nick, RFIFOB(fd,26));
  9679. WFIFOHEAD(fd,packet_len_table[0xd1]);
  9680. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9681. WFIFOB(fd,2) = RFIFOB(fd,26);
  9682. // do nothing only if nick can not exist
  9683. if (strlen(nick) < 4) {
  9684. WFIFOB(fd,3) = 1; // fail
  9685. WFIFOSET(fd, packet_len_table[0x0d1]);
  9686. if (RFIFOB(fd,26) == 0) // type
  9687. clif_wis_message(fd, wisp_server_name, "It's impossible to block this player.", strlen("It's impossible to block this player.") + 1);
  9688. else
  9689. clif_wis_message(fd, wisp_server_name, "It's impossible to unblock this player.", strlen("It's impossible to unblock this player.") + 1);
  9690. return;
  9691. // name can exist
  9692. } else {
  9693. // deny action (we add nick only if it's not already exist
  9694. if (RFIFOB(fd,26) == 0) { // type
  9695. pos = -1;
  9696. for(i = 0; i < MAX_IGNORE_LIST; i++) {
  9697. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9698. WFIFOB(fd,3) = 1; // fail
  9699. WFIFOSET(fd, packet_len_table[0x0d1]);
  9700. clif_wis_message(fd, wisp_server_name, "This player is already blocked.", strlen("This player is already blocked.") + 1);
  9701. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9702. 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);
  9703. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9704. }
  9705. return;
  9706. } else if (pos == -1 && sd->ignore[i].name[0] == '\0')
  9707. pos = i;
  9708. }
  9709. // if a position is found and name not found, we add it in the list
  9710. if (pos != -1) {
  9711. memcpy(sd->ignore[pos].name, nick, NAME_LENGTH-1);
  9712. WFIFOB(fd,3) = 0; // success
  9713. WFIFOSET(fd, packet_len_table[0x0d1]);
  9714. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9715. 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);
  9716. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9717. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9718. 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);
  9719. }
  9720. } else {
  9721. WFIFOB(fd,3) = 1; // fail
  9722. WFIFOSET(fd, packet_len_table[0x0d1]);
  9723. clif_wis_message(fd, wisp_server_name, "You can not block more people.", strlen("You can not block more people.") + 1);
  9724. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9725. 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);
  9726. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9727. }
  9728. }
  9729. // allow action (we remove all same nicks if they exist)
  9730. } else {
  9731. pos = -1;
  9732. for(i = 0; i < MAX_IGNORE_LIST; i++)
  9733. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9734. memset(sd->ignore[i].name, 0, sizeof(sd->ignore[i].name));
  9735. if (pos == -1) {
  9736. WFIFOB(fd,3) = 0; // success
  9737. WFIFOSET(fd, packet_len_table[0x0d1]);
  9738. pos = i; // don't break, to remove ALL same nick
  9739. }
  9740. }
  9741. if (pos == -1) {
  9742. WFIFOB(fd,3) = 1; // fail
  9743. WFIFOSET(fd, packet_len_table[0x0d1]);
  9744. clif_wis_message(fd, wisp_server_name, "This player is not blocked by you.", strlen("This player is not blocked by you.") + 1);
  9745. }
  9746. }
  9747. }
  9748. // for(i = 0; i < MAX_IGNORE_LIST; i++) // for debug only
  9749. // if (sd->ignore[i].name[0] != '\0')
  9750. // printf("Ignored player: '%s'\n", sd->ignore[i].name);
  9751. return;
  9752. }
  9753. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9754. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9755. RFIFOHEAD(fd);
  9756. if (RFIFOB(fd,2) == 0) {// S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9757. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9758. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9759. WFIFOB(fd,2) = 0;
  9760. if (sd->ignoreAll == 0) {
  9761. sd->ignoreAll = 1;
  9762. WFIFOB(fd,3) = 0; // success
  9763. WFIFOSET(fd, packet_len_table[0x0d2]);
  9764. } else {
  9765. WFIFOB(fd,3) = 1; // fail
  9766. WFIFOSET(fd, packet_len_table[0x0d2]);
  9767. clif_wis_message(fd, wisp_server_name, "You already block everyone.", strlen("You already block everyone.") + 1);
  9768. }
  9769. } else {
  9770. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9771. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9772. WFIFOB(fd,2) = 1;
  9773. if (sd->ignoreAll == 1) {
  9774. sd->ignoreAll = 0;
  9775. WFIFOB(fd,3) = 0; // success
  9776. WFIFOSET(fd, packet_len_table[0x0d2]);
  9777. } else {
  9778. WFIFOB(fd,3) = 1; // fail
  9779. WFIFOSET(fd, packet_len_table[0x0d2]);
  9780. clif_wis_message(fd, wisp_server_name, "You already allow everyone.", strlen("You already allow everyone.") + 1);
  9781. }
  9782. }
  9783. return;
  9784. }
  9785. /*==========================================
  9786. * Wis拒否リスト
  9787. *------------------------------------------
  9788. */
  9789. int pstrcmp(const void *a, const void *b)
  9790. {
  9791. return strcmp((char *)a, (char *)b);
  9792. }
  9793. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9794. {
  9795. int i,j=0,count=0;
  9796. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9797. for(i = 0; i < MAX_IGNORE_LIST; i++){ //中身があるのを数える
  9798. if(sd->ignore[i].name[0] != 0)
  9799. count++;
  9800. }
  9801. WFIFOHEAD(fd, 4 + (NAME_LENGTH * count));
  9802. WFIFOW(fd,0) = 0xd4;
  9803. WFIFOW(fd,2) = 4 + (NAME_LENGTH * count);
  9804. for(i = 0; i < MAX_IGNORE_LIST; i++){
  9805. if(sd->ignore[i].name[0] != 0){
  9806. memcpy(WFIFOP(fd, 4 + j * 24),sd->ignore[i].name, NAME_LENGTH);
  9807. j++;
  9808. }
  9809. }
  9810. WFIFOSET(fd, WFIFOW(fd,2));
  9811. if(count >= MAX_IGNORE_LIST) //満タンなら最後の1個を消す
  9812. sd->ignore[MAX_IGNORE_LIST - 1].name[0] = 0;
  9813. return;
  9814. }
  9815. /*==========================================
  9816. * スパノビの/doridoriによるSPR2倍
  9817. *------------------------------------------
  9818. */
  9819. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9820. int level;
  9821. sd->doridori_counter = 1;
  9822. if ((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON
  9823. && sd->state.rest && (level = pc_checkskill(sd,TK_SPTIME)))
  9824. status_change_start(&sd->bl,SkillStatusChangeTable[TK_SPTIME],100,level,0,0,0,skill_get_time(TK_SPTIME, level),0);
  9825. return;
  9826. }
  9827. /*==========================================
  9828. * スパノビの爆裂波動
  9829. *------------------------------------------
  9830. */
  9831. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9832. {
  9833. if(sd){
  9834. int nextbaseexp=pc_nextbaseexp(sd);
  9835. if (battle_config.etc_log){
  9836. if(nextbaseexp != 0)
  9837. 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));
  9838. else
  9839. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9840. }
  9841. 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){
  9842. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9843. status_change_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  9844. 5,0,0,0,skill_get_time(MO_EXPLOSIONSPIRITS,5),0));
  9845. }
  9846. }
  9847. return;
  9848. }
  9849. // random notes:
  9850. // 0x214: monster/player info ?
  9851. /*==========================================
  9852. * Friends List
  9853. *------------------------------------------
  9854. */
  9855. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9856. { //Toggles a single friend online/offline [Skotlex]
  9857. int i;
  9858. //Seek friend.
  9859. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9860. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9861. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9862. return; //Not found
  9863. WFIFOHEAD(sd->fd,packet_len_table[0x206]);
  9864. WFIFOW(sd->fd, 0) = 0x206;
  9865. WFIFOL(sd->fd, 2) = sd->status.friends[i].account_id;
  9866. WFIFOL(sd->fd, 6) = sd->status.friends[i].char_id;
  9867. WFIFOB(sd->fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9868. WFIFOSET(sd->fd, packet_len_table[0x206]);
  9869. }
  9870. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9871. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9872. {
  9873. int account_id, char_id, online;
  9874. account_id = va_arg(ap, int);
  9875. char_id = va_arg(ap, int);
  9876. online = va_arg(ap, int);
  9877. clif_friendslist_toggle(sd, account_id, char_id, online);
  9878. return 0;
  9879. }
  9880. //For sending the whole friends list.
  9881. void clif_friendslist_send(struct map_session_data *sd) {
  9882. int i = 0, n;
  9883. // Send friends list
  9884. WFIFOHEAD(sd->fd, MAX_FRIENDS * 32 + 4);
  9885. WFIFOW(sd->fd, 0) = 0x201;
  9886. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9887. {
  9888. WFIFOL(sd->fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9889. WFIFOL(sd->fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9890. memcpy(WFIFOP(sd->fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9891. }
  9892. WFIFOW(sd->fd,2) = 4 + 32 * i;
  9893. WFIFOSET(sd->fd, WFIFOW(sd->fd,2));
  9894. for (n = 0; n < i; n++)
  9895. { //Sending the online players
  9896. if (map_charid2sd(sd->status.friends[n].char_id))
  9897. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9898. }
  9899. }
  9900. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9901. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9902. {
  9903. int fd;
  9904. nullpo_retv(sd);
  9905. fd = sd->fd;
  9906. WFIFOHEAD(fd,packet_len_table[0x209]);
  9907. WFIFOW(fd,0) = 0x209;
  9908. WFIFOW(fd,2) = type;
  9909. if (f_sd)
  9910. {
  9911. WFIFOW(fd,4) = f_sd->status.account_id;
  9912. WFIFOW(fd,8) = f_sd->status.char_id;
  9913. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9914. }
  9915. WFIFOSET(fd, packet_len_table[0x209]);
  9916. }
  9917. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9918. struct map_session_data *f_sd;
  9919. int i, f_fd;
  9920. RFIFOHEAD(fd);
  9921. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9922. // Friend doesn't exist (no player with this name)
  9923. if (f_sd == NULL) {
  9924. clif_displaymessage(fd, msg_txt(3));
  9925. return;
  9926. }
  9927. // Friend already exists
  9928. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9929. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9930. clif_displaymessage(fd, "Friend already exists.");
  9931. return;
  9932. }
  9933. }
  9934. if (i == MAX_FRIENDS) {
  9935. //No space, list full.
  9936. clif_friendslist_reqack(sd, f_sd, 2);
  9937. return;
  9938. }
  9939. f_fd = f_sd->fd;
  9940. WFIFOHEAD(fd,packet_len_table[0x207]);
  9941. WFIFOW(f_fd,0) = 0x207;
  9942. WFIFOL(f_fd,2) = sd->status.account_id;
  9943. WFIFOL(f_fd,6) = sd->status.char_id;
  9944. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9945. WFIFOSET(f_fd, packet_len_table[0x207]);
  9946. return;
  9947. }
  9948. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9949. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9950. struct map_session_data *f_sd;
  9951. int char_id, account_id;
  9952. char reply;
  9953. RFIFOHEAD(fd);
  9954. account_id = RFIFOL(fd,2);
  9955. char_id = RFIFOL(fd,6);
  9956. reply = RFIFOB(fd,10);
  9957. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9958. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9959. if (f_sd == NULL)
  9960. return;
  9961. if (reply == 0)
  9962. clif_friendslist_reqack(f_sd, sd, 1);
  9963. else {
  9964. int i;
  9965. // Find an empty slot
  9966. for (i = 0; i < MAX_FRIENDS; i++)
  9967. if (f_sd->status.friends[i].char_id == 0)
  9968. break;
  9969. if (i == MAX_FRIENDS) {
  9970. clif_friendslist_reqack(f_sd, sd, 2);
  9971. return;
  9972. }
  9973. f_sd->status.friends[i].account_id = sd->status.account_id;
  9974. f_sd->status.friends[i].char_id = sd->status.char_id;
  9975. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9976. clif_friendslist_reqack(f_sd, sd, 0);
  9977. // clif_friendslist_send(sd); //This is not needed anymore.
  9978. }
  9979. return;
  9980. }
  9981. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9982. // 0x203 </o> <ID to be removed W 4B>
  9983. int account_id, char_id;
  9984. int i, j;
  9985. RFIFOHEAD(fd);
  9986. account_id = RFIFOL(fd,2);
  9987. char_id = RFIFOL(fd,6);
  9988. // Search friend
  9989. for (i = 0; i < MAX_FRIENDS &&
  9990. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9991. if (i == MAX_FRIENDS) {
  9992. clif_displaymessage(fd, "Name not found in list.");
  9993. return;
  9994. }
  9995. // move all chars down
  9996. for(j = i + 1; j < MAX_FRIENDS; j++)
  9997. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9998. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9999. clif_displaymessage(fd, "Friend removed");
  10000. WFIFOHEAD(fd,packet_len_table[0x20a]);
  10001. WFIFOW(fd,0) = 0x20a;
  10002. WFIFOL(fd,2) = account_id;
  10003. WFIFOL(fd,6) = char_id;
  10004. WFIFOSET(fd, packet_len_table[0x20a]);
  10005. // clif_friendslist_send(sd); //This is not needed anymore.
  10006. return;
  10007. }
  10008. /*==========================================
  10009. * /killall
  10010. *------------------------------------------
  10011. */
  10012. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  10013. {
  10014. char message[50];
  10015. strncpy(message,sd->status.name, NAME_LENGTH);
  10016. is_atcommand(fd, sd, strcat(message," : @kickall"),0);
  10017. return;
  10018. }
  10019. /*==========================================
  10020. * /pvpinfo
  10021. *------------------------------------------
  10022. */
  10023. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10024. {
  10025. WFIFOHEAD(fd,packet_len_table[0x210]);
  10026. WFIFOW(fd,0) = 0x210;
  10027. //WFIFOL(fd,2) = 0; // not sure what for yet
  10028. //WFIFOL(fd,6) = 0;
  10029. WFIFOL(fd,10) = sd->pvp_won; // times won
  10030. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10031. WFIFOL(fd,18) = sd->pvp_point;
  10032. WFIFOSET(fd, packet_len_table[0x210]);
  10033. return;
  10034. }
  10035. /*==========================================
  10036. * /blacksmith
  10037. *------------------------------------------
  10038. */
  10039. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10040. {
  10041. int i;
  10042. char *name;
  10043. WFIFOHEAD(fd,packet_len_table[0x219]);
  10044. WFIFOW(fd,0) = 0x219;
  10045. for (i = 0; i < 10; i++) {
  10046. if (smith_fame_list[i].id > 0) {
  10047. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10048. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10049. {
  10050. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10051. } else
  10052. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10053. } else
  10054. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10055. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10056. }
  10057. WFIFOSET(fd, packet_len_table[0x219]);
  10058. }
  10059. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  10060. {
  10061. int fd = sd->fd;
  10062. WFIFOHEAD(fd,packet_len_table[0x21b]);
  10063. WFIFOW(fd,0) = 0x21b;
  10064. WFIFOL(fd,2) = points;
  10065. WFIFOL(fd,6) = sd->status.fame;
  10066. WFIFOSET(fd, packet_len_table[0x21b]);
  10067. return 0;
  10068. }
  10069. /*==========================================
  10070. * /alchemist
  10071. *------------------------------------------
  10072. */
  10073. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10074. {
  10075. int i;
  10076. char *name;
  10077. WFIFOHEAD(fd,packet_len_table[0x21a]);
  10078. WFIFOW(fd,0) = 0x21a;
  10079. for (i = 0; i < 10; i++) {
  10080. if (chemist_fame_list[i].id > 0) {
  10081. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10082. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10083. {
  10084. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10085. } else
  10086. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10087. } else
  10088. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10089. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10090. }
  10091. WFIFOSET(fd, packet_len_table[0x21a]);
  10092. }
  10093. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10094. {
  10095. int fd = sd->fd;
  10096. WFIFOHEAD(fd,packet_len_table[0x21c]);
  10097. WFIFOW(fd,0) = 0x21c;
  10098. WFIFOL(fd,2) = points;
  10099. WFIFOL(fd,6) = sd->status.fame;
  10100. WFIFOSET(fd, packet_len_table[0x21c]);
  10101. return 0;
  10102. }
  10103. /*==========================================
  10104. * /taekwon
  10105. *------------------------------------------
  10106. */
  10107. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10108. {
  10109. int i;
  10110. char *name;
  10111. WFIFOHEAD(fd,packet_len_table[0x226]);
  10112. WFIFOW(fd,0) = 0x226;
  10113. for (i = 0; i < 10; i++) {
  10114. if (taekwon_fame_list[i].id > 0) {
  10115. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10116. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10117. {
  10118. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10119. } else
  10120. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10121. } else
  10122. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10123. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10124. }
  10125. WFIFOSET(fd, packet_len_table[0x226]);
  10126. }
  10127. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10128. {
  10129. int fd = sd->fd;
  10130. WFIFOHEAD(fd,packet_len_table[0x224]);
  10131. WFIFOW(fd,0) = 0x224;
  10132. WFIFOL(fd,2) = points;
  10133. WFIFOL(fd,6) = sd->status.fame;
  10134. WFIFOSET(fd, packet_len_table[0x224]);
  10135. return 0;
  10136. }
  10137. /*==========================================
  10138. * PK Ranking table?
  10139. *------------------------------------------
  10140. */
  10141. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10142. {
  10143. int i;
  10144. WFIFOHEAD(fd,packet_len_table[0x238]);
  10145. WFIFOW(fd,0) = 0x238;
  10146. for(i=0;i<10;i++){
  10147. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10148. WFIFOL(fd,i*4+242) = 0;
  10149. }
  10150. WFIFOSET(fd, packet_len_table[0x238]);
  10151. return;
  10152. }
  10153. /*==========================================
  10154. * SG Feel save OK [Komurka]
  10155. *------------------------------------------
  10156. */
  10157. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10158. {
  10159. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  10160. int i;
  10161. if (sd->menuskill_id != SG_FEEL)
  10162. return;
  10163. i = sd->menuskill_lv-1;
  10164. if (i<0 || i > 2) return; //Bug?
  10165. sd->feel_map[i].index = map[sd->bl.m].index;
  10166. sd->feel_map[i].m = sd->bl.m;
  10167. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  10168. WFIFOHEAD(fd,packet_len_table[0x20e]);
  10169. WFIFOW(fd,0)=0x20e;
  10170. memcpy(WFIFOP(fd,2),map[sd->bl.m].name, MAP_NAME_LENGTH);
  10171. WFIFOL(fd,26)=sd->bl.id;
  10172. WFIFOW(fd,30)=i;
  10173. WFIFOSET(fd, packet_len_table[0x20e]);
  10174. if (pc_checkskill(sd,SG_KNOWLEDGE)) status_calc_pc(sd,0);
  10175. sd->menuskill_lv = sd->menuskill_id = 0;
  10176. }
  10177. /*==========================================
  10178. * Question about Star Glaldiator save map [Komurka]
  10179. *------------------------------------------
  10180. */
  10181. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  10182. WFIFOHEAD(fd,packet_len_table[0x253]);
  10183. WFIFOW(fd,0)=0x253;
  10184. WFIFOSET(fd, packet_len_table[0x253]);
  10185. sd->menuskill_id=SG_FEEL;
  10186. sd->menuskill_lv=skilllv;
  10187. }
  10188. /*==========================================
  10189. * パケットデバッグ
  10190. *------------------------------------------
  10191. */
  10192. void clif_parse_debug(int fd,struct map_session_data *sd)
  10193. {
  10194. int i, cmd, len;
  10195. RFIFOHEAD(fd);
  10196. cmd = RFIFOW(fd,0);
  10197. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10198. ShowDebug("packet debug 0x%4X\n",cmd);
  10199. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10200. for(i=0;i<len;i++){
  10201. if((i&15)==0)
  10202. printf("\n%04X ",i);
  10203. printf("%02X ",RFIFOB(fd,i));
  10204. }
  10205. printf("\n");
  10206. }
  10207. /*==========================================
  10208. * クライアントからのパケット解析
  10209. * socket.cのdo_parsepacketから呼び出される
  10210. *------------------------------------------
  10211. */
  10212. int clif_parse(int fd) {
  10213. int packet_len = 0, cmd, packet_ver, dump = 0;
  10214. struct map_session_data *sd;
  10215. RFIFOHEAD(fd);
  10216. if (fd <= 0)
  10217. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  10218. ShowError("clif_parse: Received invalid session %d\n", fd);
  10219. return 0;
  10220. }
  10221. sd = (struct map_session_data*)session[fd]->session_data;
  10222. // 接続が切れてるので後始末
  10223. if (!chrif_isconnect() && kick_on_disconnect)
  10224. {
  10225. ShowInfo("Closing session #%d (Not connected to Char server)\n", fd);
  10226. if (sd && sd->state.auth)
  10227. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  10228. do_close(fd);
  10229. return 0;
  10230. } else
  10231. if (session[fd]->eof) {
  10232. if (sd && sd->state.autotrade) {
  10233. //Disassociate character from the socket connection.
  10234. session[fd]->session_data = NULL;
  10235. sd->fd = 0;
  10236. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  10237. } else if (sd && sd->state.auth) {
  10238. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  10239. if (sd->status.name != NULL)
  10240. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  10241. else
  10242. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id); // Player logout display [Yor]
  10243. } else {
  10244. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  10245. 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]);
  10246. }
  10247. do_close(fd);
  10248. return 0;
  10249. }
  10250. if (RFIFOREST(fd) < 2)
  10251. return 0;
  10252. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  10253. cmd = RFIFOW(fd,0);
  10254. // 管理用パケット処理
  10255. if (cmd >= 30000) {
  10256. switch(cmd) {
  10257. case 0x7530: { // Athena情報所得
  10258. WFIFOHEAD(fd, 10);
  10259. WFIFOW(fd,0) = 0x7531;
  10260. WFIFOB(fd,2) = ATHENA_MAJOR_VERSION;
  10261. WFIFOB(fd,3) = ATHENA_MINOR_VERSION;
  10262. WFIFOB(fd,4) = ATHENA_REVISION;
  10263. WFIFOB(fd,5) = ATHENA_RELEASE_FLAG;
  10264. WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG;
  10265. WFIFOB(fd,7) = ATHENA_SERVER_MAP;
  10266. WFIFOW(fd,8) = ATHENA_MOD_VERSION;
  10267. WFIFOSET(fd,10);
  10268. RFIFOSKIP(fd,2);
  10269. break;
  10270. }
  10271. case 0x7532: // 接続の切断
  10272. ShowWarning("clif_parse: session #%d disconnected for sending packet 0x04%x\n", fd, cmd);
  10273. session[fd]->eof=1;
  10274. break;
  10275. }
  10276. ShowWarning("Ignoring incoming packet (command: 0x%04x, session: %d)\n", cmd, fd);
  10277. return 0;
  10278. }
  10279. // get packet version before to parse
  10280. packet_ver = 0;
  10281. if (sd) {
  10282. packet_ver = sd->packet_ver;
  10283. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  10284. session[fd]->eof = 1;
  10285. return 0;
  10286. }
  10287. } else {
  10288. // check authentification packet to know packet version
  10289. packet_ver = clif_guess_PacketVer(fd, 0);
  10290. // check if version is accepted
  10291. if (packet_ver < 5 || // reject really old client versions
  10292. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  10293. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
  10294. packet_ver > MAX_PACKET_VER) // no packet version support yet
  10295. {
  10296. ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
  10297. WFIFOHEAD(fd, 23);
  10298. WFIFOW(fd,0) = 0x6a;
  10299. WFIFOB(fd,2) = 5; // 05 = Game's EXE is not the latest version
  10300. WFIFOSET(fd,23);
  10301. packet_len = RFIFOREST(fd);
  10302. RFIFOSKIP(fd, packet_len);
  10303. clif_setwaitclose(fd);
  10304. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  10305. session[fd]->func_send(fd);
  10306. return 0;
  10307. }
  10308. }
  10309. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  10310. 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
  10311. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10312. session[fd]->eof = 1;
  10313. return 0;
  10314. }
  10315. // パケット長を計算
  10316. packet_len = packet_db[packet_ver][cmd].len;
  10317. if (packet_len == -1) {
  10318. if (RFIFOREST(fd) < 4)
  10319. return 0; // 可変長パケットで長さの所までデータが来てない
  10320. packet_len = RFIFOW(fd,2);
  10321. if (packet_len < 4 || packet_len > 32768) {
  10322. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10323. session[fd]->eof =1;
  10324. return 0;
  10325. }
  10326. }
  10327. if ((int)RFIFOREST(fd) < packet_len)
  10328. return 0; // まだ1パケット分データが揃ってない
  10329. #if DUMP_ALL_PACKETS
  10330. dump = 1;
  10331. #endif
  10332. if (sd && sd->state.auth == 1 && sd->state.waitingdisconnect == 1) { // 切断待ちの場合パケットを処理しない
  10333. } else if (packet_db[packet_ver][cmd].func) {
  10334. if (sd
  10335. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10336. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10337. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10338. packet_db[packet_ver][cmd].func(fd, sd);
  10339. } else {
  10340. // 不明なパケット
  10341. if (battle_config.error_log) {
  10342. #if DUMP_UNKNOWN_PACKET
  10343. {
  10344. int i;
  10345. FILE *fp;
  10346. char packet_txt[256] = "save/packet.txt";
  10347. time_t now;
  10348. dump = 1;
  10349. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10350. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10351. return 1;
  10352. } else {
  10353. time(&now);
  10354. if (sd && sd->state.auth) {
  10355. if (sd->status.name != NULL)
  10356. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10357. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10358. else
  10359. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10360. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10361. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10362. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10363. for(i = 0; i < packet_len; i++) {
  10364. if ((i & 15) == 0)
  10365. fprintf(fp, "\n\t%04X ", i);
  10366. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10367. }
  10368. fprintf(fp, "\n\n");
  10369. fclose(fp);
  10370. }
  10371. }
  10372. #endif
  10373. }
  10374. }
  10375. if (dump) {
  10376. int i;
  10377. if (fd)
  10378. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10379. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10380. for(i = 0; i < packet_len; i++) {
  10381. if ((i & 15) == 0)
  10382. printf("\n%04X ",i);
  10383. printf("%02X ", RFIFOB(fd,i));
  10384. }
  10385. printf("\n");
  10386. if (sd && sd->state.auth) {
  10387. if (sd->status.name != NULL)
  10388. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10389. sd->status.account_id, sd->status.char_id, sd->status.name);
  10390. else
  10391. printf("\nAccount ID %d.\n", sd->bl.id);
  10392. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10393. printf("\nAccount ID %d.\n", sd->bl.id);
  10394. }
  10395. RFIFOSKIP(fd, packet_len);
  10396. return 0;
  10397. }
  10398. /*==========================================
  10399. * パケットデータベース読み込み
  10400. *------------------------------------------
  10401. */
  10402. static int packetdb_readdb(void)
  10403. {
  10404. FILE *fp;
  10405. char line[1024];
  10406. int ln=0;
  10407. int cmd,i,j,k,packet_ver;
  10408. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10409. struct {
  10410. void (*func)(int, struct map_session_data *);
  10411. char *name;
  10412. } clif_parse_func[]={
  10413. {clif_parse_WantToConnection,"wanttoconnection"},
  10414. {clif_parse_LoadEndAck,"loadendack"},
  10415. {clif_parse_TickSend,"ticksend"},
  10416. {clif_parse_WalkToXY,"walktoxy"},
  10417. {clif_parse_QuitGame,"quitgame"},
  10418. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10419. {clif_parse_GlobalMessage,"globalmessage"},
  10420. {clif_parse_MapMove,"mapmove"},
  10421. {clif_parse_ChangeDir,"changedir"},
  10422. {clif_parse_Emotion,"emotion"},
  10423. {clif_parse_HowManyConnections,"howmanyconnections"},
  10424. {clif_parse_ActionRequest,"actionrequest"},
  10425. {clif_parse_Restart,"restart"},
  10426. {clif_parse_Wis,"wis"},
  10427. {clif_parse_GMmessage,"gmmessage"},
  10428. {clif_parse_TakeItem,"takeitem"},
  10429. {clif_parse_DropItem,"dropitem"},
  10430. {clif_parse_UseItem,"useitem"},
  10431. {clif_parse_EquipItem,"equipitem"},
  10432. {clif_parse_UnequipItem,"unequipitem"},
  10433. {clif_parse_NpcClicked,"npcclicked"},
  10434. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10435. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10436. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10437. {clif_parse_CreateChatRoom,"createchatroom"},
  10438. {clif_parse_ChatAddMember,"chataddmember"},
  10439. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10440. {clif_parse_ChangeChatOwner,"changechatowner"},
  10441. {clif_parse_KickFromChat,"kickfromchat"},
  10442. {clif_parse_ChatLeave,"chatleave"},
  10443. {clif_parse_TradeRequest,"traderequest"},
  10444. {clif_parse_TradeAck,"tradeack"},
  10445. {clif_parse_TradeAddItem,"tradeadditem"},
  10446. {clif_parse_TradeOk,"tradeok"},
  10447. {clif_parse_TradeCancel,"tradecancel"},
  10448. {clif_parse_TradeCommit,"tradecommit"},
  10449. {clif_parse_StopAttack,"stopattack"},
  10450. {clif_parse_PutItemToCart,"putitemtocart"},
  10451. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10452. {clif_parse_RemoveOption,"removeoption"},
  10453. {clif_parse_ChangeCart,"changecart"},
  10454. {clif_parse_StatusUp,"statusup"},
  10455. {clif_parse_SkillUp,"skillup"},
  10456. {clif_parse_UseSkillToId,"useskilltoid"},
  10457. {clif_parse_UseSkillToPos,"useskilltopos"},
  10458. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10459. {clif_parse_UseSkillMap,"useskillmap"},
  10460. {clif_parse_RequestMemo,"requestmemo"},
  10461. {clif_parse_ProduceMix,"producemix"},
  10462. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10463. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10464. {clif_parse_NpcAmountInput,"npcamountinput"},
  10465. {clif_parse_NpcStringInput,"npcstringinput"},
  10466. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10467. {clif_parse_ItemIdentify,"itemidentify"},
  10468. {clif_parse_SelectArrow,"selectarrow"},
  10469. {clif_parse_AutoSpell,"autospell"},
  10470. {clif_parse_UseCard,"usecard"},
  10471. {clif_parse_InsertCard,"insertcard"},
  10472. {clif_parse_RepairItem,"repairitem"},
  10473. {clif_parse_WeaponRefine,"weaponrefine"},
  10474. {clif_parse_SolveCharName,"solvecharname"},
  10475. {clif_parse_ResetChar,"resetchar"},
  10476. {clif_parse_LGMmessage,"lgmmessage"},
  10477. {clif_parse_MoveToKafra,"movetokafra"},
  10478. {clif_parse_MoveFromKafra,"movefromkafra"},
  10479. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10480. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10481. {clif_parse_CloseKafra,"closekafra"},
  10482. {clif_parse_CreateParty,"createparty"},
  10483. {clif_parse_CreateParty2,"createparty2"},
  10484. {clif_parse_PartyInvite,"partyinvite"},
  10485. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10486. {clif_parse_LeaveParty,"leaveparty"},
  10487. {clif_parse_RemovePartyMember,"removepartymember"},
  10488. {clif_parse_PartyChangeOption,"partychangeoption"},
  10489. {clif_parse_PartyMessage,"partymessage"},
  10490. {clif_parse_CloseVending,"closevending"},
  10491. {clif_parse_VendingListReq,"vendinglistreq"},
  10492. {clif_parse_PurchaseReq,"purchasereq"},
  10493. {clif_parse_OpenVending,"openvending"},
  10494. {clif_parse_CreateGuild,"createguild"},
  10495. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10496. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10497. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10498. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10499. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10500. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10501. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10502. {clif_parse_GuildInvite,"guildinvite"},
  10503. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10504. {clif_parse_GuildLeave,"guildleave"},
  10505. {clif_parse_GuildExplusion,"guildexplusion"},
  10506. {clif_parse_GuildMessage,"guildmessage"},
  10507. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10508. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10509. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10510. {clif_parse_GuildOpposition,"guildopposition"},
  10511. {clif_parse_GuildBreak,"guildbreak"},
  10512. {clif_parse_PetMenu,"petmenu"},
  10513. {clif_parse_CatchPet,"catchpet"},
  10514. {clif_parse_SelectEgg,"selectegg"},
  10515. {clif_parse_SendEmotion,"sendemotion"},
  10516. {clif_parse_ChangePetName,"changepetname"},
  10517. {clif_parse_GMKick,"gmkick"},
  10518. {clif_parse_GMHide,"gmhide"},
  10519. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10520. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10521. {clif_parse_NoviceDoriDori,"sndoridori"},
  10522. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10523. {clif_parse_PMIgnore,"wisexin"},
  10524. {clif_parse_PMIgnoreList,"wisexlist"},
  10525. {clif_parse_PMIgnoreAll,"wisall"},
  10526. {clif_parse_FriendsListAdd,"friendslistadd"},
  10527. {clif_parse_FriendsListRemove,"friendslistremove"},
  10528. {clif_parse_FriendsListReply,"friendslistreply"},
  10529. {clif_parse_GMKillAll,"killall"},
  10530. {clif_parse_Recall,"summon"},
  10531. {clif_parse_GM_Monster_Item,"itemmonster"},
  10532. {clif_parse_Shift,"shift"},
  10533. {clif_parse_Blacksmith,"blacksmith"},
  10534. {clif_parse_Alchemist,"alchemist"},
  10535. {clif_parse_Taekwon,"taekwon"},
  10536. {clif_parse_RankingPk,"rankingpk"},
  10537. {clif_parse_FeelSaveOk,"feelsaveok"},
  10538. {clif_parse_debug,"debug"},
  10539. {NULL,NULL}
  10540. };
  10541. sprintf(line, "%s/packet_db.txt", db_path);
  10542. if( (fp=fopen(line,"r"))==NULL ){
  10543. ShowFatalError("can't read %s\n", line);
  10544. exit(1);
  10545. }
  10546. clif_config.packet_db_ver = MAX_PACKET_VER;
  10547. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10548. while(fgets(line,1020,fp)){
  10549. if(line[0]=='/' && line[1]=='/')
  10550. continue;
  10551. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10552. if(strcmpi(w1,"packet_ver")==0) {
  10553. int prev_ver = packet_ver;
  10554. packet_ver = atoi(w2);
  10555. if (packet_ver > MAX_PACKET_VER)
  10556. { //Check to avoid overflowing. [Skotlex]
  10557. ShowWarning("The packet_db table only has support up to version %d\n", MAX_PACKET_VER);
  10558. break;
  10559. }
  10560. // copy from previous version into new version and continue
  10561. // - indicating all following packets should be read into the newer version
  10562. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10563. continue;
  10564. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10565. //This is the preferred version.
  10566. if(strcmpi(w2,"default")==0)
  10567. clif_config.packet_db_ver = MAX_PACKET_VER;
  10568. else {
  10569. // to manually set the packet DB version
  10570. clif_config.packet_db_ver = atoi(w2);
  10571. // check for invalid version
  10572. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10573. clif_config.packet_db_ver < 0)
  10574. clif_config.packet_db_ver = MAX_PACKET_VER;
  10575. }
  10576. continue;
  10577. }
  10578. }
  10579. memset(str,0,sizeof(str));
  10580. for(j=0,p=line;j<4 && p;j++){
  10581. str[j]=p;
  10582. p=strchr(p,',');
  10583. if(p) *p++=0;
  10584. }
  10585. if(str[0]==NULL)
  10586. continue;
  10587. cmd=strtol(str[0],(char **)NULL,0);
  10588. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10589. continue;
  10590. if(str[1]==NULL){
  10591. ShowError("packet_db: packet len error\n");
  10592. continue;
  10593. }
  10594. k = atoi(str[1]);
  10595. packet_db[packet_ver][cmd].len = k;
  10596. if(str[2]==NULL){
  10597. packet_db[packet_ver][cmd].func = NULL;
  10598. ln++;
  10599. continue;
  10600. }
  10601. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10602. if(clif_parse_func[j].name != NULL &&
  10603. strcmp(str[2],clif_parse_func[j].name)==0)
  10604. {
  10605. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10606. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10607. for(i=0;i<MAX_PACKET_DB;i++){
  10608. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10609. {
  10610. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10611. break;
  10612. }
  10613. }
  10614. }
  10615. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10616. break;
  10617. }
  10618. }
  10619. // set the identifying cmd for the packet_db version
  10620. if (strcmp(str[2],"wanttoconnection")==0)
  10621. clif_config.connect_cmd[packet_ver] = cmd;
  10622. if(str[3]==NULL){
  10623. ShowError("packet_db: packet error\n");
  10624. exit(1);
  10625. }
  10626. for(j=0,p2=str[3];p2;j++){
  10627. str2[j]=p2;
  10628. p2=strchr(p2,':');
  10629. if(p2) *p2++=0;
  10630. k = atoi(str2[j]);
  10631. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10632. packet_db[packet_ver][cmd].pos[j] = k;
  10633. }
  10634. ln++;
  10635. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10636. // 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);
  10637. }
  10638. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10639. { //Locate the nearest version that we still support. [Skotlex]
  10640. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10641. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10642. }
  10643. 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);
  10644. return 0;
  10645. }
  10646. /*==========================================
  10647. *
  10648. *------------------------------------------
  10649. */
  10650. int do_init_clif(void) {
  10651. #ifndef __WIN32
  10652. int i;
  10653. #endif
  10654. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10655. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10656. memset(packet_db,0,sizeof(packet_db));
  10657. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10658. packetdb_readdb();
  10659. set_defaultparse(clif_parse);
  10660. #ifdef __WIN32
  10661. //if (!make_listen_port(map_port)) {
  10662. if (!make_listen_bind(bind_ip,map_port)) {
  10663. ShowFatalError("cant bind game port\n");
  10664. exit(1);
  10665. }
  10666. #else
  10667. for(i = 0; i < 10; i++) {
  10668. //if (make_listen_port(map_port))
  10669. if (make_listen_bind(bind_ip,map_port))
  10670. break;
  10671. sleep(20);
  10672. }
  10673. if (i == 10) {
  10674. ShowFatalError("cant bind game port\n");
  10675. exit(1);
  10676. }
  10677. #endif
  10678. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10679. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10680. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10681. return 0;
  10682. }